mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 16:27:26 +08:00
Add OptionItem class
Allow for centalised logic for all option UI controls.
This commit is contained in:
parent
b98ae5d7c3
commit
153951d3dd
27
osu.Game/Overlays/Options/OptionCheckbox.cs
Normal file
27
osu.Game/Overlays/Options/OptionCheckbox.cs
Normal file
@ -0,0 +1,27 @@
|
||||
// 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
|
||||
{
|
||||
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; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
@ -13,34 +14,11 @@ 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 +33,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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
84
osu.Game/Overlays/Options/OptionItem.cs
Normal file
84
osu.Game/Overlays/Options/OptionItem.cs
Normal file
@ -0,0 +1,84 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
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;
|
||||
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 set; }
|
||||
|
||||
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;
|
||||
(Control as IHasCurrentValue<T>)?.Current.BindTo(bindable);
|
||||
}
|
||||
}
|
||||
|
||||
public string[] FilterTerms => new[] { LabelText };
|
||||
|
||||
public bool MatchingCurrentFilter
|
||||
{
|
||||
set
|
||||
{
|
||||
// probably needs a better transition.
|
||||
FadeTo(value ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,18 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
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)
|
||||
{
|
||||
|
@ -17,52 +17,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,14 @@
|
||||
// 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.UserInterface;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,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 +29,4 @@ namespace osu.Game.Overlays.Options.Sections.Audio
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ namespace osu.Game.Overlays.Options.Sections.Debug
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "Bypass caching",
|
||||
Bindable = config.GetBindable<bool>(FrameworkDebugConfig.BypassCaching)
|
||||
|
@ -22,12 +22,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)
|
||||
|
@ -17,7 +17,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),
|
||||
|
@ -17,12 +17,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 +30,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,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 +64,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
|
||||
{
|
||||
Children = new[]
|
||||
{
|
||||
new OsuCheckbox
|
||||
new OptionCheckbox
|
||||
{
|
||||
LabelText = "Parallax",
|
||||
Bindable = config.GetBindable<bool>(OsuConfig.MenuParallax)
|
||||
@ -24,4 +24,4 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,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 +33,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