mirror of
https://github.com/ppy/osu.git
synced 2025-01-29 02:12: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;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@ -11,6 +12,7 @@ using osu.Framework.Graphics.Primitives;
|
|||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Options
|
namespace osu.Game.Overlays.Options
|
||||||
{
|
{
|
||||||
@ -68,9 +70,6 @@ namespace osu.Game.Overlays.Options
|
|||||||
Direction = FlowDirection.VerticalOnly;
|
Direction = FlowDirection.VerticalOnly;
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
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[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
text = new SpriteText { Alpha = 0 },
|
text = new SpriteText { Alpha = 0 },
|
||||||
@ -78,7 +77,7 @@ namespace osu.Game.Overlays.Options
|
|||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5 },
|
Margin = new MarginPadding { Top = 5 },
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Items = items.Select(item => new StyledDropDownMenuItem<T>(item.Item1, item.Item2))
|
Items = (T[])Enum.GetValues(typeof(T)),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dropdown.ValueChanged += Dropdown_ValueChanged;
|
dropdown.ValueChanged += Dropdown_ValueChanged;
|
||||||
@ -92,6 +91,17 @@ namespace osu.Game.Overlays.Options
|
|||||||
{
|
{
|
||||||
return new StyledDropDownComboBox();
|
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()
|
public StyledDropDownMenu()
|
||||||
{
|
{
|
||||||
@ -101,7 +111,7 @@ namespace osu.Game.Overlays.Options
|
|||||||
|
|
||||||
protected override void AnimateOpen()
|
protected override void AnimateOpen()
|
||||||
{
|
{
|
||||||
foreach (StyledDropDownMenuItem<U> child in DropDownList.Children)
|
foreach (StyledDropDownMenuItem<U> child in DropDownItemsContainer.Children)
|
||||||
{
|
{
|
||||||
child.FadeIn(200);
|
child.FadeIn(200);
|
||||||
child.ResizeTo(new Vector2(1, 24), 200);
|
child.ResizeTo(new Vector2(1, 24), 200);
|
||||||
@ -111,7 +121,7 @@ namespace osu.Game.Overlays.Options
|
|||||||
|
|
||||||
protected override void AnimateClose()
|
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.ResizeTo(new Vector2(1, 0), 200);
|
||||||
child.FadeOut(200);
|
child.FadeOut(200);
|
||||||
@ -121,45 +131,67 @@ namespace osu.Game.Overlays.Options
|
|||||||
|
|
||||||
private class StyledDropDownComboBox : DropDownComboBox
|
private class StyledDropDownComboBox : DropDownComboBox
|
||||||
{
|
{
|
||||||
protected override Color4 BackgroundColour => new Color4(255, 255, 255, 100);
|
protected override Color4 BackgroundColour => new Color4(0, 0, 0, 128);
|
||||||
protected override Color4 BackgroundColourHover => Color4.HotPink;
|
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()
|
public StyledDropDownComboBox()
|
||||||
{
|
{
|
||||||
Foreground.Padding = new MarginPadding(4);
|
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>
|
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)
|
public StyledDropDownMenuItem(string text, U value) : base(text, value)
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.None;
|
AutoSizeAxes = Axes.None;
|
||||||
Height = 0;
|
Height = 0;
|
||||||
Foreground.Padding = new MarginPadding(2);
|
Foreground.Padding = new MarginPadding(2);
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnSelectChange()
|
Children = new[]
|
||||||
{
|
{
|
||||||
if (!IsLoaded)
|
new FlowContainer
|
||||||
return;
|
{
|
||||||
|
Direction = FlowDirection.HorizontalOnly,
|
||||||
FormatBackground();
|
RelativeSizeAxes = Axes.X,
|
||||||
FormatCaret();
|
AutoSizeAxes = Axes.Y,
|
||||||
FormatLabel();
|
Children = new Drawable[]
|
||||||
}
|
{
|
||||||
|
new TextAwesome
|
||||||
protected override void FormatCaret()
|
{
|
||||||
{
|
Icon = FontAwesome.fa_chevron_right,
|
||||||
(Caret as SpriteText).Text = IsSelected ? @"+" : @"-";
|
Colour = Color4.Black,
|
||||||
}
|
Margin = new MarginPadding { Right = 3 },
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
protected override void FormatLabel()
|
Anchor = Anchor.CentreLeft,
|
||||||
{
|
},
|
||||||
if (IsSelected)
|
new SpriteText { Text = text }
|
||||||
(Label as SpriteText).Text = @"*" + Value + @"*";
|
}
|
||||||
else
|
}
|
||||||
(Label as SpriteText).Text = Value.ToString();
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user