More work on Prompt Widget
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Widgets/SOverlay.h"
|
||||
#include "Widgets/Layout/SBox.h"
|
||||
#include "Widgets/Layout/SScaleBox.h"
|
||||
#include "Containers/Ticker.h"
|
||||
#include "PromptWidget.generated.h"
|
||||
|
||||
class UInputAction;
|
||||
@@ -62,8 +63,6 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category="Prompt")
|
||||
void SetDepressed(bool InDepressed);
|
||||
|
||||
UFUNCTION()
|
||||
void OnHardwareDeviceChanged(const FPlatformUserId UserId, const FInputDeviceId DeviceId);
|
||||
|
||||
protected:
|
||||
virtual TSharedRef<SWidget> RebuildWidget() override;
|
||||
@@ -84,4 +83,7 @@ private:
|
||||
FMargin GetScaledMargins() const;
|
||||
int32 ChooseIcon(bool Playstation, FKey Key) const;
|
||||
void ChooseAppearance(int32 &OutIcon, FString &OutGlyph);
|
||||
bool OnTick(float DeltaTime);
|
||||
|
||||
FTSTicker::FDelegateHandle TickHandle;
|
||||
};
|
||||
|
||||
@@ -283,17 +283,12 @@ ElxControllerType UlxUtilityLibrary::DetectControllerType(ULocalPlayer *Player)
|
||||
UInputDeviceSubsystem *IDS = GEngine->GetEngineSubsystem<UInputDeviceSubsystem>();
|
||||
if (!IDS) return ElxControllerType::KeyboardMouse;
|
||||
|
||||
FHardwareDeviceIdentifier Device = IDS->GetMostRecentlyUsedHardwareDevice(Player->GetPlatformUserId());
|
||||
if (Device.PrimaryDeviceType != EHardwareDevicePrimaryType::Gamepad)
|
||||
{
|
||||
return ElxControllerType::KeyboardMouse;
|
||||
}
|
||||
FName Id = IDS->GetMostRecentlyUsedHardwareDevice(Player->GetPlatformUserId()).HardwareDeviceIdentifier;
|
||||
|
||||
FString DeviceName = Device.HardwareDeviceIdentifier.ToString();
|
||||
if (DeviceName.Contains(TEXT("PS4")) || DeviceName.Contains(TEXT("PS5")) || DeviceName.Contains(TEXT("PlayStation")))
|
||||
{
|
||||
return ElxControllerType::PlayStationGamepad;
|
||||
}
|
||||
return ElxControllerType::XboxGamepad;
|
||||
if (Id == TEXT("ps3") || Id == TEXT("ps4") || Id == TEXT("ps5")) return ElxControllerType::PlayStationGamepad;
|
||||
if (Id == TEXT("xbox360") || Id == TEXT("xboxone")) return ElxControllerType::XboxGamepad;
|
||||
|
||||
// Unknown or unrecognized device — assume keyboard/mouse
|
||||
return ElxControllerType::KeyboardMouse;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user