Going through the process of using UInputActions instead of a custom class wherever possible, to make using the plugin less confusing.
This commit is contained in:
parent
b1ef780086
commit
cb7e8feb8c
@ -37,7 +37,7 @@ void UComboManagerComponent::BeginPlay()
|
||||
}
|
||||
|
||||
|
||||
void UComboManagerComponent::HandleComboInput(const UComboInputAsset *Input, const EComboActionTriggerEvent &TriggerEvent)
|
||||
void UComboManagerComponent::HandleComboInput(const UInputAction *Input, const EComboActionTriggerEvent &TriggerEvent)
|
||||
{
|
||||
switch (TriggerEvent)
|
||||
{
|
||||
@ -52,10 +52,10 @@ void UComboManagerComponent::HandleComboInput(const UComboInputAsset *Input, con
|
||||
}
|
||||
}
|
||||
|
||||
void UComboManagerComponent::ActivateComboAction(const UComboInputAsset *Input)
|
||||
void UComboManagerComponent::ActivateComboAction(const UInputAction *Input)
|
||||
{
|
||||
/************ DEBUG ************/
|
||||
for (const TPair<TObjectPtr<const UComboInputAsset>, float> &Pair : this->DEBUG__UnlockTimers)
|
||||
for (const TPair<TObjectPtr<const UInputAction>, float> &Pair : this->DEBUG__UnlockTimers)
|
||||
{
|
||||
if (!this->DEBUG__TimerHandles.Contains(Pair.Key))
|
||||
{
|
||||
@ -102,14 +102,14 @@ void UComboManagerComponent::ActivateComboAction(const UComboInputAsset *Input)
|
||||
return;
|
||||
}
|
||||
}
|
||||
void UComboManagerComponent::DEBUG__UnlockAction(TObjectPtr<const UComboInputAsset> Unlock)
|
||||
void UComboManagerComponent::DEBUG__UnlockAction(TObjectPtr<const UInputAction> Unlock)
|
||||
{
|
||||
APlayerController *Controller = UGameplayStatics::GetPlayerController(this, 0);
|
||||
UInputBufferLocalPlayerSubsystem *Subsystem = Controller->GetLocalPlayer()->GetSubsystem<UInputBufferLocalPlayerSubsystem>();
|
||||
Subsystem->UnlockComboInput(Unlock);
|
||||
}
|
||||
|
||||
void UComboManagerComponent::ReleaseComboAction(const class UComboInputAsset *Input)
|
||||
void UComboManagerComponent::ReleaseComboAction(const class UInputAction *Input)
|
||||
{
|
||||
if (this->LastComboAction)
|
||||
{
|
||||
|
||||
@ -24,7 +24,7 @@ void UInputBufferLocalPlayerSubsystem::AttachComboManager(UComboManagerComponent
|
||||
// Get all unique EnhancedInput actions bound to combo input actions.
|
||||
const UInputBufferSubsystemGlobalSettings *Settings = GetDefault<UInputBufferSubsystemGlobalSettings>();
|
||||
TSet<const UInputAction*> InputActionsToBind;
|
||||
for (TSoftObjectPtr<const UComboInputAsset> ComboInput : Settings->ComboActions)
|
||||
for (TSoftObjectPtr<const UComboInputGroup> ComboInput : Settings->ComboActions)
|
||||
{
|
||||
for (const UInputAction *InputAction : ComboInput->ActionGroup)
|
||||
{
|
||||
@ -46,7 +46,7 @@ void UInputBufferLocalPlayerSubsystem::AddActionToBuffer(const FInputActionValue
|
||||
|
||||
// Find any combo input that matches this action, plus buffered actions.
|
||||
const UInputBufferSubsystemGlobalSettings *Settings = GetDefault<UInputBufferSubsystemGlobalSettings>();
|
||||
for (TSoftObjectPtr<const UComboInputAsset> ComboInput : Settings->ComboActions)
|
||||
for (TSoftObjectPtr<const UComboInputGroup> ComboInput : Settings->ComboActions)
|
||||
{
|
||||
if (ComboInput->MatchesInputActions(this->MostRecentActions))
|
||||
{
|
||||
@ -71,10 +71,8 @@ void UInputBufferLocalPlayerSubsystem::ClearMultiPresses()
|
||||
this->MostRecentActions.Empty();
|
||||
}
|
||||
|
||||
void UInputBufferLocalPlayerSubsystem::ActivateComboInput(const UComboInputAsset *ComboInput)
|
||||
void UInputBufferLocalPlayerSubsystem::ActivateComboInput(const UInputAction *ComboInput)
|
||||
{
|
||||
checkf(ComboInput, TEXT("Invalid %s."), *UComboInputAsset::StaticClass()->GetName());
|
||||
|
||||
const bool bNewInputLocked = this->LockedComboInputs.Contains(ComboInput);
|
||||
const bool bNewSupercedesActive = (this->InputBufferActive && this->InputBufferActive->ContainsOneOf(ComboInput->ActionGroup) && !bNewInputLocked);
|
||||
|
||||
@ -114,7 +112,7 @@ void UInputBufferLocalPlayerSubsystem::ActivateComboInput(const UComboInputAsset
|
||||
}
|
||||
}
|
||||
|
||||
void UInputBufferLocalPlayerSubsystem::HoldComboInput(const UComboInputAsset *ComboInput)
|
||||
void UInputBufferLocalPlayerSubsystem::HoldComboInput(const UInputAction *ComboInput)
|
||||
{
|
||||
this->InputBufferHold = ComboInput;
|
||||
UE_SUPPRESS(LogInputBufferLocalPlayerSubsystem, Verbose,
|
||||
@ -131,7 +129,7 @@ void UInputBufferLocalPlayerSubsystem::HoldComboInput(const UComboInputAsset *Co
|
||||
);
|
||||
}
|
||||
|
||||
void UInputBufferLocalPlayerSubsystem::UnlockComboInput(const UComboInputAsset *Unlocked)
|
||||
void UInputBufferLocalPlayerSubsystem::UnlockComboInput(const UInputAction *Unlocked)
|
||||
{
|
||||
// Remove the newly-unlocked asset from the locked combo inputs.
|
||||
UE_CLOG(this->LockedComboInputs.Contains(Unlocked), LogInputBufferLocalPlayerSubsystem, Verbose, TEXT("%s has unlocked."), *Unlocked->ComboInputName.ToString());
|
||||
@ -143,7 +141,7 @@ void UInputBufferLocalPlayerSubsystem::UnlockComboInput(const UComboInputAsset *
|
||||
const UComboInputAsset *OriginalActive = this->InputBufferActive;
|
||||
|
||||
// Activate the held combo input.
|
||||
const UComboInputAsset *HeldAsset = this->InputBufferHold;
|
||||
const UInputAction *HeldAsset = this->InputBufferHold;
|
||||
this->InputBufferHold = nullptr;
|
||||
if (HeldAsset)
|
||||
{
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
#include "InputAction.h"
|
||||
#include "Engine/DataAsset.h"
|
||||
|
||||
#include "ComboInputAssets.generated.h"
|
||||
@ -55,7 +56,7 @@ class COMBOINPUT_API UComboSequenceNode : public UDataAsset
|
||||
|
||||
public:
|
||||
UPROPERTY(BlueprintReadOnly, EditAnywhere)
|
||||
TMap<const class UComboInputAsset *, struct FComboSequenceAction> ComboBranch;
|
||||
TMap<const class UInputAction *, struct FComboSequenceAction> ComboBranch;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -65,7 +66,7 @@ public:
|
||||
* in the current ComboSequenceNode.
|
||||
*/
|
||||
UCLASS(BlueprintType)
|
||||
class COMBOINPUT_API UComboInputAsset : public UDataAsset
|
||||
class COMBOINPUT_API UComboInputGroup : public UInputAction
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
@ -112,19 +113,19 @@ public:
|
||||
}
|
||||
|
||||
// Human-readable name of this combo input.
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Combo Input Group")
|
||||
FName ComboInputName;
|
||||
|
||||
// Combined actions that add up to this combo input when activated
|
||||
// within a short time of one another. If only one is present, then
|
||||
// this combo input asset will simply represent that action.
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Combo Input Group")
|
||||
TSet<const class UInputAction*> ActionGroup;
|
||||
|
||||
// Combo inputs that should be prevented from occurring during this
|
||||
// action. These will be locked when the action is broadcast, and
|
||||
// should be unlocked by the receiving actor by sending an unlock
|
||||
// event.
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Combo Input Group")
|
||||
TSet<TObjectPtr<const class UComboInputAsset>> LockedComboInputs;
|
||||
};
|
||||
|
||||
@ -31,8 +31,8 @@ struct COMBOINPUT_API FComboOffsetMap
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UPROPERTY(BlueprintReadOnly, EditAnywhere) TObjectPtr<const class UComboInputAsset> ComboInput;
|
||||
UPROPERTY(BlueprintReadOnly, EditAnywhere) TObjectPtr<const class UComboAction> ComboAction;
|
||||
UPROPERTY(BlueprintReadOnly, EditAnywhere) TObjectPtr<const class UInputAction> ComboInput;
|
||||
UPROPERTY(BlueprintReadOnly, EditAnywhere) TObjectPtr<const class UComboAction> ComboAction;
|
||||
};
|
||||
|
||||
UCLASS(BlueprintType, ClassGroup=(Input), meta=(BlueprintSpawnableComponent))
|
||||
@ -45,7 +45,7 @@ public:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void HandleComboInput(const class UComboInputAsset *Input, const EComboActionTriggerEvent &TriggerEvent);
|
||||
void HandleComboInput(const class UInputAction *Input, const EComboActionTriggerEvent &TriggerEvent);
|
||||
|
||||
void BindAction(UObject *ObjectToBindTo, FName FunctionName, const class UComboAction *ComboAction, const EComboActionTriggerEvent &TriggerEvent)
|
||||
{
|
||||
@ -69,17 +69,17 @@ protected:
|
||||
// A list of default input->action mappings. If you wish for an action to be handled
|
||||
// outside the scope of a combo sequence node, it should go here.
|
||||
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly)
|
||||
TMap<TObjectPtr<const class UComboInputAsset>, TObjectPtr<const class UComboAction>> FallbackActions;
|
||||
TMap<TObjectPtr<const class UInputAction>, TObjectPtr<const class UComboAction>> FallbackActions;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly)
|
||||
TMap<TObjectPtr<const class UComboInputAsset>, float> DEBUG__UnlockTimers;
|
||||
TMap<TObjectPtr<const class UInputAction>, float> DEBUG__UnlockTimers;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, BlueprintAssignable)
|
||||
FComboActionHandlerDelegate OnUnhandledAction;
|
||||
|
||||
private:
|
||||
void ActivateComboAction(const class UComboInputAsset *Input);
|
||||
void ReleaseComboAction(const class UComboInputAsset *Input);
|
||||
void ActivateComboAction(const class UInputAction *Input);
|
||||
void ReleaseComboAction(const class UInputAction *Input);
|
||||
|
||||
void BeginNodeTransition(const class UComboSequenceNode *NextNode);
|
||||
void FinishTransition();
|
||||
@ -87,7 +87,7 @@ private:
|
||||
|
||||
void BroadcastDelegates(const class UComboAction *ComboAction, const EComboActionTriggerEvent &TriggerEvent);
|
||||
|
||||
void DEBUG__UnlockAction(TObjectPtr<const class UComboInputAsset> Unlock);
|
||||
void DEBUG__UnlockAction(TObjectPtr<const class UInputAction> Unlock);
|
||||
|
||||
TObjectPtr<const class UComboSequenceNode> ActiveNode = nullptr;
|
||||
TObjectPtr<const class UComboSequenceNode> PreviousNode = nullptr;
|
||||
@ -101,5 +101,5 @@ private:
|
||||
FTimerHandle FinishTransitionTimer;
|
||||
FTimerHandle DEBUG__ResetComboTimer;
|
||||
|
||||
TMap<TObjectPtr<const class UComboInputAsset>, FTimerHandle> DEBUG__TimerHandles;
|
||||
TMap<TObjectPtr<const class UInputAction>, FTimerHandle> DEBUG__TimerHandles;
|
||||
};
|
||||
|
||||
@ -20,7 +20,7 @@ public:
|
||||
// either if an action is made while the current combo is inactive, or when the previous
|
||||
// action expires.
|
||||
UPROPERTY(Config, BlueprintReadOnly, EditDefaultsOnly)
|
||||
TSet<TSoftObjectPtr<const class UComboInputAsset>> ComboActions;
|
||||
TSet<TSoftObjectPtr<const class UComboInputGroup>> ComboActions;
|
||||
|
||||
// Length of time after releasing an input to keep the associated combo action buffered before clearing it.
|
||||
UPROPERTY(Config, BlueprintReadOnly, EditDefaultsOnly, meta=(UIMin="0.0", UIMax="0.5", ClampMin="0.0", ClampMax="0.5"))
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogInputBufferLocalPlayerSubsystem, Log, All);
|
||||
|
||||
DECLARE_DELEGATE_TwoParams(FNewComboInput, const class UComboInputAsset*, const EComboActionTriggerEvent &);
|
||||
DECLARE_DELEGATE_TwoParams(FNewComboInput, const class UInputAction*, const EComboActionTriggerEvent &);
|
||||
|
||||
|
||||
/**
|
||||
@ -26,14 +26,14 @@ public:
|
||||
void AttachComboManager(class UComboManagerComponent *ComboManager, class UEnhancedInputComponent *InputComponent);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void UnlockComboInput(const class UComboInputAsset *Unlocked);
|
||||
void UnlockComboInput(const class UInputAction *Unlocked);
|
||||
|
||||
private:
|
||||
void AddActionToBuffer(const FInputActionValue &Value, const class UInputAction *Action);
|
||||
void ExpireAction(const FInputActionValue &Value, const class UInputAction *Action);
|
||||
|
||||
void ActivateComboInput(const class UComboInputAsset *ComboInput);
|
||||
void HoldComboInput(const class UComboInputAsset *ComboInput);
|
||||
void ActivateComboInput(const class UInputAction *ComboInput);
|
||||
void HoldComboInput(const class UInputAction *ComboInput);
|
||||
|
||||
void ClearMultiPresses();
|
||||
void ExpireBufferedActions();
|
||||
@ -41,13 +41,13 @@ private:
|
||||
TObjectPtr<class UEnhancedInputComponent> EnhancedInputComponent;
|
||||
|
||||
// Currently active combo input.
|
||||
TObjectPtr<const class UComboInputAsset> InputBufferActive;
|
||||
TObjectPtr<const class UInputAction> InputBufferActive;
|
||||
|
||||
// Combo input held until the current input has expired.
|
||||
TObjectPtr<const class UComboInputAsset> InputBufferHold;
|
||||
TObjectPtr<const class UInputAction> InputBufferHold;
|
||||
|
||||
// Set of currently locked actions; will not be activated until an unlock signal is received.
|
||||
TSet<TObjectPtr<const class UComboInputAsset>> LockedComboInputs;
|
||||
TSet<TObjectPtr<const class UInputAction>> LockedComboInputs;
|
||||
|
||||
TSet<const class UInputAction*> MostRecentActions;
|
||||
TSet<const class UInputAction*> ExpiringActions;
|
||||
|
||||
@ -38,14 +38,14 @@ public:
|
||||
virtual UClass *GetSupportedClass() const override { return UComboSequenceNode::StaticClass(); }
|
||||
};
|
||||
|
||||
class FAssetTypeActions_ComboInputAsset : public FAssetTypeActions_DataAsset
|
||||
class FAssetTypeActions_ComboInputGroup : public FAssetTypeActions_DataAsset
|
||||
{
|
||||
public:
|
||||
virtual FText GetName() const override { return NSLOCTEXT("AssetTypeActions", "AssetTypeActions_ComboInputAsset", "Combo Input Asset"); }
|
||||
virtual FText GetName() const override { return NSLOCTEXT("AssetTypeActions", "AssetTypeActions_ComboInputGroup", "Combo Input Asset"); }
|
||||
virtual uint32 GetCategories() override { return FComboInputEditorModule::GetInputAssetsCategory(); }
|
||||
virtual FColor GetTypeColor() const override { return FColor(255, 127, 255); }
|
||||
virtual FText GetAssetDescription(const FAssetData &AssetData) const override { return NSLOCTEXT("AssetTypeActions", "AssetTypeActions_ComboInputAssetDesc", "This maps a sequence of button inputs from EnhancedInput to a combo action that can be used to execute a sequence of moves.This gets sent from the input buffer subsystem to the player controller's ComboManagerComponent, which executes the associated action in the current ComboSequenceNode."); }
|
||||
virtual UClass *GetSupportedClass() const override { return UComboInputAsset::StaticClass(); }
|
||||
virtual FText GetAssetDescription(const FAssetData &AssetData) const override { return NSLOCTEXT("AssetTypeActions", "AssetTypeActions_ComboInputGroupDesc", "This maps a sequence of button inputs from EnhancedInput to a combo action that can be used to execute a sequence of moves.This gets sent from the input buffer subsystem to the player controller's ComboManagerComponent, which executes the associated action in the current ComboSequenceNode."); }
|
||||
virtual UClass *GetSupportedClass() const override { return UComboInputGroup::StaticClass(); }
|
||||
};
|
||||
|
||||
|
||||
@ -94,24 +94,24 @@ UObject *UComboSequenceNode_Factory::FactoryCreateNew(UClass *Class, UObject *In
|
||||
}
|
||||
|
||||
|
||||
UComboInputAsset_Factory::UComboInputAsset_Factory(const FObjectInitializer &ObjectInitializer)
|
||||
UComboInputGroup_Factory::UComboInputGroup_Factory(const FObjectInitializer &ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
SupportedClass = UComboInputAsset::StaticClass();
|
||||
SupportedClass = UComboInputGroup::StaticClass();
|
||||
bEditAfterNew = true;
|
||||
bCreateNew = true;
|
||||
}
|
||||
|
||||
UObject *UComboInputAsset_Factory::FactoryCreateNew(UClass *Class, UObject *InParent, FName Name, EObjectFlags Flags, UObject *Context, FFeedbackContext *Warn)
|
||||
UObject *UComboInputGroup_Factory::FactoryCreateNew(UClass *Class, UObject *InParent, FName Name, EObjectFlags Flags, UObject *Context, FFeedbackContext *Warn)
|
||||
{
|
||||
if (this->ComboInputAssetClass != nullptr)
|
||||
if (this->ComboInputGroupClass != nullptr)
|
||||
{
|
||||
return NewObject<UComboInputAsset>(InParent, this->ComboInputAssetClass, Name, Flags | RF_Transactional, Context);
|
||||
return NewObject<UComboInputGroup>(InParent, this->ComboInputGroupClass, Name, Flags | RF_Transactional, Context);
|
||||
}
|
||||
else
|
||||
{
|
||||
check(Class->IsChildOf(UComboInputAsset::StaticClass()));
|
||||
return NewObject<UComboInputAsset>(InParent, Class, Name, Flags | RF_Transactional, Context);
|
||||
check(Class->IsChildOf(UComboInputGroup::StaticClass()));
|
||||
return NewObject<UComboInputGroup>(InParent, Class, Name, Flags | RF_Transactional, Context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,8 +142,8 @@ public:
|
||||
this->Set("ClassIcon.ComboSequenceNode", new IMAGE_BRUSH_SVG("Icons/ComboSequenceNode_16", Icon16));
|
||||
this->Set("ClassThumbnail.ComboSequenceNode", new IMAGE_BRUSH_SVG("Icons/ComboSequenceNode_64", Icon64));
|
||||
|
||||
this->Set("ClassIcon.ComboInputAsset", new IMAGE_BRUSH_SVG("Icons/ComboInputAsset_16", Icon16));
|
||||
this->Set("ClassThumbnail.ComboInputAsset", new IMAGE_BRUSH_SVG("Icons/ComboInputAsset_64", Icon64));
|
||||
this->Set("ClassIcon.ComboInputGroup", new IMAGE_BRUSH_SVG("Icons/ComboInputGroup_16", Icon16));
|
||||
this->Set("ClassThumbnail.ComboInputGroup", new IMAGE_BRUSH_SVG("Icons/ComboInputGroup_64", Icon64));
|
||||
}
|
||||
};
|
||||
|
||||
@ -156,7 +156,7 @@ void FComboInputEditorModule::StartupModule()
|
||||
FComboInputEditorModule::ComboAssetsCategory = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("Input")), LOCTEXT("InputAssetsCategory", "Input"));
|
||||
this->RegisterAssetTypeActions(AssetTools, MakeShareable(new FAssetTypeActions_ComboAction));
|
||||
this->RegisterAssetTypeActions(AssetTools, MakeShareable(new FAssetTypeActions_ComboSequenceNode));
|
||||
this->RegisterAssetTypeActions(AssetTools, MakeShareable(new FAssetTypeActions_ComboInputAsset));
|
||||
this->RegisterAssetTypeActions(AssetTools, MakeShareable(new FAssetTypeActions_ComboInputGroup));
|
||||
|
||||
// Make a new style set for Combo Input, which will register any custom icons for the types in this plugin
|
||||
StyleSet = MakeShared<FComboInputSlateStyle>();
|
||||
|
||||
@ -42,15 +42,15 @@ public:
|
||||
};
|
||||
|
||||
UCLASS()
|
||||
class COMBOINPUTEDITOR_API UComboInputAsset_Factory : public UFactory
|
||||
class COMBOINPUTEDITOR_API UComboInputGroup_Factory : public UFactory
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UComboInputAsset_Factory(const class FObjectInitializer &ObjectInitializer);
|
||||
UComboInputGroup_Factory(const class FObjectInitializer &ObjectInitializer);
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Combo Input")
|
||||
TSubclassOf<class UComboInputAsset> ComboInputAssetClass;
|
||||
TSubclassOf<class UComboInputGroup> ComboInputGroupClass;
|
||||
|
||||
virtual UObject *FactoryCreateNew(UClass *Class, UObject *InParent, FName Name, EObjectFlags Flags, UObject *Context, FFeedbackContext *Warn) override;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user