Much work on input mode switching
This commit is contained in:
@@ -7,52 +7,44 @@
|
||||
#include "InputEvents.h"
|
||||
#include "Common.h"
|
||||
|
||||
bool FlxEventRequest::operator==(const FlxEventRequest &Other) const
|
||||
bool FlxInputModeRequest::operator==(const FlxInputModeRequest &Other) const
|
||||
{
|
||||
return (Widget == Other.Widget) &&
|
||||
(UseUIOnly == Other.UseUIOnly) &&
|
||||
(Focus == Other.Focus) &&
|
||||
(ShowPointer == Other.ShowPointer) &&
|
||||
(Hotkeys == Other.Hotkeys);
|
||||
(BlockInput == Other.BlockInput);
|
||||
}
|
||||
|
||||
bool FlxEventRequests::SanityCheck(const FlxEventRequest &Request)
|
||||
bool FlxInputModeRequests::SanityCheck(const FlxInputModeRequest &Request)
|
||||
{
|
||||
if (Request.Widget == nullptr)
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("RequestEvents called with null widget."));
|
||||
return false;
|
||||
}
|
||||
if (Request.ShowPointer && !Request.UseUIOnly)
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("RequestEvents: ShowPointer requires UseUIOnly."));
|
||||
return false;
|
||||
}
|
||||
if (Request.UseUIOnly && !Request.Hotkeys.IsEmpty())
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("RequestEvents: Widget asked for all events, and also, specific events"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FlxEventRequests::SplitHighLow(View &High, View &Low)
|
||||
void FlxInputModeRequests::SplitHighLow(View &High, View &Low)
|
||||
{
|
||||
int32 NumHigh = 0;
|
||||
while ((NumHigh < Requests.Num()) && (Requests[NumHigh].UseUIOnly)) NumHigh++;
|
||||
while ((NumHigh < Requests.Num()) && (Requests[NumHigh].IsHighPrio())) NumHigh++;
|
||||
int32 NumLow = Requests.Num() - NumHigh;
|
||||
High = View(Requests.GetData(), NumHigh);
|
||||
Low = View(Requests.GetData() + NumHigh, NumLow);
|
||||
}
|
||||
|
||||
void FlxEventRequests::Request(const FlxEventRequest &NewRequest)
|
||||
void FlxInputModeRequests::Request(const FlxInputModeRequest &NewRequest)
|
||||
{
|
||||
bool IsHigh = NewRequest.IsHighPrio();
|
||||
|
||||
// Divide the array into a high-priority slice and a low-priority slice.
|
||||
View High, Low;
|
||||
SplitHighLow(High, Low);
|
||||
|
||||
// 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.UseUIOnly)
|
||||
if (IsHigh)
|
||||
{
|
||||
if ((High.Num() > 0) && (High[0] == NewRequest)) return;
|
||||
}
|
||||
@@ -62,36 +54,45 @@ void FlxEventRequests::Request(const FlxEventRequest &NewRequest)
|
||||
}
|
||||
|
||||
// We're going to build a new version of the requests array.
|
||||
TArray<FlxEventRequest> Updated;
|
||||
TArray<FlxInputModeRequest> Updated;
|
||||
|
||||
// Add all high priority requests to the updated array, new request first.
|
||||
if (NewRequest.UseUIOnly) Updated.Add(NewRequest);
|
||||
for (const FlxEventRequest &Req : High)
|
||||
if (IsHigh) Updated.Add(NewRequest);
|
||||
for (const FlxInputModeRequest &Req : High)
|
||||
if (Req.Widget != NewRequest.Widget) Updated.Add(Req);
|
||||
|
||||
// Add all low priority requests to the updated array, new request first.
|
||||
if (!NewRequest.UseUIOnly) Updated.Add(NewRequest);
|
||||
for (const FlxEventRequest &Req : Low)
|
||||
if (!IsHigh) Updated.Add(NewRequest);
|
||||
for (const FlxInputModeRequest &Req : Low)
|
||||
if (Req.Widget != NewRequest.Widget) Updated.Add(Req);
|
||||
|
||||
Swap(Requests, Updated);
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
void FlxEventRequests::Remove(UUserWidget *Widget)
|
||||
void FlxInputModeRequests::EnsureWidget(UUserWidget *Widget)
|
||||
{
|
||||
for (const FlxInputModeRequest &Req : Requests)
|
||||
{
|
||||
if (Req.Widget == Widget) return;
|
||||
}
|
||||
Request(FlxInputModeRequest(Widget, nullptr, false, false));
|
||||
}
|
||||
|
||||
void FlxInputModeRequests::Remove(UUserWidget *Widget)
|
||||
{
|
||||
int32 N = Requests.Num();
|
||||
Requests.RemoveAll([Widget](const FlxEventRequest &Entry)
|
||||
Requests.RemoveAll([Widget](const FlxInputModeRequest &Entry)
|
||||
{
|
||||
return Entry.Widget == Widget;
|
||||
});
|
||||
if (Requests.Num() < N) Dirty = true;
|
||||
}
|
||||
|
||||
void FlxEventRequests::GarbageCollect()
|
||||
void FlxInputModeRequests::GarbageCollect()
|
||||
{
|
||||
int32 N = Requests.Num();
|
||||
Requests.RemoveAll([](const FlxEventRequest &Entry)
|
||||
Requests.RemoveAll([](const FlxInputModeRequest &Entry)
|
||||
{
|
||||
UUserWidget *W = Entry.Widget;
|
||||
return W == nullptr || !IsValid(W) || W->GetParent() == nullptr;
|
||||
@@ -99,14 +100,3 @@ void FlxEventRequests::GarbageCollect()
|
||||
if (Requests.Num() < N) Dirty = true;
|
||||
}
|
||||
|
||||
FlxEventRequests::InputMode FlxEventRequests::GetRequestedMode() const
|
||||
{
|
||||
if ((Requests.Num() > 0) && (Requests[0].UseUIOnly))
|
||||
{
|
||||
return InputMode::UIOnly;
|
||||
}
|
||||
else
|
||||
{
|
||||
return InputMode::GameOnly;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user