添加了进度条
This commit is contained in:
65
Source/PHY/Private/UI/Synty/Synty_ProgressBar.cpp
Normal file
65
Source/PHY/Private/UI/Synty/Synty_ProgressBar.cpp
Normal file
@@ -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);
|
||||||
|
}
|
||||||
62
Source/PHY/Private/UI/Synty/Synty_ProgressBar.h
Normal file
62
Source/PHY/Private/UI/Synty/Synty_ProgressBar.h
Normal file
@@ -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<EProgressBarFillStyle::Type> 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);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user