//////////////////////////////////////////////////////////// // // 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; // True if this request wants any high-priority resource: // keyboard focus, the mouse pointer, or input blocking. bool IsHighPrio() const { return Focus != nullptr || ShowPointer || BlockInput; } 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: using View = TArrayView; // 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); // Divide Requests into a high-priority slice and a low-priority slice. void SplitHighLow(View &High, View &Low); // Apply a request. Replaces any previous request by the same widget. void Request(const FlxInputModeRequest &NewRequest); // 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(); };