mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 18:15:54 +00:00
Music visualizer resource
This commit is contained in:
parent
34ed3bbc9a
commit
e8b884f54b
10 changed files with 82 additions and 19 deletions
|
|
@ -6,23 +6,21 @@ using GTweens.Builders;
|
|||
using GTweens.Easings;
|
||||
using GTweens.Tweens;
|
||||
using GTweensGodot.Extensions;
|
||||
using Cirno.Scripts.Resources;
|
||||
|
||||
public partial class AudioNameVisualizer : AudioStreamPlayer2D
|
||||
{
|
||||
[Export]
|
||||
public string TrackName { get; private set; }
|
||||
|
||||
[Export]
|
||||
public string AuthorName { get; private set; }
|
||||
public MusicResource MusicData { get; private set; }
|
||||
|
||||
[Export] public PackedScene CanvasTemplate;
|
||||
|
||||
|
||||
private MusicVisualizerCanvas _canvasLayer;
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Setup();
|
||||
|
||||
|
||||
if (Autoplay)
|
||||
{
|
||||
ShowName();
|
||||
|
|
@ -31,6 +29,11 @@ public partial class AudioNameVisualizer : AudioStreamPlayer2D
|
|||
|
||||
private void Setup()
|
||||
{
|
||||
if (MusicData?.Track is not null)
|
||||
{
|
||||
this.Stream = MusicData.Track;
|
||||
}
|
||||
|
||||
var existingCanvas = this.GetTree().Root.GetNodeOrNull<CanvasLayer>("AudioCanvas");
|
||||
|
||||
if (existingCanvas is null)
|
||||
|
|
@ -54,7 +57,11 @@ public partial class AudioNameVisualizer : AudioStreamPlayer2D
|
|||
|
||||
public void ShowName()
|
||||
{
|
||||
GD.Print("show name");
|
||||
_canvasLayer.ShowName(TrackName, AuthorName);
|
||||
if (MusicData is null)
|
||||
{
|
||||
GD.PushWarning("Music data was null");
|
||||
return;
|
||||
}
|
||||
_canvasLayer.ShowName(MusicData.TrackName, MusicData.ShowAuthor ? MusicData.AuthorName : null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public partial class MusicVisualizerCanvas : CanvasLayer
|
|||
|
||||
private void ResetLabel(string trackName, string authorName)
|
||||
{
|
||||
_nameLabel.Text = $"{trackName} ({authorName})";
|
||||
_nameLabel.Text = string.IsNullOrWhiteSpace(authorName) ? authorName : $"{trackName} ({authorName})";
|
||||
_nameLabel.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.BottomRight, margin: 0);
|
||||
_nameLabel.Modulate = Colors.White;
|
||||
_nameLabel.Hide();
|
||||
|
|
@ -30,7 +30,7 @@ public partial class MusicVisualizerCanvas : CanvasLayer
|
|||
//_tween?.Complete();
|
||||
ResetLabel(trackName, authorName);
|
||||
_nameLabel.Show();
|
||||
|
||||
|
||||
_tween = GTweenSequenceBuilder.New()
|
||||
.Append(_nameLabel.TweenPositionX(_nameLabel.Position.X + 32, 0f)) // Add offset
|
||||
.Join(_nameLabel.TweenModulateAlpha(0, 0f)) // Invisibilify
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue