diff --git a/osu.Game/Graphics/UserInterface/OsuDropdown.cs b/osu.Game/Graphics/UserInterface/OsuDropdown.cs index d8d4a93091..04b7d18de7 100644 --- a/osu.Game/Graphics/UserInterface/OsuDropdown.cs +++ b/osu.Game/Graphics/UserInterface/OsuDropdown.cs @@ -4,7 +4,13 @@ using System.Linq; using OpenTK.Graphics; using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; +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.Sprites; namespace osu.Game.Graphics.UserInterface { @@ -36,5 +42,131 @@ namespace osu.Game.Graphics.UserInterface } protected override DropdownMenuItem CreateMenuItem(string text, T value) => new OsuDropdownMenuItem(text, value) { AccentColour = AccentColour }; + + private class OsuDropdownMenuItem : DropdownMenuItem + { + public OsuDropdownMenuItem(string text, U value) : base(text, value) + { + Foreground.Padding = new MarginPadding(2); + + Masking = true; + CornerRadius = 6; + + Children = new[] + { + new FillFlowContainer + { + Direction = FillDirection.Horizontal, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Children = new Drawable[] + { + chevron = new TextAwesome + { + AlwaysPresent = true, + Icon = FontAwesome.fa_chevron_right, + UseFullGlyphHeight = false, + Colour = Color4.Black, + Alpha = 0.5f, + TextSize = 8, + Margin = new MarginPadding { Left = 3, Right = 3 }, + Origin = Anchor.CentreLeft, + Anchor = Anchor.CentreLeft, + }, + new OsuSpriteText { + Text = text, + Origin = Anchor.CentreLeft, + Anchor = Anchor.CentreLeft, + } + } + } + }; + } + + 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.Transparent; + BackgroundColourHover = accentColour ?? colours.PinkDarker; + BackgroundColourSelected = Color4.Black.Opacity(0.5f); + } + } + + protected class OsuDropdownHeader : DropdownHeader + { + private SpriteText label; + protected override string Label + { + get { return label.Text; } + 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); + + AutoSizeAxes = Axes.None; + Margin = new MarginPadding { Bottom = 4 }; + CornerRadius = 4; + Height = 40; + + Foreground.Children = new Drawable[] + { + label = new OsuSpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + }, + new TextAwesome + { + Icon = FontAwesome.fa_chevron_down, + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + Margin = new MarginPadding { Right = 4 }, + TextSize = 20 + } + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BackgroundColour = Color4.Black.Opacity(0.5f); + BackgroundColourHover = accentColour ?? colours.PinkDarker; + } + } } } \ No newline at end of file diff --git a/osu.Game/Graphics/UserInterface/OsuDropdownHeader.cs b/osu.Game/Graphics/UserInterface/OsuDropdownHeader.cs deleted file mode 100644 index 8bef24a6f8..0000000000 --- a/osu.Game/Graphics/UserInterface/OsuDropdownHeader.cs +++ /dev/null @@ -1,69 +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.Graphics; -using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.UserInterface; -using osu.Game.Graphics.Sprites; -using OpenTK.Graphics; -using osu.Framework.Extensions.Color4Extensions; - -namespace osu.Game.Graphics.UserInterface -{ - public class OsuDropdownHeader : DropdownHeader - { - private SpriteText label; - protected override string Label - { - get { return label.Text; } - 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); - - AutoSizeAxes = Axes.None; - Margin = new MarginPadding { Bottom = 4 }; - CornerRadius = 4; - Height = 40; - - Foreground.Children = new Drawable[] - { - label = new OsuSpriteText - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - }, - new TextAwesome - { - Icon = FontAwesome.fa_chevron_down, - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - Margin = new MarginPadding { Right = 4 }, - TextSize = 20 - } - }; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - BackgroundColour = Color4.Black.Opacity(0.5f); - BackgroundColourHover = accentColour ?? colours.PinkDarker; - } - } -} \ No newline at end of file diff --git a/osu.Game/Graphics/UserInterface/OsuDropdownMenuItem.cs b/osu.Game/Graphics/UserInterface/OsuDropdownMenuItem.cs deleted file mode 100644 index bcd53a8dbd..0000000000 --- a/osu.Game/Graphics/UserInterface/OsuDropdownMenuItem.cs +++ /dev/null @@ -1,85 +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.Containers; -using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.UserInterface; -using osu.Game.Graphics.Sprites; -using OpenTK.Graphics; - -namespace osu.Game.Graphics.UserInterface -{ - public class OsuDropdownMenuItem : DropdownMenuItem - { - public OsuDropdownMenuItem(string text, T value) : base(text, value) - { - Foreground.Padding = new MarginPadding(2); - - Masking = true; - CornerRadius = 6; - - Children = new[] - { - new FillFlowContainer - { - Direction = FillDirection.Horizontal, - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Children = new Drawable[] - { - chevron = new TextAwesome - { - AlwaysPresent = true, - Icon = FontAwesome.fa_chevron_right, - UseFullGlyphHeight = false, - Colour = Color4.Black, - Alpha = 0.5f, - TextSize = 8, - Margin = new MarginPadding { Left = 3, Right = 3 }, - Origin = Anchor.CentreLeft, - Anchor = Anchor.CentreLeft, - }, - new OsuSpriteText { - Text = text, - Origin = Anchor.CentreLeft, - Anchor = Anchor.CentreLeft, - } - } - } - }; - } - - 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.Transparent; - BackgroundColourHover = accentColour ?? colours.PinkDarker; - BackgroundColourSelected = Color4.Black.Opacity(0.5f); - } - } -} \ No newline at end of file diff --git a/osu.Game/Graphics/UserInterface/OsuTabControl.cs b/osu.Game/Graphics/UserInterface/OsuTabControl.cs index 8a22347c76..20f75cf932 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabControl.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabControl.cs @@ -6,11 +6,15 @@ using System.Linq; using OpenTK; using OpenTK.Graphics; using osu.Framework.Allocation; +using osu.Framework.Extensions; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transforms; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; +using osu.Game.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { @@ -53,7 +57,111 @@ namespace osu.Game.Graphics.UserInterface } } - public class OsuTabDropdown : OsuDropdown + private class OsuTabItem : TabItem + { + private SpriteText text; + private Box box; + + private Color4? accentColour; + public Color4 AccentColour + { + get { return accentColour.GetValueOrDefault(); } + set + { + accentColour = value; + if (!Active) + text.Colour = value; + } + } + + public new U Value + { + get { return base.Value; } + set + { + base.Value = value; + text.Text = (value as Enum)?.GetDescription(); + } + } + + public override bool Active + { + get { return base.Active; } + set + { + if (Active == value) return; + + if (value) + fadeActive(); + else + fadeInactive(); + base.Active = value; + } + } + + private const float transition_length = 500; + + private void fadeActive() + { + box.FadeIn(transition_length, EasingTypes.OutQuint); + text.FadeColour(Color4.White, transition_length, EasingTypes.OutQuint); + } + + private void fadeInactive() + { + box.FadeOut(transition_length, EasingTypes.OutQuint); + text.FadeColour(AccentColour, transition_length, EasingTypes.OutQuint); + } + + protected override bool OnHover(InputState state) + { + if (!Active) + fadeActive(); + return true; + } + + protected override void OnHoverLost(InputState state) + { + if (!Active) + fadeInactive(); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + if (accentColour == null) + AccentColour = colours.Blue; + } + + public OsuTabItem() + { + AutoSizeAxes = Axes.X; + RelativeSizeAxes = Axes.Y; + + Children = new Drawable[] + { + text = new OsuSpriteText + { + Margin = new MarginPadding(5), + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + TextSize = 14, + Font = @"Exo2.0-Bold", // Font should only turn bold when active? + }, + box = new Box + { + RelativeSizeAxes = Axes.X, + Height = 1, + Alpha = 0, + Colour = Color4.White, + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + } + }; + } + } + + private class OsuTabDropdown : OsuDropdown { protected override DropdownHeader CreateHeader() => new OsuTabDropdownHeader { @@ -80,7 +188,7 @@ namespace osu.Game.Graphics.UserInterface DropdownMenu.MaxHeight = 400; } - public class OsuTabDropdownHeader : OsuDropdownHeader + protected class OsuTabDropdownHeader : OsuDropdownHeader { public override Color4 AccentColour { diff --git a/osu.Game/Graphics/UserInterface/OsuTabItem.cs b/osu.Game/Graphics/UserInterface/OsuTabItem.cs deleted file mode 100644 index acfca1b67b..0000000000 --- a/osu.Game/Graphics/UserInterface/OsuTabItem.cs +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using OpenTK.Graphics; -using osu.Framework.Allocation; -using osu.Framework.Extensions; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Transforms; -using osu.Framework.Graphics.UserInterface; -using osu.Framework.Input; -using osu.Game.Graphics.Sprites; - -namespace osu.Game.Graphics.UserInterface -{ - public class OsuTabItem : TabItem - { - private SpriteText text; - private Box box; - - private Color4? accentColour; - public Color4 AccentColour - { - get { return accentColour.GetValueOrDefault(); } - set - { - accentColour = value; - if (!Active) - text.Colour = value; - } - } - - public new T Value - { - get { return base.Value; } - set - { - base.Value = value; - text.Text = (value as Enum)?.GetDescription(); - } - } - - public override bool Active - { - get { return base.Active; } - set - { - if (Active == value) return; - - if (value) - fadeActive(); - else - fadeInactive(); - base.Active = value; - } - } - - private const float transition_length = 500; - - private void fadeActive() - { - box.FadeIn(transition_length, EasingTypes.OutQuint); - text.FadeColour(Color4.White, transition_length, EasingTypes.OutQuint); - } - - private void fadeInactive() - { - box.FadeOut(transition_length, EasingTypes.OutQuint); - text.FadeColour(AccentColour, transition_length, EasingTypes.OutQuint); - } - - protected override bool OnHover(InputState state) - { - if (!Active) - fadeActive(); - return true; - } - - protected override void OnHoverLost(InputState state) - { - if (!Active) - fadeInactive(); - } - - public OsuTabItem() - { - AutoSizeAxes = Axes.X; - RelativeSizeAxes = Axes.Y; - - Children = new Drawable[] - { - text = new OsuSpriteText - { - Margin = new MarginPadding(5), - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - TextSize = 14, - Font = @"Exo2.0-Bold", // Font should only turn bold when active? - }, - box = new Box - { - RelativeSizeAxes = Axes.X, - Height = 1, - Alpha = 0, - Colour = Color4.White, - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - } - }; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - if (accentColour == null) - AccentColour = colours.Blue; - } - } -} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 879ca9ddbe..c2bb88d2f8 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -161,9 +161,7 @@ - - @@ -363,7 +361,6 @@ -