//////////////////////////////////////////////////////////// // // InputModeRequest.h // // Custom input event dispatching system. Uses Unreal's // built-in input modes (GameOnly / UIOnly) with an // enhanced input component for GameOnly mode hotkeys. // //////////////////////////////////////////////////////////// #pragma once #include "CoreMinimal.h" #include "Blueprint/UserWidget.h" #include "InputModeRequest.generated.h" //////////////////////////////////////////////////////////// // // FlxInputModeRequest // // Using this struct, a Widget can express a need for a // particular input mode. These requests go to the player // controller, which arbitrates. // //////////////////////////////////////////////////////////// USTRUCT(BlueprintType) struct FlxInputModeRequest { GENERATED_BODY() FlxInputModeRequest() = default; bool operator == (const FlxInputModeRequest &Other) const; bool operator < (const FlxInputModeRequest &Other) const; UPROPERTY(BlueprintReadWrite) UUserWidget* Widget = nullptr; UPROPERTY(BlueprintReadWrite) UWidget* Focus = nullptr; UPROPERTY(BlueprintReadWrite) bool ShowPointer = false; UPROPERTY(BlueprintReadWrite) bool BlockInput = false; UPROPERTY(BlueprintReadWrite) bool EnableInputComponent = true; UPROPERTY() int32 SequenceNumber = 0; }; USTRUCT() struct FlxInputModeRequests { GENERATED_BODY() private: UPROPERTY() // Sorted by highest priority first, then most recent first. TArray Requests; UPROPERTY() int32 NextSequenceNumber = 0; public: // Get the requests array. const TArray &GetRequests() const { return Requests; } // Sanity check a request to see if it is reasonable. static bool SanityCheck(const FlxInputModeRequest &Request); // Apply a request. Replaces any previous request by the same widget. void Request(const FlxInputModeRequest &NewRequest, bool UpdateSequence = true); // Find the specified widget, and modify the 'EnableInputComponent' // flag. Adds the widget if it's not already present. void SetEnableInputComponent(UUserWidget *Widget, bool EnableInputComponent); // Remove all requests by the specified widget. void Remove(UUserWidget *Widget); // Remove any requests by dead widgets or widgets with no parents. void GarbageCollect(); private: // Find specified widget. If not present, returns Requests.Num() int32 FindWidget(UUserWidget *Widget); // Move item at Index to its proper place in the array by priority. void BubbleItem(int32 Index); };