118 lines
2.8 KiB
C++
118 lines
2.8 KiB
C++
////////////////////////////////////////////////////////////
|
|
//
|
|
// InputModeRequest.cpp
|
|
//
|
|
////////////////////////////////////////////////////////////
|
|
|
|
#include "InputModeRequest.h"
|
|
#include "Common.h"
|
|
|
|
bool FlxInputModeRequest::operator<(const FlxInputModeRequest &Other) const
|
|
{
|
|
// The highest priority request goes to the front of the array.
|
|
// Therefore, in this context, 'less than' means 'higher priority'.
|
|
// It's a little confusing.
|
|
if (ShowPointer != Other.ShowPointer) return ShowPointer > Other.ShowPointer;
|
|
return SequenceNumber > Other.SequenceNumber;
|
|
}
|
|
|
|
bool FlxInputModeRequest::operator==(const FlxInputModeRequest &Other) const
|
|
{
|
|
return (Widget == Other.Widget) &&
|
|
(Focus == Other.Focus) &&
|
|
(ShowPointer == Other.ShowPointer) &&
|
|
(BlockInput == Other.BlockInput) &&
|
|
(EnableInputComponent == Other.EnableInputComponent);
|
|
}
|
|
|
|
bool FlxInputModeRequests::SanityCheck(const FlxInputModeRequest &Request)
|
|
{
|
|
if (Request.Widget == nullptr)
|
|
{
|
|
UE_LOG(LogLuprexIntegration, Error, TEXT("RequestEvents called with null widget."));
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
int32 FlxInputModeRequests::FindWidget(UUserWidget *Widget)
|
|
{
|
|
for (const FlxInputModeRequest &Req : Requests)
|
|
{
|
|
if (Req.Widget == Widget) return &Req - Requests.GetData();
|
|
}
|
|
return Requests.Num();
|
|
}
|
|
|
|
void FlxInputModeRequests::BubbleItem(int32 Index)
|
|
{
|
|
while ((Index > 0) && (Requests[Index] < Requests[Index - 1]))
|
|
{
|
|
Swap(Requests[Index], Requests[Index - 1]);
|
|
--Index;
|
|
}
|
|
while ((Index < Requests.Num() - 1) && (Requests[Index + 1] < Requests[Index]))
|
|
{
|
|
Swap(Requests[Index], Requests[Index + 1]);
|
|
++Index;
|
|
}
|
|
}
|
|
|
|
void FlxInputModeRequests::Request(const FlxInputModeRequest &NewRequest, bool UpdateSequence)
|
|
{
|
|
int32 Index = FindWidget(NewRequest.Widget);
|
|
|
|
if (Index == Requests.Num())
|
|
{
|
|
Requests.Emplace(NewRequest);
|
|
Requests[Index].SequenceNumber = ++NextSequenceNumber;
|
|
}
|
|
else
|
|
{
|
|
int32 SequenceNumber = Requests[Index].SequenceNumber;
|
|
if (UpdateSequence) SequenceNumber = ++NextSequenceNumber;
|
|
Requests[Index] = NewRequest;
|
|
Requests[Index].SequenceNumber = SequenceNumber;
|
|
}
|
|
|
|
BubbleItem(Index);
|
|
}
|
|
|
|
void FlxInputModeRequests::SetEnableInputComponent(UUserWidget *Widget, bool EnableInputComponent)
|
|
{
|
|
int32 Index = FindWidget(Widget);
|
|
|
|
if (Index == Requests.Num())
|
|
{
|
|
FlxInputModeRequest NewReq;
|
|
NewReq.Widget = Widget;
|
|
NewReq.EnableInputComponent = EnableInputComponent;
|
|
NewReq.SequenceNumber = ++NextSequenceNumber;
|
|
Requests.Emplace(NewReq);
|
|
}
|
|
else
|
|
{
|
|
Requests[Index].EnableInputComponent = EnableInputComponent;
|
|
}
|
|
|
|
BubbleItem(Index);
|
|
}
|
|
|
|
void FlxInputModeRequests::Remove(UUserWidget *Widget)
|
|
{
|
|
Requests.RemoveAll([Widget](const FlxInputModeRequest &Entry)
|
|
{
|
|
return Entry.Widget == Widget;
|
|
});
|
|
}
|
|
|
|
void FlxInputModeRequests::GarbageCollect()
|
|
{
|
|
Requests.RemoveAll([](const FlxInputModeRequest &Entry)
|
|
{
|
|
return !IsValid(Entry.Widget);
|
|
});
|
|
}
|
|
|