More work on prompt widget
This commit is contained in:
@@ -17,66 +17,57 @@
|
|||||||
// Row 7: Space Bar, unused, unused, unused
|
// Row 7: Space Bar, unused, unused, unused
|
||||||
// Row 8: unused, 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();
|
UWorld* World = GetWorld();
|
||||||
APlayerController* PC = World ? World->GetFirstPlayerController() : nullptr;
|
APlayerController* PC = World ? World->GetFirstPlayerController() : nullptr;
|
||||||
AlxPlayerControllerBase* LPC = Cast<AlxPlayerControllerBase>(PC);
|
AlxPlayerControllerBase* LPC = Cast<AlxPlayerControllerBase>(PC);
|
||||||
|
|
||||||
ElxInputMode Mode = LPC ? LPC->CurrentInputMode : ElxInputMode::KeyboardMouse;
|
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
|
FKey Key = (Mode == ElxInputMode::KeyboardMouse) ? KeyboardKey : GamepadKey;
|
||||||
{
|
|
||||||
// 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; }
|
|
||||||
|
|
||||||
// Generic keyboard key: blank icon with the key name as glyph.
|
OutIcon = ChooseIcon(Mode == ElxInputMode::PlayStationGamepad, Key);
|
||||||
OutIcon = 0;
|
if (OutIcon == 0) OutGlyph = Key.GetDisplayName().ToString();
|
||||||
OutGlyph = KeyboardKey.GetDisplayName().ToString();
|
else OutGlyph = TEXT("");
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FBox2f UlxPromptWidget::GetIconUVs(int32 IconIndex)
|
FBox2f UlxPromptWidget::GetIconUVs(int32 IconIndex)
|
||||||
@@ -104,7 +95,7 @@ void UlxPromptWidget::SynchronizeProperties()
|
|||||||
|
|
||||||
int32 Icon = 0;
|
int32 Icon = 0;
|
||||||
FString Glyph;
|
FString Glyph;
|
||||||
CalcAppearance(Icon, Glyph);
|
ChooseAppearance(Icon, Glyph);
|
||||||
|
|
||||||
MyBrush.SetUVRegion(GetIconUVs(Icon));
|
MyBrush.SetUVRegion(GetIconUVs(Icon));
|
||||||
MyImage->InvalidateImage();
|
MyImage->InvalidateImage();
|
||||||
@@ -125,34 +116,46 @@ void UlxPromptWidget::SynchronizeProperties()
|
|||||||
|
|
||||||
void UlxPromptWidget::SetSize(FVector2D InSize)
|
void UlxPromptWidget::SetSize(FVector2D InSize)
|
||||||
{
|
{
|
||||||
Size = InSize;
|
if (Size != InSize)
|
||||||
SynchronizeProperties();
|
{
|
||||||
|
Size = InSize;
|
||||||
|
SynchronizeProperties();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UlxPromptWidget::SetGlyphMargins(FMargin InMargins)
|
void UlxPromptWidget::SetGlyphMargins(FMargin InMargins)
|
||||||
{
|
{
|
||||||
GlyphMargins = InMargins;
|
if (GlyphMargins != InMargins)
|
||||||
SynchronizeProperties();
|
{
|
||||||
|
GlyphMargins = InMargins;
|
||||||
|
SynchronizeProperties();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UlxPromptWidget::SetGlyphColor(FLinearColor InColor)
|
void UlxPromptWidget::SetGlyphColor(FLinearColor InColor)
|
||||||
{
|
{
|
||||||
GlyphColor = InColor;
|
if (GlyphColor != InColor)
|
||||||
SynchronizeProperties();
|
{
|
||||||
|
GlyphColor = InColor;
|
||||||
|
SynchronizeProperties();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UlxPromptWidget::SetKeys(FKey InGamepadKey, FKey InKeyboardKey)
|
void UlxPromptWidget::SetKeys(FKey InGamepadKey, FKey InKeyboardKey)
|
||||||
{
|
{
|
||||||
GamepadKey = InGamepadKey;
|
if ((GamepadKey != InGamepadKey) || (KeyboardKey != InKeyboardKey))
|
||||||
KeyboardKey = InKeyboardKey;
|
{
|
||||||
SynchronizeProperties();
|
GamepadKey = InGamepadKey;
|
||||||
|
KeyboardKey = InKeyboardKey;
|
||||||
|
SynchronizeProperties();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TSharedRef<SWidget> UlxPromptWidget::RebuildWidget()
|
TSharedRef<SWidget> UlxPromptWidget::RebuildWidget()
|
||||||
{
|
{
|
||||||
int32 Icon = 0;
|
int32 Icon = 0;
|
||||||
FString Glyph;
|
FString Glyph;
|
||||||
CalcAppearance(Icon, Glyph);
|
ChooseAppearance(Icon, Glyph);
|
||||||
|
|
||||||
MyBrush.SetResourceObject(ButtonAtlas);
|
MyBrush.SetResourceObject(ButtonAtlas);
|
||||||
MyBrush.ImageSize = Size;
|
MyBrush.ImageSize = Size;
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ private:
|
|||||||
|
|
||||||
FBox2f GetIconUVs(int32 IconIndex);
|
FBox2f GetIconUVs(int32 IconIndex);
|
||||||
FMargin GetScaledMargins() const;
|
FMargin GetScaledMargins() const;
|
||||||
void CalcAppearance(int32& OutIcon, FString& OutGlyph) const;
|
int32 ChooseIcon(bool Playstation, FKey Key) const;
|
||||||
void CalcKeyboardAppearance(int32& OutIcon, FString& OutGlyph) const;
|
void ChooseAppearance(int32 &OutIcon, FString &OutGlyph);
|
||||||
void CalcGamepadAppearance(ElxInputMode Mode, int32& OutIcon, FString& OutGlyph) const;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user