diff --git a/OpenRA.Game/GameRules/MusicInfo.cs b/OpenRA.Game/GameRules/MusicInfo.cs index a46ff9f66a..993ec12ea2 100644 --- a/OpenRA.Game/GameRules/MusicInfo.cs +++ b/OpenRA.Game/GameRules/MusicInfo.cs @@ -16,7 +16,7 @@ namespace OpenRA.GameRules { public readonly string Filename = null; public readonly string Title = null; - public readonly float Length = 0; // seconds + public readonly int Length = 0; // seconds public MusicInfo( string key, MiniYaml value ) { diff --git a/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs b/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs index ba3f6f45d9..54fa130e37 100644 --- a/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs @@ -1,5 +1,7 @@ using System.Linq; using OpenRA.FileFormats; +using System.Drawing; +using OpenRA.Support; #region Copyright & License Information /* * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) @@ -61,6 +63,44 @@ namespace OpenRA.Widgets.Delegates CurrentSong = GetPrevSong(); return bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi); }; + + bg.GetWidget("TIME").GetText = () => "{0:D2}:{1:D2} / {2:D2}:{3:D2}".F(0,0,Rules.Music[CurrentSong].Length / 60, Rules.Music[CurrentSong].Length % 60); + + var ml = bg.GetWidget("MUSIC_LIST"); + var itemTemplate = ml.GetWidget("MUSIC_TEMPLATE"); + int offset = itemTemplate.Bounds.Y; + + foreach (var kv in Rules.Music) + { + var song = kv.Key; + if (!FileSystem.Exists(Rules.Music[song].Filename)) + continue; + + if (CurrentSong == null) + CurrentSong = song; + + var template = itemTemplate.Clone() as LabelWidget; + template.Id = "SONG_{0}".F(song); + template.GetBackground = () => ((song == CurrentSong) ? "dialog2" : null); + template.OnMouseDown = mi => + { + CurrentSong = song; + bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi); + return true; + }; + template.Parent = ml; + + template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height); + template.IsVisible = () => true; + + template.GetWidget("TITLE").GetText = () => " " + Rules.Music[song].Title; + template.GetWidget("LENGTH").GetText = () => "{0:D2}:{1:D2}".F(Rules.Music[song].Length / 60, Rules.Music[song].Length % 60); + + ml.AddChild(template); + + offset += template.Bounds.Height; + ml.ContentHeight += template.Bounds.Height; + } } string GetNextSong() diff --git a/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs b/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs index c42d9ce7a9..a578a3e50a 100644 --- a/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs @@ -65,14 +65,6 @@ namespace OpenRA.Widgets.Delegates musicslider.OnChange += x => { Sound.MusicVolume = x; }; musicslider.GetOffset = () => { return Sound.MusicVolume; }; - var music = audio.GetWidget("MUSICPLAYER_CHECKBOX"); - music.Checked = () => { return Game.Settings.MusicPlayer; }; - music.OnMouseDown = mi => - { - Game.Settings.MusicPlayer ^= true; - Widget.RootWidget.GetWidget("MUSIC_BG").Visible = Game.Settings.MusicPlayer; - return true; - }; // Display var display = bg.GetWidget("DISPLAY_PANE"); diff --git a/mods/ra/chrome/mainmenu.yaml b/mods/ra/chrome/mainmenu.yaml index f1df036750..91ee4c8149 100644 --- a/mods/ra/chrome/mainmenu.yaml +++ b/mods/ra/chrome/mainmenu.yaml @@ -96,15 +96,14 @@ Background@PERF_BG: Background@MUSIC_BG: Id:MUSIC_BG Delegate:MusicPlayerDelegate - X:WINDOW_RIGHT - 175 - Y:WINDOW_BOTTOM - 95 - Width: 160 - Height: 55 + X:WINDOW_RIGHT - WIDTH - 20 + Y:WINDOW_BOTTOM - HEIGHT - 20 + Width: 300 + Height: 210 Visible: true Children: Button@BUTTON_PLAY: Id:BUTTON_PLAY - Visible:false X:50 Y:15 Width:25 @@ -120,6 +119,7 @@ Background@MUSIC_BG: ImageName:play Button@BUTTON_PAUSE: Id:BUTTON_PAUSE + Visible:false X:50 Y:15 Width:25 @@ -177,4 +177,53 @@ Background@MUSIC_BG: Width:25 Height:25 ImageCollection:music - ImageName:prev \ No newline at end of file + ImageName:prev + Label@TIME: + Id:TIME + X:PARENT_RIGHT - WIDTH - 20 + Y:15 + Width:100 + Height:25 + Align: Right + ListBox@MUSIC_LIST: + Id:MUSIC_LIST + X:10 + Y:50 + Width:280 + Height:120 + Children: + Label@MUSIC_TEMPLATE: + Id:MUSIC_TEMPLATE + Width:PARENT_RIGHT-28 + Height:25 + ClickThrough:false + X:2 + Y:0 + Visible:false + Children: + Label@TITLE: + Id:TITLE + X:5 + Width:PARENT_RIGHT - 10 + Height:PARENT_BOTTOM + Align: Left + Label@LENGTH: + Id:LENGTH + X:5 + Width:PARENT_RIGHT - 10 + Height:PARENT_BOTTOM + Align: Right + Checkbox@SHUFFLE: + Id:SHUFFLE + X:15 + Y:175 + Width:100 + Height:20 + Text:Shuffle + Checkbox@REPEAT: + Id:REPEAT + X:120 + Y:175 + Width:100 + Height:20 + Text:Repeat \ No newline at end of file diff --git a/mods/ra/chrome/settings.yaml b/mods/ra/chrome/settings.yaml index 06f2629c16..4c1a30dc73 100644 --- a/mods/ra/chrome/settings.yaml +++ b/mods/ra/chrome/settings.yaml @@ -123,13 +123,6 @@ Background@SETTINGS_MENU: Width:250 Height:20 Ticks:5 - Checkbox@MUSICPLAYER_CHECKBOX: - Id:MUSICPLAYER_CHECKBOX - X:0 - Y:70 - Width:300 - Height:20 - Text:Show Music Player Container@DISPLAY_PANE: Id:DISPLAY_PANE X:37