From a1f8c0df64e84332a5351d11e5966b6530bc37b3 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 3 Jan 2017 23:00:28 -0500 Subject: [PATCH 1/4] Style dropdown to match osu!stable --- osu.Game/Overlays/Options/DropdownOption.cs | 79 ++++++++++++++------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/osu.Game/Overlays/Options/DropdownOption.cs b/osu.Game/Overlays/Options/DropdownOption.cs index 3cdc6da2ab..ec2bad5bdc 100644 --- a/osu.Game/Overlays/Options/DropdownOption.cs +++ b/osu.Game/Overlays/Options/DropdownOption.cs @@ -11,6 +11,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 { @@ -97,6 +98,7 @@ namespace osu.Game.Overlays.Options { ComboBox.CornerRadius = 4; DropDown.CornerRadius = 4; + DropDown.Masking = true; } protected override void AnimateOpen() @@ -121,45 +123,74 @@ 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 : DropDownMenuItem { + 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 Framework.Graphics.Containers.Container + { + Width = 20, + Height = 20, + Margin = new MarginPadding { Top = 1, Right = 3 }, + Children = new[] + { + new TextAwesome + { + Icon = FontAwesome.fa_chevron_right, + Colour = Color4.Black, + Anchor = Anchor.Centre, + } + } + }, + new SpriteText { Text = text } + } + } + }; } } } From af4aeeab095d5cf53843d8757cd568768fc11d8f Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 4 Jan 2017 01:14:25 -0500 Subject: [PATCH 2/4] Update following framework changes --- osu.Game/Overlays/Options/DropdownOption.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/Options/DropdownOption.cs b/osu.Game/Overlays/Options/DropdownOption.cs index ec2bad5bdc..5d6fc0d835 100644 --- a/osu.Game/Overlays/Options/DropdownOption.cs +++ b/osu.Game/Overlays/Options/DropdownOption.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; @@ -69,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( - a.GetCustomAttribute()?.Description ?? a.Name, b)); Children = new Drawable[] { text = new SpriteText { Alpha = 0 }, @@ -79,7 +77,7 @@ namespace osu.Game.Overlays.Options { Margin = new MarginPadding { Top = 5 }, RelativeSizeAxes = Axes.X, - Items = items.Select(item => new StyledDropDownMenuItem(item.Item1, item.Item2)) + Items = (T[])Enum.GetValues(typeof(T)), } }; dropdown.ValueChanged += Dropdown_ValueChanged; @@ -93,6 +91,17 @@ namespace osu.Game.Overlays.Options { return new StyledDropDownComboBox(); } + + protected override IEnumerable> GetDropDownItems(IEnumerable values) + { + return values.Select(v => + { + var field = typeof(U).GetField(Enum.GetName(typeof(U), v)); + return new StyledDropDownMenuItem( + field.GetCustomAttribute()?.Description ?? field.Name, v); + }); + + } public StyledDropDownMenu() { From b27139c2bdf36123c4e0a6c3b7e15670ed332473 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 5 Jan 2017 00:57:19 -0500 Subject: [PATCH 3/4] Simplify layout of dropdown menu item --- osu.Game/Overlays/Options/DropdownOption.cs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/osu.Game/Overlays/Options/DropdownOption.cs b/osu.Game/Overlays/Options/DropdownOption.cs index 5d6fc0d835..150dddc13d 100644 --- a/osu.Game/Overlays/Options/DropdownOption.cs +++ b/osu.Game/Overlays/Options/DropdownOption.cs @@ -107,7 +107,6 @@ namespace osu.Game.Overlays.Options { ComboBox.CornerRadius = 4; DropDown.CornerRadius = 4; - DropDown.Masking = true; } protected override void AnimateOpen() @@ -181,20 +180,13 @@ namespace osu.Game.Overlays.Options AutoSizeAxes = Axes.Y, Children = new Drawable[] { - new Framework.Graphics.Containers.Container + new TextAwesome { - Width = 20, - Height = 20, - Margin = new MarginPadding { Top = 1, Right = 3 }, - Children = new[] - { - new TextAwesome - { - Icon = FontAwesome.fa_chevron_right, - Colour = Color4.Black, - Anchor = Anchor.Centre, - } - } + Icon = FontAwesome.fa_chevron_right, + Colour = Color4.Black, + Margin = new MarginPadding { Right = 3 }, + Origin = Anchor.CentreLeft, + Anchor = Anchor.CentreLeft, }, new SpriteText { Text = text } } From 4899d88d190c965bc85271892b547e3f2c338a60 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 5 Jan 2017 02:10:05 -0500 Subject: [PATCH 4/4] Update framework --- osu-framework | 2 +- osu.Game/Overlays/Options/DropdownOption.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu-framework b/osu-framework index 45bff5838d..4ce11f434d 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 45bff5838d133d918547e90bd74c9d0d5fadecc1 +Subproject commit 4ce11f434dccb07b35b64618bf3db97c09d310a5 diff --git a/osu.Game/Overlays/Options/DropdownOption.cs b/osu.Game/Overlays/Options/DropdownOption.cs index 150dddc13d..e843e15993 100644 --- a/osu.Game/Overlays/Options/DropdownOption.cs +++ b/osu.Game/Overlays/Options/DropdownOption.cs @@ -111,7 +111,7 @@ namespace osu.Game.Overlays.Options protected override void AnimateOpen() { - foreach (StyledDropDownMenuItem child in DropDownList.Children) + foreach (StyledDropDownMenuItem child in DropDownItemsContainer.Children) { child.FadeIn(200); child.ResizeTo(new Vector2(1, 24), 200); @@ -121,7 +121,7 @@ namespace osu.Game.Overlays.Options protected override void AnimateClose() { - foreach (StyledDropDownMenuItem child in DropDownList.Children) + foreach (StyledDropDownMenuItem child in DropDownItemsContainer.Children) { child.ResizeTo(new Vector2(1, 0), 200); child.FadeOut(200);