From f0edf5d3d3ec772961c51cce18e45af51c199b61 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 22 Mar 2017 06:51:26 +0800 Subject: [PATCH] Update to DropDown and Menu. --- .../Graphics/UserInterface/OsuDropDown.cs | 40 ++++++++++++ .../Graphics/UserInterface/OsuDropDownMenu.cs | 61 ------------------- osu.Game/Graphics/UserInterface/OsuMenu.cs | 34 +++++++++++ .../Graphics/UserInterface/OsuTabControl.cs | 20 +++--- osu.Game/Overlays/Options/OptionDropDown.cs | 4 +- osu.Game/osu.Game.csproj | 3 +- 6 files changed, 88 insertions(+), 74 deletions(-) create mode 100644 osu.Game/Graphics/UserInterface/OsuDropDown.cs delete mode 100644 osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs create mode 100644 osu.Game/Graphics/UserInterface/OsuMenu.cs diff --git a/osu.Game/Graphics/UserInterface/OsuDropDown.cs b/osu.Game/Graphics/UserInterface/OsuDropDown.cs new file mode 100644 index 0000000000..51fb335698 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/OsuDropDown.cs @@ -0,0 +1,40 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Linq; +using OpenTK.Graphics; +using osu.Framework.Allocation; +using osu.Framework.Graphics.UserInterface; + +namespace osu.Game.Graphics.UserInterface +{ + public class OsuDropDown : DropDown + { + protected override DropDownHeader CreateHeader() => new OsuDropDownHeader { AccentColour = AccentColour }; + + protected override Menu CreateMenu() => new OsuMenu(); + + private Color4? accentColour; + public virtual Color4 AccentColour + { + get { return accentColour.GetValueOrDefault(); } + set + { + accentColour = value; + if (Header != null) + ((OsuDropDownHeader)Header).AccentColour = value; + foreach (var item in MenuItems.OfType>()) + item.AccentColour = value; + } + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + if (accentColour == null) + AccentColour = colours.PinkDarker; + } + + protected override DropDownMenuItem CreateMenuItem(string key, T value) => new OsuDropDownMenuItem(key, value) { AccentColour = AccentColour }; + } +} \ No newline at end of file diff --git a/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs b/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs deleted file mode 100644 index 5d9e30db8d..0000000000 --- a/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System.Linq; -using osu.Framework.Allocation; -using OpenTK; -using OpenTK.Graphics; -using osu.Framework.Extensions.Color4Extensions; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.Transforms; -using osu.Framework.Graphics.UserInterface; - -namespace osu.Game.Graphics.UserInterface -{ - public class OsuDropDownMenu : DropDownMenu - { - protected override DropDownHeader CreateHeader() => new OsuDropDownHeader { AccentColour = AccentColour }; - - private Color4? accentColour; - public virtual Color4 AccentColour - { - get { return accentColour.GetValueOrDefault(); } - set - { - accentColour = value; - if (Header != null) - ((OsuDropDownHeader)Header).AccentColour = value; - foreach (var item in ItemList.OfType>()) - item.AccentColour = value; - } - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - if (accentColour == null) - AccentColour = colours.PinkDarker; - } - - public OsuDropDownMenu() - { - ContentContainer.CornerRadius = 4; - ContentBackground.Colour = Color4.Black.Opacity(0.5f); - - DropDownItemsContainer.Padding = new MarginPadding(5); - } - - protected override void AnimateOpen() => ContentContainer.FadeIn(300, EasingTypes.OutQuint); - - protected override void AnimateClose() => ContentContainer.FadeOut(300, EasingTypes.OutQuint); - - protected override void UpdateContentHeight() - { - var actualHeight = (RelativeSizeAxes & Axes.Y) > 0 ? 1 : ContentHeight; - ContentContainer.ResizeTo(new Vector2(1, State == DropDownMenuState.Opened ? actualHeight : 0), 300, EasingTypes.OutQuint); - } - - protected override DropDownMenuItem CreateDropDownItem(string key, T value) => new OsuDropDownMenuItem(key, value) { AccentColour = AccentColour }; - } -} \ No newline at end of file diff --git a/osu.Game/Graphics/UserInterface/OsuMenu.cs b/osu.Game/Graphics/UserInterface/OsuMenu.cs new file mode 100644 index 0000000000..4e80e1502a --- /dev/null +++ b/osu.Game/Graphics/UserInterface/OsuMenu.cs @@ -0,0 +1,34 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.Transforms; +using osu.Framework.Graphics.UserInterface; + +namespace osu.Game.Graphics.UserInterface +{ + public class OsuMenu : Menu + { + public OsuMenu() + { + CornerRadius = 4; + ContentBackground.Colour = Color4.Black.Opacity(0.5f); + + ItemsContainer.Padding = new MarginPadding(5); + } + + protected override void AnimateOpen() => FadeIn(300, EasingTypes.OutQuint); + + protected override void AnimateClose() => FadeOut(300, EasingTypes.OutQuint); + + protected override void UpdateContentHeight() + { + var actualHeight = (RelativeSizeAxes & Axes.Y) > 0 ? 1 : ContentHeight; + ResizeTo(new Vector2(1, State == MenuState.Opened ? actualHeight : 0), 300, EasingTypes.OutQuint); + } + } +} diff --git a/osu.Game/Graphics/UserInterface/OsuTabControl.cs b/osu.Game/Graphics/UserInterface/OsuTabControl.cs index de81757fdf..947b39f621 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabControl.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabControl.cs @@ -16,7 +16,7 @@ namespace osu.Game.Graphics.UserInterface { public class OsuTabControl : TabControl { - protected override DropDownMenu CreateDropDownMenu() => new OsuTabDropDownMenu(); + protected override DropDown CreateDropDownMenu() => new OsuTabDropDown(); protected override TabItem CreateTabItem(T value) => new OsuTabItem { Value = value }; @@ -45,7 +45,7 @@ namespace osu.Game.Graphics.UserInterface set { accentColour = value; - var dropDown = DropDown as OsuTabDropDownMenu; + var dropDown = DropDown as OsuTabDropDown; if (dropDown != null) dropDown.AccentColour = value; foreach (var item in TabContainer.Children.OfType>()) @@ -53,7 +53,7 @@ namespace osu.Game.Graphics.UserInterface } } - public class OsuTabDropDownMenu : OsuDropDownMenu + public class OsuTabDropDown : OsuDropDown { protected override DropDownHeader CreateHeader() => new OsuTabDropDownHeader { @@ -62,22 +62,22 @@ namespace osu.Game.Graphics.UserInterface Origin = Anchor.TopRight, }; - protected override DropDownMenuItem CreateDropDownItem(string key, T value) + protected override DropDownMenuItem CreateMenuItem(string key, T value) { - var item = base.CreateDropDownItem(key, value); + var item = base.CreateMenuItem(key, value); item.ForegroundColourHover = Color4.Black; return item; } - public OsuTabDropDownMenu() + public OsuTabDropDown() { - ContentContainer.Anchor = Anchor.TopRight; - ContentContainer.Origin = Anchor.TopRight; + DropDownMenu.Anchor = Anchor.TopRight; + DropDownMenu.Origin = Anchor.TopRight; RelativeSizeAxes = Axes.X; - ContentBackground.Colour = Color4.Black.Opacity(0.7f); - MaxDropDownHeight = 400; + DropDownMenu.Colour = Color4.Black.Opacity(0.7f); + DropDownMenu.MaxHeight = 400; } public class OsuTabDropDownHeader : OsuDropDownHeader diff --git a/osu.Game/Overlays/Options/OptionDropDown.cs b/osu.Game/Overlays/Options/OptionDropDown.cs index 4387e90b5a..690d3d21a5 100644 --- a/osu.Game/Overlays/Options/OptionDropDown.cs +++ b/osu.Game/Overlays/Options/OptionDropDown.cs @@ -16,7 +16,7 @@ namespace osu.Game.Overlays.Options { public class OptionDropDown : FillFlowContainer { - private DropDownMenu dropdown; + private DropDown dropdown; private SpriteText text; public string LabelText @@ -97,7 +97,7 @@ namespace osu.Game.Overlays.Options text = new OsuSpriteText { Alpha = 0, }, - dropdown = new OsuDropDownMenu + dropdown = new OsuDropDown { Margin = new MarginPadding { Top = 5 }, RelativeSizeAxes = Axes.X, diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 188d929888..3f97e196db 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -85,6 +85,7 @@ + @@ -159,7 +160,7 @@ - +