2025-10-28 23:51:17 +08:00
|
|
|
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; } }
|
2025-11-02 15:51:28 +08:00
|
|
|
// protected UBusyWidgetSatietyBar? WBP_SatietyBar { get { return GetWidget("WBP_SatietyBar") as UBusyWidgetSatietyBar; } }
|
|
|
|
|
|
|
|
|
|
protected List<UBusyWidgetSatietyBar> SatietyBars = new();
|
|
|
|
|
protected List<UBusyWidgetHealthBar> HealthBars = new();
|
2025-10-28 23:51:17 +08:00
|
|
|
|
|
|
|
|
protected UBusyRoleStateController? UIController;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void Construct()
|
|
|
|
|
{
|
|
|
|
|
base.Construct();
|
2025-11-02 15:51:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (GetWidget($"WBP_SatietyBar_{i}") is UBusyWidgetSatietyBar Bar)
|
|
|
|
|
{
|
|
|
|
|
SatietyBars.Add(Bar);
|
|
|
|
|
}
|
|
|
|
|
if (GetWidget("WBP_HealthBar") is UBusyWidgetHealthBar HpBar)
|
|
|
|
|
{
|
|
|
|
|
HealthBars.Add(HpBar);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-28 23:51:17 +08:00
|
|
|
|
|
|
|
|
UIController = UUIFunctionLibrary.GetUIController(this, "RoleState") as UBusyRoleStateController;
|
|
|
|
|
|
|
|
|
|
InitRoleAttribute();
|
|
|
|
|
UIController.OnAttributeChangeDelegate += OnAttributeChanged;
|
|
|
|
|
|
2025-11-02 15:51:28 +08:00
|
|
|
|
2025-10-28 23:51:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2025-11-02 15:51:28 +08:00
|
|
|
|
|
|
|
|
foreach (UBusyWidgetSatietyBar Bar in SatietyBars)
|
|
|
|
|
{
|
|
|
|
|
Bar.SetSatietyConfig(CurSatiety, MaxSatiety);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-28 23:51:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Destruct()
|
|
|
|
|
{
|
|
|
|
|
base.Destruct();
|
|
|
|
|
UIController.OnAttributeChangeDelegate -= OnAttributeChanged;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-02 15:51:28 +08:00
|
|
|
public void SetSatiety(float Satiety)
|
|
|
|
|
{
|
|
|
|
|
foreach(UBusyWidgetSatietyBar Bar in SatietyBars)
|
|
|
|
|
{
|
|
|
|
|
Bar.OnSatietyChanged(Satiety);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-28 23:51:17 +08:00
|
|
|
|
|
|
|
|
[UFunction()]
|
|
|
|
|
protected void OnAttributeChanged(FName AttributeName, float NewValue, float OldValue)
|
|
|
|
|
{
|
|
|
|
|
if (AttributeName == "Hunger")
|
|
|
|
|
{
|
2025-11-02 15:51:28 +08:00
|
|
|
SetSatiety(NewValue);
|
2025-10-28 23:51:17 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|