Refactor UI components to inherit from Control and update node paths for consistency
This commit is contained in:
@@ -16,16 +16,13 @@ public partial class DamageComponent : Node
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Area == null)
|
||||
if (Area != null)
|
||||
{
|
||||
GD.PushError($"DamageComponent: Area2D node is not set.");
|
||||
return;
|
||||
Area.BodyEntered += OnAreaBodyEntered;
|
||||
Area.BodyExited += OnAreaBodyExited;
|
||||
Area.AreaEntered += OnAreaAreaEntered;
|
||||
}
|
||||
|
||||
Area.BodyEntered += OnAreaBodyEntered;
|
||||
Area.BodyExited += OnAreaBodyExited;
|
||||
Area.AreaEntered += OnAreaAreaEntered;
|
||||
|
||||
if (DamageTimer != null)
|
||||
{
|
||||
DamageTimer.Timeout += OnDamageTimerTimeout;
|
||||
|
@@ -18,6 +18,8 @@ public partial class ExitDoorComponent : Node, IUnlockable
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
||||
|
||||
if (ExitArea == null)
|
||||
{
|
||||
GD.PushError("ExitDoorComponent: ExitArea is not set.");
|
||||
@@ -26,12 +28,15 @@ public partial class ExitDoorComponent : Node, IUnlockable
|
||||
|
||||
ExitArea.BodyEntered += OnExitAreaBodyEntered;
|
||||
|
||||
_gameManager = GetNode<GameManager>("/root/gameManager");
|
||||
}
|
||||
|
||||
private void OnExitAreaBodyEntered(Node2D body)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
if (Locked) return;
|
||||
|
||||
EmitSignalExitTriggered();
|
||||
_gameManager.UnlockLevel((int)_gameManager.PlayerState["CurrentLevel"] + 1);
|
||||
CallDeferred(nameof(GoToNextLevel));
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
|
@@ -4,7 +4,7 @@ using Mr.BrickAdventures.scripts.interfaces;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class PlayerController : Node2D
|
||||
public partial class PlayerController : CharacterBody2D
|
||||
{
|
||||
[Export]
|
||||
public string DefaultMovementType { get; set; } = "platform";
|
||||
|
@@ -14,7 +14,7 @@ public partial class PlayerDeathComponent : Node2D
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>("/root/gameManager");
|
||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
||||
HealthComponent.Death += OnDeath;
|
||||
}
|
||||
|
||||
|
@@ -20,10 +20,12 @@ public partial class ScoreComponent : Node
|
||||
return;
|
||||
}
|
||||
|
||||
var coins = GetTree().GetNodesInGroup("Coins");
|
||||
var coins = GetTree().GetNodesInGroup("coins");
|
||||
GD.Print($"Found {coins.Count} coins in the scene.");
|
||||
foreach (var coin in coins)
|
||||
{
|
||||
var c = coin.GetNodeOrNull<CollectableComponent>("CollectableComponent");
|
||||
GD.Print(c == null ? "CollectableComponent not found on coin." : "CollectableComponent found on coin.");
|
||||
if (c != null)
|
||||
{
|
||||
c.Collected += OnCollected;
|
||||
@@ -31,6 +33,17 @@ public partial class ScoreComponent : Node
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
GetCoinsInScene();
|
||||
}
|
||||
|
||||
private void GetCoinsInScene()
|
||||
{
|
||||
var coins = GetTree().GetNodesInGroup("Coins");
|
||||
GD.Print($"Found {coins.Count} coins in the scene.");
|
||||
}
|
||||
|
||||
private void OnCollected(float amount, CollectableType type, Node2D body)
|
||||
{
|
||||
if (type != CollectableType.Coin) return;
|
||||
|
@@ -2,9 +2,8 @@ using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class TooltipComponent : Node
|
||||
public partial class TooltipComponent : Area2D
|
||||
{
|
||||
[Export] public Area2D Area { get; set; }
|
||||
[Export] public Control UiRoot { get; set; }
|
||||
[Export] public string Text { get; set; } = string.Empty;
|
||||
[Export] public Label TooltipLabel { get; set; }
|
||||
@@ -13,8 +12,8 @@ public partial class TooltipComponent : Node
|
||||
{
|
||||
TooltipLabel.Text = Text;
|
||||
UiRoot.Visible = false;
|
||||
Area.BodyEntered += OnBodyEntered;
|
||||
Area.BodyExited += OnBodyExited;
|
||||
BodyEntered += OnBodyEntered;
|
||||
BodyExited += OnBodyExited;
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node2D body)
|
||||
|
Reference in New Issue
Block a user