From 78c85660c992c52d9792165279645bc9a72936a5 Mon Sep 17 00:00:00 2001 From: jyelon Date: Mon, 4 May 2026 15:52:05 -0400 Subject: [PATCH] Prompt widget is pretty good now --- Content/Widgets/WB_Hotkey_Image.uasset | 4 +-- Source/Integration/PromptWidget.cpp | 45 +++++++++++++++----------- Source/Integration/PromptWidget.h | 9 ++++++ 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/Content/Widgets/WB_Hotkey_Image.uasset b/Content/Widgets/WB_Hotkey_Image.uasset index 1a66f36a..cbeb26fe 100644 --- a/Content/Widgets/WB_Hotkey_Image.uasset +++ b/Content/Widgets/WB_Hotkey_Image.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a00d2efc8527f8098b87ce787da061302f1881018b6b9b5f549648d96b74f22d -size 49505 +oid sha256:ca22cd1c0df43b4842564e21f69a36429ce3288f50a281b8069669b9a4236355 +size 48775 diff --git a/Source/Integration/PromptWidget.cpp b/Source/Integration/PromptWidget.cpp index 2bf6c98a..3922f707 100644 --- a/Source/Integration/PromptWidget.cpp +++ b/Source/Integration/PromptWidget.cpp @@ -109,8 +109,12 @@ void UlxPromptWidget::SynchronizeProperties() MyBrush.SetUVRegion(GetIconUVs(Icon)); MyImage->InvalidateImage(); - MyImage->SetDesiredSizeOverride(Size); - MyGlyphSlot->SetPadding(GetScaledMargins()); + MyBox->SetWidthOverride(Size.X); + MyBox->SetHeightOverride(Size.Y); + const float Extra = Depressed ? 0.05f : 0.0f; + const FMargin ExtraPadding(Extra * Size.X, Extra * Size.Y, Extra * Size.X, Extra * Size.Y); + MyImageSlot->SetPadding(ExtraPadding); + MyGlyphSlot->SetPadding(GetScaledMargins() + ExtraPadding); MyGlyph->SetColorAndOpacity(GlyphColor); if (!Glyph.IsEmpty()) @@ -151,6 +155,15 @@ void UlxPromptWidget::SetGlyphColor(FLinearColor InColor) } } +void UlxPromptWidget::SetDepressed(bool InDepressed) +{ + if (Depressed != InDepressed) + { + Depressed = InDepressed; + SynchronizeProperties(); + } +} + void UlxPromptWidget::SetKeys(FKey InGamepadKey, FKey InKeyboardKey) { if ((GamepadKey != InGamepadKey) || (KeyboardKey != InKeyboardKey)) @@ -200,32 +213,26 @@ TSharedRef UlxPromptWidget::RebuildWidget() } } - int32 Icon = 0; - FString Glyph; - ChooseAppearance(Icon, Glyph); - MyBrush.SetResourceObject(ButtonAtlas.Get()); - MyBrush.ImageSize = Size; - MyBrush.SetUVRegion(GetIconUVs(Icon)); SAssignNew(MyImage, SImage).Image(&MyBrush); - EVisibility GlyphVisibility = Glyph.IsEmpty() ? EVisibility::Collapsed : EVisibility::HitTestInvisible; - SAssignNew(MyGlyph, STextBlock) - .Text(FText::FromString(Glyph)) - .ColorAndOpacity(GlyphColor) - .Visibility(GlyphVisibility); + SAssignNew(MyGlyph, STextBlock); SAssignNew(MyScaleBox, SScaleBox) .Stretch(EStretch::ScaleToFit) [ MyGlyph.ToSharedRef() ]; - MyOverlay = SNew(SOverlay) - + SOverlay::Slot() [ MyImage.ToSharedRef() ]; - - MyOverlay->AddSlot().Padding(GetScaledMargins()).HAlign(HAlign_Fill).VAlign(VAlign_Fill).Expose(MyGlyphSlot) + MyOverlay = SNew(SOverlay); + MyOverlay->AddSlot().Expose(MyImageSlot) + [ MyImage.ToSharedRef() ]; + MyOverlay->AddSlot().HAlign(HAlign_Fill).VAlign(VAlign_Fill).Expose(MyGlyphSlot) [ MyScaleBox.ToSharedRef() ]; - return MyOverlay.ToSharedRef(); + SAssignNew(MyBox, SBox) + [ MyOverlay.ToSharedRef() ]; + + SynchronizeProperties(); + return MyBox.ToSharedRef(); } void UlxPromptWidget::ReleaseSlateResources(bool bReleaseChildren) @@ -238,9 +245,11 @@ void UlxPromptWidget::ReleaseSlateResources(bool bReleaseChildren) IDS->OnInputHardwareDeviceChanged.RemoveDynamic(this, &UlxPromptWidget::OnHardwareDeviceChanged); } } + MyBox.Reset(); MyOverlay.Reset(); MyImage.Reset(); MyScaleBox.Reset(); MyGlyph.Reset(); + MyImageSlot = nullptr; MyGlyphSlot = nullptr; } diff --git a/Source/Integration/PromptWidget.h b/Source/Integration/PromptWidget.h index 0887f115..bf1c7aba 100644 --- a/Source/Integration/PromptWidget.h +++ b/Source/Integration/PromptWidget.h @@ -5,6 +5,7 @@ #include "Components/Widget.h" #include "InputCoreTypes.h" #include "Widgets/SOverlay.h" +#include "Widgets/Layout/SBox.h" #include "Widgets/Layout/SScaleBox.h" #include "PromptWidget.generated.h" @@ -39,6 +40,9 @@ public: UPROPERTY(EditAnywhere, Setter, Category="Prompt") FLinearColor GlyphColor = FLinearColor::White; + UPROPERTY(EditAnywhere, Setter, Category="Prompt") + bool Depressed = false; + public: UFUNCTION(BlueprintCallable, Category="Prompt") void SetKeys(FKey InGamepadKey, FKey InKeyboardKey); @@ -55,6 +59,9 @@ public: UFUNCTION(BlueprintCallable, Category="Prompt") void SetSize(FVector2D InSize); + UFUNCTION(BlueprintCallable, Category="Prompt") + void SetDepressed(bool InDepressed); + UFUNCTION() void OnHardwareDeviceChanged(const FPlatformUserId UserId, const FInputDeviceId DeviceId); @@ -65,10 +72,12 @@ protected: private: FSlateBrush MyBrush; + TSharedPtr MyBox; TSharedPtr MyOverlay; TSharedPtr MyImage; TSharedPtr MyScaleBox; TSharedPtr MyGlyph; + SOverlay::FOverlaySlot* MyImageSlot = nullptr; SOverlay::FOverlaySlot* MyGlyphSlot = nullptr; FBox2f GetIconUVs(int32 IconIndex);