From 9daf52412091741cff8628a2b406e234aa50f0d3 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 1 Dec 2016 16:36:04 -0500 Subject: [PATCH] Add OptionsDropdown and wire up one example --- osu.Game/Configuration/OsuConfigManager.cs | 2 +- osu.Game/Configuration/ProgressBarType.cs | 12 ++++ .../Gameplay/GeneralGameplayOptions.cs | 6 +- osu.Game/Overlays/Options/OptionsDropdown.cs | 70 +++++++++++++++++++ osu.Game/osu.Game.csproj | 4 +- 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 osu.Game/Configuration/ProgressBarType.cs create mode 100644 osu.Game/Overlays/Options/OptionsDropdown.cs diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index ef95a3ac3f..5a1d6e79ef 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -110,7 +110,7 @@ namespace osu.Game.Configuration Set(OsuConfig.NotifyFriends, true); Set(OsuConfig.NotifySubmittedThread, true); Set(OsuConfig.PopupDuringGameplay, true); - //Set(OsuConfig.ProgressBarType, ProgressBarTypes.Pie); + Set(OsuConfig.ProgressBarType, ProgressBarType.Pie); //Set(OsuConfig.RankType, RankingType.Top); Set(OsuConfig.RefreshRate, 60); Set(OsuConfig.OverrideRefreshRate, Get(OsuConfig.RefreshRate) != 60); diff --git a/osu.Game/Configuration/ProgressBarType.cs b/osu.Game/Configuration/ProgressBarType.cs new file mode 100644 index 0000000000..15f1e35712 --- /dev/null +++ b/osu.Game/Configuration/ProgressBarType.cs @@ -0,0 +1,12 @@ +using System; +namespace osu.Game.Configuration +{ + public enum ProgressBarType + { + Off, + Pie, + TopRight, + BottomRight, + Bottom + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/Options/Gameplay/GeneralGameplayOptions.cs b/osu.Game/Overlays/Options/Gameplay/GeneralGameplayOptions.cs index 15607c9bde..be791161ec 100644 --- a/osu.Game/Overlays/Options/Gameplay/GeneralGameplayOptions.cs +++ b/osu.Game/Overlays/Options/Gameplay/GeneralGameplayOptions.cs @@ -25,7 +25,11 @@ namespace osu.Game.Overlays.Options.Gameplay LabelText = "Background dim", Bindable = (BindableInt)config.GetBindable(OsuConfig.DimLevel) }, - new SpriteText { Text = "Progress display: TODO dropdown" }, + new OptionsDropdown + { + Label = "Progress display", + Bindable = config.GetBindable(OsuConfig.ProgressBarType) + }, new SpriteText { Text = "Score meter type: TODO dropdown" }, new SliderOption { diff --git a/osu.Game/Overlays/Options/OptionsDropdown.cs b/osu.Game/Overlays/Options/OptionsDropdown.cs new file mode 100644 index 0000000000..d1641cd8cf --- /dev/null +++ b/osu.Game/Overlays/Options/OptionsDropdown.cs @@ -0,0 +1,70 @@ +using System; +using System.Linq; +using OpenTK.Graphics; +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; + +namespace osu.Game.Overlays.Options +{ + public class OptionsDropdown : FlowContainer + { + private DropDownMenu dropdown; + private SpriteText text; + + public string Label + { + get { return text.Text; } + set + { + text.Text = value; + text.Alpha = string.IsNullOrEmpty(value) ? 0 : 1; + } + } + + public Bindable Bindable + { + get { return bindable; } + set + { + if (bindable != null) + bindable.ValueChanged -= Bindable_ValueChanged; + bindable = value; + bindable.ValueChanged += Bindable_ValueChanged; + Bindable_ValueChanged(null, null); + } + } + + private Bindable bindable; + + void Bindable_ValueChanged(object sender, EventArgs e) + { + dropdown.SelectedValue = bindable.Value; + } + + public OptionsDropdown() + { + if (!typeof(T).IsEnum) + throw new InvalidOperationException("OptionsDropdown only supports enums as the generic type argument"); + Direction = FlowDirection.VerticalOnly; + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + var items = Enum.GetNames(typeof(T)).Zip( + (T[])Enum.GetValues(typeof(T)), (a, b) => new Tuple(a, b)); + Children = new Drawable[] + { + text = new SpriteText { Alpha = 0 }, + dropdown = new DropDownMenu + { + Margin = new MarginPadding { Top = 5 }, + Height = 10, + RelativeSizeAxes = Axes.X, + Items = items.Select(item => new DropDownMenuItem(item.Item1, item.Item2)) + } + }; + } + } +} \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 2e5367d44b..eda53c848b 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -223,6 +223,8 @@ + + @@ -251,4 +253,4 @@ --> - \ No newline at end of file +