mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 19:02:57 +08:00
Merge pull request #281 from SirCmpwn/custom-dropdowns
Style dropdown to match osu!stable
This commit is contained in:
commit
d3397e2cfc
@ -1 +1 @@
|
||||
Subproject commit 45bff5838d133d918547e90bd74c9d0d5fadecc1
|
||||
Subproject commit 4ce11f434dccb07b35b64618bf3db97c09d310a5
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@ -11,6 +12,7 @@ using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Options
|
||||
{
|
||||
@ -68,9 +70,6 @@ namespace osu.Game.Overlays.Options
|
||||
Direction = FlowDirection.VerticalOnly;
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
var items = typeof(T).GetFields().Where(f => !f.IsSpecialName).Zip(
|
||||
(T[])Enum.GetValues(typeof(T)), (a, b) => new Tuple<string, T>(
|
||||
a.GetCustomAttribute<DescriptionAttribute>()?.Description ?? a.Name, b));
|
||||
Children = new Drawable[]
|
||||
{
|
||||
text = new SpriteText { Alpha = 0 },
|
||||
@ -78,7 +77,7 @@ namespace osu.Game.Overlays.Options
|
||||
{
|
||||
Margin = new MarginPadding { Top = 5 },
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Items = items.Select(item => new StyledDropDownMenuItem<T>(item.Item1, item.Item2))
|
||||
Items = (T[])Enum.GetValues(typeof(T)),
|
||||
}
|
||||
};
|
||||
dropdown.ValueChanged += Dropdown_ValueChanged;
|
||||
@ -92,6 +91,17 @@ namespace osu.Game.Overlays.Options
|
||||
{
|
||||
return new StyledDropDownComboBox();
|
||||
}
|
||||
|
||||
protected override IEnumerable<DropDownMenuItem<U>> GetDropDownItems(IEnumerable<U> values)
|
||||
{
|
||||
return values.Select(v =>
|
||||
{
|
||||
var field = typeof(U).GetField(Enum.GetName(typeof(U), v));
|
||||
return new StyledDropDownMenuItem<U>(
|
||||
field.GetCustomAttribute<DescriptionAttribute>()?.Description ?? field.Name, v);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public StyledDropDownMenu()
|
||||
{
|
||||
@ -101,7 +111,7 @@ namespace osu.Game.Overlays.Options
|
||||
|
||||
protected override void AnimateOpen()
|
||||
{
|
||||
foreach (StyledDropDownMenuItem<U> child in DropDownList.Children)
|
||||
foreach (StyledDropDownMenuItem<U> child in DropDownItemsContainer.Children)
|
||||
{
|
||||
child.FadeIn(200);
|
||||
child.ResizeTo(new Vector2(1, 24), 200);
|
||||
@ -111,7 +121,7 @@ namespace osu.Game.Overlays.Options
|
||||
|
||||
protected override void AnimateClose()
|
||||
{
|
||||
foreach (StyledDropDownMenuItem<U> child in DropDownList.Children)
|
||||
foreach (StyledDropDownMenuItem<U> child in DropDownItemsContainer.Children)
|
||||
{
|
||||
child.ResizeTo(new Vector2(1, 0), 200);
|
||||
child.FadeOut(200);
|
||||
@ -121,45 +131,67 @@ namespace osu.Game.Overlays.Options
|
||||
|
||||
private class StyledDropDownComboBox : DropDownComboBox
|
||||
{
|
||||
protected override Color4 BackgroundColour => new Color4(255, 255, 255, 100);
|
||||
protected override Color4 BackgroundColourHover => Color4.HotPink;
|
||||
protected override Color4 BackgroundColour => new Color4(0, 0, 0, 128);
|
||||
protected override Color4 BackgroundColourHover => new Color4(187, 17, 119, 255);
|
||||
|
||||
private SpriteText label;
|
||||
protected override string Label
|
||||
{
|
||||
get { return label.Text; }
|
||||
set { label.Text = value; }
|
||||
}
|
||||
|
||||
public StyledDropDownComboBox()
|
||||
{
|
||||
Foreground.Padding = new MarginPadding(4);
|
||||
|
||||
Children = new[]
|
||||
{
|
||||
label = new SpriteText(),
|
||||
new TextAwesome
|
||||
{
|
||||
Icon = FontAwesome.fa_chevron_down,
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
Margin = new MarginPadding { Right = 4 },
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class StyledDropDownMenuItem<U> : DropDownMenuItem<U>
|
||||
{
|
||||
protected override Color4 BackgroundColour => new Color4(0, 0, 0, 128);
|
||||
protected override Color4 BackgroundColourSelected => new Color4(0, 0, 0, 128);
|
||||
protected override Color4 BackgroundColourHover => new Color4(187, 17, 119, 255);
|
||||
|
||||
public StyledDropDownMenuItem(string text, U value) : base(text, value)
|
||||
{
|
||||
AutoSizeAxes = Axes.None;
|
||||
Height = 0;
|
||||
Foreground.Padding = new MarginPadding(2);
|
||||
}
|
||||
|
||||
protected override void OnSelectChange()
|
||||
{
|
||||
if (!IsLoaded)
|
||||
return;
|
||||
|
||||
FormatBackground();
|
||||
FormatCaret();
|
||||
FormatLabel();
|
||||
}
|
||||
|
||||
protected override void FormatCaret()
|
||||
{
|
||||
(Caret as SpriteText).Text = IsSelected ? @"+" : @"-";
|
||||
}
|
||||
|
||||
protected override void FormatLabel()
|
||||
{
|
||||
if (IsSelected)
|
||||
(Label as SpriteText).Text = @"*" + Value + @"*";
|
||||
else
|
||||
(Label as SpriteText).Text = Value.ToString();
|
||||
Children = new[]
|
||||
{
|
||||
new FlowContainer
|
||||
{
|
||||
Direction = FlowDirection.HorizontalOnly,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new TextAwesome
|
||||
{
|
||||
Icon = FontAwesome.fa_chevron_right,
|
||||
Colour = Color4.Black,
|
||||
Margin = new MarginPadding { Right = 3 },
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
},
|
||||
new SpriteText { Text = text }
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user