From d79c8b9695eddd906d1ecdc2f01af887b9dc6f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sat, 11 Feb 2017 16:29:33 +0100 Subject: [PATCH] Update AudioDevicesOptions when devices are found or lost This commit hooks up AudioDevicesOptions to the new events exposed by the AudioManager of osu-framework. The device list is now updated when new devices become available or are lost. --- .../Sections/Audio/AudioDevicesOptions.cs | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs b/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs index 370676ead6..2301080411 100644 --- a/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs @@ -14,6 +14,7 @@ namespace osu.Game.Overlays.Options.Sections.Audio protected override string Header => "Devices"; private AudioManager audio; + private OptionDropDown dropdown; [BackgroundDependencyLoader] private void load(AudioManager audio) @@ -21,21 +22,40 @@ namespace osu.Game.Overlays.Options.Sections.Audio this.audio = audio; } + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + audio.OnNewDevice -= onDeviceChanged; + audio.OnLostDevice -= onDeviceChanged; + } + + private void updateItems() + { + var deviceItems = new List>(); + deviceItems.Add(new KeyValuePair("Default", string.Empty)); + deviceItems.AddRange(audio.AudioDeviceNames.Select(d => new KeyValuePair(d, d))); + dropdown.Items = deviceItems; + } + + private void onDeviceChanged(string name) => updateItems(); + protected override void LoadComplete() { base.LoadComplete(); - var deviceItems = new List>(); - deviceItems.Add(new KeyValuePair("Default", string.Empty)); - deviceItems.AddRange(audio.GetDeviceNames().Select(d => new KeyValuePair(d, d))); Children = new Drawable[] { - new OptionDropDown() + dropdown = new OptionDropDown() { - Items = deviceItems, Bindable = audio.AudioDevice }, }; + + updateItems(); + + audio.OnNewDevice += onDeviceChanged; + audio.OnLostDevice += onDeviceChanged; } } } \ No newline at end of file