forge friendlier health and damage management

Removed knockback though
This commit is contained in:
2026-04-28 11:22:24 +02:00
parent dcfd937e53
commit ec44306d48
24 changed files with 776 additions and 490 deletions

View File

@@ -0,0 +1,92 @@
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(IAutoOn), typeof(IAutoConnect))]
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 Initialize(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)
{
}
}

View File

@@ -0,0 +1 @@
uid://l5cjcaehyssk

View File

@@ -0,0 +1,49 @@
[gd_scene format=3 uid="uid://cyw8p0p6a78tl"]
[ext_resource type="Script" uid="uid://l5cjcaehyssk" path="res://scenes/ui/healthbar/Healthbar.cs" id="1_0k5hr"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_0sgot"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0k5hr"]
bg_color = Color(0.69803923, 0.047058824, 0, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0sgot"]
bg_color = Color(0.14767182, 0.14767182, 0.14767176, 1)
expand_margin_left = 2.0
expand_margin_top = 2.0
expand_margin_right = 2.0
expand_margin_bottom = 2.0
shadow_color = Color(0, 0, 0, 0.27450982)
shadow_offset = Vector2(0, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kl70x"]
bg_color = Color(0.8862616, 0.88626146, 0.8862615, 1)
[node name="Healthbar" type="ProgressBar" unique_id=1713862004]
z_index = 10
custom_minimum_size = Vector2(512, 12)
offset_right = 512.0
offset_bottom = 12.0
theme_override_styles/background = SubResource("StyleBoxEmpty_0sgot")
theme_override_styles/fill = SubResource("StyleBoxFlat_0k5hr")
value = 60.0
show_percentage = false
script = ExtResource("1_0k5hr")
[node name="Damagebar" type="ProgressBar" parent="." unique_id=2024383291]
z_index = -10
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/background = SubResource("StyleBoxFlat_0sgot")
theme_override_styles/fill = SubResource("StyleBoxFlat_kl70x")
value = 80.0
show_percentage = false
[node name="DamageCatchUp" type="Timer" parent="." unique_id=1286697842]
wait_time = 0.8
one_shot = true
ignore_time_scale = true