diff --git a/osu.Game/Overlays/Options/OptionCheckbox.cs b/osu.Game/Overlays/Options/OptionCheckbox.cs new file mode 100644 index 0000000000..de7b138c3c --- /dev/null +++ b/osu.Game/Overlays/Options/OptionCheckbox.cs @@ -0,0 +1,21 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Overlays.Options +{ + public class OptionCheckbox : OptionItem + { + private OsuCheckbox checkbox; + + protected override Drawable CreateControl() => checkbox = new OsuCheckbox(); + + public override string LabelText + { + get { return checkbox.LabelText; } + set { checkbox.LabelText = value; } + } + } +} diff --git a/osu.Game/Overlays/Options/OptionDropdown.cs b/osu.Game/Overlays/Options/OptionDropdown.cs index 6837e71c2c..1427eafe39 100644 --- a/osu.Game/Overlays/Options/OptionDropdown.cs +++ b/osu.Game/Overlays/Options/OptionDropdown.cs @@ -2,45 +2,18 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; -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; namespace osu.Game.Overlays.Options { - public class OptionDropdown : FillFlowContainer + public class OptionDropdown : OptionItem { - private readonly Dropdown dropdown; - private readonly SpriteText text; + private Dropdown dropdown; - public string LabelText - { - get { return text.Text; } - set - { - text.Text = value; - text.Alpha = !string.IsNullOrEmpty(value) ? 1 : 0; - } - } - - public Bindable Bindable - { - get { return bindable; } - set - { - bindable = value; - dropdown.Current.BindTo(bindable); - } - } - - private Bindable bindable; - - private IEnumerable> items; + private IEnumerable> items = new KeyValuePair[] { }; public IEnumerable> Items { get @@ -55,30 +28,11 @@ namespace osu.Game.Overlays.Options } } - public OptionDropdown() + protected override Drawable CreateControl() => dropdown = new OsuDropdown { - Items = new KeyValuePair[0]; - - Direction = FillDirection.Vertical; - RelativeSizeAxes = Axes.X; - AutoSizeAxes = Axes.Y; - Children = new Drawable[] - { - text = new OsuSpriteText { - Alpha = 0, - }, - dropdown = new OsuDropdown - { - Margin = new MarginPadding { Top = 5 }, - RelativeSizeAxes = Axes.X, - Items = Items, - } - }; - - dropdown.Current.DisabledChanged += disabled => - { - Alpha = disabled ? 0.3f : 1; - }; - } + Margin = new MarginPadding { Top = 5 }, + RelativeSizeAxes = Axes.X, + Items = Items, + }; } } diff --git a/osu.Game/Overlays/Options/OptionItem.cs b/osu.Game/Overlays/Options/OptionItem.cs new file mode 100644 index 0000000000..c09eba7f11 --- /dev/null +++ b/osu.Game/Overlays/Options/OptionItem.cs @@ -0,0 +1,82 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +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; +using osu.Game.Graphics.Sprites; + +namespace osu.Game.Overlays.Options +{ + public abstract class OptionItem : FillFlowContainer, IFilterable + { + protected abstract Drawable CreateControl(); + + protected Drawable Control { get; } + + private IHasCurrentValue controlWithCurrent => Control as IHasCurrentValue; + + private SpriteText text; + + public virtual string LabelText + { + get { return text?.Text ?? string.Empty; } + set + { + if (text == null) + { + // construct lazily for cases where the label is not needed (may be provided by the Control). + Add(text = new OsuSpriteText() { Depth = 1 }); + } + + text.Text = value; + } + } + + // hold a reference to the provided bindable so we don't have to in every options section. + private Bindable bindable; + + public Bindable Bindable + { + get + { + return bindable; + } + + set + { + bindable = value; + (Control as IHasCurrentValue)?.Current.BindTo(bindable); + } + } + + public string[] FilterTerms => new[] { LabelText }; + + public bool MatchingCurrentFilter + { + set + { + // probably needs a better transition. + FadeTo(value ? 1 : 0); + } + } + + protected OptionItem() + { + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + Padding = new MarginPadding { Right = 5 }; + + if ((Control = CreateControl()) != null) + { + if (controlWithCurrent != null) + controlWithCurrent.Current.DisabledChanged += disabled => { Colour = disabled ? Color4.Gray : Color4.White; }; + Add(Control); + } + } + } +} diff --git a/osu.Game/Overlays/Options/OptionLabel.cs b/osu.Game/Overlays/Options/OptionLabel.cs index 4b0f1e4ec0..3f3c569f3a 100644 --- a/osu.Game/Overlays/Options/OptionLabel.cs +++ b/osu.Game/Overlays/Options/OptionLabel.cs @@ -2,13 +2,15 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; +using osu.Framework.Graphics; using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; namespace osu.Game.Overlays.Options { - internal class OptionLabel : OsuSpriteText + internal class OptionLabel : OptionItem { + protected override Drawable CreateControl() => null; + [BackgroundDependencyLoader] private void load(OsuColour colour) { diff --git a/osu.Game/Overlays/Options/OptionSlider.cs b/osu.Game/Overlays/Options/OptionSlider.cs index 2d98bc991a..2cceb085a7 100644 --- a/osu.Game/Overlays/Options/OptionSlider.cs +++ b/osu.Game/Overlays/Options/OptionSlider.cs @@ -1,13 +1,9 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -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; namespace osu.Game.Overlays.Options @@ -17,52 +13,14 @@ namespace osu.Game.Overlays.Options { } - public class OptionSlider : FillFlowContainer + public class OptionSlider : OptionItem where T : struct where U : SliderBar, new() { - private readonly SliderBar slider; - private readonly SpriteText text; - - public string LabelText + protected override Drawable CreateControl() => new U() { - get { return text.Text; } - set - { - text.Text = value; - text.Alpha = string.IsNullOrEmpty(value) ? 0 : 1; - } - } - - private Bindable bindable; - - public Bindable Bindable - { - set - { - bindable = value; - slider.Current.BindTo(bindable); - } - } - - public OptionSlider() - { - RelativeSizeAxes = Axes.X; - AutoSizeAxes = Axes.Y; - Padding = new MarginPadding { Right = 5 }; - - Children = new Drawable[] - { - text = new OsuSpriteText - { - Alpha = 0, - }, - slider = new U() - { - Margin = new MarginPadding { Top = 5, Bottom = 5 }, - RelativeSizeAxes = Axes.X - } - }; - } + Margin = new MarginPadding { Top = 5, Bottom = 5 }, + RelativeSizeAxes = Axes.X + }; } } diff --git a/osu.Game/Overlays/Options/OptionTextBox.cs b/osu.Game/Overlays/Options/OptionTextBox.cs index 4927122181..498f27796a 100644 --- a/osu.Game/Overlays/Options/OptionTextBox.cs +++ b/osu.Game/Overlays/Options/OptionTextBox.cs @@ -1,22 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.Configuration; +using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options { - public class OptionTextBox : OsuTextBox + public class OptionTextBox : OptionItem { - private Bindable bindable; - - public Bindable Bindable - { - set - { - bindable = value; - Current.BindTo(bindable); - } - } + protected override Drawable CreateControl() => new OsuTextBox(); } } diff --git a/osu.Game/Overlays/Options/Sections/Audio/MainMenuOptions.cs b/osu.Game/Overlays/Options/Sections/Audio/MainMenuOptions.cs index 9de74e1b02..b2d1235b97 100644 --- a/osu.Game/Overlays/Options/Sections/Audio/MainMenuOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Audio/MainMenuOptions.cs @@ -3,7 +3,6 @@ using osu.Framework.Allocation; using osu.Game.Configuration; -using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options.Sections.Audio { @@ -16,12 +15,12 @@ namespace osu.Game.Overlays.Options.Sections.Audio { Children = new[] { - new OsuCheckbox + new OptionCheckbox { LabelText = "Interface voices", Bindable = config.GetBindable(OsuConfig.MenuVoice) }, - new OsuCheckbox + new OptionCheckbox { LabelText = "osu! music theme", Bindable = config.GetBindable(OsuConfig.MenuMusic) @@ -29,4 +28,4 @@ namespace osu.Game.Overlays.Options.Sections.Audio }; } } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/Options/Sections/Debug/GeneralOptions.cs b/osu.Game/Overlays/Options/Sections/Debug/GeneralOptions.cs index 34901e1dac..9258b8fbeb 100644 --- a/osu.Game/Overlays/Options/Sections/Debug/GeneralOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Debug/GeneralOptions.cs @@ -4,7 +4,6 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; -using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options.Sections.Debug { @@ -17,7 +16,7 @@ namespace osu.Game.Overlays.Options.Sections.Debug { Children = new Drawable[] { - new OsuCheckbox + new OptionCheckbox { LabelText = "Bypass caching", Bindable = config.GetBindable(FrameworkDebugConfig.BypassCaching) diff --git a/osu.Game/Overlays/Options/Sections/Gameplay/GeneralOptions.cs b/osu.Game/Overlays/Options/Sections/Gameplay/GeneralOptions.cs index c278b59a51..2598d95949 100644 --- a/osu.Game/Overlays/Options/Sections/Gameplay/GeneralOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Gameplay/GeneralOptions.cs @@ -4,7 +4,6 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Configuration; -using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options.Sections.Gameplay { @@ -22,12 +21,12 @@ namespace osu.Game.Overlays.Options.Sections.Gameplay LabelText = "Background dim", Bindable = config.GetBindable(OsuConfig.DimLevel) }, - new OsuCheckbox + new OptionCheckbox { LabelText = "Show score overlay", Bindable = config.GetBindable(OsuConfig.ShowInterface) }, - new OsuCheckbox + new OptionCheckbox { LabelText = "Always show key overlay", Bindable = config.GetBindable(OsuConfig.KeyOverlay) diff --git a/osu.Game/Overlays/Options/Sections/General/LanguageOptions.cs b/osu.Game/Overlays/Options/Sections/General/LanguageOptions.cs index 7bc1a54455..2778f2567d 100644 --- a/osu.Game/Overlays/Options/Sections/General/LanguageOptions.cs +++ b/osu.Game/Overlays/Options/Sections/General/LanguageOptions.cs @@ -4,7 +4,6 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; -using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options.Sections.General { @@ -17,7 +16,7 @@ namespace osu.Game.Overlays.Options.Sections.General { Children = new Drawable[] { - new OsuCheckbox + new OptionCheckbox { LabelText = "Prefer metadata in original language", Bindable = frameworkConfig.GetBindable(FrameworkConfig.ShowUnicode) diff --git a/osu.Game/Overlays/Options/Sections/General/LoginOptions.cs b/osu.Game/Overlays/Options/Sections/General/LoginOptions.cs index a5e38dd284..a3612a6396 100644 --- a/osu.Game/Overlays/Options/Sections/General/LoginOptions.cs +++ b/osu.Game/Overlays/Options/Sections/General/LoginOptions.cs @@ -132,12 +132,12 @@ namespace osu.Game.Overlays.Options.Sections.General TabbableContentContainer = this, OnCommit = (sender, newText) => performLogin() }, - new OsuCheckbox + new OptionCheckbox { LabelText = "Remember username", Bindable = config.GetBindable(OsuConfig.SaveUsername), }, - new OsuCheckbox + new OptionCheckbox { LabelText = "Stay logged in", Bindable = config.GetBindable(OsuConfig.SavePassword), diff --git a/osu.Game/Overlays/Options/Sections/Graphics/DetailOptions.cs b/osu.Game/Overlays/Options/Sections/Graphics/DetailOptions.cs index d8906d74ba..6503a7ea90 100644 --- a/osu.Game/Overlays/Options/Sections/Graphics/DetailOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Graphics/DetailOptions.cs @@ -4,7 +4,6 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Configuration; -using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options.Sections.Graphics { @@ -17,12 +16,12 @@ namespace osu.Game.Overlays.Options.Sections.Graphics { Children = new Drawable[] { - new OsuCheckbox + new OptionCheckbox { LabelText = "Snaking in sliders", Bindable = config.GetBindable(OsuConfig.SnakingInSliders) }, - new OsuCheckbox + new OptionCheckbox { LabelText = "Snaking out sliders", Bindable = config.GetBindable(OsuConfig.SnakingOutSliders) @@ -30,4 +29,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics }; } } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/Options/Sections/Graphics/LayoutOptions.cs b/osu.Game/Overlays/Options/Sections/Graphics/LayoutOptions.cs index aed39ca764..1b4b0b3c7d 100644 --- a/osu.Game/Overlays/Options/Sections/Graphics/LayoutOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Graphics/LayoutOptions.cs @@ -4,7 +4,6 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; -using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options.Sections.Graphics { @@ -29,7 +28,7 @@ namespace osu.Game.Overlays.Options.Sections.Graphics LabelText = "Screen mode", Bindable = config.GetBindable(FrameworkConfig.WindowMode), }, - new OsuCheckbox + new OptionCheckbox { LabelText = "Letterboxing", Bindable = letterboxing, @@ -64,4 +63,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics } } } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/Options/Sections/Graphics/MainMenuOptions.cs b/osu.Game/Overlays/Options/Sections/Graphics/MainMenuOptions.cs index 83a2a382ad..6ebb8f263d 100644 --- a/osu.Game/Overlays/Options/Sections/Graphics/MainMenuOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Graphics/MainMenuOptions.cs @@ -3,7 +3,6 @@ using osu.Framework.Allocation; using osu.Game.Configuration; -using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options.Sections.Graphics { @@ -16,7 +15,7 @@ namespace osu.Game.Overlays.Options.Sections.Graphics { Children = new[] { - new OsuCheckbox + new OptionCheckbox { LabelText = "Parallax", Bindable = config.GetBindable(OsuConfig.MenuParallax) @@ -24,4 +23,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics }; } } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/Options/Sections/Graphics/RendererOptions.cs b/osu.Game/Overlays/Options/Sections/Graphics/RendererOptions.cs index 58bf2b7996..f11c18d3b4 100644 --- a/osu.Game/Overlays/Options/Sections/Graphics/RendererOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Graphics/RendererOptions.cs @@ -5,7 +5,6 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Game.Configuration; -using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options.Sections.Graphics { @@ -25,7 +24,7 @@ namespace osu.Game.Overlays.Options.Sections.Graphics LabelText = "Frame limiter", Bindable = config.GetBindable(FrameworkConfig.FrameSync) }, - new OsuCheckbox + new OptionCheckbox { LabelText = "Show FPS", Bindable = osuConfig.GetBindable(OsuConfig.ShowFpsDisplay) @@ -33,4 +32,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics }; } } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/Options/Sections/Input/MouseOptions.cs b/osu.Game/Overlays/Options/Sections/Input/MouseOptions.cs index 12789aa0ec..b4ce11e2bc 100644 --- a/osu.Game/Overlays/Options/Sections/Input/MouseOptions.cs +++ b/osu.Game/Overlays/Options/Sections/Input/MouseOptions.cs @@ -24,12 +24,12 @@ namespace osu.Game.Overlays.Options.Sections.Input LabelText = "Confine mouse cursor", Bindable = config.GetBindable(FrameworkConfig.ConfineMouseMode), }, - new OsuCheckbox + new OptionCheckbox { LabelText = "Disable mouse wheel during gameplay", Bindable = osuConfig.GetBindable(OsuConfig.MouseDisableWheel) }, - new OsuCheckbox + new OptionCheckbox { LabelText = "Disable mouse buttons during gameplay", Bindable = osuConfig.GetBindable(OsuConfig.MouseDisableButtons) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 929811226f..3535bc0028 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -371,8 +371,10 @@ + +