Player controller code to sort input components better: widgets with 'Stop Input' go to top of priority stack, and also, priority actually works now.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include "Common.h"
|
||||
#include "Tangible.h"
|
||||
#include "TangibleManager.h"
|
||||
#include "Components/InputComponent.h"
|
||||
#include "Engine/LevelScriptActor.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Engine/GameInstance.h"
|
||||
|
||||
@@ -53,6 +55,99 @@ FVector2D AlxPlayerControllerBase::GetLookAtPixel(const UObject *Context)
|
||||
return ScreenPosition;
|
||||
}
|
||||
|
||||
void AlxPlayerControllerBase::PushInputComponent(UInputComponent* InInputComponent)
|
||||
{
|
||||
if (InInputComponent)
|
||||
{
|
||||
CurrentInputStack.RemoveSingle(InInputComponent);
|
||||
CurrentInputStack.Add(InInputComponent);
|
||||
}
|
||||
}
|
||||
|
||||
bool AlxPlayerControllerBase::PopInputComponent(UInputComponent* InInputComponent)
|
||||
{
|
||||
if (InInputComponent)
|
||||
{
|
||||
if (CurrentInputStack.RemoveSingle(InInputComponent) > 0)
|
||||
{
|
||||
InInputComponent->ClearBindingValues();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AlxPlayerControllerBase::BuildInputStack(TArray<UInputComponent*>& InputStack)
|
||||
{
|
||||
// Controlled pawn gets last dibs on the input stack
|
||||
APawn* ControlledPawn = GetPawnOrSpectator();
|
||||
if (ControlledPawn)
|
||||
{
|
||||
if (ControlledPawn->InputEnabled())
|
||||
{
|
||||
// Get the explicit input component that is created upon Pawn possession. This one gets last dibs.
|
||||
if (ControlledPawn->InputComponent)
|
||||
{
|
||||
InputStack.Push(ControlledPawn->InputComponent);
|
||||
}
|
||||
|
||||
// See if there is another InputComponent that was added to the Pawn's components array (possibly by script).
|
||||
for (UActorComponent* ActorComponent : ControlledPawn->GetComponents())
|
||||
{
|
||||
UInputComponent* PawnInputComponent = Cast<UInputComponent>(ActorComponent);
|
||||
if (PawnInputComponent && PawnInputComponent != ControlledPawn->InputComponent)
|
||||
{
|
||||
InputStack.Push(PawnInputComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// LevelScriptActors are put on the stack next
|
||||
for (ULevel* Level : GetWorld()->GetLevels())
|
||||
{
|
||||
ALevelScriptActor* ScriptActor = Level->GetLevelScriptActor();
|
||||
if (ScriptActor)
|
||||
{
|
||||
if (ScriptActor->InputEnabled() && ScriptActor->InputComponent)
|
||||
{
|
||||
InputStack.Push(ScriptActor->InputComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (InputEnabled())
|
||||
{
|
||||
InputStack.Push(InputComponent);
|
||||
}
|
||||
|
||||
// Sort the components first by bBlockInput, then by
|
||||
// priority. We don't touch the original array, because
|
||||
// we want to preserve information about which component
|
||||
// was pushed last.
|
||||
TArray<UInputComponent*, TInlineAllocator<20>> Pushed;
|
||||
for (int32 Idx = 0; Idx < CurrentInputStack.Num(); ++Idx)
|
||||
{
|
||||
UInputComponent* IC = CurrentInputStack[Idx].Get();
|
||||
if (IsValid(IC))
|
||||
{
|
||||
Pushed.Add(IC);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentInputStack.RemoveAt(Idx--);
|
||||
}
|
||||
}
|
||||
|
||||
Pushed.StableSort([](const UInputComponent& A, const UInputComponent& B)
|
||||
{
|
||||
if (A.bBlockInput != B.bBlockInput) return !A.bBlockInput;
|
||||
return A.Priority < B.Priority;
|
||||
});
|
||||
|
||||
InputStack.Append(Pushed);
|
||||
}
|
||||
|
||||
void AlxPlayerControllerBase::UpdateLookAt()
|
||||
{
|
||||
UlxTangibleManager *TM = GetGameInstance()->GetSubsystem<UlxTangibleManager>();
|
||||
|
||||
@@ -36,6 +36,11 @@ public:
|
||||
// Called by GameMode each tick.
|
||||
void UpdateLookAt();
|
||||
|
||||
// Input stack overrides: unsorted, append-on-push.
|
||||
virtual void PushInputComponent(UInputComponent* InInputComponent) override;
|
||||
virtual bool PopInputComponent(UInputComponent* InInputComponent) override;
|
||||
virtual void BuildInputStack(TArray<UInputComponent*>& InputStack) override;
|
||||
|
||||
// Get the player controller, cast to AlxPlayerControllerBase.
|
||||
static AlxPlayerControllerBase *FromContext(const UObject *Context);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user