Files
PHY/Source/PHY/Private/UI/Synty/Synty_ProgressBar.cpp
2026-03-03 14:49:01 +08:00

66 lines
1.7 KiB
C++

//
#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);
}