diff --git a/osu.Game/Overlays/Options/OptionDropdown.cs b/osu.Game/Overlays/Options/OptionDropdown.cs index e2c2e7e8bb..15df777c4c 100644 --- a/osu.Game/Overlays/Options/OptionDropdown.cs +++ b/osu.Game/Overlays/Options/OptionDropdown.cs @@ -7,6 +7,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 { @@ -56,10 +57,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; @@ -72,7 +88,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/Gameplay/GeneralOptions.cs b/osu.Game/Overlays/Options/Sections/Gameplay/GeneralOptions.cs index f9cde39eb6..7e2cb06791 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 937845c5ed..c903089d22 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 6f9b24ac07..9a334ee8f5 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 6565352c51..1b6f9c2016 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 894fa2a2b3..9047f36f3c 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 5f7c171cfe..74d897c6ff 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -99,6 +99,7 @@ + @@ -239,7 +240,7 @@ - +