CPP class changes
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AbilitySystemComponent.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "PlayerGameplayAbilitiesDataAsset.h"
|
||||
#include "ElistriaAbilitySystemComponent.generated.h"
|
||||
|
||||
/**
|
||||
@@ -13,5 +15,31 @@ UCLASS()
|
||||
class ELISTRIA_CALLING_API UElistriaAbilitySystemComponent : public UAbilitySystemComponent
|
||||
{
|
||||
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
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "PlayerGameplayAbilitiesDataAsset.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "InputMappingContext.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "ElistriaEnhancedInputComponent.h"
|
||||
#include "MagickPlayerController.generated.h"
|
||||
|
||||
/**
|
||||
@@ -13,7 +17,25 @@ UCLASS()
|
||||
class ELISTRIA_CALLING_API AMagickPlayerController : public APlayerController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
|
||||
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)
|
||||
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