Much work on input mode switching
This commit is contained in:
@@ -11,52 +11,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "InputCoreTypes.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "InputEvents.generated.h"
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// FlxEventRequest
|
||||
// FlxInputModeRequest
|
||||
//
|
||||
// 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.
|
||||
// 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.
|
||||
// Hotkeys: Keys that go to this widget when the
|
||||
// player is in GameOnly mode.
|
||||
// BlockInput: If true, input actions should be blocked from
|
||||
// reaching lower-priority consumers (e.g. the pawn).
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FlxEventRequest
|
||||
struct FlxInputModeRequest
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
FlxEventRequest() = default;
|
||||
FlxEventRequest(UUserWidget *InWidget, bool InUseUIOnly, bool InShowPointer, const TArray<FKey> &InHotkeys)
|
||||
: Widget(InWidget), UseUIOnly(InUseUIOnly), ShowPointer(InShowPointer), Hotkeys(InHotkeys) {}
|
||||
FlxInputModeRequest() = default;
|
||||
FlxInputModeRequest(UUserWidget *InWidget, UWidget *InFocus, bool InShowPointer, bool InBlockInput)
|
||||
: Widget(InWidget), Focus(InFocus), ShowPointer(InShowPointer), BlockInput(InBlockInput) {}
|
||||
|
||||
bool operator == (const FlxEventRequest &Other) const;
|
||||
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)
|
||||
bool UseUIOnly = false;
|
||||
UWidget* Focus = nullptr;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
bool ShowPointer = false;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
TArray<FKey> Hotkeys;
|
||||
bool BlockInput = false;
|
||||
};
|
||||
|
||||
USTRUCT()
|
||||
struct FlxEventRequests
|
||||
struct FlxInputModeRequests
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
@@ -64,27 +67,29 @@ private:
|
||||
UPROPERTY()
|
||||
// High priority requests are always before low-priority.
|
||||
// Otherwise, these are in order of most recent first.
|
||||
TArray<FlxEventRequest> Requests;
|
||||
TArray<FlxInputModeRequest> Requests;
|
||||
|
||||
UPROPERTY()
|
||||
bool Dirty = true;
|
||||
|
||||
public:
|
||||
enum class InputMode { UIOnly, GameOnly };
|
||||
|
||||
using View = TArrayView<FlxEventRequest>;
|
||||
using View = TArrayView<FlxInputModeRequest>;
|
||||
|
||||
// Get the requests array.
|
||||
const TArray<FlxEventRequest> &GetRequests() const { return Requests; }
|
||||
const TArray<FlxInputModeRequest> &GetRequests() const { return Requests; }
|
||||
|
||||
// Sanity check a request to see if it is reasonable.
|
||||
static bool SanityCheck(const FlxEventRequest &Request);
|
||||
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 FlxEventRequest &NewRequest);
|
||||
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);
|
||||
@@ -100,7 +105,4 @@ public:
|
||||
|
||||
// Set the dirty flag.
|
||||
void SetDirty() { Dirty = true; }
|
||||
|
||||
// Get the currently-requested mode.
|
||||
InputMode GetRequestedMode() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user