UI框架调整,主界面重做 #16

初步调整
This commit is contained in:
2025-10-28 23:51:17 +08:00
parent 60596f2772
commit 239425c47d
40 changed files with 713 additions and 17 deletions

View File

@ -0,0 +1,71 @@
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;
}
}

View File

@ -0,0 +1,36 @@
using UnrealSharp.Engine;
using UnrealSharp.Attributes;
using UnrealSharp.BusyRabbit;
using UnrealSharp.UMG;
namespace UI.Level.StateBar;
[UClass]
public class UBusyWidgetSatietyBar : UPW_MinimalWidget
{
protected UProgressBar? SatietyBar { get { return GetWidget("SatietyBar") as UProgressBar; } }
protected float CurrSatiety;
protected float MaxSatiety;
public void SetSatietyConfig(float CurrSatiety, float MaxSatiety)
{
this.MaxSatiety = MaxSatiety;
this.CurrSatiety = CurrSatiety;
RefreshDisplay();
}
public void OnSatietyChanged(float CurSatiety)
{
this.CurrSatiety = CurSatiety;
RefreshDisplay();
}
public void RefreshDisplay()
{
float Percent = MaxSatiety > 0 ? CurrSatiety / MaxSatiety : 0;
if (SatietyBar != null)
{
SatietyBar.Percent = Percent;
}
}
}

View File

@ -0,0 +1,55 @@
using UnrealSharp.Engine;
using UI.Level.Controllers;
using UnrealSharp.Attributes;
using UnrealSharp.BusyRabbit;
using UnrealSharp;
namespace UI.Level.StateBar;
[UClass]
public class UBusyWidgetStateBar : UPW_MinimalWidget
{
protected UBusyWidgetHealthBar? WBP_HealthBar { get { return GetWidget("WBP_HealthBar") as UBusyWidgetHealthBar; } }
protected UBusyWidgetSatietyBar? WBP_SatietyBar { get { return GetWidget("WBP_SatietyBar") as UBusyWidgetSatietyBar; } }
protected UBusyRoleStateController? UIController;
public override void Construct()
{
base.Construct();
WBP_SatietyBar.SetSatietyConfig(100, 200);
UIController = UUIFunctionLibrary.GetUIController(this, "RoleState") as UBusyRoleStateController;
InitRoleAttribute();
UIController.OnAttributeChangeDelegate += OnAttributeChanged;
}
public void InitRoleAttribute()
{
float CurHealth = UIController.GetControlledAttribute("Health");
float MaxHealth = UIController.GetControlledAttribute("MaxHealth");
float CurSatiety = UIController.GetControlledAttribute("Hunger");
float MaxSatiety = UIController.GetControlledAttribute("MaxHunger");
WBP_HealthBar.SetHpConfig(CurHealth, MaxHealth);
WBP_SatietyBar.SetSatietyConfig(CurSatiety, MaxSatiety);
}
public override void Destruct()
{
base.Destruct();
UIController.OnAttributeChangeDelegate -= OnAttributeChanged;
}
[UFunction()]
protected void OnAttributeChanged(FName AttributeName, float NewValue, float OldValue)
{
if (AttributeName == "Hunger")
{
WBP_SatietyBar.OnSatietyChanged(NewValue);
}
}
}