Files
BusyRabbit/Script/ManagedBusyRabbit/UI/Level/StateBar/BusyHealthBar.cs
2025-10-28 23:51:17 +08:00

71 lines
2.0 KiB
C#

using UnrealSharp.Attributes;
using UnrealSharp.BusyRabbit;
using UnrealSharp.UMG;
namespace UI.Level.StateBar;
[UClass]
public class UBusyWidgetHealthBar : UPW_MinimalWidget
{
[UProperty(PropertyFlags.EditAnywhere)]
public float Percent { get; set; }
[UProperty(PropertyFlags.EditAnywhere)]
public float Test { get; set; }
protected UProgressBar? HpBarHurt { get { return GetWidget("HpBarHurt") as UProgressBar; } }
protected UProgressBar? HpBarHealth { get { return GetWidget("HpBarHealth") as UProgressBar; } }
protected UProgressBar? HpBarNormal { get { return GetWidget("HpBarNormal") as UProgressBar; } }
protected USizeBox ? SizeboxMain { get { return GetWidget("SizeboxMain") as USizeBox; } }
[UProperty(PropertyFlags.EditAnywhere)]
public float MaxHp { get; set; }
[UProperty(PropertyFlags.EditAnywhere)]
public float CurHp { get; set; }
[UProperty(PropertyFlags.EditAnywhere)]
public float Width { get; set; }
[UProperty(PropertyFlags.EditAnywhere)]
public float Height { get; set; }
protected float LastHp = 200;
public override void PreConstruct(bool isDesignTime)
{
SetHpConfig(CurHp, MaxHp);
RefreshHealthBarDisplay();
}
public override void Construct()
{
base.Construct();
SetHpConfig(180, 200);
}
public void SetHpConfig(float CurHp, float MaxHp)
{
LastHp = CurHp;
this.CurHp = CurHp;
this.MaxHp = MaxHp;
RefreshHealthBarDisplay();
}
protected void RefreshHealthBarDisplay()
{
if (HpBarHealth == null || HpBarHurt == null || HpBarNormal == null || SizeboxMain == null)
{
return;
}
HpBarHurt.Visibility = ESlateVisibility.Collapsed;
HpBarHealth.Visibility = ESlateVisibility.Collapsed;
HpBarNormal.Percent = MaxHp != 0 ? (CurHp / MaxHp) : 0;
SizeboxMain.WidthOverride = Width;
SizeboxMain.HeightOverride = Height;
}
}