We have more music
This commit is contained in:
@@ -50,6 +50,7 @@ namespace OpenRA.FileFormats
|
|||||||
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
|
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
|
||||||
public Dictionary<string, MiniYaml> Weapons = new Dictionary<string, MiniYaml>();
|
public Dictionary<string, MiniYaml> Weapons = new Dictionary<string, MiniYaml>();
|
||||||
public Dictionary<string, MiniYaml> Voices = new Dictionary<string, MiniYaml>();
|
public Dictionary<string, MiniYaml> Voices = new Dictionary<string, MiniYaml>();
|
||||||
|
public Dictionary<string, MiniYaml> Music = new Dictionary<string, MiniYaml>();
|
||||||
public Dictionary<string, MiniYaml> Terrain = new Dictionary<string, MiniYaml>();
|
public Dictionary<string, MiniYaml> Terrain = new Dictionary<string, MiniYaml>();
|
||||||
// Binary map data
|
// Binary map data
|
||||||
public byte TileFormat = 1;
|
public byte TileFormat = 1;
|
||||||
|
|||||||
@@ -8,43 +8,33 @@ namespace OpenRA.GameRules
|
|||||||
{
|
{
|
||||||
public class MusicInfo
|
public class MusicInfo
|
||||||
{
|
{
|
||||||
public readonly Lazy<Dictionary<string, MusicPool>> Pools;
|
public readonly MusicPool Pool;
|
||||||
public readonly string[] Music = { };
|
public readonly string[] Music = { };
|
||||||
|
|
||||||
public MusicInfo( MiniYaml y )
|
public MusicInfo( MiniYaml y )
|
||||||
{
|
{
|
||||||
FieldLoader.Load(this, y);
|
FieldLoader.Load(this, y);
|
||||||
|
Pool = new MusicPool(Music);
|
||||||
Pools = Lazy.New(() =>
|
|
||||||
new Dictionary<string, MusicPool>
|
|
||||||
{
|
|
||||||
{ "Music", new MusicPool(Music) },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MusicPool
|
public class MusicPool
|
||||||
{
|
{
|
||||||
readonly string[] clips;
|
readonly string[] clips;
|
||||||
readonly List<string> liveclips = new List<string>();
|
int playing = 0;
|
||||||
|
|
||||||
public MusicPool(params string[] clips)
|
public MusicPool(params string[] clips)
|
||||||
{
|
{
|
||||||
this.clips = clips;
|
this.clips = clips;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetNext()
|
public string GetNext() {
|
||||||
{
|
playing = (playing + 1) % clips.Length;
|
||||||
if (liveclips.Count == 0)
|
return clips[playing];
|
||||||
liveclips.AddRange(clips);
|
}
|
||||||
|
public string GetPrev() {
|
||||||
if (liveclips.Count == 0)
|
playing = (playing + clips.Length - 1) % clips.Length;
|
||||||
return null; /* avoid crashing if there's no clips at all */
|
return clips[playing];
|
||||||
|
|
||||||
var i = Game.CosmeticRandom.Next(liveclips.Count);
|
|
||||||
var s = liveclips[i];
|
|
||||||
liveclips.RemoveAt(i);
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ namespace OpenRA
|
|||||||
Info = LoadYamlRules(m.Rules, map.Rules, (k, y) => new ActorInfo(k.Key.ToLowerInvariant(), k.Value, y));
|
Info = LoadYamlRules(m.Rules, map.Rules, (k, y) => new ActorInfo(k.Key.ToLowerInvariant(), k.Value, y));
|
||||||
Weapons = LoadYamlRules(m.Weapons, map.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value));
|
Weapons = LoadYamlRules(m.Weapons, map.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value));
|
||||||
Voices = LoadYamlRules(m.Voices, map.Voices, (k, _) => new VoiceInfo(k.Value));
|
Voices = LoadYamlRules(m.Voices, map.Voices, (k, _) => new VoiceInfo(k.Value));
|
||||||
|
Music = LoadYamlRules(m.Music, map.Music, (k, _) => new MusicInfo(k.Value));
|
||||||
TerrainTypes = LoadYamlRules(m.Terrain, map.Terrain, (k, _) => new TerrainCost(k.Value))
|
TerrainTypes = LoadYamlRules(m.Terrain, map.Terrain, (k, _) => new TerrainCost(k.Value))
|
||||||
.ToDictionary(kv => (TerrainType)Enum.Parse(typeof(TerrainType), kv.Key, true), kv => kv.Value);
|
.ToDictionary(kv => (TerrainType)Enum.Parse(typeof(TerrainType), kv.Key, true), kv => kv.Value);
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
bg.GetWidget("BUTTON_PREV").OnMouseUp = mi => {
|
bg.GetWidget("BUTTON_PREV").OnMouseUp = mi => {
|
||||||
Sound.PlayMusic(GetNextSong());
|
Sound.PlayMusic(GetPrevSong());
|
||||||
Sound.MusicPaused = false;
|
Sound.MusicPaused = false;
|
||||||
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
||||||
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
||||||
@@ -58,10 +58,7 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetNextSong()
|
string GetNextSong() { return Rules.Music["allmusic"].Pool.GetNext(); }
|
||||||
{
|
string GetPrevSong() { return Rules.Music["allmusic"].Pool.GetPrev(); }
|
||||||
//goes boom here
|
|
||||||
return Rules.Music["AllMusic"].Pools.Value["Music"].GetNext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user