mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-07-04 19:01:16 +00:00
Music room visualizer
This commit is contained in:
parent
e8b884f54b
commit
67d7986330
5 changed files with 67 additions and 7 deletions
|
|
@ -1,11 +1,14 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://c84shrj84g4t2"]
|
[gd_scene load_steps=8 format=3 uid="uid://c84shrj84g4t2"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://c06tspxwnj7pg" path="res://Scripts/UI/MusicRoom.cs" id="1_u3ui8"]
|
[ext_resource type="Script" uid="uid://c06tspxwnj7pg" path="res://Scripts/UI/MusicRoom.cs" id="1_u3ui8"]
|
||||||
[ext_resource type="LabelSettings" uid="uid://wr7cb2qa6w71" path="res://Resources/Styles/Title_Text_Style.tres" id="1_w47yj"]
|
[ext_resource type="LabelSettings" uid="uid://wr7cb2qa6w71" path="res://Resources/Styles/Title_Text_Style.tres" id="1_w47yj"]
|
||||||
|
[ext_resource type="Script" uid="uid://cx63lvsuj1787" path="res://Scripts/Resources/MusicResource.cs" id="2_kybwj"]
|
||||||
[ext_resource type="Theme" uid="uid://dnsadvmunm76k" path="res://Resources/Styles/MainMenuButtons.tres" id="2_rcbhv"]
|
[ext_resource type="Theme" uid="uid://dnsadvmunm76k" path="res://Resources/Styles/MainMenuButtons.tres" id="2_rcbhv"]
|
||||||
|
[ext_resource type="Resource" uid="uid://byo74ews118nl" path="res://Resources/Music/No_Reason.tres" id="3_nkbmj"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bpd4ldfmt3s51" path="res://Sprites/UI/Note.png" id="3_u3ui8"]
|
[ext_resource type="Texture2D" uid="uid://bpd4ldfmt3s51" path="res://Sprites/UI/Note.png" id="3_u3ui8"]
|
||||||
|
[ext_resource type="Resource" uid="uid://b0aryixgv2vkj" path="res://Resources/Music/No_Restraint.tres" id="4_cv0ke"]
|
||||||
|
|
||||||
[node name="MusicRoom" type="VBoxContainer"]
|
[node name="MusicRoom" type="VBoxContainer" node_paths=PackedStringArray("TracksContainer")]
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
|
|
@ -14,6 +17,9 @@ grow_vertical = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
script = ExtResource("1_u3ui8")
|
script = ExtResource("1_u3ui8")
|
||||||
|
Tracks = Array[ExtResource("2_kybwj")]([ExtResource("3_nkbmj"), ExtResource("4_cv0ke")])
|
||||||
|
TracksContainer = NodePath("HBoxContainer/ItemList")
|
||||||
|
Icon = ExtResource("3_u3ui8")
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="."]
|
[node name="Label" type="Label" parent="."]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ public partial class MusicResource : Resource
|
||||||
[Export]
|
[Export]
|
||||||
public string AuthorName { get; set; }
|
public string AuthorName { get; set; }
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public bool ShowAuthor { get; set; }
|
public bool ShowAuthor { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ using Cirno.Scripts.Resources;
|
||||||
public partial class AudioNameVisualizer : AudioStreamPlayer2D
|
public partial class AudioNameVisualizer : AudioStreamPlayer2D
|
||||||
{
|
{
|
||||||
[Export]
|
[Export]
|
||||||
public MusicResource MusicData { get; private set; }
|
public MusicResource MusicData { get; set; }
|
||||||
|
|
||||||
[Export] public PackedScene CanvasTemplate;
|
[Export] public PackedScene CanvasTemplate;
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ public partial class AudioNameVisualizer : AudioStreamPlayer2D
|
||||||
|
|
||||||
if (Autoplay)
|
if (Autoplay)
|
||||||
{
|
{
|
||||||
ShowName();
|
PlayWithName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,56 @@
|
||||||
|
|
||||||
public partial class MusicRoom : MenuBase
|
using Cirno.Scripts.Resources;
|
||||||
|
using Godot;
|
||||||
|
using Godot.Collections;
|
||||||
|
|
||||||
|
public partial class MusicRoom : MenuBase
|
||||||
{
|
{
|
||||||
|
[Export]
|
||||||
|
public Array<MusicResource> Tracks { get; private set; } = new();
|
||||||
|
|
||||||
}
|
[Export]
|
||||||
|
public ItemList TracksContainer { get; private set; }
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public Texture2D Icon { get; private set; }
|
||||||
|
|
||||||
|
private Dictionary<long, AudioNameVisualizer> _tracks = new();
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
TracksContainer.Clear();
|
||||||
|
foreach (var track in Tracks)
|
||||||
|
{
|
||||||
|
var index = TracksContainer.AddItem($"{track.TrackName} ({track.AuthorName})", Icon);
|
||||||
|
|
||||||
|
var visualizer = new AudioNameVisualizer();
|
||||||
|
visualizer.MusicData = track;
|
||||||
|
TracksContainer.CallDeferred("add_child", visualizer);
|
||||||
|
|
||||||
|
_tracks.Add((long)index, visualizer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TracksContainer.ItemSelected += (long selectedItem) =>
|
||||||
|
{
|
||||||
|
var vis = _tracks[selectedItem];
|
||||||
|
if (vis.MusicData is null) { return; }
|
||||||
|
StopAllTracks();
|
||||||
|
vis.PlayWithName();
|
||||||
|
UpdateDescription(vis.MusicData.Description);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopAllTracks()
|
||||||
|
{
|
||||||
|
foreach (var track in _tracks)
|
||||||
|
{
|
||||||
|
track.Value.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateDescription(string name)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ public partial class MusicVisualizerCanvas : CanvasLayer
|
||||||
|
|
||||||
private void ResetLabel(string trackName, string authorName)
|
private void ResetLabel(string trackName, string authorName)
|
||||||
{
|
{
|
||||||
_nameLabel.Text = string.IsNullOrWhiteSpace(authorName) ? authorName : $"{trackName} ({authorName})";
|
_nameLabel.Text = string.IsNullOrWhiteSpace(authorName) ? trackName : $"{trackName} ({authorName})";
|
||||||
_nameLabel.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.BottomRight, margin: 0);
|
_nameLabel.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.BottomRight, margin: 0);
|
||||||
_nameLabel.Modulate = Colors.White;
|
_nameLabel.Modulate = Colors.White;
|
||||||
_nameLabel.Hide();
|
_nameLabel.Hide();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue