Refactor UI components to inherit from Control and update node paths for consistency
This commit is contained in:
@@ -3,7 +3,7 @@ using Mr.BrickAdventures.Autoloads;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.UI;
|
||||
|
||||
public partial class AudioSettings : Node
|
||||
public partial class AudioSettings : Control
|
||||
{
|
||||
[Export] public Slider MasterVolumeSlider { get; set; }
|
||||
[Export] public Slider MusicVolumeSlider { get; set; }
|
||||
|
@@ -4,7 +4,7 @@ using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.UI;
|
||||
|
||||
public partial class ChargeProgressBar : Node
|
||||
public partial class ChargeProgressBar : ProgressBar
|
||||
{
|
||||
[Export] public ProgressBar ProgressBar { get; set; }
|
||||
[Export] public BrickThrowComponent ThrowComponent { get; set; }
|
||||
@@ -27,6 +27,11 @@ public partial class ChargeProgressBar : Node
|
||||
|
||||
private void SetupDependencies()
|
||||
{
|
||||
if (ThrowComponent == null || ProgressBar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ThrowComponent.ThrowInputBehavior is ChargeThrowInputResource throwInput)
|
||||
{
|
||||
_throwInput = throwInput;
|
||||
|
72
scripts/UI/DeathScreen.cs
Normal file
72
scripts/UI/DeathScreen.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.UI;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class DeathScreen : Control
|
||||
{
|
||||
[Export] public LevelResource CurrentLevel { get; set; }
|
||||
[Export] public Label CurrentLevelLabel { get; set; }
|
||||
[Export] public Label LivesLeftLabel { get; set; }
|
||||
[Export] public float TimeoutTime { get; set; } = 2.0f;
|
||||
[Export] public Godot.Collections.Array<Node> NodesToDisable { get; set; } = new();
|
||||
|
||||
private GameManager _gameManager;
|
||||
private Timer _timer;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
||||
SetLabels();
|
||||
}
|
||||
|
||||
private void SetLabels()
|
||||
{
|
||||
if (_gameManager == null) return;
|
||||
|
||||
if (CurrentLevel != null)
|
||||
{
|
||||
CurrentLevelLabel.Text = CurrentLevel.LevelName;
|
||||
}
|
||||
LivesLeftLabel.Text = $" x {_gameManager.GetLives()}";
|
||||
}
|
||||
|
||||
private void SetupTimer()
|
||||
{
|
||||
_timer = new Timer();
|
||||
_timer.WaitTime = TimeoutTime;
|
||||
_timer.OneShot = true;
|
||||
_timer.Timeout += OnTimeout;
|
||||
AddChild(_timer);
|
||||
_timer.Start();
|
||||
}
|
||||
|
||||
private void ToggleNodes()
|
||||
{
|
||||
foreach (var node in NodesToDisable)
|
||||
{
|
||||
node.ProcessMode = node.ProcessMode == ProcessModeEnum.Disabled
|
||||
? ProcessModeEnum.Inherit
|
||||
: ProcessModeEnum.Disabled;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPlayerDeath()
|
||||
{
|
||||
if (_gameManager == null) return;
|
||||
|
||||
ToggleNodes();
|
||||
SetLabels();
|
||||
Show();
|
||||
SetupTimer();
|
||||
}
|
||||
|
||||
private void OnTimeout()
|
||||
{
|
||||
if (_gameManager == null || _gameManager.GetLives() == 0) return;
|
||||
|
||||
GetTree().ReloadCurrentScene();
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@ using Mr.BrickAdventures.Autoloads;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.UI;
|
||||
|
||||
public partial class GameOverScreen : Node
|
||||
public partial class GameOverScreen : Control
|
||||
{
|
||||
[Export] public Control GameOverPanel { get; set; }
|
||||
[Export] public Button RestartButton { get; set; }
|
||||
|
@@ -4,7 +4,7 @@ using Mr.BrickAdventures.scripts.components;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.UI;
|
||||
|
||||
public partial class Hud : Node
|
||||
public partial class Hud : Control
|
||||
{
|
||||
[Export] public HealthComponent Health { get; set; }
|
||||
[Export] public Label CoinsLabel { get; set; }
|
||||
|
@@ -3,7 +3,7 @@ using Mr.BrickAdventures.Autoloads;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.UI;
|
||||
|
||||
public partial class MainMenu : Node
|
||||
public partial class MainMenu : Control
|
||||
{
|
||||
[Export] public Control MainMenuControl { get; set; }
|
||||
[Export] public Button NewGameButton { get; set; }
|
||||
|
@@ -7,7 +7,7 @@ using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.UI;
|
||||
|
||||
public partial class Marketplace : Node
|
||||
public partial class Marketplace : Control
|
||||
{
|
||||
[Export] public Array<SkillData> Skills { get; set; } = [];
|
||||
[Export] public GridContainer ToUnlockGrid { get; set; }
|
||||
@@ -24,6 +24,8 @@ public partial class Marketplace : Node
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
||||
|
||||
var skillsToUnlock = new List<SkillData>();
|
||||
|
||||
foreach (var skill in Skills) skillsToUnlock.Add(skill);
|
||||
|
@@ -3,7 +3,7 @@ using Mr.BrickAdventures.Autoloads;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.UI;
|
||||
|
||||
public partial class PauseMenu : Node
|
||||
public partial class PauseMenu : Control
|
||||
{
|
||||
[Export] public Control PauseMenuControl { get; set; }
|
||||
[Export] public Control SettingsControl { get; set; }
|
||||
|
@@ -3,7 +3,7 @@ using Mr.BrickAdventures.Autoloads;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.UI;
|
||||
|
||||
public partial class SettingsMenu : Node
|
||||
public partial class SettingsMenu : Control
|
||||
{
|
||||
[Export] public Control InputSettingsControl { get; set; }
|
||||
[Export] public Control AudioSettingsControl { get; set; }
|
||||
|
Reference in New Issue
Block a user