// © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action. #pragma once #include "CoreMinimal.h" #include "OLSGameFeatureAction_WorldActionBase.h" #include "OLSGameFeatureAction_AddInputContextMapping.generated.h" DECLARE_LOG_CATEGORY_EXTERN(LogOLSGameFA_AddInputContextMapping, Verbose, All); USTRUCT() struct FOLSInputMappingContextAndPriority { GENERATED_BODY() UPROPERTY(EditAnywhere, Category="Input", meta=(AssetBundles="Client,Server")) TSoftObjectPtr InputMapping; // Higher priority input mappings will be prioritized over mappings with a lower priority. UPROPERTY(EditAnywhere, Category="Input") int32 Priority = 0; /** If true, then this mapping context will be registered with the settings when this game feature action is registered. */ UPROPERTY(EditAnywhere, Category="Input") uint8 bShouldRegisterWithSettings : 1 = true; }; /** * Adds InputMappingContext to local players' EnhancedInput system. * Expects that local players are set up to use the EnhancedInput system. */ UCLASS(MinimalAPI, meta = (DisplayName = "Add Input Mapping")) class UOLSGameFeatureAction_AddInputContextMapping : public UOLSGameFeatureAction_WorldActionBase { GENERATED_BODY() public: //~ Begin UGameFeatureAction interface virtual void OnGameFeatureRegistering() override; virtual void OnGameFeatureActivating(FGameFeatureActivatingContext& context) override; virtual void OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& context) override; virtual void OnGameFeatureUnregistering() override; //~ End UGameFeatureAction interface //~ Begin UObject interface #if WITH_EDITOR virtual EDataValidationResult IsDataValid(class FDataValidationContext& context) const override; #endif //~ End UObject interface private: /** Registers owned Input Mapping Contexts to the Input Registry Subsystem. Also binds onto the start of GameInstances and the adding/removal of Local Players. */ void RegisterInputMappingContexts(); /** Registers owned Input Mapping Contexts to the Input Registry Subsystem for a specified GameInstance. This also gets called by a GameInstance Start. */ void RegisterInputContextMappingsForGameInstance(class UGameInstance* gameInstance); /** Registers owned Input Mapping Contexts to the Input Registry Subsystem for a specified Local Player. This also gets called when a Local Player is added. */ void RegisterInputMappingContextsForLocalPlayer(class ULocalPlayer* localPlayer); /** Unregisters owned Input Mapping Contexts from the Input Registry Subsystem. Also unbinds from the start of GameInstances and the adding/removal of Local Players. */ void UnregisterInputMappingContexts(); /** Unregisters owned Input Mapping Contexts from the Input Registry Subsystem for a specified GameInstance. */ void UnregisterInputContextMappingsForGameInstance(class UGameInstance* gameInstance); /** Unregisters owned Input Mapping Contexts from the Input Registry Subsystem for a specified Local Player. This also gets called when a Local Player is removed. */ void UnregisterInputMappingContextsForLocalPlayer(class ULocalPlayer* localPlayer); //~UGameFeatureAction_WorldActionBase interface virtual void AddToWorld(const FWorldContext& worldContext, const struct FGameFeatureStateChangeContext& changeContext) override; //~End of UGameFeatureAction_WorldActionBase interface struct FPerContextData { TArray> ExtensionRequestHandles; TArray> ControllersAddedTo; }; void Reset(FPerContextData& activeData); void HandleControllerExtension(class AActor* actor, FName eventName, struct FGameFeatureStateChangeContext changeContext); void AddInputMappingForPlayer(class UPlayer* player, struct FPerContextData& activeData); void RemoveInputMapping(class APlayerController* playerController, FPerContextData& activeData); public: UPROPERTY(EditAnywhere, Category="Input") TArray InputMappings; private: TMap ContextData; /** Delegate for when the game instance is changed to register IMC's */ FDelegateHandle RegisterInputContextMappingsForGameInstanceHandle; };