CPP class changes
This commit is contained in:
Binary file not shown.
@@ -10,7 +10,8 @@
|
|||||||
"LoadingPhase": "Default",
|
"LoadingPhase": "Default",
|
||||||
"AdditionalDependencies": [
|
"AdditionalDependencies": [
|
||||||
"GameplayAbilities",
|
"GameplayAbilities",
|
||||||
"Engine"
|
"Engine",
|
||||||
|
"EnhancedInput"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class Elistria_Calling : ModuleRules
|
|||||||
{
|
{
|
||||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||||
|
|
||||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore","GameplayAbilities", "GameplayTags", "GameplayTasks" });
|
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore","GameplayAbilities", "GameplayTags", "GameplayTasks", "EnhancedInput","TargetingSystem" });
|
||||||
|
|
||||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||||
|
|
||||||
|
|||||||
@@ -3,3 +3,59 @@
|
|||||||
|
|
||||||
#include "ElistriaAbilitySystemComponent.h"
|
#include "ElistriaAbilitySystemComponent.h"
|
||||||
|
|
||||||
|
#include "PlayerGameplayAbilitiesDataAsset.h"
|
||||||
|
|
||||||
|
void UElistriaAbilitySystemComponent::ServerActivateAbilityByInputID_Implementation(FGameplayAbilitySpecHandle Handle,int32 InputID)
|
||||||
|
{
|
||||||
|
TryActivateAbility(Handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UElistriaAbilitySystemComponent::GrantAbilitiesFromDataAsset(const UPlayerGameplayAbilitiesDataAsset* AbilitiesDataAsset)
|
||||||
|
{
|
||||||
|
if (!AbilitiesDataAsset) return;
|
||||||
|
|
||||||
|
for (const FGameplayInputAbilityInfo& AbilityInfo : AbilitiesDataAsset->GetInputAbilities())
|
||||||
|
{
|
||||||
|
if (AbilityInfo.IsValid())
|
||||||
|
{
|
||||||
|
FGameplayAbilitySpec AbilitySpec(AbilityInfo.AbilityClass, 1, AbilityInfo.InputID);
|
||||||
|
FGameplayAbilitySpecHandle SpecHandle = GiveAbility(AbilitySpec);
|
||||||
|
InputIDToAbilitySpecHandleMap.Add(AbilityInfo.InputID, SpecHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UElistriaAbilitySystemComponent::AbilityLocalInputPressed(int32 InputID)
|
||||||
|
{
|
||||||
|
if (FGameplayAbilitySpecHandle* HandlePtr = SlotToAbilityHandleMap.Find(InputID))
|
||||||
|
{
|
||||||
|
if (GetOwnerRole() < ROLE_Authority)
|
||||||
|
{
|
||||||
|
ServerActivateAbilityByInputID(*HandlePtr, InputID);
|
||||||
|
}
|
||||||
|
TryActivateAbility(*HandlePtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UElistriaAbilitySystemComponent::EquipAbility(TSubclassOf<UGameplayAbility> NewAbility, int32 SlotIndex)
|
||||||
|
{
|
||||||
|
if (!NewAbility) return;
|
||||||
|
UnequipAbility(SlotIndex);
|
||||||
|
|
||||||
|
FGameplayAbilitySpec Spec(NewAbility,1,SlotIndex);
|
||||||
|
FGameplayAbilitySpecHandle SpecHandle = GiveAbility(Spec);
|
||||||
|
SlotToAbilityHandleMap.Add(SlotIndex, SpecHandle);
|
||||||
|
|
||||||
|
OnAbilitiesChanged.Broadcast(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UElistriaAbilitySystemComponent::UnequipAbility(int32 SlotIndex)
|
||||||
|
{
|
||||||
|
if (FGameplayAbilitySpecHandle* HandlePtr = SlotToAbilityHandleMap.Find(SlotIndex))
|
||||||
|
{
|
||||||
|
ClearAbility(*HandlePtr);
|
||||||
|
SlotToAbilityHandleMap.Remove(SlotIndex);
|
||||||
|
|
||||||
|
OnAbilitiesChanged.Broadcast(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "ElistriaEnhancedInputComponent.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void UElistriaEnhancedInputComponent::ClearAbilityBindings()
|
||||||
|
{
|
||||||
|
for (uint32 Handle : AbilityActionBindings)
|
||||||
|
{
|
||||||
|
RemoveBindingByHandle(Handle);
|
||||||
|
}
|
||||||
|
AbilityActionBindings.Empty();
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "MagickPlayerController.h"
|
#include "MagickPlayerController.h"
|
||||||
|
|
||||||
|
#include "ElistriaEnhancedInputComponent.h"
|
||||||
#include "MagickPlayerState.h"
|
#include "MagickPlayerState.h"
|
||||||
|
|
||||||
void AMagickPlayerController::OnPossess(APawn *InPawn)
|
void AMagickPlayerController::OnPossess(APawn *InPawn)
|
||||||
@@ -10,8 +11,65 @@ void AMagickPlayerController::OnPossess(APawn *InPawn)
|
|||||||
Super::OnPossess(InPawn);
|
Super::OnPossess(InPawn);
|
||||||
UE_LOG(LogTemp, Display, TEXT("OnPossess"));
|
UE_LOG(LogTemp, Display, TEXT("OnPossess"));
|
||||||
AMagickPlayerState* PS = GetPlayerState<AMagickPlayerState>();
|
AMagickPlayerState* PS = GetPlayerState<AMagickPlayerState>();
|
||||||
|
UElistriaAbilitySystemComponent* ASC = PS ? PS->GetAbilitySystemComponent() : nullptr;
|
||||||
if (PS)
|
if (PS)
|
||||||
{
|
{
|
||||||
PS->SetupAbilityActorInfo();
|
PS->SetupAbilityActorInfo();
|
||||||
|
if (ASC)
|
||||||
|
{
|
||||||
|
ASC->OnAbilitiesChanged.AddDynamic(this,&AMagickPlayerController::OnAbilitiesChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AMagickPlayerController::OnAbilitiesChanged(UElistriaAbilitySystemComponent* ASC)
|
||||||
|
{
|
||||||
|
RebindAbilityInputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AMagickPlayerController::SetupInputComponent()
|
||||||
|
{
|
||||||
|
Super::SetupInputComponent();
|
||||||
|
if (UElistriaEnhancedInputComponent* EIC = Cast<UElistriaEnhancedInputComponent>(InputComponent))
|
||||||
|
{
|
||||||
|
if (InputAbilitiesDataAsset)
|
||||||
|
{
|
||||||
|
EIC->BindAbilityActions(InputAbilitiesDataAsset, this, &AMagickPlayerController::AbilityInputPressed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AMagickPlayerController::AbilityInputPressed(int32 InputID)
|
||||||
|
{
|
||||||
|
if (AMagickPlayerState* PS = GetPlayerState<AMagickPlayerState>())
|
||||||
|
{
|
||||||
|
if (UElistriaAbilitySystemComponent* ASC = PS ? PS->GetAbilitySystemComponent() : nullptr)
|
||||||
|
{
|
||||||
|
ASC->AbilityLocalInputPressed(InputID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AMagickPlayerController::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
if (UInputMappingContext* IMC = InputMappingContext)
|
||||||
|
{
|
||||||
|
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
|
||||||
|
{
|
||||||
|
Subsystem->AddMappingContext(IMC, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AMagickPlayerController::RebindAbilityInputs()
|
||||||
|
{
|
||||||
|
if (UElistriaEnhancedInputComponent* EIC = Cast<UElistriaEnhancedInputComponent>(InputComponent))
|
||||||
|
{
|
||||||
|
EIC -> ClearAbilityBindings();
|
||||||
|
if (InputAbilitiesDataAsset)
|
||||||
|
{
|
||||||
|
EIC->BindAbilityActions(InputAbilitiesDataAsset,this,&AMagickPlayerController::AbilityInputPressed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "PlayerGameplayAbilitiesDataAsset.h"
|
||||||
|
|
||||||
|
UPlayerGameplayAbilitiesDataAsset::UPlayerGameplayAbilitiesDataAsset(const FObjectInitializer& ObjectInitializer)
|
||||||
|
: Super(ObjectInitializer)
|
||||||
|
{
|
||||||
|
// Constructor implementation
|
||||||
|
}
|
||||||
|
|
||||||
|
const TSet<FGameplayInputAbilityInfo>& UPlayerGameplayAbilitiesDataAsset::GetInputAbilities() const
|
||||||
|
{
|
||||||
|
return InputAbilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if WITH_EDITOR
|
||||||
|
void UPlayerGameplayAbilitiesDataAsset::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
|
||||||
|
{
|
||||||
|
Super::PostEditChangeProperty(PropertyChangedEvent);
|
||||||
|
|
||||||
|
const FProperty* Property = PropertyChangedEvent.Property;
|
||||||
|
if (Property && Property->GetName()==GET_MEMBER_NAME_CHECKED(UPlayerGameplayAbilitiesDataAsset, InputAbilities)&& !InputAbilities.IsEmpty())
|
||||||
|
{
|
||||||
|
TArray<FGameplayInputAbilityInfo> InputAbilitiesArray = InputAbilities.Array();
|
||||||
|
for (int32 i = InputAbilitiesArray.Num() - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
const int32 PrevIndex = i - 1;
|
||||||
|
if (InputAbilitiesArray[i]==InputAbilitiesArray[PrevIndex])
|
||||||
|
{
|
||||||
|
InputAbilitiesArray.RemoveAtSwap(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
InputAbilities.Reset();
|
||||||
|
|
||||||
|
for (int32 i=0; i<InputAbilitiesArray.Num(); i++)
|
||||||
|
{
|
||||||
|
FGameplayInputAbilityInfo& AbilityInfo = InputAbilitiesArray[i];
|
||||||
|
AbilityInfo.InputID = i;
|
||||||
|
InputAbilities.Add(AbilityInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "AbilitySystemComponent.h"
|
#include "AbilitySystemComponent.h"
|
||||||
|
#include "EnhancedInputComponent.h"
|
||||||
|
#include "PlayerGameplayAbilitiesDataAsset.h"
|
||||||
#include "ElistriaAbilitySystemComponent.generated.h"
|
#include "ElistriaAbilitySystemComponent.generated.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,5 +15,31 @@ UCLASS()
|
|||||||
class ELISTRIA_CALLING_API UElistriaAbilitySystemComponent : public UAbilitySystemComponent
|
class ELISTRIA_CALLING_API UElistriaAbilitySystemComponent : public UAbilitySystemComponent
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UFUNCTION(Server, Reliable)
|
||||||
|
void ServerActivateAbilityByInputID(FGameplayAbilitySpecHandle Handle, int32 InputID);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void EquipAbility(TSubclassOf<UGameplayAbility> NewAbility, int32 SlotIndex);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void UnequipAbility(int32 SlotIndex);
|
||||||
|
|
||||||
|
void RefreshInputBindings();
|
||||||
|
|
||||||
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAbilitiesChanged, UElistriaAbilitySystemComponent*, ASC);
|
||||||
|
UPROPERTY(BlueprintAssignable)
|
||||||
|
FOnAbilitiesChanged OnAbilitiesChanged;
|
||||||
|
|
||||||
|
void GrantAbilitiesFromDataAsset(const UPlayerGameplayAbilitiesDataAsset* AbilitiesDataAsset);
|
||||||
|
virtual void AbilityLocalInputPressed(int32 InputID) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
TMap<int32, FGameplayAbilitySpecHandle> InputIDToAbilitySpecHandleMap;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
TMap<int32, FGameplayAbilitySpecHandle> SlotToAbilityHandleMap;
|
||||||
|
|
||||||
|
void ServerActivateAbilityByInputID_Implementation(FGameplayAbilitySpecHandle Handle, int32 InputID);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "EnhancedInputComponent.h"
|
||||||
|
#include "PlayerGameplayAbilitiesDataAsset.h"
|
||||||
|
#include "ElistriaEnhancedInputComponent.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class ELISTRIA_CALLING_API UElistriaEnhancedInputComponent : public UEnhancedInputComponent
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
public:
|
||||||
|
template<class UserClass, typename FuncType>
|
||||||
|
void BindAbilityActions(const UPlayerGameplayAbilitiesDataAsset* InputConfig, UserClass* Object, FuncType Func);
|
||||||
|
|
||||||
|
void ClearAbilityBindings();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
TArray<uint32> AbilityActionBindings;
|
||||||
|
};
|
||||||
|
template<class UserClass, typename FuncType>
|
||||||
|
void UElistriaEnhancedInputComponent::BindAbilityActions(const UPlayerGameplayAbilitiesDataAsset* InputConfig, UserClass* Object, FuncType Func)
|
||||||
|
{
|
||||||
|
if (!InputConfig) return;
|
||||||
|
|
||||||
|
for (const FGameplayInputAbilityInfo& AbilityInfo : InputConfig->GetInputAbilities())
|
||||||
|
{
|
||||||
|
if (AbilityInfo.IsValid())
|
||||||
|
{
|
||||||
|
BindAction(AbilityInfo.InputAction,ETriggerEvent::Triggered,Object,Func,AbilityInfo.InputID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "PlayerGameplayAbilitiesDataAsset.h"
|
||||||
#include "GameFramework/PlayerController.h"
|
#include "GameFramework/PlayerController.h"
|
||||||
|
#include "InputMappingContext.h"
|
||||||
|
#include "EnhancedInputSubsystems.h"
|
||||||
|
#include "ElistriaEnhancedInputComponent.h"
|
||||||
#include "MagickPlayerController.generated.h"
|
#include "MagickPlayerController.generated.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,7 +17,25 @@ UCLASS()
|
|||||||
class ELISTRIA_CALLING_API AMagickPlayerController : public APlayerController
|
class ELISTRIA_CALLING_API AMagickPlayerController : public APlayerController
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
|
||||||
virtual void OnPossess(APawn* InPawn) override;
|
virtual void OnPossess(APawn* InPawn) override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void OnAbilitiesChanged(UElistriaAbilitySystemComponent* ASC);
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Input")
|
||||||
|
TObjectPtr<UPlayerGameplayAbilitiesDataAsset> InputAbilitiesDataAsset;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Input")
|
||||||
|
TObjectPtr<UInputMappingContext> InputMappingContext;
|
||||||
|
|
||||||
|
virtual void SetupInputComponent() override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void AbilityInputPressed(int32 InputID);
|
||||||
|
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
void RebindAbilityInputs();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,4 +33,7 @@ protected:
|
|||||||
|
|
||||||
UPROPERTY(Replicated)
|
UPROPERTY(Replicated)
|
||||||
TObjectPtr<class UManaAttributeSet> ManaSet;
|
TObjectPtr<class UManaAttributeSet> ManaSet;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Engine/DataAsset.h"
|
||||||
|
#include "Abilities/GameplayAbility.h"
|
||||||
|
#include "PlayerGameplayAbilitiesDataAsset.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class UInputAction;
|
||||||
|
|
||||||
|
USTRUCT()
|
||||||
|
struct FGameplayInputAbilityInfo
|
||||||
|
{
|
||||||
|
GENERATED_USTRUCT_BODY()
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "GameplayInputAbilityInfo")
|
||||||
|
TSubclassOf<UGameplayAbility> AbilityClass;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "GameplayInputAbilityInfo")
|
||||||
|
TObjectPtr<UInputAction> InputAction;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere, Category = "GameplayInputAbilityInfo")
|
||||||
|
int32 InputID;
|
||||||
|
|
||||||
|
bool IsValid() const
|
||||||
|
{
|
||||||
|
return AbilityClass && InputAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const FGameplayInputAbilityInfo& other) const
|
||||||
|
{
|
||||||
|
return AbilityClass == other.AbilityClass && InputID == other.InputID;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const FGameplayInputAbilityInfo& other) const
|
||||||
|
{
|
||||||
|
return !operator==(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend uint32 GetTypeHash(const FGameplayInputAbilityInfo& Item)
|
||||||
|
{
|
||||||
|
return HashCombine(GetTypeHash(Item.AbilityClass), Item.InputID);
|
||||||
|
}
|
||||||
|
|
||||||
|
FGameplayInputAbilityInfo()
|
||||||
|
: InputID(INDEX_NONE)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
UCLASS()
|
||||||
|
class ELISTRIA_CALLING_API UPlayerGameplayAbilitiesDataAsset : public UDataAsset
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UPROPERTY(EditAnywhere, Category = "AbilitySystem")
|
||||||
|
TSet<FGameplayInputAbilityInfo> InputAbilities;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPlayerGameplayAbilitiesDataAsset(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
|
||||||
|
|
||||||
|
const TSet<FGameplayInputAbilityInfo>& GetInputAbilities() const;
|
||||||
|
|
||||||
|
#if WITH_EDITOR
|
||||||
|
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user