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
|
|
|
|
|
2017-09-13 22:18:02 +08:00
|
|
|
using System.Collections.Generic;
|
2017-05-04 22:07:24 +08:00
|
|
|
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).
|
2017-07-13 14:02:45 +08:00
|
|
|
Add(text = new OsuSpriteText { Depth = 1 });
|
2017-05-04 22:07:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2017-06-05 12:24:54 +08:00
|
|
|
public virtual Bindable<T> Bindable
|
2017-05-04 22:07:24 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-13 22:18:02 +08:00
|
|
|
public IEnumerable<string> FilterTerms => new[] { LabelText };
|
2017-05-04 22:07:24 +08:00
|
|
|
|
2017-05-30 15:33:26 +08:00
|
|
|
public bool MatchingFilter
|
2017-05-04 22:07:24 +08:00
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
// probably needs a better transition.
|
2017-07-15 00:18:12 +08:00
|
|
|
this.FadeTo(value ? 1 : 0);
|
2017-05-04 22:07:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|