diff options
| author | alex <[email protected]> | 2026-11-09 11:46:51 +0100 |
|---|---|---|
| committer | alex <[email protected]> | 2026-11-09 11:46:51 +0100 |
| commit | 26972abbe2dd670d2afac067c548cfaf1da73b2d (patch) | |
| tree | 8d286077301ed39646c8ebaf9589a33c2f19c7ea /DungeonSystem/scripts/EncounterHud.cs | |
| parent | 5bc1a8224bb73dcac910e1f05f5e036b4f89ceb8 (diff) | |
| download | godot-testing-26972abbe2dd670d2afac067c548cfaf1da73b2d.tar.xz godot-testing-26972abbe2dd670d2afac067c548cfaf1da73b2d.zip | |
boos room
Diffstat (limited to 'DungeonSystem/scripts/EncounterHud.cs')
| -rw-r--r-- | DungeonSystem/scripts/EncounterHud.cs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/DungeonSystem/scripts/EncounterHud.cs b/DungeonSystem/scripts/EncounterHud.cs new file mode 100644 index 0000000..74a8af0 --- /dev/null +++ b/DungeonSystem/scripts/EncounterHud.cs @@ -0,0 +1,77 @@ +using Godot; + +namespace DungeonSystem; + +public partial class EncounterHud : CanvasLayer +{ + [Export] public NodePath DungeonGeneratorPath { get; set; } = new NodePath("../DungeonGenerator"); + [Export] public NodePath StatusLabelPath { get; set; } = new NodePath("StatusLabel"); + + private Label? _statusLabel; + + public override void _Ready() + { + _statusLabel = GetNodeOrNull<Label>(StatusLabelPath); + if (_statusLabel == null) + { + GD.PrintErr("[EncounterHud] Missing status label."); + return; + } + + _statusLabel.Visible = false; + CallDeferred(MethodName.ConnectToEncounterManager); + } + + private void ConnectToEncounterManager() + { + DungeonGenerator? generator = GetNodeOrNull<DungeonGenerator>(DungeonGeneratorPath); + if (generator?.EncounterManager == null) + { + GD.PrintErr("[EncounterHud] Could not find DungeonGenerator/RoomEncounterManager."); + return; + } + + RoomEncounterManager manager = generator.EncounterManager; + manager.WaveStarted += OnWaveStarted; + manager.WaveCleared += OnWaveCleared; + manager.EncounterCleared += OnEncounterCleared; + } + + private void OnWaveStarted(Room room, int waveNumber, int totalWaves) + { + if (_statusLabel == null) + { + return; + } + + _statusLabel.Visible = true; + _statusLabel.Text = $"{room.Name}: Wave {waveNumber}/{totalWaves}"; + } + + private void OnWaveCleared(Room room, int waveNumber, int totalWaves) + { + if (_statusLabel == null) + { + return; + } + + _statusLabel.Visible = true; + _statusLabel.Text = $"{room.Name}: Wave {waveNumber}/{totalWaves} cleared"; + } + + private async void OnEncounterCleared(Room room) + { + if (_statusLabel == null) + { + return; + } + + _statusLabel.Visible = true; + _statusLabel.Text = $"{room.Name} cleared"; + await ToSignal(GetTree().CreateTimer(1.5f), SceneTreeTimer.SignalName.Timeout); + if (GodotObject.IsInstanceValid(_statusLabel)) + { + _statusLabel.Visible = false; + } + } +} |
