More work on managing input events
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
bool FlxEventRequest::operator==(const FlxEventRequest &Other) const
|
||||
{
|
||||
return (Widget == Other.Widget) &&
|
||||
(TakeControl == Other.TakeControl) &&
|
||||
(UseUIOnly == Other.UseUIOnly) &&
|
||||
(ShowPointer == Other.ShowPointer) &&
|
||||
(Hotkeys == Other.Hotkeys);
|
||||
}
|
||||
@@ -22,12 +22,12 @@ bool FlxEventRequests::SanityCheck(const FlxEventRequest &Request)
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("RequestEvents called with null widget."));
|
||||
return false;
|
||||
}
|
||||
if (Request.ShowPointer && !Request.TakeControl)
|
||||
if (Request.ShowPointer && !Request.UseUIOnly)
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("RequestEvents: ShowPointer requires TakeControl."));
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("RequestEvents: ShowPointer requires UseUIOnly."));
|
||||
return false;
|
||||
}
|
||||
if (Request.TakeControl && !Request.Hotkeys.IsEmpty())
|
||||
if (Request.UseUIOnly && !Request.Hotkeys.IsEmpty())
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("RequestEvents: Widget asked for all events, and also, specific events"));
|
||||
return false;
|
||||
@@ -38,7 +38,7 @@ bool FlxEventRequests::SanityCheck(const FlxEventRequest &Request)
|
||||
void FlxEventRequests::SplitHighLow(View &High, View &Low)
|
||||
{
|
||||
int32 NumHigh = 0;
|
||||
while ((NumHigh < Requests.Num()) && (Requests[NumHigh].TakeControl)) NumHigh++;
|
||||
while ((NumHigh < Requests.Num()) && (Requests[NumHigh].UseUIOnly)) NumHigh++;
|
||||
int32 NumLow = Requests.Num() - NumHigh;
|
||||
High = View(Requests.GetData(), NumHigh);
|
||||
Low = View(Requests.GetData() + NumHigh, NumLow);
|
||||
@@ -52,7 +52,7 @@ void FlxEventRequests::Request(const FlxEventRequest &NewRequest)
|
||||
|
||||
// This is a simple test to see if anything is going to change.
|
||||
// If not, we return early and avoid setting the dirty bit.
|
||||
if (NewRequest.TakeControl)
|
||||
if (NewRequest.UseUIOnly)
|
||||
{
|
||||
if ((High.Num() > 0) && (High[0] == NewRequest)) return;
|
||||
}
|
||||
@@ -65,12 +65,12 @@ void FlxEventRequests::Request(const FlxEventRequest &NewRequest)
|
||||
TArray<FlxEventRequest> Updated;
|
||||
|
||||
// Add all high priority requests to the updated array, new request first.
|
||||
if (NewRequest.TakeControl) Updated.Add(NewRequest);
|
||||
if (NewRequest.UseUIOnly) Updated.Add(NewRequest);
|
||||
for (const FlxEventRequest &Req : High)
|
||||
if (Req.Widget != NewRequest.Widget) Updated.Add(Req);
|
||||
|
||||
// Add all low priority requests to the updated array, new request first.
|
||||
if (!NewRequest.TakeControl) Updated.Add(NewRequest);
|
||||
if (!NewRequest.UseUIOnly) Updated.Add(NewRequest);
|
||||
for (const FlxEventRequest &Req : Low)
|
||||
if (Req.Widget != NewRequest.Widget) Updated.Add(Req);
|
||||
|
||||
@@ -101,7 +101,7 @@ void FlxEventRequests::GarbageCollect()
|
||||
|
||||
FlxEventRequests::InputMode FlxEventRequests::GetRequestedMode() const
|
||||
{
|
||||
if ((Requests.Num() > 0) && (Requests[0].TakeControl))
|
||||
if ((Requests.Num() > 0) && (Requests[0].UseUIOnly))
|
||||
{
|
||||
return InputMode::UIOnly;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// Custom input event dispatching system. Uses Unreal's
|
||||
// built-in input modes (GameOnly / UIOnly) with an
|
||||
// enhanced input component for character mode hotkeys.
|
||||
// enhanced input component for GameOnly mode hotkeys.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
// A widget's declaration of interest in input events.
|
||||
//
|
||||
// Widget: The widget that wants to receive events.
|
||||
// TakeControl: If true, activating this request puts
|
||||
// the system into Widget Mode.
|
||||
// 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 Character mode.
|
||||
// player is in GameOnly mode.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -37,8 +37,8 @@ struct FlxEventRequest
|
||||
GENERATED_BODY()
|
||||
|
||||
FlxEventRequest() = default;
|
||||
FlxEventRequest(UUserWidget *InWidget, bool InTakeControl, bool InShowPointer, const TArray<FKey> &InHotkeys)
|
||||
: Widget(InWidget), TakeControl(InTakeControl), ShowPointer(InShowPointer), Hotkeys(InHotkeys) {}
|
||||
FlxEventRequest(UUserWidget *InWidget, bool InUseUIOnly, bool InShowPointer, const TArray<FKey> &InHotkeys)
|
||||
: Widget(InWidget), UseUIOnly(InUseUIOnly), ShowPointer(InShowPointer), Hotkeys(InHotkeys) {}
|
||||
|
||||
bool operator == (const FlxEventRequest &Other) const;
|
||||
|
||||
@@ -46,7 +46,7 @@ struct FlxEventRequest
|
||||
UUserWidget* Widget = nullptr;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
bool TakeControl = false;
|
||||
bool UseUIOnly = false;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
bool ShowPointer = false;
|
||||
|
||||
@@ -74,9 +74,9 @@ FVector2D AlxPlayerControllerBase::GetLookAtPixel(const UObject *Context)
|
||||
void AlxPlayerControllerBase::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
CharacterModeInput = NewObject<UInputComponent>(this);
|
||||
CharacterModeInput->bBlockInput = false;
|
||||
PushInputComponent(CharacterModeInput);
|
||||
HotkeyInputComponent = NewObject<UInputComponent>(this);
|
||||
HotkeyInputComponent->bBlockInput = false;
|
||||
PushInputComponent(HotkeyInputComponent);
|
||||
}
|
||||
|
||||
void AlxPlayerControllerBase::UpdateEventDispatch()
|
||||
@@ -121,7 +121,7 @@ void AlxPlayerControllerBase::UpdateEventDispatch()
|
||||
{
|
||||
SetInputMode(FInputModeGameOnly());
|
||||
|
||||
CharacterModeInput->KeyBindings.Empty();
|
||||
HotkeyInputComponent->KeyBindings.Empty();
|
||||
TSet<FKey> BoundKeys;
|
||||
for (const FlxEventRequest &Req : Requests)
|
||||
{
|
||||
@@ -130,7 +130,7 @@ void AlxPlayerControllerBase::UpdateEventDispatch()
|
||||
if (!BoundKeys.Contains(Key))
|
||||
{
|
||||
BoundKeys.Add(Key);
|
||||
CharacterModeInput->BindKey(Key, IE_Pressed, this, &AlxPlayerControllerBase::ForwardKeyEvent);
|
||||
HotkeyInputComponent->BindKey(Key, IE_Pressed, this, &AlxPlayerControllerBase::ForwardKeyEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
// Rebuild input component and switch input mode.
|
||||
void UpdateEventDispatch();
|
||||
|
||||
// Handler for character mode hotkey presses.
|
||||
// Handler for GameOnly mode hotkey presses.
|
||||
void ForwardKeyEvent(FKey Key);
|
||||
|
||||
// Walk up from a Slate widget to find the nearest UMG widget class name.
|
||||
@@ -65,9 +65,9 @@ public:
|
||||
UPROPERTY()
|
||||
FlxEventRequests EventRequests;
|
||||
|
||||
// Input component for Character Mode: catches hotkeys only.
|
||||
// Input component for GameOnly mode: catches hotkeys only.
|
||||
UPROPERTY()
|
||||
UInputComponent *CharacterModeInput = nullptr;
|
||||
UInputComponent *HotkeyInputComponent = nullptr;
|
||||
|
||||
// Current input mode.
|
||||
InputMode CurrentInputMode = InputMode::GameOnly;
|
||||
|
||||
Reference in New Issue
Block a user