Add FloatingTextManager and FloatingText for displaying UI messages; update CollectableComponent and HealthComponent to utilize new floating text features

This commit is contained in:
2025-09-11 04:35:30 +02:00
parent f9cb59d182
commit f229ff5b7d
16 changed files with 131 additions and 139 deletions

View File

@@ -1 +0,0 @@
uid://bbupymh6krrgx

View File

@@ -1,41 +1,35 @@
using System.Globalization;
using Godot;
namespace Mr.BrickAdventures.scripts.UI;
[GlobalClass]
public partial class DamageNumber : Label
public partial class FloatingText : Label
{
[Export] public float Duration { get; set; } = 0.8f;
[Export] public float Duration { get; set; } = 1f;
[Export] public float FallDistance { get; set; } = 40f;
[Export] public float HorizontalDrift { get; set; } = 15f;
public void ShowDamage(float damageAmount, Vector2 position)
public void Show(string textToShow, Vector2 position, Color color)
{
Text = Mathf.Round(damageAmount * 100f).ToString(CultureInfo.InvariantCulture);
Text = textToShow;
GlobalPosition = position;
Modulate = color;
var rng = new RandomNumberGenerator();
var horizontalOffset = rng.RandfRange(-HorizontalDrift, HorizontalDrift);
var startPosition = GlobalPosition;
var endPosition = GlobalPosition + new Vector2(horizontalOffset, FallDistance);
var startColor = Colors.White;
startColor.A = 1f;
Modulate = startColor;
var tween = CreateTween();
tween.SetParallel();
var tween = CreateTween().SetParallel();
tween.TweenProperty(this, "global_position", endPosition, Duration)
.SetTrans(Tween.TransitionType.Quad)
.SetEase(Tween.EaseType.In);
.SetEase(Tween.EaseType.Out);
tween.Chain().TweenProperty(this, "modulate:a", 0f, Duration * 0.5f)
.SetTrans(Tween.TransitionType.Sine)
.SetEase(Tween.EaseType.Out);
.SetEase(Tween.EaseType.In);
tween.TweenCallback(Callable.From(QueueFree));
}
}