mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
Merge pull request #718 from peppy/option-item-refactor
Add OptionItem class
This commit is contained in:
commit
ad4ec7023f
21
osu.Game/Overlays/Options/OptionCheckbox.cs
Normal file
21
osu.Game/Overlays/Options/OptionCheckbox.cs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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<bool>
|
||||
{
|
||||
private OsuCheckbox checkbox;
|
||||
|
||||
protected override Drawable CreateControl() => checkbox = new OsuCheckbox();
|
||||
|
||||
public override string LabelText
|
||||
{
|
||||
get { return checkbox.LabelText; }
|
||||
set { checkbox.LabelText = value; }
|
||||
}
|
||||
}
|
||||
}
|
@ -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<T> : FillFlowContainer
|
||||
public class OptionDropdown<T> : OptionItem<T>
|
||||
{
|
||||
private readonly Dropdown<T> dropdown;
|
||||
private readonly SpriteText text;
|
||||
private Dropdown<T> dropdown;
|
||||
|
||||
public string LabelText
|
||||
{
|
||||
get { return text.Text; }
|
||||
set
|
||||
{
|
||||
text.Text = value;
|
||||
text.Alpha = !string.IsNullOrEmpty(value) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Bindable<T> Bindable
|
||||
{
|
||||
get { return bindable; }
|
||||
set
|
||||
{
|
||||
bindable = value;
|
||||
dropdown.Current.BindTo(bindable);
|
||||
}
|
||||
}
|
||||
|
||||
private Bindable<T> bindable;
|
||||
|
||||
private IEnumerable<KeyValuePair<string, T>> items;
|
||||
private IEnumerable<KeyValuePair<string, T>> items = new KeyValuePair<string, T>[] { };
|
||||
public IEnumerable<KeyValuePair<string, T>> Items
|
||||
{
|
||||
get
|
||||
@ -55,30 +28,11 @@ namespace osu.Game.Overlays.Options
|
||||
}
|
||||
}
|
||||
|
||||
public OptionDropdown()
|
||||
protected override Drawable CreateControl() => dropdown = new OsuDropdown<T>
|
||||
{
|
||||
Items = new KeyValuePair<string, T>[0];
|
||||
|
||||
Direction = FillDirection.Vertical;
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Children = new Drawable[]
|
||||
{
|
||||
text = new OsuSpriteText {
|
||||
Alpha = 0,
|
||||
},
|
||||
dropdown = new OsuDropdown<T>
|
||||
{
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
82
osu.Game/Overlays/Options/OptionItem.cs
Normal file
82
osu.Game/Overlays/Options/OptionItem.cs
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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<T> : FillFlowContainer, IFilterable
|
||||
{
|
||||
protected abstract Drawable CreateControl();
|
||||
|
||||
protected Drawable Control { get; }
|
||||
|
||||
private IHasCurrentValue<T> controlWithCurrent => Control as IHasCurrentValue<T>;
|
||||
|
||||
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<T> bindable;
|
||||
|
||||
public Bindable<T> Bindable
|
||||
{
|
||||
get
|
||||
{
|
||||
return bindable;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
bindable = value;
|
||||
controlWithCurrent?.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<string>
|
||||
{
|
||||
protected override Drawable CreateControl() => null;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colour)
|
||||
{
|
||||
|
@ -1,13 +1,9 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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<T, U> : FillFlowContainer
|
||||
public class OptionSlider<T, U> : OptionItem<T>
|
||||
where T : struct
|
||||
where U : SliderBar<T>, new()
|
||||
{
|
||||
private readonly SliderBar<T> 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<T> bindable;
|
||||
|
||||
public Bindable<T> 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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,13 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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<string>
|
||||
{
|
||||
private Bindable<string> bindable;
|
||||
|
||||
public Bindable<string> Bindable
|
||||
{
|
||||
set
|
||||
{
|
||||
bindable = value;
|
||||
Current.BindTo(bindable);
|
||||
}
|
||||
}
|
||||
protected override Drawable CreateControl() => new OsuTextBox();
|
||||
}
|
||||
}
|
||||
|
@ -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<bool>(OsuConfig.MenuVoice)
|
||||
},
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "osu! music theme",
|
||||
Bindable = config.GetBindable<bool>(OsuConfig.MenuMusic)
|
||||
@ -29,4 +28,4 @@ namespace osu.Game.Overlays.Options.Sections.Audio
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<bool>(FrameworkDebugConfig.BypassCaching)
|
||||
|
@ -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<double>(OsuConfig.DimLevel)
|
||||
},
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "Show score overlay",
|
||||
Bindable = config.GetBindable<bool>(OsuConfig.ShowInterface)
|
||||
},
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "Always show key overlay",
|
||||
Bindable = config.GetBindable<bool>(OsuConfig.KeyOverlay)
|
||||
|
@ -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<bool>(FrameworkConfig.ShowUnicode)
|
||||
|
@ -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<bool>(OsuConfig.SaveUsername),
|
||||
},
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "Stay logged in",
|
||||
Bindable = config.GetBindable<bool>(OsuConfig.SavePassword),
|
||||
|
@ -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<bool>(OsuConfig.SnakingInSliders)
|
||||
},
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "Snaking out sliders",
|
||||
Bindable = config.GetBindable<bool>(OsuConfig.SnakingOutSliders)
|
||||
@ -30,4 +29,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<WindowMode>(FrameworkConfig.WindowMode),
|
||||
},
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "Letterboxing",
|
||||
Bindable = letterboxing,
|
||||
@ -64,4 +63,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<bool>(OsuConfig.MenuParallax)
|
||||
@ -24,4 +23,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<FrameSync>(FrameworkConfig.FrameSync)
|
||||
},
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "Show FPS",
|
||||
Bindable = osuConfig.GetBindable<bool>(OsuConfig.ShowFpsDisplay)
|
||||
@ -33,4 +32,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,12 @@ namespace osu.Game.Overlays.Options.Sections.Input
|
||||
LabelText = "Confine mouse cursor",
|
||||
Bindable = config.GetBindable<ConfineMouseMode>(FrameworkConfig.ConfineMouseMode),
|
||||
},
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "Disable mouse wheel during gameplay",
|
||||
Bindable = osuConfig.GetBindable<bool>(OsuConfig.MouseDisableWheel)
|
||||
},
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "Disable mouse buttons during gameplay",
|
||||
Bindable = osuConfig.GetBindable<bool>(OsuConfig.MouseDisableButtons)
|
||||
|
@ -371,8 +371,10 @@
|
||||
<Compile Include="Overlays\Options\Sections\SkinSection.cs" />
|
||||
<Compile Include="Graphics\UserInterface\OsuCheckbox.cs" />
|
||||
<Compile Include="Overlays\Options\SidebarButton.cs" />
|
||||
<Compile Include="Overlays\Options\OptionCheckbox.cs" />
|
||||
<Compile Include="Overlays\Options\OptionTextBox.cs" />
|
||||
<Compile Include="Overlays\Options\OptionSlider.cs" />
|
||||
<Compile Include="Overlays\Options\OptionItem.cs" />
|
||||
<Compile Include="Overlays\Options\OptionEnumDropdown.cs" />
|
||||
<Compile Include="Configuration\RankingType.cs" />
|
||||
<Compile Include="Configuration\ScoreMeterType.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user