2017-02-07 12:59:30 +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 System;
|
2016-12-02 05:36:04 +08:00
|
|
|
|
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;
|
2017-02-06 08:21:26 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-12-02 05:36:04 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Options
|
|
|
|
|
{
|
2017-03-02 02:33:01 +08:00
|
|
|
|
public class OptionDropDown<T> : FillFlowContainer
|
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)
|
2017-02-13 23:35:24 +08:00
|
|
|
|
bindable.ValueChanged -= bindable_ValueChanged;
|
2016-12-02 05:36:04 +08:00
|
|
|
|
bindable = value;
|
2017-02-13 23:35:24 +08:00
|
|
|
|
bindable.ValueChanged += bindable_ValueChanged;
|
|
|
|
|
bindable_ValueChanged(null, null);
|
|
|
|
|
|
|
|
|
|
if (bindable?.Disabled ?? true)
|
|
|
|
|
Alpha = 0.3f;
|
2016-12-02 05:36:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Bindable<T> bindable;
|
|
|
|
|
|
2017-02-13 23:35:24 +08:00
|
|
|
|
void bindable_ValueChanged(object sender, EventArgs e)
|
2016-12-02 05:36:04 +08:00
|
|
|
|
{
|
|
|
|
|
dropdown.SelectedValue = bindable.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 23:35:24 +08:00
|
|
|
|
void dropdown_ValueChanged(object sender, EventArgs e)
|
2016-12-05 22:24:54 +08:00
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
2017-02-13 23:35:24 +08:00
|
|
|
|
bindable.ValueChanged -= bindable_ValueChanged;
|
|
|
|
|
dropdown.ValueChanged -= dropdown_ValueChanged;
|
2016-12-05 22:24:54 +08:00
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 08:21:26 +08:00
|
|
|
|
private IEnumerable<KeyValuePair<string, T>> items;
|
|
|
|
|
public IEnumerable<KeyValuePair<string, T>> Items
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
items = value;
|
|
|
|
|
if(dropdown != null)
|
2017-02-11 23:27:15 +08:00
|
|
|
|
{
|
2017-02-06 08:21:26 +08:00
|
|
|
|
dropdown.Items = value;
|
2017-02-11 23:27:15 +08:00
|
|
|
|
|
|
|
|
|
// We need to refresh the dropdown because our items changed,
|
|
|
|
|
// thus its selected value may be outdated.
|
|
|
|
|
if (bindable != null)
|
|
|
|
|
dropdown.SelectedValue = bindable.Value;
|
|
|
|
|
}
|
2017-02-06 08:21:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-03 18:13:10 +08:00
|
|
|
|
public OptionDropDown()
|
2016-12-02 05:36:04 +08:00
|
|
|
|
{
|
2017-02-06 08:21:26 +08:00
|
|
|
|
Items = new KeyValuePair<string, T>[0];
|
|
|
|
|
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Vertical;
|
2016-12-02 05:36:04 +08:00
|
|
|
|
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-02-27 22:37:38 +08:00
|
|
|
|
Items = Items,
|
2016-12-02 05:36:04 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2017-02-13 23:35:24 +08:00
|
|
|
|
dropdown.ValueChanged += dropdown_ValueChanged;
|
2016-12-02 05:36:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-02 19:35:55 +08:00
|
|
|
|
}
|