Prompt widget is pretty good now
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<SBox> MyBox;
|
||||
TSharedPtr<SOverlay> MyOverlay;
|
||||
TSharedPtr<SImage> MyImage;
|
||||
TSharedPtr<SScaleBox> MyScaleBox;
|
||||
TSharedPtr<STextBlock> MyGlyph;
|
||||
SOverlay::FOverlaySlot* MyImageSlot = nullptr;
|
||||
SOverlay::FOverlaySlot* MyGlyphSlot = nullptr;
|
||||
|
||||
FBox2f GetIconUVs(int32 IconIndex);
|
||||
|
||||
Reference in New Issue
Block a user