Skip to content

Commit c5c50d6

Browse files
committed
move weird instrument dialog to song detail
1 parent fba8fa7 commit c5c50d6

7 files changed

+33
-59
lines changed

godot/scenes/Services/NumberHelper.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public static string ToMinSec(this double value, bool frac = false) {
1010
var fracStr = frac ? $" {(int)((decimal)value % 1 * 1000)}ms" : null;
1111
return $"{Math.Floor(value/60f)}m {Math.Floor(value % 60)}s{fracStr}";
1212
}
13-
14-
public static string ToFixedPlaces(this float value, int count, bool leadChar) {
13+
14+
public static string ToFixedPlaces(this float value, int count, bool leadChar = false) {
1515
return ((double)value).ToFixedPlaces(count, leadChar);
1616
}
1717

18-
public static string ToFixedPlaces(this double value, int count, bool leadChar) {
18+
public static string ToFixedPlaces(this double value, int count, bool leadChar = false) {
1919
if (count < 0) count = 0;
2020
var zeros = new string('0', count);
2121
if (leadChar)

godot/scenes/SongDisplay.cs

+18-9
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@ namespace murph9.TabPlayer.scenes;
1010
public partial class SongDisplay : VBoxContainer
1111
{
1212
[Signal]
13-
public delegate void SongSelectedEventHandler(string folder);
13+
public delegate void SongSelectedEventHandler(string folder, string instrument);
1414

1515
private string _folderName;
1616

1717
public override void _Ready() {}
1818

1919
public override void _Process(double delta) { }
2020

21-
private void Play_Selected() => EmitSignal(SignalName.SongSelected, _folderName);
22-
2321
public void SongChanged(string folderName) {
2422
_folderName = folderName;
25-
GetNode<Button>("PlayButton").Visible = true; // please don't press it before we are ready
2623
LoadSong();
2724
}
2825

@@ -42,18 +39,30 @@ private void LoadSong() {
4239
var grid = GetNode<GridContainer>("InstrumentGridContainer");
4340
grid.GetChildren().ToList().ForEach(grid.RemoveChild); // remove all children from the grid
4441

45-
grid.AddChild(new Label() { Text = "Instrument Name"});
42+
grid.AddChild(new Label());
4643
grid.AddChild(new Label() { Text = "Tuning"});
4744
grid.AddChild(new Label() { Text = "Note Counts"});
4845
grid.AddChild(new Label() { Text = "Note Density"});
49-
46+
5047
grid.Columns = grid.GetChildren().Count;
5148

52-
foreach (var i in songInfo.Instruments) {
53-
grid.AddChild(new Label() { Text = i.Name });
49+
var insturmentsOrdered = songInfo.Instruments.OrderBy(x =>
50+
{
51+
if (SongInfo.INSTRUMENT_ORDER.ContainsKey(x.Name))
52+
return SongInfo.INSTRUMENT_ORDER[x.Name];
53+
// handle all other entries as in given order
54+
return 999;
55+
}).ToList();
56+
57+
foreach (var i in insturmentsOrdered) {
58+
var button = new Button() { Text = "Play " + i.Name.Capitalize() };
59+
button.Pressed += () => {
60+
EmitSignal(SignalName.SongSelected, _folderName, i.Name);
61+
};
62+
grid.AddChild(button);
5463
grid.AddChild(new Label() { Text = Instrument.CalcTuningName(i.Config.Tuning, i.Config.CapoFret) });
5564
grid.AddChild(new Label() { Text = $"{i.TotalNoteCount()}, c: {i.ChordCount()}, n: {i.SingleNoteCount()}" });
56-
grid.AddChild(new Label() { Text = i.GetNoteDensity(songInfo).ToString() });
65+
grid.AddChild(new Label() { Text = i.GetNoteDensity(songInfo).ToFixedPlaces(2) });
5766
}
5867
}
5968
}

godot/scenes/SongDisplay.tscn

-7
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ texture = SubResource("GradientTexture2D_348oa")
2525
expand_mode = 3
2626
stretch_mode = 5
2727

28-
[node name="PlayButton" type="Button" parent="."]
29-
visible = false
30-
layout_mode = 2
31-
text = "Play"
32-
3328
[node name="ArtistLabel" type="Label" parent="."]
3429
layout_mode = 2
3530
text = "Select a song to start"
@@ -48,5 +43,3 @@ layout_mode = 2
4843

4944
[node name="InstrumentGridContainer" type="GridContainer" parent="."]
5045
layout_mode = 2
51-
52-
[connection signal="pressed" from="PlayButton" to="." method="Play_Selected"]

godot/scenes/SongPick.cs

+5-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using Godot;
2-
using murph9.TabPlayer.scenes.Services;
32
using murph9.TabPlayer.Songs;
4-
using murph9.TabPlayer.Songs.Models;
53
using System.Linq;
64

75
namespace murph9.TabPlayer.scenes;
@@ -18,10 +16,10 @@ public partial class SongPick : Control
1816

1917
public SongPick() {
2018
_songDisplay = GD.Load<PackedScene>("res://scenes/SongDisplay.tscn").Instantiate<SongDisplay>();
21-
_songDisplay.SongSelected += (string s) =>
19+
_songDisplay.SongSelected += (string folder, string instrument) =>
2220
{
2321
SongFileList songList = SongFileManager.GetSongFileList();
24-
ChooseSong(songList.Data.First(x => s == x.FolderName));
22+
ChooseSong(songList.Data.First(x => folder == x.FolderName), instrument);
2523
};
2624

2725
_songList = GD.Load<PackedScene>("res://scenes/SongList.tscn").Instantiate<SongList>();
@@ -37,35 +35,11 @@ public override void _Ready() {
3735
vbox.AddChild(_songList);
3836
}
3937

40-
public override void _Process(double delta)
41-
{
42-
}
38+
public override void _Process(double delta) { }
4339

44-
private void ChooseSong(SongFile song) {
45-
GD.Print("Selected: " + song.SongName);
40+
private void ChooseSong(SongFile song, string instrument) {
41+
GD.Print($"Selected: {song.SongName} with path {instrument}");
4642

47-
var panel = GetNode<PopupPanel>("PopupPanel");
48-
panel.GetChildren().ToList().ForEach(panel.RemoveChild);
49-
50-
var layout = new VBoxContainer();
51-
panel.AddChild(layout);
52-
53-
layout.AddChild(new Label() {
54-
Text = $"Select an instrument for song:\n{song.SongName}\n{song.Artist} ({song.Year})\n{song.Length.ToMinSec()}"
55-
});
56-
57-
foreach (var i in song.Instruments) {
58-
var b = new Button() {
59-
Text = $"{i.Name} Tuning: {Instrument.CalcTuningName(i.Tuning, i.CapoFret)} | Notes: {i.NoteCount} @ {i.GetNoteDensity(song).ToFixedPlaces(2, false)}"
60-
};
61-
b.Pressed += () => SelectedItem_LoadSong(song, i.Name);
62-
layout.AddChild(b);
63-
}
64-
65-
panel.PopupCentered();
66-
}
67-
68-
private void SelectedItem_LoadSong(SongFile song, string instrument) {
6943
EmitSignal(SignalName.OpenedSong, song.FolderName, instrument);
7044
}
7145

godot/scenes/SongPick.tscn

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ size_flags_horizontal = 3
1616
size_flags_vertical = 3
1717
script = ExtResource("1_tdao1")
1818

19-
[node name="PopupPanel" type="PopupPanel" parent="."]
20-
2119
[node name="MarginContainer" type="MarginContainer" parent="."]
2220
layout_mode = 1
2321
anchors_preset = 15

godot/scenes/StartMenu.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override void _Process(double delta) {
3636
GetNode<Label>("ReloadProgressLabel").Text = _progressText;
3737
}
3838

39-
private void StartButton_Pressed() {
39+
private void PlayButton_Pressed() {
4040
AnimateOut();
4141
EmitSignal(SignalName.SongPickOpened);
4242
}
@@ -52,8 +52,8 @@ private void ConvertButton_Pressed() {
5252
}
5353

5454
private void ReloadButton_Pressed() {
55-
var startButton = GetNode<Button>("%StartButton");
56-
startButton.Disabled = true;
55+
var PlayButton = GetNode<Button>("%PlayButton");
56+
PlayButton.Disabled = true;
5757
var convertButton = GetNode<Button>("%ConvertButton");
5858
convertButton.Disabled = true;
5959
var reloadButton = GetNode<Button>("%ReloadButton");
@@ -65,7 +65,7 @@ private void ReloadButton_Pressed() {
6565
CallDeferred("emit_signal", SignalName.SongListFileChanged);
6666
reloadButton.SetDeferred("disabled", false);
6767
convertButton.SetDeferred("disabled", false);
68-
startButton.SetDeferred("disabled", false);
68+
PlayButton.SetDeferred("disabled", false);
6969
});
7070
}
7171

godot/scenes/StartMenu.tscn

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ offset_top = 700.0
5454
offset_right = 250.0
5555
offset_bottom = 906.0
5656

57-
[node name="StartButton" type="Button" parent="VBoxContainer"]
57+
[node name="PlayButton" type="Button" parent="VBoxContainer"]
5858
unique_name_in_owner = true
5959
custom_minimum_size = Vector2(150, 0)
6060
layout_mode = 2
61-
text = "Start"
61+
text = "Play"
6262

6363
[node name="ConvertButton" type="Button" parent="VBoxContainer"]
6464
unique_name_in_owner = true
@@ -84,7 +84,7 @@ layout_mode = 2
8484
text = "Quit
8585
"
8686

87-
[connection signal="pressed" from="VBoxContainer/StartButton" to="." method="StartButton_Pressed"]
87+
[connection signal="pressed" from="VBoxContainer/PlayButton" to="." method="PlayButton_Pressed"]
8888
[connection signal="pressed" from="VBoxContainer/ConvertButton" to="." method="ConvertButton_Pressed"]
8989
[connection signal="pressed" from="VBoxContainer/ReloadButton" to="." method="ReloadButton_Pressed"]
9090
[connection signal="pressed" from="VBoxContainer/InfoButton" to="." method="InfoButton_Pressed"]

0 commit comments

Comments
 (0)