Add FloatingTextManager and FloatingText for displaying UI messages; update CollectableComponent and HealthComponent to utilize new floating text features
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
@@ -15,6 +16,8 @@ public partial class CollectableComponent : Node
|
||||
[Export] public AudioStreamPlayer2D Sfx {get; set; }
|
||||
|
||||
[Signal] public delegate void CollectedEventHandler(float amount, CollectableType type, Node2D body);
|
||||
|
||||
private FloatingTextManager _floatingTextManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -25,6 +28,8 @@ public partial class CollectableComponent : Node
|
||||
|
||||
if (Owner.HasNode("FadeAwayComponent"))
|
||||
_hasFadeAway = true;
|
||||
|
||||
_floatingTextManager = GetNode<FloatingTextManager>("/root/FloatingTextManager");
|
||||
}
|
||||
|
||||
private async void OnArea2DBodyEntered(Node2D body)
|
||||
@@ -32,6 +37,22 @@ public partial class CollectableComponent : Node
|
||||
try
|
||||
{
|
||||
if (!body.HasNode("CanPickUpComponent")) return;
|
||||
|
||||
if (Owner is Node2D ownerNode)
|
||||
{
|
||||
switch (Data.Type)
|
||||
{
|
||||
case CollectableType.Coin:
|
||||
_floatingTextManager?.ShowCoin((int)Data.Amount, ownerNode.GlobalPosition);
|
||||
break;
|
||||
case CollectableType.Health:
|
||||
_floatingTextManager?.ShowMessage("Healed!", ownerNode.GlobalPosition);
|
||||
break;
|
||||
case CollectableType.Kid:
|
||||
_floatingTextManager?.ShowMessage("Rescued!", ownerNode.GlobalPosition);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EmitSignalCollected(Data.Amount, Data.Type, body);
|
||||
CollisionShape?.CallDeferred("set_disabled", true);
|
||||
|
@@ -15,12 +15,11 @@ public partial class HealthComponent : Node2D
|
||||
[Signal] public delegate void HealthChangedEventHandler(float delta, float totalHealth);
|
||||
[Signal] public delegate void DeathEventHandler();
|
||||
|
||||
private DamageNumberManager _damageNumberManager;
|
||||
private FloatingTextManager _floatingTextManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_damageNumberManager = GetNode<DamageNumberManager>("/root/DamageNumberManager");
|
||||
_damageNumberManager?.Register(Owner);
|
||||
_floatingTextManager = GetNode<FloatingTextManager>("/root/FloatingTextManager");
|
||||
}
|
||||
|
||||
public void SetHealth(float newValue)
|
||||
@@ -47,6 +46,11 @@ public partial class HealthComponent : Node2D
|
||||
|
||||
if (delta == 0.0f)
|
||||
return;
|
||||
|
||||
if (delta < 0.0f)
|
||||
_floatingTextManager?.ShowDamage(Mathf.Abs(delta), GlobalPosition);
|
||||
else
|
||||
_floatingTextManager?.ShowHeal(delta, GlobalPosition);
|
||||
|
||||
if (playSfx)
|
||||
{
|
||||
|
Reference in New Issue
Block a user