using Godot; using System; using Chickensoft.AutoInject; using Chickensoft.Introspection; using Gamesmiths.Forge.Attributes; using Gamesmiths.Forge.Core; using Gamesmiths.Forge.Cues; using Gamesmiths.Forge.Godot.Core; using Gamesmiths.Forge.Tags; [GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_heart.png"), Meta(typeof(IAutoNode))] public partial class ResourceBar : ProgressBar, ICueHandler { public override void _Notification(int what) => this.Notify(what); [Node("DamageCatchUp")] public required Timer DamageCatchUp { get; set; } [Node("Damagebar")] public required ProgressBar DamageBar { get; set; } [Export] public StyleBox? BarStyle; private float _currentValue; public float CurrentValue { get => _currentValue; set => SetValue(value); } public void OnReady() { DamageCatchUp.Timeout += OnDamageCatchUp; Visible = false; if (BarStyle != null) AddThemeStyleboxOverride("fill", BarStyle); } public void Init(EntityAttribute attribute, Tag cueTag) { _currentValue = attribute.BaseValue; MaxValue = attribute.Max; Value = attribute.BaseValue; DamageBar.MaxValue = attribute.Max; DamageBar.Value = attribute.BaseValue; var cuesManager = ForgeManagers.Instance.CuesManager; cuesManager.RegisterCue(cueTag, this); } public void SetValue(float newValue) { var previousValue = _currentValue; _currentValue = Mathf.Min(newValue, (float) MaxValue); _currentValue = newValue; Value = _currentValue; Visible = _currentValue < MaxValue; if (_currentValue < previousValue) { DamageCatchUp.Start(); } else { DamageBar.Value = _currentValue; } } public void OnDamageCatchUp() { DamageBar.Value = _currentValue; } public void OnExecute(IForgeEntity? target, CueParameters? parameters) { if (target == null || !parameters.HasValue) return; float magnitude = parameters.Value.Magnitude; CurrentValue += magnitude; } public void OnApply(IForgeEntity? target, CueParameters? parameters) { } public void OnRemove(IForgeEntity? target, bool interrupted) { } public void OnUpdate(IForgeEntity? target, CueParameters? parameters) { } }