diff --git a/prefabs/fight/fighterVisuals/blob_fighter_visual.tscn b/prefabs/fight/fighterVisuals/blob_fighter_visual.tscn index df51740..6f61899 100644 --- a/prefabs/fight/fighterVisuals/blob_fighter_visual.tscn +++ b/prefabs/fight/fighterVisuals/blob_fighter_visual.tscn @@ -14,5 +14,5 @@ position = Vector2(23, -96) scale = Vector2(0.547474, 0.547474) texture = SubResource("AtlasTexture_ane0o") -[node name="ChacacterSizeIndicator" parent="Visuals" index="1"] -visible = true +[node name="Sprite2D" parent="TargetSelection/HoverIndicator" index="0"] +position = Vector2(1, -126) diff --git a/prefabs/fight/fighterVisuals/vesna_fighter_visual.tscn b/prefabs/fight/fighterVisuals/vesna_fighter_visual.tscn index 606b028..2927637 100644 --- a/prefabs/fight/fighterVisuals/vesna_fighter_visual.tscn +++ b/prefabs/fight/fighterVisuals/vesna_fighter_visual.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=8 format=3 uid="uid://7jsxokx67gpq"] +[gd_scene load_steps=9 format=3 uid="uid://7jsxokx67gpq"] [ext_resource type="Script" uid="uid://by88f32fou7lh" path="res://scripts/CSharp/Common/Fight/FighterVisual.cs" id="1_hai27"] [ext_resource type="Texture2D" uid="uid://f7htcxiwvuup" path="res://art/animation/vesna/Side/S01-Idle/0001.png" id="2_6l7g5"] [ext_resource type="Script" uid="uid://boprnfciqgixf" path="res://scripts/CSharp/Common/Fight/UI/TargetSelectionClick.cs" id="3_wil2y"] [ext_resource type="Texture2D" uid="uid://qlfwuakhe57t" path="res://art/ui/UI/attack_select_wheel.png" id="4_8ldlc"] +[ext_resource type="Script" uid="uid://b2dx06p6i7pu0" path="res://scripts/CSharp/Common/Fight/UI/FighterHealthBarVisual.cs" id="5_xv37w"] [sub_resource type="AtlasTexture" id="AtlasTexture_wil2y"] atlas = ExtResource("2_6l7g5") @@ -16,10 +17,11 @@ size = Vector2(250, 401) radius = 173.0 height = 588.0 -[node name="VesnaFighterVisual" type="Node2D" node_paths=PackedStringArray("_visualParent", "_targetSelectionParent")] +[node name="VesnaFighterVisual" type="Node2D" node_paths=PackedStringArray("_visualParent", "_targetSelectionParent", "healthBarVisual")] script = ExtResource("1_hai27") _visualParent = NodePath("Visuals") _targetSelectionParent = NodePath("TargetSelection") +healthBarVisual = NodePath("HealthBar") [node name="Visuals" type="Node2D" parent="."] @@ -53,6 +55,18 @@ position = Vector2(-3, -227) scale = Vector2(1.65625, 1.65625) texture = ExtResource("4_8ldlc") +[node name="HealthBar" type="Node2D" parent="." node_paths=PackedStringArray("_tmpHealthLabel")] +script = ExtResource("5_xv37w") +_tmpHealthLabel = NodePath("tmpLabel") + +[node name="tmpLabel" type="Label" parent="HealthBar"] +offset_left = -110.0 +offset_top = -528.0 +offset_right = 111.0 +offset_bottom = -431.0 +theme_override_font_sizes/font_size = 71 +text = "xx / xx" + [connection signal="TargetSelected" from="TargetSelection/Click" to="." method="ClickedTarget"] [connection signal="mouse_entered" from="TargetSelection/Click" to="TargetSelection/HoverIndicator" method="show"] [connection signal="mouse_exited" from="TargetSelection/Click" to="TargetSelection/HoverIndicator" method="hide"] diff --git a/scripts/CSharp/Common/Fight/AllFightersVisual.cs b/scripts/CSharp/Common/Fight/AllFightersVisual.cs index 678deee..cc046f3 100644 --- a/scripts/CSharp/Common/Fight/AllFightersVisual.cs +++ b/scripts/CSharp/Common/Fight/AllFightersVisual.cs @@ -54,6 +54,11 @@ public partial class AllFightersVisual : Node { HideTargetSelect(); } + + if (from == FightHappening.FightState.ActionAnim) + { + _fighterVisuals.Values.ForEach(fv=>fv.UpdateHealthBar()); + } } public void EnterFighter() diff --git a/scripts/CSharp/Common/Fight/FighterVisual.cs b/scripts/CSharp/Common/Fight/FighterVisual.cs index f7da460..94b2da5 100644 --- a/scripts/CSharp/Common/Fight/FighterVisual.cs +++ b/scripts/CSharp/Common/Fight/FighterVisual.cs @@ -1,12 +1,13 @@ using System; using System.Threading.Tasks; using Babushka.scripts.CSharp.Common.Fight.ActionDetails; +using Babushka.scripts.CSharp.Common.Fight.UI; using Godot; using Godot.Collections; namespace Babushka.scripts.CSharp.Common.Fight; -[Tool] + public partial class FighterVisual : Node2D { #region Shortcuts @@ -15,23 +16,11 @@ public partial class FighterVisual : Node2D FightWorld.Instance.fightHappeningData ?? throw new NoFightHappeningException(); #endregion - - [ExportCategory("References")] - [Export] private Node2D _visualParent; - [Export] private Node2D _targetSelectionParent; - - - [Signal] - public delegate void DamageTakenEventHandler(); - - [Signal] - public delegate void AttackingEventHandler(); - [Signal] - public delegate void DyingEventHandler(); - - [Signal] - public delegate void HealedEventHandler(); + [ExportCategory("References")] + [Export] private Node2D _visualParent = null!; + [Export] private Node2D _targetSelectionParent = null!; + [Export] public FighterHealthBarVisual healthBarVisual = null!; private FightWorld.Fighter _boundFighter; @@ -40,6 +29,7 @@ public partial class FighterVisual : Node2D { _boundFighter = fighter; UpdateMirrorState(); + UpdateHealthBar(); } /// @@ -51,6 +41,11 @@ public partial class FighterVisual : Node2D _visualParent.Scale = new Vector2(_boundFighter.isEnemy ? -1 : 1, 1); } + public void UpdateHealthBar() + { + healthBarVisual.UpdateHealth(_boundFighter.GetHealth(), _boundFighter.maxHealth); + } + public void SetTargetSelectionActive(bool value) { _targetSelectionParent.Visible = value; @@ -66,7 +61,7 @@ public partial class FighterVisual : Node2D targetDetail.SetTarget(_boundFighter); FightHappening.Instance.DetailFilled(); } - + // Animations //public void AttackAnimation(FightAttack attack) //{ @@ -100,7 +95,7 @@ public partial class FighterVisual : Node2D .SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out); await ToSignal(tween, "finished"); } - + //private void HitAnimation(FightAttack attack) //{ diff --git a/scripts/CSharp/Common/Fight/UI/FighterHealthBarVisual.cs b/scripts/CSharp/Common/Fight/UI/FighterHealthBarVisual.cs new file mode 100644 index 0000000..9af7959 --- /dev/null +++ b/scripts/CSharp/Common/Fight/UI/FighterHealthBarVisual.cs @@ -0,0 +1,14 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Common.Fight.UI; + +[GlobalClass] +public partial class FighterHealthBarVisual : Node2D +{ + [Export] private Label _tmpHealthLabel = null!; + + public void UpdateHealth(int currentHealth, int maxHealth) + { + _tmpHealthLabel.Text = $"{currentHealth} / {maxHealth}"; + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Fight/UI/FighterHealthBarVisual.cs.uid b/scripts/CSharp/Common/Fight/UI/FighterHealthBarVisual.cs.uid new file mode 100644 index 0000000..80da99b --- /dev/null +++ b/scripts/CSharp/Common/Fight/UI/FighterHealthBarVisual.cs.uid @@ -0,0 +1 @@ +uid://b2dx06p6i7pu0