Skip to content

Commit

Permalink
Disable sound controls when no audio device is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote authored and reaperrr committed Dec 29, 2019
1 parent 4052620 commit a7ae939
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 112 deletions.
26 changes: 20 additions & 6 deletions OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs
Expand Up @@ -352,6 +352,9 @@ Action InitAudioPanel(Widget panel)

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();
Expand All @@ -362,12 +365,23 @@ Action InitAudioPanel(Widget panel)
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();
Expand Down
115 changes: 62 additions & 53 deletions mods/cnc/chrome/settings.yaml
Expand Up @@ -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
Expand Down
115 changes: 62 additions & 53 deletions mods/common/chrome/settings.yaml
Expand Up @@ -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
Expand Down

0 comments on commit a7ae939

Please sign in to comment.