Skip to content

Commit

Permalink
move weird instrument dialog to song detail
Browse files Browse the repository at this point in the history
  • Loading branch information
Murph9 committed Oct 8, 2023
1 parent fba8fa7 commit c5c50d6
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 59 deletions.
6 changes: 3 additions & 3 deletions godot/scenes/Services/NumberHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public static string ToMinSec(this double value, bool frac = false) {
var fracStr = frac ? $" {(int)((decimal)value % 1 * 1000)}ms" : null;
return $"{Math.Floor(value/60f)}m {Math.Floor(value % 60)}s{fracStr}";
}

public static string ToFixedPlaces(this float value, int count, bool leadChar) {
public static string ToFixedPlaces(this float value, int count, bool leadChar = false) {
return ((double)value).ToFixedPlaces(count, leadChar);
}

public static string ToFixedPlaces(this double value, int count, bool leadChar) {
public static string ToFixedPlaces(this double value, int count, bool leadChar = false) {
if (count < 0) count = 0;
var zeros = new string('0', count);
if (leadChar)
Expand Down
27 changes: 18 additions & 9 deletions godot/scenes/SongDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ namespace murph9.TabPlayer.scenes;
public partial class SongDisplay : VBoxContainer
{
[Signal]
public delegate void SongSelectedEventHandler(string folder);
public delegate void SongSelectedEventHandler(string folder, string instrument);

private string _folderName;

public override void _Ready() {}

public override void _Process(double delta) { }

private void Play_Selected() => EmitSignal(SignalName.SongSelected, _folderName);

public void SongChanged(string folderName) {
_folderName = folderName;
GetNode<Button>("PlayButton").Visible = true; // please don't press it before we are ready
LoadSong();
}

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

grid.AddChild(new Label() { Text = "Instrument Name"});
grid.AddChild(new Label());
grid.AddChild(new Label() { Text = "Tuning"});
grid.AddChild(new Label() { Text = "Note Counts"});
grid.AddChild(new Label() { Text = "Note Density"});

grid.Columns = grid.GetChildren().Count;

foreach (var i in songInfo.Instruments) {
grid.AddChild(new Label() { Text = i.Name });
var insturmentsOrdered = songInfo.Instruments.OrderBy(x =>
{
if (SongInfo.INSTRUMENT_ORDER.ContainsKey(x.Name))
return SongInfo.INSTRUMENT_ORDER[x.Name];
// handle all other entries as in given order
return 999;
}).ToList();

foreach (var i in insturmentsOrdered) {
var button = new Button() { Text = "Play " + i.Name.Capitalize() };
button.Pressed += () => {
EmitSignal(SignalName.SongSelected, _folderName, i.Name);
};
grid.AddChild(button);
grid.AddChild(new Label() { Text = Instrument.CalcTuningName(i.Config.Tuning, i.Config.CapoFret) });
grid.AddChild(new Label() { Text = $"{i.TotalNoteCount()}, c: {i.ChordCount()}, n: {i.SingleNoteCount()}" });
grid.AddChild(new Label() { Text = i.GetNoteDensity(songInfo).ToString() });
grid.AddChild(new Label() { Text = i.GetNoteDensity(songInfo).ToFixedPlaces(2) });
}
}
}
7 changes: 0 additions & 7 deletions godot/scenes/SongDisplay.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ texture = SubResource("GradientTexture2D_348oa")
expand_mode = 3
stretch_mode = 5

[node name="PlayButton" type="Button" parent="."]
visible = false
layout_mode = 2
text = "Play"

[node name="ArtistLabel" type="Label" parent="."]
layout_mode = 2
text = "Select a song to start"
Expand All @@ -48,5 +43,3 @@ layout_mode = 2

[node name="InstrumentGridContainer" type="GridContainer" parent="."]
layout_mode = 2

[connection signal="pressed" from="PlayButton" to="." method="Play_Selected"]
36 changes: 5 additions & 31 deletions godot/scenes/SongPick.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Godot;
using murph9.TabPlayer.scenes.Services;
using murph9.TabPlayer.Songs;
using murph9.TabPlayer.Songs.Models;
using System.Linq;

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

public SongPick() {
_songDisplay = GD.Load<PackedScene>("res://scenes/SongDisplay.tscn").Instantiate<SongDisplay>();
_songDisplay.SongSelected += (string s) =>
_songDisplay.SongSelected += (string folder, string instrument) =>
{
SongFileList songList = SongFileManager.GetSongFileList();
ChooseSong(songList.Data.First(x => s == x.FolderName));
ChooseSong(songList.Data.First(x => folder == x.FolderName), instrument);
};

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

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

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

var panel = GetNode<PopupPanel>("PopupPanel");
panel.GetChildren().ToList().ForEach(panel.RemoveChild);

var layout = new VBoxContainer();
panel.AddChild(layout);

layout.AddChild(new Label() {
Text = $"Select an instrument for song:\n{song.SongName}\n{song.Artist} ({song.Year})\n{song.Length.ToMinSec()}"
});

foreach (var i in song.Instruments) {
var b = new Button() {
Text = $"{i.Name} Tuning: {Instrument.CalcTuningName(i.Tuning, i.CapoFret)} | Notes: {i.NoteCount} @ {i.GetNoteDensity(song).ToFixedPlaces(2, false)}"
};
b.Pressed += () => SelectedItem_LoadSong(song, i.Name);
layout.AddChild(b);
}

panel.PopupCentered();
}

private void SelectedItem_LoadSong(SongFile song, string instrument) {
EmitSignal(SignalName.OpenedSong, song.FolderName, instrument);
}

Expand Down
2 changes: 0 additions & 2 deletions godot/scenes/SongPick.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource("1_tdao1")

[node name="PopupPanel" type="PopupPanel" parent="."]

[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 1
anchors_preset = 15
Expand Down
8 changes: 4 additions & 4 deletions godot/scenes/StartMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void _Process(double delta) {
GetNode<Label>("ReloadProgressLabel").Text = _progressText;
}

private void StartButton_Pressed() {
private void PlayButton_Pressed() {
AnimateOut();
EmitSignal(SignalName.SongPickOpened);
}
Expand All @@ -52,8 +52,8 @@ private void ConvertButton_Pressed() {
}

private void ReloadButton_Pressed() {
var startButton = GetNode<Button>("%StartButton");
startButton.Disabled = true;
var PlayButton = GetNode<Button>("%PlayButton");
PlayButton.Disabled = true;
var convertButton = GetNode<Button>("%ConvertButton");
convertButton.Disabled = true;
var reloadButton = GetNode<Button>("%ReloadButton");
Expand All @@ -65,7 +65,7 @@ private void ReloadButton_Pressed() {
CallDeferred("emit_signal", SignalName.SongListFileChanged);
reloadButton.SetDeferred("disabled", false);
convertButton.SetDeferred("disabled", false);
startButton.SetDeferred("disabled", false);
PlayButton.SetDeferred("disabled", false);
});
}

Expand Down
6 changes: 3 additions & 3 deletions godot/scenes/StartMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ offset_top = 700.0
offset_right = 250.0
offset_bottom = 906.0

[node name="StartButton" type="Button" parent="VBoxContainer"]
[node name="PlayButton" type="Button" parent="VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
text = "Start"
text = "Play"

[node name="ConvertButton" type="Button" parent="VBoxContainer"]
unique_name_in_owner = true
Expand All @@ -84,7 +84,7 @@ layout_mode = 2
text = "Quit
"

[connection signal="pressed" from="VBoxContainer/StartButton" to="." method="StartButton_Pressed"]
[connection signal="pressed" from="VBoxContainer/PlayButton" to="." method="PlayButton_Pressed"]
[connection signal="pressed" from="VBoxContainer/ConvertButton" to="." method="ConvertButton_Pressed"]
[connection signal="pressed" from="VBoxContainer/ReloadButton" to="." method="ReloadButton_Pressed"]
[connection signal="pressed" from="VBoxContainer/InfoButton" to="." method="InfoButton_Pressed"]
Expand Down

0 comments on commit c5c50d6

Please sign in to comment.