diff --git a/Source/Integration/PromptWidget.cpp b/Source/Integration/PromptWidget.cpp index 64df2669..f5d04800 100644 --- a/Source/Integration/PromptWidget.cpp +++ b/Source/Integration/PromptWidget.cpp @@ -17,66 +17,57 @@ // Row 7: Space Bar, unused, unused, unused // Row 8: unused, unused, unused, unused. -void UlxPromptWidget::CalcAppearance(int32& OutIcon, FString& OutGlyph) const +int32 UlxPromptWidget::ChooseIcon(bool Playstation, FKey Key) const +{ + // Mouse buttons (row 1) + if (Key == EKeys::LeftMouseButton) return 1; + if (Key == EKeys::MiddleMouseButton) return 2; + if (Key == EKeys::RightMouseButton) return 3; + + // Gamepad triggers and shoulders (row 2) + if (Key == EKeys::Gamepad_LeftTrigger) return 4; + if (Key == EKeys::Gamepad_RightTrigger) return 5; + if (Key == EKeys::Gamepad_LeftShoulder) return 6; + if (Key == EKeys::Gamepad_RightShoulder) return 7; + + // Gamepad Face buttons (rows 3 and 4) + if (Key == EKeys::Gamepad_FaceButton_Bottom) return Playstation ? 12 : 8; + if (Key == EKeys::Gamepad_FaceButton_Left) return Playstation ? 13 : 9; + if (Key == EKeys::Gamepad_FaceButton_Top) return Playstation ? 14 : 10; + if (Key == EKeys::Gamepad_FaceButton_Right) return Playstation ? 15 : 11; + + // Arrow keys (row 5) + if (Key == EKeys::Down) return 16; + if (Key == EKeys::Left) return 17; + if (Key == EKeys::Up) return 18; + if (Key == EKeys::Right) return 19; + + // Gamepad D-Pad (row 6) + if (Key == EKeys::Gamepad_DPad_Down) return 20; + if (Key == EKeys::Gamepad_DPad_Left) return 21; + if (Key == EKeys::Gamepad_DPad_Up) return 22; + if (Key == EKeys::Gamepad_DPad_Right) return 23; + + // Space bar (row 7) + if (Key == EKeys::SpaceBar) return 24; + + // No icon for this key. Use the blank icon with a label. + return 0; +} + +void UlxPromptWidget::ChooseAppearance(int32 &OutIcon, FString &OutGlyph) { UWorld* World = GetWorld(); APlayerController* PC = World ? World->GetFirstPlayerController() : nullptr; AlxPlayerControllerBase* LPC = Cast(PC); ElxInputMode Mode = LPC ? LPC->CurrentInputMode : ElxInputMode::KeyboardMouse; - if (Mode == ElxInputMode::KeyboardMouse) - { - CalcKeyboardAppearance(OutIcon, OutGlyph); - } - else - { - CalcGamepadAppearance(Mode, OutIcon, OutGlyph); - } -} -void UlxPromptWidget::CalcKeyboardAppearance(int32& OutIcon, FString& OutGlyph) const -{ - // Fixed-icon keys: no glyph needed. - if (KeyboardKey == EKeys::LeftMouseButton) { OutIcon = 1; OutGlyph = TEXT(""); return; } - if (KeyboardKey == EKeys::MiddleMouseButton) { OutIcon = 2; OutGlyph = TEXT(""); return; } - if (KeyboardKey == EKeys::RightMouseButton) { OutIcon = 3; OutGlyph = TEXT(""); return; } - if (KeyboardKey == EKeys::SpaceBar) { OutIcon = 24; OutGlyph = TEXT(""); return; } - if (KeyboardKey == EKeys::Down) { OutIcon = 16; OutGlyph = TEXT(""); return; } - if (KeyboardKey == EKeys::Left) { OutIcon = 17; OutGlyph = TEXT(""); return; } - if (KeyboardKey == EKeys::Up) { OutIcon = 18; OutGlyph = TEXT(""); return; } - if (KeyboardKey == EKeys::Right) { OutIcon = 19; OutGlyph = TEXT(""); return; } + FKey Key = (Mode == ElxInputMode::KeyboardMouse) ? KeyboardKey : GamepadKey; - // Generic keyboard key: blank icon with the key name as glyph. - OutIcon = 0; - OutGlyph = KeyboardKey.GetDisplayName().ToString(); -} - -void UlxPromptWidget::CalcGamepadAppearance(ElxInputMode Mode, int32& OutIcon, FString& OutGlyph) const -{ - OutGlyph = TEXT(""); - - // Triggers and shoulders. - if (GamepadKey == EKeys::Gamepad_LeftTrigger) { OutIcon = 4; return; } - if (GamepadKey == EKeys::Gamepad_RightTrigger) { OutIcon = 5; return; } - if (GamepadKey == EKeys::Gamepad_LeftShoulder) { OutIcon = 6; return; } - if (GamepadKey == EKeys::Gamepad_RightShoulder) { OutIcon = 7; return; } - - // Face buttons — Xbox vs PlayStation. - bool bPS = (Mode == ElxInputMode::PlayStationGamepad); - if (GamepadKey == EKeys::Gamepad_FaceButton_Bottom) { OutIcon = bPS ? 12 : 8; return; } - if (GamepadKey == EKeys::Gamepad_FaceButton_Left) { OutIcon = bPS ? 13 : 9; return; } - if (GamepadKey == EKeys::Gamepad_FaceButton_Top) { OutIcon = bPS ? 14 : 10; return; } - if (GamepadKey == EKeys::Gamepad_FaceButton_Right) { OutIcon = bPS ? 15 : 11; return; } - - // DPad. - if (GamepadKey == EKeys::Gamepad_DPad_Down) { OutIcon = 20; return; } - if (GamepadKey == EKeys::Gamepad_DPad_Left) { OutIcon = 21; return; } - if (GamepadKey == EKeys::Gamepad_DPad_Up) { OutIcon = 22; return; } - if (GamepadKey == EKeys::Gamepad_DPad_Right) { OutIcon = 23; return; } - - // Fallback: blank key with name. - OutIcon = 0; - OutGlyph = GamepadKey.GetDisplayName().ToString(); + OutIcon = ChooseIcon(Mode == ElxInputMode::PlayStationGamepad, Key); + if (OutIcon == 0) OutGlyph = Key.GetDisplayName().ToString(); + else OutGlyph = TEXT(""); } FBox2f UlxPromptWidget::GetIconUVs(int32 IconIndex) @@ -104,7 +95,7 @@ void UlxPromptWidget::SynchronizeProperties() int32 Icon = 0; FString Glyph; - CalcAppearance(Icon, Glyph); + ChooseAppearance(Icon, Glyph); MyBrush.SetUVRegion(GetIconUVs(Icon)); MyImage->InvalidateImage(); @@ -125,34 +116,46 @@ void UlxPromptWidget::SynchronizeProperties() void UlxPromptWidget::SetSize(FVector2D InSize) { - Size = InSize; - SynchronizeProperties(); + if (Size != InSize) + { + Size = InSize; + SynchronizeProperties(); + } } void UlxPromptWidget::SetGlyphMargins(FMargin InMargins) { - GlyphMargins = InMargins; - SynchronizeProperties(); + if (GlyphMargins != InMargins) + { + GlyphMargins = InMargins; + SynchronizeProperties(); + } } void UlxPromptWidget::SetGlyphColor(FLinearColor InColor) { - GlyphColor = InColor; - SynchronizeProperties(); + if (GlyphColor != InColor) + { + GlyphColor = InColor; + SynchronizeProperties(); + } } void UlxPromptWidget::SetKeys(FKey InGamepadKey, FKey InKeyboardKey) { - GamepadKey = InGamepadKey; - KeyboardKey = InKeyboardKey; - SynchronizeProperties(); + if ((GamepadKey != InGamepadKey) || (KeyboardKey != InKeyboardKey)) + { + GamepadKey = InGamepadKey; + KeyboardKey = InKeyboardKey; + SynchronizeProperties(); + } } TSharedRef UlxPromptWidget::RebuildWidget() { int32 Icon = 0; FString Glyph; - CalcAppearance(Icon, Glyph); + ChooseAppearance(Icon, Glyph); MyBrush.SetResourceObject(ButtonAtlas); MyBrush.ImageSize = Size; diff --git a/Source/Integration/PromptWidget.h b/Source/Integration/PromptWidget.h index e2875b79..34b5933d 100644 --- a/Source/Integration/PromptWidget.h +++ b/Source/Integration/PromptWidget.h @@ -61,7 +61,6 @@ private: FBox2f GetIconUVs(int32 IconIndex); FMargin GetScaledMargins() const; - void CalcAppearance(int32& OutIcon, FString& OutGlyph) const; - void CalcKeyboardAppearance(int32& OutIcon, FString& OutGlyph) const; - void CalcGamepadAppearance(ElxInputMode Mode, int32& OutIcon, FString& OutGlyph) const; + int32 ChooseIcon(bool Playstation, FKey Key) const; + void ChooseAppearance(int32 &OutIcon, FString &OutGlyph); };