cirnogodot/Scripts/UI/MusicVisualizerCanvas.cs

49 lines
1.7 KiB
C#
Raw Normal View History

2025-02-25 14:06:41 +01:00
using Godot;
using System;
using GTweens.Builders;
using GTweens.Easings;
using GTweens.Tweens;
using GTweensGodot.Extensions;
public partial class MusicVisualizerCanvas : CanvasLayer
{
private Label _nameLabel;
private GTween _tween;
public override void _Ready()
{
_nameLabel = GetNode<Label>("Title");
_nameLabel.Hide();
}
private void ResetLabel(string trackName, string authorName)
{
2025-02-27 09:14:00 +01:00
_nameLabel.Text = string.IsNullOrWhiteSpace(authorName) ? authorName : $"{trackName} ({authorName})";
2025-02-25 14:06:41 +01:00
_nameLabel.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.BottomRight, margin: 0);
_nameLabel.Modulate = Colors.White;
_nameLabel.Hide();
}
public void ShowName(string trackName, string authorName)
{
_tween?.Kill();
//_tween?.Complete();
ResetLabel(trackName, authorName);
_nameLabel.Show();
2025-02-27 09:14:00 +01:00
2025-02-25 14:06:41 +01:00
_tween = GTweenSequenceBuilder.New()
.Append(_nameLabel.TweenPositionX(_nameLabel.Position.X + 32, 0f)) // Add offset
.Join(_nameLabel.TweenModulateAlpha(0, 0f)) // Invisibilify
.Append(_nameLabel.TweenPositionX(_nameLabel.Position.X - 32, 1f)) // Animate back
.Join(_nameLabel.TweenModulateAlpha(1, 0.5f))
.AppendTime(3f) // Wait before hiding
.Append(_nameLabel.TweenPositionX(_nameLabel.Position.X + 32, 1f)) // Start moving and hiding
.Join(_nameLabel.TweenModulateAlpha(0, 0.5f))
.Append(_nameLabel.TweenPositionX(_nameLabel.Position.X - 32, 0f)) // Move back to default position
.AppendCallback(() => _nameLabel.Hide())
.Build();
_tween.SetEasing(Easing.OutCubic);
_tween.Play();
}
}