2016-12-02 05:36:04 +08:00
|
|
|
|
using System;
|
|
|
|
|
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;
|
2017-01-31 17:53:52 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-02-03 18:13:10 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2016-12-02 05:36:04 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Options
|
|
|
|
|
{
|
2017-02-03 18:13:10 +08:00
|
|
|
|
public class OptionDropDown<T> : FlowContainer
|
2016-12-02 05:36:04 +08:00
|
|
|
|
{
|
|
|
|
|
private DropDownMenu<T> dropdown;
|
|
|
|
|
private SpriteText text;
|
2017-01-31 17:37:11 +08:00
|
|
|
|
|
2016-12-02 06:33:30 +08:00
|
|
|
|
public string LabelText
|
2016-12-02 05:36:04 +08:00
|
|
|
|
{
|
|
|
|
|
get { return text.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
text.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-31 17:37:11 +08:00
|
|
|
|
|
2016-12-02 05:36:04 +08:00
|
|
|
|
public Bindable<T> Bindable
|
|
|
|
|
{
|
|
|
|
|
get { return bindable; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (bindable != null)
|
|
|
|
|
bindable.ValueChanged -= Bindable_ValueChanged;
|
|
|
|
|
bindable = value;
|
|
|
|
|
bindable.ValueChanged += Bindable_ValueChanged;
|
|
|
|
|
Bindable_ValueChanged(null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Bindable<T> bindable;
|
|
|
|
|
|
|
|
|
|
void Bindable_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
dropdown.SelectedValue = bindable.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-05 22:24:54 +08:00
|
|
|
|
void Dropdown_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
bindable.Value = dropdown.SelectedValue;
|
|
|
|
|
}
|
2017-01-31 17:37:11 +08:00
|
|
|
|
|
2016-12-05 22:24:54 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
bindable.ValueChanged -= Bindable_ValueChanged;
|
|
|
|
|
dropdown.ValueChanged -= Dropdown_ValueChanged;
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-03 18:13:10 +08:00
|
|
|
|
public OptionDropDown()
|
2016-12-02 05:36:04 +08:00
|
|
|
|
{
|
|
|
|
|
if (!typeof(T).IsEnum)
|
|
|
|
|
throw new InvalidOperationException("OptionsDropdown only supports enums as the generic type argument");
|
|
|
|
|
Direction = FlowDirection.VerticalOnly;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-01-31 17:53:52 +08:00
|
|
|
|
text = new OsuSpriteText {
|
2017-01-31 17:37:11 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
2017-02-03 18:13:10 +08:00
|
|
|
|
dropdown = new OsuDropDownMenu<T>
|
2016-12-02 05:36:04 +08:00
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding { Top = 5 },
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-01-04 14:14:25 +08:00
|
|
|
|
Items = (T[])Enum.GetValues(typeof(T)),
|
2016-12-02 05:36:04 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2016-12-05 22:24:54 +08:00
|
|
|
|
dropdown.ValueChanged += Dropdown_ValueChanged;
|
2016-12-02 05:36:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-02 19:35:55 +08:00
|
|
|
|
}
|