Refactor ChargeProgressBar and SkillManager; update skill handling and improve component interactions

This commit is contained in:
2025-08-27 00:14:41 +02:00
parent 421a31917d
commit c34b9bc16f
4 changed files with 47 additions and 17 deletions

View File

@@ -1,4 +1,5 @@
using Godot;
using Mr.BrickAdventures.Autoloads;
using Mr.BrickAdventures.scripts.components;
using Mr.BrickAdventures.scripts.Resources;
@@ -7,25 +8,36 @@ namespace Mr.BrickAdventures.scripts.UI;
public partial class ChargeProgressBar : ProgressBar
{
[Export] public ProgressBar ProgressBar { get; set; }
[Export] public BrickThrowComponent ThrowComponent { get; set; }
[Export] private SkillManager _skillManager;
private BrickThrowComponent _throwComponent;
private ChargeThrowInputResource _throwInput;
public override void _Ready()
{
Owner.ChildEnteredTree += OnNodeEntered;
Owner.TreeExiting += OnOwnerExiting;
ProgressBar.Hide();
if (_skillManager == null)
{
return;
}
_skillManager.ActiveThrowSkillChanged += OnActiveThrowSkillChanged;
SetupDependencies();
}
private void OnActiveThrowSkillChanged(BrickThrowComponent throwComponent)
{
OnOwnerExiting();
if (throwComponent == null) return;
_throwComponent = throwComponent;
_throwComponent.TreeExiting += OnOwnerExiting;
SetupDependencies();
}
private void OnNodeEntered(Node node)
{
if (node is not BrickThrowComponent throwComponent || ThrowComponent != null) return;
ThrowComponent = throwComponent;
SetupDependencies();
}
private void OnOwnerExiting()
{
if (_throwInput != null)
@@ -35,18 +47,18 @@ public partial class ChargeProgressBar : ProgressBar
_throwInput.ChargeUpdated -= OnChargeUpdated;
_throwInput = null;
}
ThrowComponent = null;
_throwComponent = null;
}
private void SetupDependencies()
{
if (ThrowComponent == null || ProgressBar == null)
if (_throwComponent == null || ProgressBar == null)
{
return;
}
if (ThrowComponent.ThrowInputBehavior is ChargeThrowInputResource throwInput)
if (_throwComponent.ThrowInputBehavior is ChargeThrowInputResource throwInput)
{
_throwInput = throwInput;
}