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

View File

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

View File

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