//////////////////////////////////////////////////////////// // // InputEvents.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 "InputCoreTypes.h" #include "Blueprint/UserWidget.h" #include "InputEvents.generated.h" //////////////////////////////////////////////////////////// // // FlxEventRequest // // A widget's declaration of interest in input events. // // Widget: The widget that wants to receive events. // UseUIOnly: If true, activating this request puts // the system into UIOnly mode. // ShowPointer: If true, the mouse pointer should be // visible when this widget has control. // Hotkeys: Keys that go to this widget when the // player is in GameOnly mode. // //////////////////////////////////////////////////////////// USTRUCT(BlueprintType) struct FlxEventRequest { GENERATED_BODY() FlxEventRequest() = default; FlxEventRequest(UUserWidget *InWidget, bool InUseUIOnly, bool InShowPointer, const TArray &InHotkeys) : Widget(InWidget), UseUIOnly(InUseUIOnly), ShowPointer(InShowPointer), Hotkeys(InHotkeys) {} bool operator == (const FlxEventRequest &Other) const; UPROPERTY(BlueprintReadWrite) UUserWidget* Widget = nullptr; UPROPERTY(BlueprintReadWrite) bool UseUIOnly = false; UPROPERTY(BlueprintReadWrite) bool ShowPointer = false; UPROPERTY(BlueprintReadWrite) TArray Hotkeys; }; USTRUCT() struct FlxEventRequests { GENERATED_BODY() private: UPROPERTY() // High priority requests are always before low-priority. // Otherwise, these are in order of most recent first. TArray Requests; UPROPERTY() bool Dirty = true; public: enum class InputMode { UIOnly, GameOnly }; 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 FlxEventRequest &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 FlxEventRequest &NewRequest); // Remove all requests by the specified widget. void Remove(UUserWidget *Widget); // Remove any requests by dead widgets or widgets with no parents. void GarbageCollect(); // Return true if the requests have changed since the last ClearDirty. bool IsDirty() { return Dirty; } // Clear the dirty flag. void ClearDirty() { Dirty = false; } // Set the dirty flag. void SetDirty() { Dirty = true; } // Get the currently-requested mode. InputMode GetRequestedMode() const; };