Prompt widget is pretty good now

This commit is contained in:
2026-05-04 15:52:05 -04:00
parent 3e7e6a2ae4
commit 78c85660c9
3 changed files with 38 additions and 20 deletions

View File

@@ -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<SWidget> 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;
}