From 8574e8bfb85380fac7f8ecb0e7a798d329022b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E6=98=8E=E4=B8=8D=E6=83=91?= Date: Tue, 3 Mar 2026 14:49:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Private/UI/Synty/Synty_ProgressBar.cpp | 65 +++++++++++++++++++ .../PHY/Private/UI/Synty/Synty_ProgressBar.h | 62 ++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 Source/PHY/Private/UI/Synty/Synty_ProgressBar.cpp create mode 100644 Source/PHY/Private/UI/Synty/Synty_ProgressBar.h diff --git a/Source/PHY/Private/UI/Synty/Synty_ProgressBar.cpp b/Source/PHY/Private/UI/Synty/Synty_ProgressBar.cpp new file mode 100644 index 0000000..2809921 --- /dev/null +++ b/Source/PHY/Private/UI/Synty/Synty_ProgressBar.cpp @@ -0,0 +1,65 @@ +// + + +#include "Synty_ProgressBar.h" + +#include "Components/Image.h" +#include "Components/ProgressBar.h" +#include "Components/SizeBox.h" + +void USynty_ProgressBar::UpdateSheen() const +{ + if (!Image_Sheen) return; + Image_Sheen->SetVisibility(bShowSheen ? ESlateVisibility::Visible : ESlateVisibility::Collapsed); + Image_Sheen->SetBrushFromMaterial(Material_Sheen); + if (Image_Background) + { + Image_Background->SetBrushFromTexture(Texture_Background); + Image_Background->SetBrushTintColor(Color_BackgroundTint); + } +} + +void USynty_ProgressBar::NativePreConstruct() +{ + Super::NativePreConstruct(); + if (SizeBox_Main) + { + if (bOverrideBarSize) + { + SizeBox_Main->SetWidthOverride(BarWidth); + SizeBox_Main->SetHeightOverride(BarHeight); + } + } + if (ProgressBar) + { + ProgressBar->SetBarFillStyle(FillStyle); + ProgressBar->SetPercent(FillAmount); + ProgressBar->SetFillColorAndOpacity(Color_Fill); + if (Image_Background) + { + Image_Background->SetBrushFromTexture(Texture_Background); + Image_Background->SetBrushTintColor(Color_BackgroundTint); + FProgressBarStyle Style = ProgressBar->GetWidgetStyle(); + Style.FillImage.SetResourceObject(Texture_Fill); + ProgressBar->SetWidgetStyle(Style); + UpdateSheen(); + } + } +} + +void USynty_ProgressBar::NativeTick(const FGeometry& MyGeometry, float InDeltaTime) +{ + Super::NativeTick(MyGeometry, InDeltaTime); + if (FillAmount == TargetFillAmount) return; + FillAmount = FMath::FInterpConstantTo(FillAmount, TargetFillAmount, InDeltaTime, FillSpeed); + if (ProgressBar) + { + ProgressBar->SetPercent(FillAmount); + } +} + + +void USynty_ProgressBar::SetTargetFillAmount(const float NewFillAmount) +{ + TargetFillAmount = FMath::Clamp(NewFillAmount, 0.f, 1.f); +} diff --git a/Source/PHY/Private/UI/Synty/Synty_ProgressBar.h b/Source/PHY/Private/UI/Synty/Synty_ProgressBar.h new file mode 100644 index 0000000..7c6d7fe --- /dev/null +++ b/Source/PHY/Private/UI/Synty/Synty_ProgressBar.h @@ -0,0 +1,62 @@ +// + +#pragma once + +#include "CoreMinimal.h" +#include "Blueprint/UserWidget.h" +#include "Widgets/Notifications/SProgressBar.h" +#include "Synty_ProgressBar.generated.h" + +class USizeBox; +class UImage; +class UProgressBar; +/** + * + */ +UCLASS() +class PHY_API USynty_ProgressBar : public UUserWidget +{ + GENERATED_BODY() + + UPROPERTY(meta=(BindWidget)) + UProgressBar* ProgressBar; + UPROPERTY(meta=(BindWidget)) + UImage* Image_Sheen; + UPROPERTY(meta=(BindWidget)) + UImage* Image_Background; + UPROPERTY(meta=(BindWidget)) + USizeBox* SizeBox_Main; + + UPROPERTY(EditAnywhere, Category="Synty|Config") + FLinearColor Color_Fill; + UPROPERTY(EditAnywhere, Category="Synty|Config") + FSlateColor Color_BackgroundTint; + UPROPERTY(EditAnywhere, Category="Synty|Config") + UTexture2D* Texture_Fill; + UPROPERTY(EditAnywhere, Category="Synty|Config") + UTexture2D* Texture_Background; + UPROPERTY(EditAnywhere, Category="Synty|Config") + float FillAmount = 0.5f; + UPROPERTY(EditAnywhere, Category="Synty|Config") + float FillSpeed = 1.0f; + UPROPERTY(EditAnywhere, Category="Synty|Config") + TEnumAsByte FillStyle = EProgressBarFillStyle::Mask; + UPROPERTY(EditAnywhere, Category="Synty|Config") + UMaterialInterface* Material_Sheen; + UPROPERTY(EditAnywhere, Category="Synty|Config") + bool bShowSheen = true; + UPROPERTY(EditAnywhere, Category="Synty|Config") + bool bOverrideBarSize = false; + UPROPERTY(EditAnywhere, Category="Synty|Config", meta=(EditCondition="bOverrideBarSize")) + float BarHeight = 20.0f; + UPROPERTY(EditAnywhere, Category="Synty|Config", meta=(EditCondition="bOverrideBarSize")) + float BarWidth = 200.0f; + + float TargetFillAmount = 1.f; +protected: + void UpdateSheen() const; + virtual void NativePreConstruct() override; + virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override; +public: + void SetTargetFillAmount(float NewFillAmount); +};