More work on Prompt Widget

This commit is contained in:
2026-05-07 04:11:37 -04:00
parent b5e121f884
commit 236693fca6
7 changed files with 193 additions and 37 deletions

View File

@@ -1,8 +1,6 @@
#include "PromptWidget.h"
#include "UtilityLibrary.h"
#include "PlayerControllerBase.h"
#include "Engine/Engine.h"
#include "GameFramework/InputDeviceSubsystem.h"
#include "InputAction.h"
#include "InputMappingContext.h"
#include "Widgets/SOverlay.h"
@@ -22,6 +20,7 @@
// Row 7: Space Bar, unused, unused, unused
// Row 8: unused, unused, unused, unused.
int32 UlxPromptWidget::ChooseIcon(bool Playstation, FKey Key) const
{
// Mouse buttons (row 1)
@@ -68,15 +67,6 @@ void UlxPromptWidget::ChooseAppearance(int32 &OutIcon, FString &OutGlyph)
else OutGlyph = TEXT("");
}
void UlxPromptWidget::OnHardwareDeviceChanged(const FPlatformUserId UserId, const FInputDeviceId DeviceId)
{
ElxControllerType Type = UlxUtilityLibrary::DetectControllerType(GetOwningLocalPlayer());
if (ControllerType != Type)
{
ControllerType = Type;
SynchronizeProperties();
}
}
FBox2f UlxPromptWidget::GetIconUVs(int32 IconIndex)
{
@@ -202,15 +192,23 @@ void UlxPromptWidget::SetKeysFromBindings(const UInputMappingContext* InputMappi
SetKeys(NewGamepadKey, NewKeyboardKey);
}
bool UlxPromptWidget::OnTick(float DeltaTime)
{
ElxControllerType Type = UlxUtilityLibrary::DetectControllerType(GetOwningLocalPlayer());
if (ControllerType != Type)
{
ControllerType = Type;
SynchronizeProperties();
}
return true;
}
TSharedRef<SWidget> UlxPromptWidget::RebuildWidget()
{
if (!IsDesignTime())
{
ControllerType = UlxUtilityLibrary::DetectControllerType(GetOwningLocalPlayer());
if (UInputDeviceSubsystem* IDS = GEngine->GetEngineSubsystem<UInputDeviceSubsystem>())
{
IDS->OnInputHardwareDeviceChanged.AddDynamic(this, &UlxPromptWidget::OnHardwareDeviceChanged);
}
TickHandle = FTSTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateUObject(this, &UlxPromptWidget::OnTick));
}
MyBrush.SetResourceObject(ButtonAtlas.Get());
@@ -240,10 +238,7 @@ void UlxPromptWidget::ReleaseSlateResources(bool bReleaseChildren)
Super::ReleaseSlateResources(bReleaseChildren);
if (!IsDesignTime())
{
if (UInputDeviceSubsystem* IDS = GEngine->GetEngineSubsystem<UInputDeviceSubsystem>())
{
IDS->OnInputHardwareDeviceChanged.RemoveDynamic(this, &UlxPromptWidget::OnHardwareDeviceChanged);
}
FTSTicker::GetCoreTicker().RemoveTicker(TickHandle);
}
MyBox.Reset();
MyOverlay.Reset();