tidy up ra music player
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -20,54 +21,35 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
public class MusicPlayerLogic
|
public class MusicPlayerLogic
|
||||||
{
|
{
|
||||||
string CurrentSong = null;
|
string CurrentSong = null;
|
||||||
|
Widget bg;
|
||||||
|
|
||||||
|
public void Play(string song)
|
||||||
|
{
|
||||||
|
CurrentSong = song;
|
||||||
|
if (CurrentSong == null) return;
|
||||||
|
|
||||||
|
Sound.PlayMusicThen(Rules.Music[CurrentSong],
|
||||||
|
() => Play( Game.Settings.Sound.Repeat ? CurrentSong : GetNextSong() ));
|
||||||
|
}
|
||||||
|
|
||||||
public MusicPlayerLogic()
|
public MusicPlayerLogic()
|
||||||
{
|
{
|
||||||
var bg = Widget.RootWidget.GetWidget("MUSIC_MENU");
|
bg = Widget.RootWidget.GetWidget("MUSIC_MENU");
|
||||||
CurrentSong = GetNextSong();
|
CurrentSong = GetNextSong();
|
||||||
|
|
||||||
|
bg.GetWidget( "BUTTON_PAUSE" ).IsVisible = () => Sound.MusicPlaying;
|
||||||
|
bg.GetWidget( "BUTTON_PLAY" ).IsVisible = () => !Sound.MusicPlaying;
|
||||||
|
|
||||||
bg.GetWidget<ButtonWidget>("BUTTON_CLOSE").OnClick =
|
bg.GetWidget<ButtonWidget>("BUTTON_CLOSE").OnClick =
|
||||||
() => { Game.Settings.Save(); Widget.CloseWindow(); };
|
() => { Game.Settings.Save(); Widget.CloseWindow(); };
|
||||||
|
|
||||||
bg.GetWidget("BUTTON_INSTALL").IsVisible = () => false;
|
bg.GetWidget("BUTTON_INSTALL").IsVisible = () => false;
|
||||||
|
|
||||||
bg.GetWidget<ButtonWidget>("BUTTON_PLAY").OnClick = () =>
|
bg.GetWidget<ButtonWidget>("BUTTON_PLAY").OnClick = () => Play( CurrentSong );
|
||||||
{
|
bg.GetWidget<ButtonWidget>("BUTTON_PAUSE").OnClick = Sound.PauseMusic;
|
||||||
if (CurrentSong == null)
|
bg.GetWidget<ButtonWidget>("BUTTON_STOP").OnClick = Sound.StopMusic;
|
||||||
return;
|
bg.GetWidget<ButtonWidget>("BUTTON_NEXT").OnClick = () => Play( GetNextSong() );
|
||||||
|
bg.GetWidget<ButtonWidget>("BUTTON_PREV").OnClick = () => Play( GetPrevSong() );
|
||||||
Sound.PlayMusicThen(Rules.Music[CurrentSong],
|
|
||||||
() => bg.GetWidget<ButtonWidget>(Game.Settings.Sound.Repeat ? "BUTTON_PLAY" : "BUTTON_NEXT")
|
|
||||||
.OnClick());
|
|
||||||
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
|
||||||
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
bg.GetWidget<ButtonWidget>("BUTTON_PAUSE").OnClick = () =>
|
|
||||||
{
|
|
||||||
Sound.PauseMusic();
|
|
||||||
bg.GetWidget("BUTTON_PAUSE").Visible = false;
|
|
||||||
bg.GetWidget("BUTTON_PLAY").Visible = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
bg.GetWidget<ButtonWidget>("BUTTON_STOP").OnClick = () =>
|
|
||||||
{
|
|
||||||
Sound.StopMusic();
|
|
||||||
bg.GetWidget("BUTTON_PAUSE").Visible = false;
|
|
||||||
bg.GetWidget("BUTTON_PLAY").Visible = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
bg.GetWidget<ButtonWidget>("BUTTON_NEXT").OnClick = () =>
|
|
||||||
{
|
|
||||||
CurrentSong = GetNextSong();
|
|
||||||
bg.GetWidget<ButtonWidget>("BUTTON_PLAY").OnClick();
|
|
||||||
};
|
|
||||||
|
|
||||||
bg.GetWidget<ButtonWidget>("BUTTON_PREV").OnClick = () =>
|
|
||||||
{
|
|
||||||
CurrentSong = GetPrevSong();
|
|
||||||
bg.GetWidget<ButtonWidget>("BUTTON_PLAY").OnClick();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var shuffleCheckbox = bg.GetWidget<CheckboxWidget>("SHUFFLE");
|
var shuffleCheckbox = bg.GetWidget<CheckboxWidget>("SHUFFLE");
|
||||||
shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle;
|
shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle;
|
||||||
@@ -99,12 +81,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
foreach (var kv in Rules.InstalledMusic)
|
foreach (var kv in Rules.InstalledMusic)
|
||||||
{
|
{
|
||||||
var song = kv.Key;
|
var song = kv.Key;
|
||||||
if (CurrentSong == null)
|
|
||||||
CurrentSong = song;
|
|
||||||
|
|
||||||
var item = ScrollItemWidget.Setup(itemTemplate,
|
var item = ScrollItemWidget.Setup(itemTemplate,
|
||||||
() => CurrentSong == song,
|
() => CurrentSong == song,
|
||||||
() => { CurrentSong = song; bg.GetWidget<ButtonWidget>("BUTTON_PLAY").OnClick(); });
|
() => Play( song ));
|
||||||
item.GetWidget<LabelWidget>("TITLE").GetText = () => Rules.Music[song].Title;
|
item.GetWidget<LabelWidget>("TITLE").GetText = () => Rules.Music[song].Title;
|
||||||
item.GetWidget<LabelWidget>("LENGTH").GetText =
|
item.GetWidget<LabelWidget>("LENGTH").GetText =
|
||||||
() => WidgetUtils.FormatTimeSeconds( Rules.Music[song].Length );
|
() => WidgetUtils.FormatTimeSeconds( Rules.Music[song].Length );
|
||||||
|
|||||||
Reference in New Issue
Block a user