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; using Movementtests.interfaces; using Movementtests.tools; [GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_text_panel.png"), Meta(typeof(IAutoNode))] public partial class PlayerUi : Control { public override void _Notification(int what) => this.Notify(what); [Dependency] public TagsManager TagsManager => this.DependOn(); #region Utils public enum TargetState { NoTarget, TargetWouldNotKill, TargetWouldKill } public record TargetProperties(TargetState State, Vector2 Position); #endregion #region Nodes [Node] public required TextureRect EnemyTarget { get; set; } [Node] public required ResourceBar Healthbar { get; set; } [Node] public required ResourceBar Manabar { get; set; } #endregion #region Exports [Export] public Color WouldKillColor { get; set; } = new Color("009c8f"); [Export] public Color WouldNotKillColor { get; set; } = new Color("fc001c"); #endregion private EntityAttribute? _health; private EntityAttribute? _mana; public void Init(EntityAttribute health, EntityAttribute mana) { _health = health; _mana = mana; } public void OnResolved() { if (_health == null || _mana == null) throw new Exception("Health and mana attributes are not set"); Healthbar.Init(_health, Tag.RequestTag(TagsManager, "cues.resources.health")); Manabar.Init(_mana, Tag.RequestTag(TagsManager, "cues.resources.mana")); } public void SetEnemyTargetProperties(TargetProperties targetProperties) { var (state, position) = targetProperties; var visible = state != TargetState.NoTarget; var modulation = state switch { TargetState.TargetWouldNotKill => WouldNotKillColor, TargetState.TargetWouldKill => WouldKillColor, _ => WouldNotKillColor }; EnemyTarget.SetVisible(visible); EnemyTarget.SetPosition(position - EnemyTarget.Size / 2); EnemyTarget.SetModulate(modulation); } }