Disable sound controls when no audio device is available.

This commit is contained in:
Paul Chote
2019-12-28 10:40:23 +00:00
committed by reaperrr
parent 4052620f94
commit a7ae93978a
3 changed files with 144 additions and 112 deletions

View File

@@ -352,6 +352,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var muteCheckbox = panel.Get<CheckboxWidget>("MUTE_SOUND");
var muteCheckboxOnClick = muteCheckbox.OnClick;
var muteCheckboxIsChecked = muteCheckbox.IsChecked;
muteCheckbox.IsChecked = () => muteCheckboxIsChecked() || Game.Sound.DummyEngine;
muteCheckbox.IsDisabled = () => Game.Sound.DummyEngine;
muteCheckbox.OnClick = () =>
{
muteCheckboxOnClick();
@@ -362,12 +365,23 @@ namespace OpenRA.Mods.Common.Widgets.Logic
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;
}
// Replace controls with a warning label if sound is disabled
var noDeviceLabel = panel.GetOrNull("NO_AUDIO_DEVICE");
if (noDeviceLabel != null)
noDeviceLabel.Visible = Game.Sound.DummyEngine;
var controlsContainer = panel.GetOrNull("AUDIO_CONTROLS");
if (controlsContainer != null)
controlsContainer.Visible = !Game.Sound.DummyEngine;
var soundVolumeSlider = panel.Get<SliderWidget>("SOUND_VOLUME");
soundVolumeSlider.OnChange += x => Game.Sound.SoundVolume = x;
var musicVolumeSlider = panel.Get<SliderWidget>("MUSIC_VOLUME");
musicVolumeSlider.OnChange += x => Game.Sound.MusicVolume = x;
var videoVolumeSlider = panel.Get<SliderWidget>("VIDEO_VOLUME");
videoVolumeSlider.OnChange += x => Game.Sound.VideoVolume = x;
var devices = Game.Sound.AvailableDevices();
soundDevice = devices.FirstOrDefault(d => d.Device == ss.Device) ?? devices.First();

View File

@@ -282,59 +282,68 @@ Container@SETTINGS_PANEL:
Font: Bold
Text: Audio
Align: Center
Label@SOUND_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 38
Width: 95
Height: 25
Align: Right
Text: Sound Volume:
ExponentialSlider@SOUND_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 43
Width: 250
Height: 20
Ticks: 7
Checkbox@CASH_TICKS:
X: 15
Y: 40
Width: 200
Height: 20
Font: Regular
Text: Cash Ticks
Checkbox@MUTE_SOUND:
X: 15
Y: 70
Width: 200
Height: 20
Font: Regular
Text: Mute Sound
Label@MUSIC_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 68
Width: 95
Height: 25
Align: Right
Text: Music Volume:
ExponentialSlider@MUSIC_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 73
Width: 250
Height: 20
Ticks: 7
Label@VIDEO_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 98
Width: 95
Height: 25
Align: Right
Text: Video Volume:
ExponentialSlider@VIDEO_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 103
Width: 250
Height: 20
Ticks: 7
Label@NO_AUDIO_DEVICE:
Y: 50
Width: PARENT_RIGHT
Align: Center
Text: Audio controls require an active sound device
Container@AUDIO_CONTROLS:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Children:
Label@SOUND_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 38
Width: 95
Height: 25
Align: Right
Text: Sound Volume:
ExponentialSlider@SOUND_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 43
Width: 250
Height: 20
Ticks: 7
Checkbox@CASH_TICKS:
X: 15
Y: 40
Width: 200
Height: 20
Font: Regular
Text: Cash Ticks
Checkbox@MUTE_SOUND:
X: 15
Y: 70
Width: 200
Height: 20
Font: Regular
Text: Mute Sound
Label@MUSIC_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 68
Width: 95
Height: 25
Align: Right
Text: Music Volume:
ExponentialSlider@MUSIC_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 73
Width: 250
Height: 20
Ticks: 7
Label@VIDEO_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 98
Width: 95
Height: 25
Align: Right
Text: Video Volume:
ExponentialSlider@VIDEO_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 103
Width: 250
Height: 20
Ticks: 7
Label@AUDIO_DEVICE_LABEL:
X: 190 - WIDTH - 5
Y: 245

View File

@@ -292,59 +292,68 @@ Background@SETTINGS_PANEL:
Width: PARENT_RIGHT - 10
Height: PARENT_BOTTOM
Children:
Label@SOUND_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 39
Width: 95
Height: 25
Align: Right
Text: Sound Volume:
ExponentialSlider@SOUND_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 43
Width: 250
Height: 20
Ticks: 7
Checkbox@CASH_TICKS:
X: 15
Y: 40
Width: 200
Height: 20
Font: Regular
Text: Cash Ticks
Checkbox@MUTE_SOUND:
X: 15
Y: 70
Width: 200
Height: 20
Font: Regular
Text: Mute Sound
Label@MUSIC_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 69
Width: 95
Height: 25
Align: Right
Text: Music Volume:
ExponentialSlider@MUSIC_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 73
Width: 250
Height: 20
Ticks: 7
Label@VIDEO_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 99
Width: 95
Height: 25
Align: Right
Text: Video Volume:
ExponentialSlider@VIDEO_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 103
Width: 250
Height: 20
Ticks: 7
Label@NO_AUDIO_DEVICE:
Y: 50
Width: PARENT_RIGHT
Align: Center
Text: Audio controls require an active sound device
Container@AUDIO_CONTROLS:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Children:
Label@SOUND_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 39
Width: 95
Height: 25
Align: Right
Text: Sound Volume:
ExponentialSlider@SOUND_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 43
Width: 250
Height: 20
Ticks: 7
Checkbox@CASH_TICKS:
X: 15
Y: 40
Width: 200
Height: 20
Font: Regular
Text: Cash Ticks
Checkbox@MUTE_SOUND:
X: 15
Y: 70
Width: 200
Height: 20
Font: Regular
Text: Mute Sound
Label@MUSIC_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 69
Width: 95
Height: 25
Align: Right
Text: Music Volume:
ExponentialSlider@MUSIC_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 73
Width: 250
Height: 20
Ticks: 7
Label@VIDEO_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 99
Width: 95
Height: 25
Align: Right
Text: Video Volume:
ExponentialSlider@VIDEO_VOLUME:
X: PARENT_RIGHT - WIDTH - 15
Y: 103
Width: 250
Height: 20
Ticks: 7
Label@AUDIO_DEVICE_LABEL:
X: 190 - WIDTH - 5
Y: 245