2017-05-04 22:07:24 +08:00
|
|
|
// 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.Sprites;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
2017-05-15 09:55:29 +08:00
|
|
|
namespace osu.Game.Overlays.Settings
|
2017-05-04 22:07:24 +08:00
|
|
|
{
|
2017-05-15 09:55:29 +08:00
|
|
|
public abstract class SettingsItem<T> : FillFlowContainer, IFilterable
|
2017-05-04 22:07:24 +08:00
|
|
|
{
|
|
|
|
protected abstract Drawable CreateControl();
|
|
|
|
|
2017-05-04 22:32:27 +08:00
|
|
|
protected Drawable Control { get; }
|
2017-05-04 22:07:24 +08:00
|
|
|
|
2017-05-04 22:32:27 +08:00
|
|
|
private IHasCurrentValue<T> controlWithCurrent => Control as IHasCurrentValue<T>;
|
2017-05-04 22:07:24 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 09:55:29 +08:00
|
|
|
// hold a reference to the provided bindable so we don't have to in every settings section.
|
2017-05-04 22:07:24 +08:00
|
|
|
private Bindable<T> bindable;
|
|
|
|
|
|
|
|
public Bindable<T> Bindable
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return bindable;
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
|
|
|
bindable = value;
|
2017-05-08 09:11:45 +08:00
|
|
|
controlWithCurrent?.Current.BindTo(bindable);
|
2017-05-04 22:07:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string[] FilterTerms => new[] { LabelText };
|
|
|
|
|
|
|
|
public bool MatchingCurrentFilter
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
// probably needs a better transition.
|
|
|
|
FadeTo(value ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 09:55:29 +08:00
|
|
|
protected SettingsItem()
|
2017-05-04 22:07:24 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
Padding = new MarginPadding { Right = 5 };
|
|
|
|
|
|
|
|
if ((Control = CreateControl()) != null)
|
|
|
|
{
|
2017-05-04 22:32:27 +08:00
|
|
|
if (controlWithCurrent != null)
|
|
|
|
controlWithCurrent.Current.DisabledChanged += disabled => { Colour = disabled ? Color4.Gray : Color4.White; };
|
2017-05-04 22:07:24 +08:00
|
|
|
Add(Control);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|