Add mute option to the game
This commit is contained in:
@@ -127,6 +127,7 @@ namespace OpenRA
|
|||||||
public string Device = null;
|
public string Device = null;
|
||||||
|
|
||||||
public bool CashTicks = true;
|
public bool CashTicks = true;
|
||||||
|
public bool Mute = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlayerSettings
|
public class PlayerSettings
|
||||||
@@ -204,6 +205,7 @@ namespace OpenRA
|
|||||||
public Hotkey DevReloadChromeKey = new Hotkey(Keycode.C, Modifiers.Ctrl | Modifiers.Shift);
|
public Hotkey DevReloadChromeKey = new Hotkey(Keycode.C, Modifiers.Ctrl | Modifiers.Shift);
|
||||||
public Hotkey HideUserInterfaceKey = new Hotkey(Keycode.H, Modifiers.Ctrl | Modifiers.Shift);
|
public Hotkey HideUserInterfaceKey = new Hotkey(Keycode.H, Modifiers.Ctrl | Modifiers.Shift);
|
||||||
public Hotkey TakeScreenshotKey = new Hotkey(Keycode.P, Modifiers.Ctrl);
|
public Hotkey TakeScreenshotKey = new Hotkey(Keycode.P, Modifiers.Ctrl);
|
||||||
|
public Hotkey ToggleMuteKey = new Hotkey(Keycode.M, Modifiers.None);
|
||||||
|
|
||||||
public Hotkey Production01Key = new Hotkey(Keycode.F1, Modifiers.None);
|
public Hotkey Production01Key = new Hotkey(Keycode.F1, Modifiers.None);
|
||||||
public Hotkey Production02Key = new Hotkey(Keycode.F2, Modifiers.None);
|
public Hotkey Production02Key = new Hotkey(Keycode.F2, Modifiers.None);
|
||||||
|
|||||||
@@ -114,6 +114,16 @@ namespace OpenRA
|
|||||||
soundEngine.StopAllSounds();
|
soundEngine.StopAllSounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void MuteAudio()
|
||||||
|
{
|
||||||
|
soundEngine.Volume = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnmuteAudio()
|
||||||
|
{
|
||||||
|
soundEngine.Volume = 1f;
|
||||||
|
}
|
||||||
|
|
||||||
public ISound Play(string name) { return Play(null, name, true, WPos.Zero, 1f); }
|
public ISound Play(string name) { return Play(null, name, true, WPos.Zero, 1f); }
|
||||||
public ISound Play(string name, WPos pos) { return Play(null, name, false, pos, 1f); }
|
public ISound Play(string name, WPos pos) { return Play(null, name, false, pos, 1f); }
|
||||||
public ISound Play(string name, float volumeModifier) { return Play(null, name, true, WPos.Zero, volumeModifier); }
|
public ISound Play(string name, float volumeModifier) { return Play(null, name, true, WPos.Zero, volumeModifier); }
|
||||||
|
|||||||
@@ -302,6 +302,8 @@ namespace OpenRA.Widgets
|
|||||||
return CycleStatusBars();
|
return CycleStatusBars();
|
||||||
else if (key == Game.Settings.Keys.TogglePixelDoubleKey)
|
else if (key == Game.Settings.Keys.TogglePixelDoubleKey)
|
||||||
return TogglePixelDouble();
|
return TogglePixelDouble();
|
||||||
|
else if (key == Game.Settings.Keys.ToggleMuteKey)
|
||||||
|
return ToggleMute();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -360,5 +362,23 @@ namespace OpenRA.Widgets
|
|||||||
worldRenderer.Viewport.Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1;
|
worldRenderer.Viewport.Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ToggleMute()
|
||||||
|
{
|
||||||
|
Game.Settings.Sound.Mute ^= true;
|
||||||
|
|
||||||
|
if (Game.Settings.Sound.Mute)
|
||||||
|
{
|
||||||
|
Game.Sound.MuteAudio();
|
||||||
|
Game.Debug("Audio muted");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Game.Sound.UnmuteAudio();
|
||||||
|
Game.Debug("Audio unmuted");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Func<bool> noMusic = () => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null;
|
Func<bool> noMusic = () => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null;
|
||||||
panel.Get("NO_MUSIC_LABEL").IsVisible = () => !musicPlaylist.IsMusicAvailable;
|
panel.Get("NO_MUSIC_LABEL").IsVisible = () => !musicPlaylist.IsMusicAvailable;
|
||||||
|
|
||||||
|
if (musicPlaylist.IsMusicAvailable)
|
||||||
|
{
|
||||||
|
panel.Get<LabelWidget>("MUTE_LABEL").GetText = () =>
|
||||||
|
{
|
||||||
|
if (Game.Settings.Sound.Mute)
|
||||||
|
return "Audio has been muted in settings.";
|
||||||
|
|
||||||
|
return "";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var playButton = panel.Get<ButtonWidget>("BUTTON_PLAY");
|
var playButton = panel.Get<ButtonWidget>("BUTTON_PLAY");
|
||||||
playButton.OnClick = Play;
|
playButton.OnClick = Play;
|
||||||
playButton.IsDisabled = noMusic;
|
playButton.IsDisabled = noMusic;
|
||||||
|
|||||||
@@ -305,15 +305,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var ss = Game.Settings.Sound;
|
var ss = Game.Settings.Sound;
|
||||||
|
|
||||||
BindCheckboxPref(panel, "CASH_TICKS", ss, "CashTicks");
|
BindCheckboxPref(panel, "CASH_TICKS", ss, "CashTicks");
|
||||||
|
BindCheckboxPref(panel, "MUTE_SOUND", ss, "Mute");
|
||||||
|
|
||||||
BindSliderPref(panel, "SOUND_VOLUME", ss, "SoundVolume");
|
BindSliderPref(panel, "SOUND_VOLUME", ss, "SoundVolume");
|
||||||
BindSliderPref(panel, "MUSIC_VOLUME", ss, "MusicVolume");
|
BindSliderPref(panel, "MUSIC_VOLUME", ss, "MusicVolume");
|
||||||
BindSliderPref(panel, "VIDEO_VOLUME", ss, "VideoVolume");
|
BindSliderPref(panel, "VIDEO_VOLUME", ss, "VideoVolume");
|
||||||
|
|
||||||
// Update volume immediately
|
var muteCheckbox = panel.Get<CheckboxWidget>("MUTE_SOUND");
|
||||||
panel.Get<SliderWidget>("SOUND_VOLUME").OnChange += x => Game.Sound.SoundVolume = x;
|
var muteCheckboxOnClick = muteCheckbox.OnClick;
|
||||||
panel.Get<SliderWidget>("MUSIC_VOLUME").OnChange += x => Game.Sound.MusicVolume = x;
|
muteCheckbox.OnClick = () =>
|
||||||
panel.Get<SliderWidget>("VIDEO_VOLUME").OnChange += x => Game.Sound.VideoVolume = x;
|
{
|
||||||
|
muteCheckboxOnClick();
|
||||||
|
|
||||||
|
if (ss.Mute)
|
||||||
|
Game.Sound.MuteAudio();
|
||||||
|
else
|
||||||
|
Game.Sound.UnmuteAudio();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!ss.Mute)
|
||||||
|
{
|
||||||
|
panel.Get<SliderWidget>("SOUND_VOLUME").OnChange += x => Game.Sound.SoundVolume = x;
|
||||||
|
panel.Get<SliderWidget>("MUSIC_VOLUME").OnChange += x => Game.Sound.MusicVolume = x;
|
||||||
|
panel.Get<SliderWidget>("VIDEO_VOLUME").OnChange += x => Game.Sound.VideoVolume = x;
|
||||||
|
}
|
||||||
|
|
||||||
var devices = Game.Sound.AvailableDevices();
|
var devices = Game.Sound.AvailableDevices();
|
||||||
soundDevice = devices.FirstOrDefault(d => d.Engine == ss.Engine && d.Device == ss.Device) ?? devices.First();
|
soundDevice = devices.FirstOrDefault(d => d.Engine == ss.Engine && d.Device == ss.Device) ?? devices.First();
|
||||||
@@ -339,6 +354,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
ss.MusicVolume = dss.MusicVolume;
|
ss.MusicVolume = dss.MusicVolume;
|
||||||
ss.VideoVolume = dss.VideoVolume;
|
ss.VideoVolume = dss.VideoVolume;
|
||||||
ss.CashTicks = dss.CashTicks;
|
ss.CashTicks = dss.CashTicks;
|
||||||
|
ss.Mute = dss.Mute;
|
||||||
ss.Device = dss.Device;
|
ss.Device = dss.Device;
|
||||||
ss.Engine = dss.Engine;
|
ss.Engine = dss.Engine;
|
||||||
|
|
||||||
@@ -348,6 +364,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Game.Sound.MusicVolume = ss.MusicVolume;
|
Game.Sound.MusicVolume = ss.MusicVolume;
|
||||||
panel.Get<SliderWidget>("VIDEO_VOLUME").Value = ss.VideoVolume;
|
panel.Get<SliderWidget>("VIDEO_VOLUME").Value = ss.VideoVolume;
|
||||||
Game.Sound.VideoVolume = ss.VideoVolume;
|
Game.Sound.VideoVolume = ss.VideoVolume;
|
||||||
|
Game.Sound.UnmuteAudio();
|
||||||
soundDevice = Game.Sound.AvailableDevices().First();
|
soundDevice = Game.Sound.AvailableDevices().First();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -414,6 +431,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
{ "CycleStatusBarsKey", "Cycle status bars display" },
|
{ "CycleStatusBarsKey", "Cycle status bars display" },
|
||||||
{ "TogglePixelDoubleKey", "Toggle pixel doubling" },
|
{ "TogglePixelDoubleKey", "Toggle pixel doubling" },
|
||||||
|
{ "ToggleMuteKey", "Toggle audio mute" },
|
||||||
|
|
||||||
{ "MapScrollUp", "Map scroll up" },
|
{ "MapScrollUp", "Map scroll up" },
|
||||||
{ "MapScrollDown", "Map scroll down" },
|
{ "MapScrollDown", "Map scroll down" },
|
||||||
|
|||||||
@@ -199,6 +199,9 @@ namespace OpenRA.Platforms.Default
|
|||||||
if (source == -1)
|
if (source == -1)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
if (Game.Settings.Sound.Mute)
|
||||||
|
Game.Sound.MuteAudio();
|
||||||
|
|
||||||
var slot = sourcePool[source];
|
var slot = sourcePool[source];
|
||||||
slot.Pos = pos;
|
slot.Pos = pos;
|
||||||
slot.FrameStarted = currFrame;
|
slot.FrameStarted = currFrame;
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ Container@LOBBY_MUSIC_BIN:
|
|||||||
Width: 308
|
Width: 308
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
Children:
|
Children:
|
||||||
|
Label@MUTE_LABEL:
|
||||||
|
X: 25
|
||||||
|
Y: 10
|
||||||
|
Width: 300
|
||||||
|
Height: 20
|
||||||
|
Font: Small
|
||||||
Label@TITLE_LABEL:
|
Label@TITLE_LABEL:
|
||||||
Y: 45
|
Y: 45
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
|
|||||||
@@ -176,6 +176,12 @@ Container@MUSIC_PANEL:
|
|||||||
Width: 140
|
Width: 140
|
||||||
Height: 35
|
Height: 35
|
||||||
Text: Install Music
|
Text: Install Music
|
||||||
|
Label@MUTE_LABEL:
|
||||||
|
X: 165
|
||||||
|
Y: 399
|
||||||
|
Width: 300
|
||||||
|
Height: 20
|
||||||
|
Font: Small
|
||||||
|
|
||||||
Container@INSTALL_MUSIC_PANEL:
|
Container@INSTALL_MUSIC_PANEL:
|
||||||
Logic: InstallMusicLogic
|
Logic: InstallMusicLogic
|
||||||
|
|||||||
@@ -269,6 +269,13 @@ Container@SETTINGS_PANEL:
|
|||||||
Height: 20
|
Height: 20
|
||||||
Font: Regular
|
Font: Regular
|
||||||
Text: Cash Ticks
|
Text: Cash Ticks
|
||||||
|
Checkbox@MUTE_SOUND:
|
||||||
|
X: 15
|
||||||
|
Y: 70
|
||||||
|
Width: 200
|
||||||
|
Height: 20
|
||||||
|
Font: Regular
|
||||||
|
Text: Mute Sound
|
||||||
Label@MUSIC_LABEL:
|
Label@MUSIC_LABEL:
|
||||||
X: PARENT_RIGHT - WIDTH - 270
|
X: PARENT_RIGHT - WIDTH - 270
|
||||||
Y: 67
|
Y: 67
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ Container@LOBBY_MUSIC_BIN:
|
|||||||
Width: 268
|
Width: 268
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
Children:
|
Children:
|
||||||
|
Label@MUTE_LABEL:
|
||||||
|
X: 25
|
||||||
|
Y: 10
|
||||||
|
Width: 300
|
||||||
|
Height: 20
|
||||||
|
Font: Small
|
||||||
Label@TITLE_LABEL:
|
Label@TITLE_LABEL:
|
||||||
Y: 45
|
Y: 45
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
|
|||||||
@@ -165,6 +165,12 @@ Background@MUSIC_PANEL:
|
|||||||
Text: Close
|
Text: Close
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Key: escape
|
Key: escape
|
||||||
|
Label@MUTE_LABEL:
|
||||||
|
X: 25
|
||||||
|
Y: PARENT_BOTTOM - 45
|
||||||
|
Width: 300
|
||||||
|
Height: 20
|
||||||
|
Font: Small
|
||||||
|
|
||||||
Background@INSTALL_MUSIC_PANEL:
|
Background@INSTALL_MUSIC_PANEL:
|
||||||
Logic: InstallMusicLogic
|
Logic: InstallMusicLogic
|
||||||
|
|||||||
@@ -277,6 +277,13 @@ Background@SETTINGS_PANEL:
|
|||||||
Height: 20
|
Height: 20
|
||||||
Font: Regular
|
Font: Regular
|
||||||
Text: Cash Ticks
|
Text: Cash Ticks
|
||||||
|
Checkbox@MUTE_SOUND:
|
||||||
|
X: 15
|
||||||
|
Y: 70
|
||||||
|
Width: 200
|
||||||
|
Height: 20
|
||||||
|
Font: Regular
|
||||||
|
Text: Mute Sound
|
||||||
Label@MUSIC_LABEL:
|
Label@MUSIC_LABEL:
|
||||||
X: PARENT_RIGHT - WIDTH - 270
|
X: PARENT_RIGHT - WIDTH - 270
|
||||||
Y: 67
|
Y: 67
|
||||||
|
|||||||
Reference in New Issue
Block a user