mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 18:53:51 +08:00
Avoid initial synchronous dropdown population overhead in AudioDevicesSettings
This commit is contained in:
parent
8d051d9fa0
commit
b541550ea9
@ -20,17 +20,26 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
|
||||
|
||||
private SettingsDropdown<string> dropdown;
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (audio != null)
|
||||
Children = new Drawable[]
|
||||
{
|
||||
audio.OnNewDevice -= onDeviceChanged;
|
||||
audio.OnLostDevice -= onDeviceChanged;
|
||||
}
|
||||
dropdown = new AudioDeviceSettingsDropdown
|
||||
{
|
||||
Keywords = new[] { "speaker", "headphone", "output" }
|
||||
}
|
||||
};
|
||||
|
||||
updateItems();
|
||||
|
||||
audio.OnNewDevice += onDeviceChanged;
|
||||
audio.OnLostDevice += onDeviceChanged;
|
||||
dropdown.Current = audio.AudioDevice;
|
||||
}
|
||||
|
||||
private void onDeviceChanged(string name) => updateItems();
|
||||
|
||||
private void updateItems()
|
||||
{
|
||||
var deviceItems = new List<string> { string.Empty };
|
||||
@ -49,26 +58,15 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
|
||||
dropdown.Items = deviceItems.Distinct().ToList();
|
||||
}
|
||||
|
||||
private void onDeviceChanged(string name) => updateItems();
|
||||
|
||||
protected override void LoadComplete()
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.LoadComplete();
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
Children = new Drawable[]
|
||||
if (audio != null)
|
||||
{
|
||||
dropdown = new AudioDeviceSettingsDropdown
|
||||
{
|
||||
Keywords = new[] { "speaker", "headphone", "output" }
|
||||
}
|
||||
};
|
||||
|
||||
updateItems();
|
||||
|
||||
dropdown.Current = audio.AudioDevice;
|
||||
|
||||
audio.OnNewDevice += onDeviceChanged;
|
||||
audio.OnLostDevice += onDeviceChanged;
|
||||
audio.OnNewDevice -= onDeviceChanged;
|
||||
audio.OnLostDevice -= onDeviceChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private class AudioDeviceSettingsDropdown : SettingsDropdown<string>
|
||||
|
Loading…
Reference in New Issue
Block a user