From 110bdbd0c11069fa42a1744272b8e3cbc47a7444 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 16 Mar 2017 21:17:14 +0900 Subject: [PATCH] Make everything share DropDown implementations again. Remove unnecessary files. --- .../UserInterface/OsuDropDownHeader.cs | 15 +- .../Graphics/UserInterface/OsuDropDownMenu.cs | 46 +++++-- .../UserInterface/OsuDropDownMenuItem.cs | 38 ++++- .../Graphics/UserInterface/OsuTabControl.cs | 93 ++++++++++++- .../UserInterface/OsuTabDropDownMenu.cs | 130 ------------------ .../UserInterface/OsuTabDropDownMenuItem.cs | 54 -------- osu.Game/Graphics/UserInterface/OsuTabItem.cs | 2 +- osu.Game/Screens/Play/KeyCounterCollection.cs | 1 - osu.Game/Screens/Play/KeyCounterMouse.cs | 1 - osu.Game/Screens/Select/FilterControl.cs | 2 +- osu.Game/osu.Game.csproj | 2 - 11 files changed, 173 insertions(+), 211 deletions(-) delete mode 100644 osu.Game/Graphics/UserInterface/OsuTabDropDownMenu.cs delete mode 100644 osu.Game/Graphics/UserInterface/OsuTabDropDownMenuItem.cs diff --git a/osu.Game/Graphics/UserInterface/OsuDropDownHeader.cs b/osu.Game/Graphics/UserInterface/OsuDropDownHeader.cs index 176c066af5..00dc510338 100644 --- a/osu.Game/Graphics/UserInterface/OsuDropDownHeader.cs +++ b/osu.Game/Graphics/UserInterface/OsuDropDownHeader.cs @@ -21,6 +21,17 @@ namespace osu.Game.Graphics.UserInterface set { label.Text = value; } } + private Color4? accentColour; + public virtual Color4 AccentColour + { + get { return accentColour.GetValueOrDefault(); } + set + { + accentColour = value; + BackgroundColourHover = value; + } + } + public OsuDropDownHeader() { Foreground.Padding = new MarginPadding(4); @@ -30,7 +41,7 @@ namespace osu.Game.Graphics.UserInterface CornerRadius = 4; Height = 40; - Children = new[] + Foreground.Children = new Drawable[] { label = new OsuSpriteText { @@ -51,7 +62,7 @@ namespace osu.Game.Graphics.UserInterface private void load(OsuColour colours) { BackgroundColour = Color4.Black.Opacity(0.5f); - BackgroundColourHover = colours.PinkDarker; + BackgroundColourHover = accentColour ?? colours.PinkDarker; } } } \ No newline at end of file diff --git a/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs b/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs index 14615417f7..5d9e30db8d 100644 --- a/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuDropDownMenu.cs @@ -1,39 +1,61 @@ // 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 + public class OsuDropDownMenu : DropDownMenu { - protected override DropDownHeader CreateHeader() => new OsuDropDownHeader(); + 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 AnimateOpen() => ContentContainer.FadeIn(300, EasingTypes.OutQuint); - protected override void AnimateClose() - { - ContentContainer.FadeOut(300, EasingTypes.OutQuint); - } + protected override void AnimateClose() => ContentContainer.FadeOut(300, EasingTypes.OutQuint); protected override void UpdateContentHeight() { - ContentContainer.ResizeTo(State == DropDownMenuState.Opened ? new Vector2(1, ContentHeight) : new Vector2(1, 0), 300, EasingTypes.OutQuint); + 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, U value) => new OsuDropDownMenuItem(key, value); + 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/OsuDropDownMenuItem.cs b/osu.Game/Graphics/UserInterface/OsuDropDownMenuItem.cs index b06422c302..71650dee52 100644 --- a/osu.Game/Graphics/UserInterface/OsuDropDownMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/OsuDropDownMenuItem.cs @@ -18,6 +18,9 @@ namespace osu.Game.Graphics.UserInterface { Foreground.Padding = new MarginPadding(2); + Masking = true; + CornerRadius = 6; + Children = new[] { new FillFlowContainer @@ -27,12 +30,15 @@ namespace osu.Game.Graphics.UserInterface AutoSizeAxes = Axes.Y, Children = new Drawable[] { - new TextAwesome + chevron = new TextAwesome { + AlwaysPresent = true, Icon = FontAwesome.fa_chevron_right, + UseFullGlyphHeight = false, Colour = Color4.Black, - TextSize = 12, - Margin = new MarginPadding { Right = 3 }, + Alpha = 0.5f, + TextSize = 8, + Margin = new MarginPadding { Left = 3, Right = 3 }, Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, }, @@ -46,11 +52,33 @@ namespace osu.Game.Graphics.UserInterface }; } + private Color4? accentColour; + + private TextAwesome chevron; + + protected override void FormatForeground(bool hover = false) + { + base.FormatForeground(hover); + chevron.Alpha = hover ? 1 : 0; + } + + public Color4 AccentColour + { + get { return accentColour.GetValueOrDefault(); } + set + { + accentColour = value; + BackgroundColourHover = BackgroundColourSelected = value; + FormatBackground(); + FormatForeground(); + } + } + [BackgroundDependencyLoader] private void load(OsuColour colours) { - BackgroundColour = Color4.Black.Opacity(0.5f); - BackgroundColourHover = colours.PinkDarker; + BackgroundColour = Color4.Transparent; + BackgroundColourHover = accentColour ?? colours.PinkDarker; BackgroundColourSelected = Color4.Black.Opacity(0.5f); } } diff --git a/osu.Game/Graphics/UserInterface/OsuTabControl.cs b/osu.Game/Graphics/UserInterface/OsuTabControl.cs index 4c2ec902a9..05f154a407 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabControl.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabControl.cs @@ -5,18 +5,24 @@ using System; using System.Linq; using OpenTK.Graphics; using osu.Framework.Allocation; -using osu.Framework.Graphics.UserInterface.Tab; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input; namespace osu.Game.Graphics.UserInterface { public class OsuTabControl : TabControl { - protected override TabDropDownMenu CreateDropDownMenu() => new OsuTabDropDownMenu(); + protected override DropDownMenu CreateDropDownMenu() => new OsuTabDropDownMenu(); protected override TabItem CreateTabItem(T value) => new OsuTabItem { Value = value }; public OsuTabControl() { + AlwaysReceiveInput = true; + if (!typeof(T).IsEnum) throw new InvalidOperationException("OsuTabControl only supports enums as the generic type argument"); @@ -45,5 +51,88 @@ namespace osu.Game.Graphics.UserInterface item.AccentColour = value; } } + + public class OsuTabDropDownMenu : OsuDropDownMenu + { + protected override DropDownHeader CreateHeader() => new OsuTabDropDownHeader + { + AccentColour = AccentColour, + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + }; + + protected override DropDownMenuItem CreateDropDownItem(string key, T1 value) + { + var item = base.CreateDropDownItem(key, value); + item.ForegroundColourHover = Color4.Black; + return item; + } + + public OsuTabDropDownMenu() + { + ContentContainer.Anchor = Anchor.TopRight; + ContentContainer.Origin = Anchor.TopRight; + + RelativeSizeAxes = Axes.X; + + ContentBackground.Colour = Color4.Black.Opacity(0.7f); + MaxDropDownHeight = 400; + } + + public class OsuTabDropDownHeader : OsuDropDownHeader + { + public override Color4 AccentColour + { + get { return base.AccentColour; } + set + { + base.AccentColour = value; + Foreground.Colour = value; + } + } + + protected override bool OnHover(InputState state) + { + Foreground.Colour = BackgroundColour; + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + Foreground.Colour = BackgroundColourHover; + base.OnHoverLost(state); + } + + public OsuTabDropDownHeader() + { + RelativeSizeAxes = Axes.None; + AutoSizeAxes = Axes.X; + + BackgroundColour = Color4.Black.Opacity(0.5f); + + Background.Height = 0.5f; + Background.CornerRadius = 5; + Background.Masking = true; + + Foreground.RelativeSizeAxes = Axes.None; + Foreground.AutoSizeAxes = Axes.X; + Foreground.RelativeSizeAxes = Axes.Y; + Foreground.Margin = new MarginPadding(5); + + Foreground.Children = new Drawable[] + { + new TextAwesome + { + Icon = FontAwesome.fa_ellipsis_h, + TextSize = 14, + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + } + }; + + Padding = new MarginPadding { Left = 5, Right = 5 }; + } + } + } } } diff --git a/osu.Game/Graphics/UserInterface/OsuTabDropDownMenu.cs b/osu.Game/Graphics/UserInterface/OsuTabDropDownMenu.cs deleted file mode 100644 index 1b64056d97..0000000000 --- a/osu.Game/Graphics/UserInterface/OsuTabDropDownMenu.cs +++ /dev/null @@ -1,130 +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 OpenTK; -using OpenTK.Graphics; -using osu.Framework.Allocation; -using osu.Framework.Extensions.Color4Extensions; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.Transforms; -using osu.Framework.Graphics.UserInterface; -using osu.Framework.Graphics.UserInterface.Tab; -using osu.Framework.Input; - -namespace osu.Game.Graphics.UserInterface -{ - public class OsuTabDropDownMenu : TabDropDownMenu - { - private Color4? accentColour; - public Color4 AccentColour - { - get { return accentColour.GetValueOrDefault(); } - set - { - accentColour = value; - ((OsuTabDropDownHeader)Header).AccentColour = value; - foreach (var item in ItemList.OfType>()) - item.AccentColour = value; - } - } - - protected override DropDownHeader CreateHeader() => new OsuTabDropDownHeader - { - AccentColour = AccentColour - }; - - protected override DropDownMenuItem CreateDropDownItem(string key, T value) => - new OsuTabDropDownMenuItem(key, value) { AccentColour = AccentColour }; - - public OsuTabDropDownMenu() - { - MaxDropDownHeight = int.MaxValue; - ContentContainer.CornerRadius = 4; - ContentBackground.Colour = Color4.Black.Opacity(0.9f); - ScrollContainer.ScrollDraggerVisible = false; - DropDownItemsContainer.Padding = new MarginPadding { Left = 5, Bottom = 7, Right = 5, Top = 7 }; - } - - protected override void AnimateOpen() - { - ContentContainer.FadeIn(300, EasingTypes.OutQuint); - } - - protected override void AnimateClose() - { - ContentContainer.FadeOut(300, EasingTypes.OutQuint); - } - - protected override void UpdateContentHeight() - { - ContentContainer.ResizeTo(new Vector2(1, State == DropDownMenuState.Opened ? ContentHeight : 0), 300, EasingTypes.OutQuint); - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - if (accentColour == null) - AccentColour = colours.Blue; - } - - public class OsuTabDropDownHeader : DropDownHeader - { - protected override string Label { get; set; } - - private Color4? accentColour; - public Color4 AccentColour - { - get { return accentColour.GetValueOrDefault(); } - set - { - accentColour = value; - BackgroundColourHover = value; - Foreground.Colour = value; - } - } - - protected override bool OnHover(InputState state) - { - Foreground.Colour = BackgroundColour; - return base.OnHover(state); - } - - protected override void OnHoverLost(InputState state) - { - Foreground.Colour = BackgroundColourHover; - base.OnHoverLost(state); - } - - public OsuTabDropDownHeader() - { - RelativeSizeAxes = Axes.None; - AutoSizeAxes = Axes.X; - - BackgroundColour = Color4.Black; - - Background.Height = 0.5f; - Background.CornerRadius = 3; - Background.Masking = true; - - Foreground.RelativeSizeAxes = Axes.None; - Foreground.AutoSizeAxes = Axes.X; - Foreground.RelativeSizeAxes = Axes.Y; - Foreground.Margin = new MarginPadding(5); - Foreground.Children = new Drawable[] - { - new TextAwesome - { - Icon = FontAwesome.fa_ellipsis_h, - TextSize = 14, - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - } - }; - - Padding = new MarginPadding { Left = 5, Right = 5 }; - } - } - } -} diff --git a/osu.Game/Graphics/UserInterface/OsuTabDropDownMenuItem.cs b/osu.Game/Graphics/UserInterface/OsuTabDropDownMenuItem.cs deleted file mode 100644 index 86d451f7bb..0000000000 --- a/osu.Game/Graphics/UserInterface/OsuTabDropDownMenuItem.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Allocation; -using osu.Framework.Extensions.Color4Extensions; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.UserInterface; -using OpenTK.Graphics; -using osu.Game.Graphics.Sprites; - -namespace osu.Game.Graphics.UserInterface -{ - public class OsuTabDropDownMenuItem : DropDownMenuItem - { - public OsuTabDropDownMenuItem(string text, T value) : base(text, value) - { - Foreground.Padding = new MarginPadding { Top = 4, Bottom = 4 }; - Foreground.Margin = new MarginPadding { Left = 7 }; - - Masking = true; - CornerRadius = 6; - Foreground.Add(new OsuSpriteText - { - Text = text, - Origin = Anchor.CentreLeft, - Anchor = Anchor.CentreLeft, - }); - } - - private Color4? accentColour; - public Color4 AccentColour - { - get { return accentColour.GetValueOrDefault(); } - set - { - accentColour = value; - BackgroundColourHover = BackgroundColourSelected = value; - FormatBackground(); - FormatForeground(); - } - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - BackgroundColour = Color4.Black.Opacity(0f); - ForegroundColourHover = Color4.Black; - ForegroundColourSelected = Color4.Black; - if (accentColour == null) - AccentColour = colours.Blue; - } - } -} diff --git a/osu.Game/Graphics/UserInterface/OsuTabItem.cs b/osu.Game/Graphics/UserInterface/OsuTabItem.cs index 9b8ea58a56..c394ee31a0 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabItem.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabItem.cs @@ -8,7 +8,7 @@ using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.UserInterface.Tab; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; using osu.Game.Graphics.Sprites; diff --git a/osu.Game/Screens/Play/KeyCounterCollection.cs b/osu.Game/Screens/Play/KeyCounterCollection.cs index bbda7ae318..bb6ab34cbb 100644 --- a/osu.Game/Screens/Play/KeyCounterCollection.cs +++ b/osu.Game/Screens/Play/KeyCounterCollection.cs @@ -4,7 +4,6 @@ using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using OpenTK; using OpenTK.Graphics; using osu.Framework.Input; diff --git a/osu.Game/Screens/Play/KeyCounterMouse.cs b/osu.Game/Screens/Play/KeyCounterMouse.cs index b0b93e80e7..744cb905d9 100644 --- a/osu.Game/Screens/Play/KeyCounterMouse.cs +++ b/osu.Game/Screens/Play/KeyCounterMouse.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Input; -using OpenTK; using OpenTK.Input; namespace osu.Game.Screens.Play diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index a655d0c4d4..637b6eafbc 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -9,11 +9,11 @@ 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; using osu.Game.Graphics.UserInterface; using osu.Game.Screens.Select.Filter; using Container = osu.Framework.Graphics.Containers.Container; -using osu.Framework.Graphics.UserInterface.Tab; using osu.Framework.Input; namespace osu.Game.Screens.Select diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 1936628ad5..a947742582 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -350,8 +350,6 @@ - -