109 lines
3.2 KiB
C++
109 lines
3.2 KiB
C++
////////////////////////////////////////////////////////////
|
|
//
|
|
// 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 "Blueprint/UserWidget.h"
|
|
#include "InputEvents.generated.h"
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//
|
|
// FlxInputModeRequest
|
|
//
|
|
// A widget's declaration of interest in input events.
|
|
//
|
|
// Widget: The widget that wants to receive events.
|
|
// Focus: The widget that should receive keyboard focus
|
|
// while this request is active.
|
|
// ShowPointer: If true, the mouse pointer should be
|
|
// visible when this widget has control.
|
|
// BlockInput: If true, input actions should be blocked from
|
|
// reaching lower-priority consumers (e.g. the pawn).
|
|
//
|
|
////////////////////////////////////////////////////////////
|
|
|
|
USTRUCT(BlueprintType)
|
|
struct FlxInputModeRequest
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
FlxInputModeRequest() = default;
|
|
FlxInputModeRequest(UUserWidget *InWidget, UWidget *InFocus, bool InShowPointer, bool InBlockInput)
|
|
: Widget(InWidget), Focus(InFocus), ShowPointer(InShowPointer), BlockInput(InBlockInput) {}
|
|
|
|
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;
|
|
};
|
|
|
|
USTRUCT()
|
|
struct FlxInputModeRequests
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
private:
|
|
UPROPERTY()
|
|
// High priority requests are always before low-priority.
|
|
// Otherwise, these are in order of most recent first.
|
|
TArray<FlxInputModeRequest> Requests;
|
|
|
|
UPROPERTY()
|
|
bool Dirty = true;
|
|
|
|
public:
|
|
using View = TArrayView<FlxInputModeRequest>;
|
|
|
|
// Get the requests array.
|
|
const TArray<FlxInputModeRequest> &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);
|
|
|
|
// Ensure the specified widget has a request in the array.
|
|
// If it isn't already present, register a low-priority request for it.
|
|
void EnsureWidget(UUserWidget *Widget);
|
|
|
|
// 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; }
|
|
};
|