1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 05:57:29 +08:00
osu-lazer/osu.Game/Overlays/Options/OptionDropdown.cs

85 lines
2.3 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-03-22 07:49:21 +08:00
using System.Collections.Generic;
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;
2017-02-03 18:13:10 +08:00
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Options
{
2017-03-22 22:32:32 +08:00
public class OptionDropdown<T> : FillFlowContainer
{
private readonly Dropdown<T> dropdown;
private readonly SpriteText text;
2016-12-02 06:33:30 +08:00
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;
2017-04-10 16:10:15 +08:00
dropdown.Current.BindTo(bindable);
}
}
private Bindable<T> bindable;
private IEnumerable<KeyValuePair<string, T>> items;
public IEnumerable<KeyValuePair<string, T>> Items
{
get
{
return items;
}
set
{
items = value;
2017-03-22 07:49:21 +08:00
if (dropdown != null)
dropdown.Items = value;
}
}
2017-03-22 22:32:32 +08:00
public OptionDropdown()
{
Items = new KeyValuePair<string, T>[0];
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Vertical;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Children = new Drawable[]
{
text = new OsuSpriteText {
Alpha = 0,
},
2017-03-22 22:32:32 +08:00
dropdown = new OsuDropdown<T>
{
Margin = new MarginPadding { Top = 5 },
RelativeSizeAxes = Axes.X,
2017-02-27 22:37:38 +08:00
Items = Items,
}
};
dropdown.Current.DisabledChanged += disabled =>
{
Alpha = disabled ? 0.3f : 1;
};
}
}
2016-12-02 19:35:55 +08:00
}