diff --git a/osu-framework b/osu-framework index 9da998211a..21fd81a848 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 9da998211a81db471c7b9c649702f877b1246aff +Subproject commit 21fd81a84860cf6854026458ac82905b6248f41d diff --git a/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs b/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs index ba3e3737b0..3cbc1c8674 100644 --- a/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs @@ -17,16 +17,8 @@ namespace osu.Game.Graphics.UserInterface { protected override DropDownHeader CreateHeader() => new OsuDropDownHeader(); - protected override IEnumerable> GetDropDownItems(IEnumerable values) - { - return values.Select(v => - { - var field = typeof(U).GetField(Enum.GetName(typeof(U), v)); - return new OsuDropDownMenuItem( - field.GetCustomAttribute()?.Description ?? field.Name, v); - }); - - } + protected override IEnumerable> GetDropDownItems(IEnumerable> values) + => values.Select(v => new OsuDropDownMenuItem(v.Key, v.Value)); public OsuDropDownMenu() { diff --git a/osu.Game/Overlays/Options/OptionDropDown.cs b/osu.Game/Overlays/Options/OptionDropDown.cs index 720e86dcd1..ee355d4016 100644 --- a/osu.Game/Overlays/Options/OptionDropDown.cs +++ b/osu.Game/Overlays/Options/OptionDropDown.cs @@ -10,6 +10,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; +using System.Collections.Generic; namespace osu.Game.Overlays.Options { @@ -59,10 +60,25 @@ namespace osu.Game.Overlays.Options base.Dispose(isDisposing); } + private IEnumerable> items; + public IEnumerable> Items + { + get + { + return items; + } + set + { + items = value; + if(dropdown != null) + dropdown.Items = value; + } + } + public OptionDropDown() { - if (!typeof(T).IsEnum) - throw new InvalidOperationException("OptionsDropdown only supports enums as the generic type argument"); + Items = new KeyValuePair[0]; + Direction = FlowDirection.VerticalOnly; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -75,7 +91,7 @@ namespace osu.Game.Overlays.Options { Margin = new MarginPadding { Top = 5 }, RelativeSizeAxes = Axes.X, - Items = (T[])Enum.GetValues(typeof(T)), + Items = this.Items, } }; dropdown.ValueChanged += Dropdown_ValueChanged; diff --git a/osu.Game/Overlays/Options/OptionEnumDropDown.cs b/osu.Game/Overlays/Options/OptionEnumDropDown.cs new file mode 100644 index 0000000000..81438fd59e --- /dev/null +++ b/osu.Game/Overlays/Options/OptionEnumDropDown.cs @@ -0,0 +1,37 @@ +using System; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using System.Reflection; +using System.ComponentModel; +using System.Collections.Generic; + +namespace osu.Game.Overlays.Options +{ + public class OptionEnumDropDown : OptionDropDown + { + public OptionEnumDropDown() + { + if (!typeof(T).IsEnum) + throw new InvalidOperationException("OptionsDropdown only supports enums as the generic type argument"); + + List> items = new List>(); + foreach(var val in (T[])Enum.GetValues(typeof(T))) + { + var field = typeof(T).GetField(Enum.GetName(typeof(T), val)); + items.Add( + new KeyValuePair( + field.GetCustomAttribute()?.Description ?? Enum.GetName(typeof(T), val), + val + ) + ); + } + Items = items; + } + } +} diff --git a/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs b/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs index c9b2e6e470..370676ead6 100644 --- a/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs @@ -1,17 +1,40 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Graphics; +using System.Collections.Generic; +using System.Linq; + namespace osu.Game.Overlays.Options.Sections.Audio { public class AudioDevicesOptions : OptionsSubsection { protected override string Header => "Devices"; - public AudioDevicesOptions() + private AudioManager audio; + + [BackgroundDependencyLoader] + private void load(AudioManager audio) { - Children = new[] + this.audio = audio; + } + + 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 OptionLabel { Text = "Output device: TODO dropdown" } + new OptionDropDown() + { + Items = deviceItems, + Bindable = audio.AudioDevice + }, }; } } diff --git a/osu.Game/Overlays/Options/Sections/Gameplay/GeneralOptions.cs b/osu.Game/Overlays/Options/Sections/Gameplay/GeneralOptions.cs index 3bc5eb48c4..1c28f6247d 100644 --- a/osu.Game/Overlays/Options/Sections/Gameplay/GeneralOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Gameplay/GeneralOptions.cs @@ -23,12 +23,12 @@ namespace osu.Game.Overlays.Options.Sections.Gameplay LabelText = "Background dim", Bindable = (BindableInt)config.GetBindable(OsuConfig.DimLevel) }, - new OptionDropDown + new OptionEnumDropDown { LabelText = "Progress display", Bindable = config.GetBindable(OsuConfig.ProgressBarType) }, - new OptionDropDown + new OptionEnumDropDown { LabelText = "Score meter type", Bindable = config.GetBindable(OsuConfig.ScoreMeter) diff --git a/osu.Game/Overlays/Options/Sections/General/UpdateOptions.cs b/osu.Game/Overlays/Options/Sections/General/UpdateOptions.cs index 5378d5aeb6..6c7c29d966 100644 --- a/osu.Game/Overlays/Options/Sections/General/UpdateOptions.cs +++ b/osu.Game/Overlays/Options/Sections/General/UpdateOptions.cs @@ -18,7 +18,7 @@ namespace osu.Game.Overlays.Options.Sections.General { Children = new Drawable[] { - new OptionDropDown + new OptionEnumDropDown { LabelText = "Release stream", Bindable = config.GetBindable(OsuConfig.ReleaseStream), diff --git a/osu.Game/Overlays/Options/Sections/Graphics/DetailOptions.cs b/osu.Game/Overlays/Options/Sections/Graphics/DetailOptions.cs index 1f5c9402c3..e66d097094 100644 --- a/osu.Game/Overlays/Options/Sections/Graphics/DetailOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Graphics/DetailOptions.cs @@ -57,7 +57,7 @@ namespace osu.Game.Overlays.Options.Sections.Graphics LabelText = "Softening filter", Bindable = config.GetBindable(OsuConfig.BloomSoftening) }, - new OptionDropDown + new OptionEnumDropDown { LabelText = "Screenshot", Bindable = config.GetBindable(OsuConfig.ScreenshotFormat) diff --git a/osu.Game/Overlays/Options/Sections/Graphics/RendererOptions.cs b/osu.Game/Overlays/Options/Sections/Graphics/RendererOptions.cs index 68ff2cc8f9..b98337f1e6 100644 --- a/osu.Game/Overlays/Options/Sections/Graphics/RendererOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Graphics/RendererOptions.cs @@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Options.Sections.Graphics Children = new Drawable[] { // TODO: this needs to be a custom dropdown at some point - new OptionDropDown + new OptionEnumDropDown { LabelText = "Frame limiter", Bindable = config.GetBindable(FrameworkConfig.FrameSync) diff --git a/osu.Game/Overlays/Options/Sections/Input/MouseOptions.cs b/osu.Game/Overlays/Options/Sections/Input/MouseOptions.cs index c0d6876dea..ef1dd755b7 100644 --- a/osu.Game/Overlays/Options/Sections/Input/MouseOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Input/MouseOptions.cs @@ -33,7 +33,7 @@ namespace osu.Game.Overlays.Options.Sections.Input LabelText = "Map absolute raw input to the osu! window", Bindable = config.GetBindable(OsuConfig.AbsoluteToOsuWindow) }, - new OptionDropDown + new OptionEnumDropDown { LabelText = "Confine mouse cursor", Bindable = config.GetBindable(OsuConfig.ConfineMouse), diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 3f610bed42..2ead6aad48 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -100,6 +100,7 @@ + @@ -241,7 +242,7 @@ - +