Created
February 24, 2020 02:38
-
-
Save RoyAwesome/c04462ba41d241fff1851e1aba3300a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2017-2018 Puny Human Games | |
#include "ArcAbilitySystemComponent.h" | |
#include "GameplayTags.h" | |
#include "Components/InputComponent.h" | |
#include "EngineMinimal.h" | |
#include "ArcCoreGameInstSubsys_Abilities.h" | |
UArcAbilitySystemComponent::UArcAbilitySystemComponent(const FObjectInitializer& ObjectInitializer) | |
: Super(ObjectInitializer) | |
{ | |
OnActiveGameplayEffectAddedDelegateToSelf.AddUObject(this, &UArcAbilitySystemComponent::GameplayEffectAppliedToSelfCallback); | |
//FOnGivenActiveGameplayEffectRemoved& OnAnyGameplayEffectRemovedDelegate(); | |
OnAnyGameplayEffectRemovedDelegate().AddUObject(this, &UArcAbilitySystemComponent::GameplayEffectRemovedFromSelfCallback); | |
} | |
void UArcAbilitySystemComponent::BP_AbilityLocalTagInputPressed(FGameplayTag InputTag) | |
{ | |
AbilityLocalInputPressed(FindTagBinding(InputTag)); | |
} | |
void UArcAbilitySystemComponent::BP_AbilityLocalTagInputReleased(FGameplayTag InputTag) | |
{ | |
AbilityLocalInputReleased(FindTagBinding(InputTag)); | |
} | |
void UArcAbilitySystemComponent::GetActiveGameplayEffectsWithTag(FGameplayTag Tag, TArray<FActiveGameplayEffectHandle>& OutActiveGameplayTags) | |
{ | |
OutActiveGameplayTags.Empty(); | |
OutActiveGameplayTags.Append(GetActiveEffects(FGameplayEffectQuery::MakeQuery_MatchAnyOwningTags(FGameplayTagContainer(Tag)))); | |
} | |
void UArcAbilitySystemComponent::InitAbilityActorInfo(AActor* InOwnerActor, AActor* InAvatarActor) | |
{ | |
Super::InitAbilityActorInfo(InOwnerActor, InAvatarActor); | |
} | |
void UArcAbilitySystemComponent::BindAbilityActivationToInputComponentByTag(UInputComponent* InputComponent, const FArcGameplayAbilityInputTagBinds& TagBindings) | |
{ | |
if (UArcCoreGameInstSubsys_Abilities* GIsSub = GetWorld()->GetGameInstance()->GetSubsystem<UArcCoreGameInstSubsys_Abilities>()) | |
{ | |
BlockedAbilityBindings.SetNumZeroed(GIsSub->TagMap.Num()); | |
for (auto KV : GIsSub->TagMap) | |
{ | |
FGameplayTag Tag = KV.Key; | |
int32 Binding = KV.Value; | |
//Pressed Event | |
{ | |
FInputActionBinding AB(Tag.GetTagName(), IE_Pressed); | |
AB.ActionDelegate.GetDelegateForManualSet().BindUObject(this, &UAbilitySystemComponent::AbilityLocalInputPressed, Binding); | |
InputComponent->AddActionBinding(AB); | |
} | |
//Released Event | |
{ | |
FInputActionBinding AB(Tag.GetTagName(), IE_Released); | |
AB.ActionDelegate.GetDelegateForManualSet().BindUObject(this, &UAbilitySystemComponent::AbilityLocalInputReleased, Binding); | |
InputComponent->AddActionBinding(AB); | |
} | |
} | |
} | |
//Bind Confirm/Cancel | |
if (TagBindings.ConfirmTag.IsValid()) | |
{ | |
FInputActionBinding AB(TagBindings.ConfirmTag.GetTagName(), IE_Pressed); | |
AB.ActionDelegate.GetDelegateForManualSet().BindUObject(this, &UAbilitySystemComponent::LocalInputConfirm); | |
InputComponent->AddActionBinding(AB); | |
} | |
if (TagBindings.CancelTag.IsValid()) | |
{ | |
FInputActionBinding AB(TagBindings.CancelTag.GetTagName(), IE_Pressed); | |
AB.ActionDelegate.GetDelegateForManualSet().BindUObject(this, &UAbilitySystemComponent::LocalInputCancel); | |
InputComponent->AddActionBinding(AB); | |
} | |
if (TagBindings.CancelTargetInputID >= 0) | |
{ | |
GenericCancelInputID = TagBindings.CancelTargetInputID; | |
} | |
if (TagBindings.ConfirmTargetInputID >= 0) | |
{ | |
GenericConfirmInputID = TagBindings.ConfirmTargetInputID; | |
} | |
} | |
int32 UArcAbilitySystemComponent::FindTagBinding(const FGameplayTag& GameplayTag, UInputComponent* InputComponent /* = nullptr */) | |
{ | |
if (UArcCoreGameInstSubsys_Abilities* GIsSub = GetWorld()->GetGameInstance()->GetSubsystem<UArcCoreGameInstSubsys_Abilities>()) | |
{ | |
if (GIsSub->TagMap.Contains(GameplayTag)) | |
{ | |
return GIsSub->TagMap[GameplayTag]; | |
} | |
} | |
ensure(false); | |
return INDEX_NONE; | |
} | |
TArray<FGameplayTag> FArcGameplayAbilityInputTagBinds::GetTagArrayFromParentTag(FGameplayTag ParentTag) | |
{ | |
auto TagContainer = UGameplayTagsManager::Get().RequestGameplayTagChildren(ParentTag); | |
TArray<FGameplayTag> TagArray; | |
TagContainer.GetGameplayTagArray(TagArray); | |
return TagArray; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ARCCORE_API FArcGameplayAbilityInputTagBinds | |
{ | |
public: | |
FArcGameplayAbilityInputTagBinds(FGameplayTag InConfirmTag, FGameplayTag InCancelTag, int32 InConfirmTargetInputId = INDEX_NONE, int32 InCancelTargetInputID = INDEX_NONE) | |
: ConfirmTag(InConfirmTag) | |
, CancelTag(InCancelTag) | |
, ConfirmTargetInputID(InConfirmTargetInputId) | |
, CancelTargetInputID(InCancelTargetInputID) | |
{ | |
} | |
FGameplayTag ConfirmTag; | |
FGameplayTag CancelTag; | |
/** If >=0, Confirm is bound to an entry in the array */ | |
int32 ConfirmTargetInputID; | |
/** If >=0, Cancel is bound to an entry in the array */ | |
int32 CancelTargetInputID; | |
static TArray<FGameplayTag> GetTagArrayFromParentTag(FGameplayTag ParentTag); | |
}; | |
/** | |
* | |
*/ | |
UCLASS() | |
class ARCCORE_API UArcAbilitySystemComponent : public UAbilitySystemComponent | |
{ | |
GENERATED_BODY() | |
public: | |
UArcAbilitySystemComponent(const FObjectInitializer& ObjectInitializer); | |
UFUNCTION(BlueprintCallable, Category = "Input", meta = (DisplayName = "Ability Local Input Pressed")) | |
void BP_AbilityLocalInputPressed(int32 InputID); | |
UFUNCTION(BlueprintCallable, Category = "Input", meta = (DisplayName = "Ability Local Input Released")) | |
void BPAbilityLocalInputReleased(int32 InputID); | |
UFUNCTION(BlueprintCallable, Category = "Input", meta = (DisplayName = "Ability Local Tag Input Pressed")) | |
void BP_AbilityLocalTagInputPressed(FGameplayTag InputTag); | |
UFUNCTION(BlueprintCallable, Category = "Input", meta = (DisplayName = "Ability Local Tag Input Released")) | |
void BP_AbilityLocalTagInputReleased(FGameplayTag InputTag); | |
UPROPERTY(BlueprintAssignable) | |
FArcGameplayEffectAdded OnGameplayEffectAddedToSelf; | |
UPROPERTY(BlueprintAssignable) | |
FArcGameplayEffectRemoved OnGameplayEffectRemovedFromSelf; | |
UFUNCTION(BlueprintPure, Category = "Arcanum|AbilitySystem") | |
void GetActiveGameplayEffectsWithTag(FGameplayTag Tag, TArray<FActiveGameplayEffectHandle>& OutActiveGameplayTags); | |
virtual void InitAbilityActorInfo(AActor* InOwnerActor, AActor* InAvatarActor) override; | |
virtual void BindAbilityActivationToInputComponentByTag(UInputComponent* InputComponent, const FArcGameplayAbilityInputTagBinds& TagBindings); | |
virtual int32 FindTagBinding(const FGameplayTag& GameplayTag, UInputComponent* InputComponent = nullptr); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2017-2018 Puny Human Games | |
#include "ArcCoreGameInstSubsys_Abilities.h" | |
#include "GameFramework/InputSettings.h" | |
void UArcCoreGameInstSubsys_Abilities::Initialize(FSubsystemCollectionBase& Collection) | |
{ | |
const UInputSettings* InputSettings = GetDefault<UInputSettings>(); | |
TArray<FName> ActionNames; | |
InputSettings->GetActionNames(ActionNames); | |
for (auto ActionMapping : ActionNames) | |
{ | |
FGameplayTag Tag = FGameplayTag::RequestGameplayTag(ActionMapping, false); | |
if (Tag.IsValid()) | |
{ | |
TagMap.Add(Tag, TagMap.Num()); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2017-2018 Puny Human Games | |
#pragma once | |
#include "CoreMinimal.h" | |
#include "Subsystems/GameInstanceSubsystem.h" | |
#include "GameplayTags.h" | |
#include "ArcCoreGameInstSubsys_Abilities.generated.h" | |
/** | |
* | |
*/ | |
UCLASS() | |
class ARCCORE_API UArcCoreGameInstSubsys_Abilities : public UGameInstanceSubsystem | |
{ | |
GENERATED_BODY() | |
public: | |
virtual void Initialize(FSubsystemCollectionBase& Collection) override; | |
TMap<FGameplayTag, int32> TagMap; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment