Next track / repeat on song completion.
This commit is contained in:
@@ -118,7 +118,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
lastTime += Settings.Game.Timestep;
|
lastTime += Settings.Game.Timestep;
|
||||||
Widget.DoTick(world);
|
Widget.DoTick(world);
|
||||||
|
Sound.Tick();
|
||||||
orderManager.TickImmediate(world);
|
orderManager.TickImmediate(world);
|
||||||
|
|
||||||
var isNetTick = LocalTick % NetTickScale == 0;
|
var isNetTick = LocalTick % NetTickScale == 0;
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ namespace OpenRA.GameRules
|
|||||||
public float MusicVolume = 0.5f;
|
public float MusicVolume = 0.5f;
|
||||||
public float VideoVolume = 0.5f;
|
public float VideoVolume = 0.5f;
|
||||||
public bool Shuffle = false;
|
public bool Shuffle = false;
|
||||||
|
public bool Repeat = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlayerSettings
|
public class PlayerSettings
|
||||||
|
|||||||
@@ -102,9 +102,27 @@ namespace OpenRA
|
|||||||
soundEngine.StopSound(video);
|
soundEngine.StopSound(video);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Tick()
|
||||||
|
{
|
||||||
|
// Song finished
|
||||||
|
if (MusicPlaying && !music.Playing)
|
||||||
|
{
|
||||||
|
StopMusic();
|
||||||
|
OnMusicComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Action OnMusicComplete;
|
||||||
public static bool MusicPlaying { get; private set; }
|
public static bool MusicPlaying { get; private set; }
|
||||||
|
|
||||||
public static void PlayMusic(string name)
|
public static void PlayMusic(string name)
|
||||||
{
|
{
|
||||||
|
PlayMusicThen(name, () => {});
|
||||||
|
}
|
||||||
|
public static void PlayMusicThen(string name, Action then)
|
||||||
|
{
|
||||||
|
OnMusicComplete = then;
|
||||||
|
|
||||||
if (name == "" || name == null)
|
if (name == "" || name == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -118,7 +136,7 @@ namespace OpenRA
|
|||||||
currentMusic = name;
|
currentMusic = name;
|
||||||
MusicPlaying = true;
|
MusicPlaying = true;
|
||||||
var sound = sounds[name];
|
var sound = sounds[name];
|
||||||
music = soundEngine.Play2D(sound, true, true, float2.Zero, MusicVolume);
|
music = soundEngine.Play2D(sound, false, true, float2.Zero, MusicVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PlayMusic()
|
public static void PlayMusic()
|
||||||
@@ -236,6 +254,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
float Volume { get; set; }
|
float Volume { get; set; }
|
||||||
float SeekPosition { get; }
|
float SeekPosition { get; }
|
||||||
|
bool Playing { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class OpenAlSoundEngine : ISoundEngine
|
class OpenAlSoundEngine : ISoundEngine
|
||||||
@@ -448,5 +467,15 @@ namespace OpenRA
|
|||||||
return pos/22050f;
|
return pos/22050f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Playing
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int state;
|
||||||
|
Al.alGetSourcei(source, Al.AL_SOURCE_STATE, out state);
|
||||||
|
return state == Al.AL_PLAYING;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
if (CurrentSong == null)
|
if (CurrentSong == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Sound.PlayMusic(Rules.Music[CurrentSong].Filename);
|
Sound.PlayMusicThen(Rules.Music[CurrentSong].Filename,
|
||||||
|
() => bg.GetWidget(Game.Settings.Sound.Repeat ? "BUTTON_PLAY" : "BUTTON_NEXT").OnMouseUp(new MouseInput()));
|
||||||
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
||||||
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
||||||
|
|
||||||
@@ -82,6 +83,14 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
};
|
};
|
||||||
shuffle.Checked = () => Game.Settings.Sound.Shuffle;
|
shuffle.Checked = () => Game.Settings.Sound.Shuffle;
|
||||||
|
|
||||||
|
var repeat = bg.GetWidget<CheckboxWidget>("REPEAT");
|
||||||
|
repeat.OnMouseDown = mi =>
|
||||||
|
{
|
||||||
|
Game.Settings.Sound.Repeat ^= true;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
repeat.Checked = () => Game.Settings.Sound.Repeat;
|
||||||
|
|
||||||
bg.GetWidget<LabelWidget>("TIME").GetText = () =>
|
bg.GetWidget<LabelWidget>("TIME").GetText = () =>
|
||||||
{
|
{
|
||||||
if (CurrentSong == null)
|
if (CurrentSong == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user