From b230b5cfb9421a990513784d749f5362eac5a4ff Mon Sep 17 00:00:00 2001 From: default0 Date: Mon, 6 Feb 2017 01:17:50 +0100 Subject: [PATCH 1/4] Update OsuDropDownMenu for Framework-Changes Since the DropDownMenu in the framework has changed it was necessary to update the GetDropDownItems override of OsuDropDownMenu to accomodate the new structure of the framework. --- osu-framework | 2 +- osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/osu-framework b/osu-framework index f4362fce5a..fdcd1c5b50 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit f4362fce5a891e8b8dd84fadc0a9743a8c92e030 +Subproject commit fdcd1c5b5036c7cc1d75abb605e225e7411d5742 diff --git a/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs b/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs index 08a15110fa..8e1d8f7cf6 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() { From b4f30dd417b39f6453120663f67dbe6b6af361ad Mon Sep 17 00:00:00 2001 From: default0 Date: Mon, 6 Feb 2017 01:21:26 +0100 Subject: [PATCH 2/4] Rework OptionDropdowns to be more versatile The existing OptionDropdown only supported enums and was thus renamed to OptionEnumDropDown. A new OptionDropdown has been created in its place to allow binding to arbitrary values, with a set of user-provided items. --- osu.Game/Overlays/Options/OptionDropdown.cs | 22 +++++++++-- .../Overlays/Options/OptionEnumDropDown.cs | 37 +++++++++++++++++++ .../Sections/Gameplay/GeneralOptions.cs | 4 +- .../Options/Sections/General/UpdateOptions.cs | 2 +- .../Sections/Graphics/DetailOptions.cs | 2 +- .../Sections/Graphics/RendererOptions.cs | 2 +- .../Options/Sections/Input/MouseOptions.cs | 2 +- osu.Game/osu.Game.csproj | 3 +- 8 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 osu.Game/Overlays/Options/OptionEnumDropDown.cs 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 @@ - + From ae03ef07875752960de705094946409e0b9cf655 Mon Sep 17 00:00:00 2001 From: default0 Date: Mon, 6 Feb 2017 01:22:37 +0100 Subject: [PATCH 3/4] Allow audio device selection in settings --- .../Sections/Audio/AudioDevicesOptions.cs | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs b/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs index b9171cd6f6..5e8c0617fa 100644 --- a/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs @@ -1,18 +1,41 @@ //Copyright (c) 2007-2016 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() - { - Children = new[] + private AudioManager audio; + + [BackgroundDependencyLoader] + private void load(AudioManager audio) + { + this.audio = audio; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + var deviceItems = new List>(); + deviceItems.Add(new KeyValuePair("Standard", "")); + 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 + }, + }; } } } \ No newline at end of file From 6add77c30bbfc83045677ce51a8028402e13ce87 Mon Sep 17 00:00:00 2001 From: default0 Date: Mon, 6 Feb 2017 12:26:32 +0100 Subject: [PATCH 4/4] Rename Standard device option to Default Changed the name of the option for using the default audio device to "Default" for consistency with english windows. Also changed the "" value to string.Empty for consistency with the Frameworks treatment of this special value. --- osu-framework | 2 +- .../Sections/Audio/AudioDevicesOptions.cs | 42 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/osu-framework b/osu-framework index fdcd1c5b50..f6f3c63b24 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit fdcd1c5b5036c7cc1d75abb605e225e7411d5742 +Subproject commit f6f3c63b244ab48a77801864d8a2fca20a9e7408 diff --git a/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs b/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs index 5e8c0617fa..03743e7237 100644 --- a/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs @@ -1,41 +1,41 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - +//Copyright (c) 2007-2016 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"; - - private AudioManager audio; - - [BackgroundDependencyLoader] +namespace osu.Game.Overlays.Options.Sections.Audio +{ + public class AudioDevicesOptions : OptionsSubsection + { + protected override string Header => "Devices"; + + private AudioManager audio; + + [BackgroundDependencyLoader] private void load(AudioManager audio) { this.audio = audio; - } - + } + protected override void LoadComplete() { base.LoadComplete(); var deviceItems = new List>(); - deviceItems.Add(new KeyValuePair("Standard", "")); + deviceItems.Add(new KeyValuePair("Default", string.Empty)); deviceItems.AddRange(audio.GetDeviceNames().Select(d => new KeyValuePair(d, d))); - Children = new Drawable[] - { - new OptionDropDown() + Children = new Drawable[] + { + new OptionDropDown() { Items = deviceItems, Bindable = audio.AudioDevice - }, + }, }; - } - } + } + } } \ No newline at end of file