From 30ee0afdc0d455cce0bde9412a422a53dc3055af Mon Sep 17 00:00:00 2001 From: alzeih Date: Wed, 5 May 2010 23:06:42 +1200 Subject: [PATCH] Half of having choices of music and a player of it (not finished) --- OpenRA.FileFormats/Session.cs | 3 +- OpenRA.Game/GameRules/MusicInfo.cs | 50 +++++++++++++++++++ OpenRA.Game/GameRules/Rules.cs | 2 + OpenRA.Game/OpenRA.Game.csproj | 1 + .../Widgets/Delegates/MusicPlayerDelegate.cs | 12 +++++ mods/ra/menus.yaml | 24 +++++++-- mods/ra/music.yaml | 2 + 7 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 OpenRA.Game/GameRules/MusicInfo.cs create mode 100644 mods/ra/music.yaml diff --git a/OpenRA.FileFormats/Session.cs b/OpenRA.FileFormats/Session.cs index e91c9debc2..ff9254630e 100644 --- a/OpenRA.FileFormats/Session.cs +++ b/OpenRA.FileFormats/Session.cs @@ -61,7 +61,7 @@ namespace OpenRA.FileFormats public readonly string[] Folders, Packages, Rules, Sequences, Chrome, Assemblies, ChromeLayout, - Weapons, Voices, Terrain; + Weapons, Voices, Music, Terrain; public readonly string ShellmapUid; @@ -80,6 +80,7 @@ namespace OpenRA.FileFormats ChromeLayout = YamlList(yaml, "ChromeLayout"); Weapons = YamlList(yaml, "Weapons"); Voices = YamlList(yaml, "Voices"); + Music = YamlList(yaml, "Music"); Terrain = YamlList(yaml, "Terrain"); ShellmapUid = yaml["ShellmapUid"].Value; diff --git a/OpenRA.Game/GameRules/MusicInfo.cs b/OpenRA.Game/GameRules/MusicInfo.cs new file mode 100644 index 0000000000..651f500c1f --- /dev/null +++ b/OpenRA.Game/GameRules/MusicInfo.cs @@ -0,0 +1,50 @@ + +using System; + +using System.Collections.Generic; +using OpenRA.FileFormats; + +namespace OpenRA.GameRules +{ + public class MusicInfo + { + public readonly Lazy> Pools; + public readonly string[] Music = { }; + + public MusicInfo( MiniYaml y ) + { + FieldLoader.Load(this, y); + + Pools = Lazy.New(() => + new Dictionary + { + { "Music", new MusicPool(Music) }, + }); + } + } + + public class MusicPool + { + readonly string[] clips; + readonly List liveclips = new List(); + + public MusicPool(params string[] clips) + { + this.clips = clips; + } + + public string GetNext() + { + if (liveclips.Count == 0) + liveclips.AddRange(clips); + + if (liveclips.Count == 0) + return null; /* avoid crashing if there's no clips at all */ + + var i = Game.CosmeticRandom.Next(liveclips.Count); + var s = liveclips[i]; + liveclips.RemoveAt(i); + return s; + } + } +} diff --git a/OpenRA.Game/GameRules/Rules.cs b/OpenRA.Game/GameRules/Rules.cs index 019c043731..d0f6e081c2 100755 --- a/OpenRA.Game/GameRules/Rules.cs +++ b/OpenRA.Game/GameRules/Rules.cs @@ -33,6 +33,7 @@ namespace OpenRA public static Dictionary Info; public static Dictionary Weapons; public static Dictionary Voices; + public static Dictionary Music; public static Dictionary TerrainTypes; public static void LoadRules(Manifest m) @@ -44,6 +45,7 @@ namespace OpenRA Info = LoadYamlRules(m.Rules, (k, y) => new ActorInfo(k.Key.ToLowerInvariant(), k.Value, y)); Weapons = LoadYamlRules(m.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value)); Voices = LoadYamlRules(m.Voices, (k, _) => new VoiceInfo(k.Value)); + Music = LoadYamlRules(m.Music, (k, _) => new MusicInfo(k.Value)); TerrainTypes = LoadYamlRules(m.Terrain, (k, _) => new TerrainCost(k.Value)) .ToDictionary(kv => (TerrainType)Enum.Parse(typeof(TerrainType), kv.Key, true), kv => kv.Value); diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 75a6c04b9f..2517e201c2 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -312,6 +312,7 @@ + diff --git a/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs b/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs index e9e80d8173..606d404e92 100644 --- a/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs @@ -42,6 +42,18 @@ namespace OpenRA.Widgets.Delegates bg.Visible = false; return true; }; + bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi => { + Sound.MusicPaused = false; + bg.GetWidget("BUTTON_PLAY").Visible = false; + bg.GetWidget("BUTTON_PAUSE").Visible = true; + return true; + }; + bg.GetWidget("BUTTON_PREV").OnMouseUp = mi => { + Sound.MusicPaused = false; + bg.GetWidget("BUTTON_PLAY").Visible = false; + bg.GetWidget("BUTTON_PAUSE").Visible = true; + return true; + }; } } } diff --git a/mods/ra/menus.yaml b/mods/ra/menus.yaml index 6f5926731b..f8f8b29421 100644 --- a/mods/ra/menus.yaml +++ b/mods/ra/menus.yaml @@ -629,34 +629,48 @@ Container: Background@MUSIC_BG: Id:MUSIC_BG Delegate:MusicPlayerDelegate - X:WINDOW_RIGHT - 100 + X:WINDOW_RIGHT - 175 Y:WINDOW_BOTTOM - 65 - Width: 90 + Width: 160 Height: 55 Visible: true Children: Button@BUTTON_PLAY: Id:BUTTON_PLAY Visible:false - X:15 + X:50 Y:15 Width:25 Height:25 Text:|> Button@BUTTON_PAUSE: Id:BUTTON_PAUSE - X:15 + X:50 Y:15 Width:25 Height:25 Text:|| Button@BUTTON_STOP: Id:BUTTON_STOP - X:50 + X:85 Y:15 Width:25 Height:25 Text:[] + Button@BUTTON_NEXT: + Id:BUTTON_NEXT + X:120 + Y:15 + Width:25 + Height:25 + Text:>> + Button@BUTTON_PREV: + Id:BUTTON_PREV + X:15 + Y:15 + Width:25 + Height:25 + Text:<< diff --git a/mods/ra/music.yaml b/mods/ra/music.yaml new file mode 100644 index 0000000000..4d8b4b1d48 --- /dev/null +++ b/mods/ra/music.yaml @@ -0,0 +1,2 @@ +AllMusic: + Music: hell226m.aud \ No newline at end of file