Half of having choices of music and a player of it (not finished)

This commit is contained in:
alzeih
2010-05-05 23:06:42 +12:00
parent acf55f1bb0
commit 30ee0afdc0
7 changed files with 88 additions and 6 deletions

View File

@@ -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;

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using OpenRA.FileFormats;
namespace OpenRA.GameRules
{
public class MusicInfo
{
public readonly Lazy<Dictionary<string, MusicPool>> Pools;
public readonly string[] Music = { };
public MusicInfo( MiniYaml y )
{
FieldLoader.Load(this, y);
Pools = Lazy.New(() =>
new Dictionary<string, MusicPool>
{
{ "Music", new MusicPool(Music) },
});
}
}
public class MusicPool
{
readonly string[] clips;
readonly List<string> liveclips = new List<string>();
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;
}
}
}

View File

@@ -33,6 +33,7 @@ namespace OpenRA
public static Dictionary<string, ActorInfo> Info;
public static Dictionary<string, WeaponInfo> Weapons;
public static Dictionary<string, VoiceInfo> Voices;
public static Dictionary<string, MusicInfo> Music;
public static Dictionary<TerrainType, TerrainCost> 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);

View File

@@ -312,6 +312,7 @@
<Compile Include="Traits\World\BridgeLayer.cs" />
<Compile Include="Widgets\Delegates\LobbyDelegate.cs" />
<Compile Include="Widgets\ColorBlockWidget.cs" />
<Compile Include="GameRules\MusicInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -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;
};
}
}
}

View File

@@ -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:<<

2
mods/ra/music.yaml Normal file
View File

@@ -0,0 +1,2 @@
AllMusic:
Music: hell226m.aud