From 95828b07efecaf83ef25127043f71ebb77e6c92f Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 11 Sep 2019 10:40:58 +0300 Subject: [PATCH 1/5] Implement HeaderFlag component for rankings overlay --- .../Online/TestSceneRankingsHeaderFlag.cs | 55 +++++++++++++++ osu.Game/Overlays/Rankings/HeaderFlag.cs | 68 +++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs create mode 100644 osu.Game/Overlays/Rankings/HeaderFlag.cs diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs new file mode 100644 index 0000000000..d31e3011b8 --- /dev/null +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs @@ -0,0 +1,55 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; +using osu.Game.Overlays.Rankings; +using osu.Game.Users; +using osuTK; + +namespace osu.Game.Tests.Visual.Online +{ + public class TestSceneRankingsHeaderFlag : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(HeaderFlag), + }; + + public TestSceneRankingsHeaderFlag() + { + HeaderFlag flag; + SpriteText text; + + AddRange(new Drawable[] + { + flag = new HeaderFlag + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(30, 20), + Country = new Country + { + FlagName = "BY", + FullName = "Belarus" + } + }, + text = new SpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = "Invoked", + Font = OsuFont.GetFont(size: 30), + Alpha = 0, + } + }); + + flag.Action += () => text.FadeIn().Then().FadeOut(1000, Easing.OutQuint); + + AddStep("Trigger click", () => flag.Click()); + } + } +} diff --git a/osu.Game/Overlays/Rankings/HeaderFlag.cs b/osu.Game/Overlays/Rankings/HeaderFlag.cs new file mode 100644 index 0000000000..5b00e3e487 --- /dev/null +++ b/osu.Game/Overlays/Rankings/HeaderFlag.cs @@ -0,0 +1,68 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Game.Users.Drawables; +using osuTK.Graphics; +using osuTK; +using osu.Framework.Input.Events; +using osu.Framework.Extensions.Color4Extensions; +using System; + +namespace osu.Game.Overlays.Rankings +{ + public class HeaderFlag : UpdateableFlag + { + private const int duration = 200; + + public Action Action; + + private readonly Container hoverContainer; + + public HeaderFlag() + { + AddInternal(hoverContainer = new Container + { + Alpha = 0, + Depth = -1, + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + new SpriteIcon + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(15), + Icon = FontAwesome.Solid.Times, + }, + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black.Opacity(100), + } + } + }); + } + + protected override bool OnHover(HoverEvent e) + { + hoverContainer.FadeIn(duration, Easing.OutQuint); + return base.OnHover(e); + } + + protected override void OnHoverLost(HoverLostEvent e) + { + base.OnHoverLost(e); + hoverContainer.FadeOut(duration, Easing.OutQuint); + } + + protected override bool OnClick(ClickEvent e) + { + Action?.Invoke(); + return base.OnClick(e); + } + } +} From d610c903716356593f9b774c5e768412583e13c5 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 11 Sep 2019 10:43:51 +0300 Subject: [PATCH 2/5] Add more tests --- .../Online/TestSceneRankingsHeaderFlag.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs index d31e3011b8..c9531e1016 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs @@ -24,6 +24,18 @@ namespace osu.Game.Tests.Visual.Online HeaderFlag flag; SpriteText text; + var countryA = new Country + { + FlagName = "BY", + FullName = "Belarus" + }; + + var countryB = new Country + { + FlagName = "US", + FullName = "United States" + }; + AddRange(new Drawable[] { flag = new HeaderFlag @@ -31,11 +43,7 @@ namespace osu.Game.Tests.Visual.Online Anchor = Anchor.Centre, Origin = Anchor.Centre, Size = new Vector2(30, 20), - Country = new Country - { - FlagName = "BY", - FullName = "Belarus" - } + Country = countryA, }, text = new SpriteText { @@ -50,6 +58,8 @@ namespace osu.Game.Tests.Visual.Online flag.Action += () => text.FadeIn().Then().FadeOut(1000, Easing.OutQuint); AddStep("Trigger click", () => flag.Click()); + AddStep("Change to country 2", () => flag.Country = countryB); + AddStep("Change to country 1", () => flag.Country = countryA); } } } From 1d1da1bc13c7f1c613aa8bba35c8f5b90a819b15 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 11 Sep 2019 11:26:09 +0300 Subject: [PATCH 3/5] Visual improvements --- osu.Game/Overlays/Rankings/HeaderFlag.cs | 34 +++++++++--------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/osu.Game/Overlays/Rankings/HeaderFlag.cs b/osu.Game/Overlays/Rankings/HeaderFlag.cs index 5b00e3e487..8bd4bdf13f 100644 --- a/osu.Game/Overlays/Rankings/HeaderFlag.cs +++ b/osu.Game/Overlays/Rankings/HeaderFlag.cs @@ -20,49 +20,39 @@ namespace osu.Game.Overlays.Rankings public Action Action; - private readonly Container hoverContainer; + private readonly SpriteIcon hoverIcon; public HeaderFlag() { - AddInternal(hoverContainer = new Container + AddInternal(hoverIcon = new SpriteIcon { - Alpha = 0, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, Depth = -1, - RelativeSizeAxes = Axes.Both, - Children = new Drawable[] - { - new SpriteIcon - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(15), - Icon = FontAwesome.Solid.Times, - }, - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Color4.Black.Opacity(100), - } - } + Alpha = 0, + Size = new Vector2(10), + Icon = FontAwesome.Solid.Times, }); } protected override bool OnHover(HoverEvent e) { - hoverContainer.FadeIn(duration, Easing.OutQuint); + hoverIcon.FadeIn(duration, Easing.OutQuint); + this.FadeColour(Color4.Gray, duration, Easing.OutQuint); return base.OnHover(e); } protected override void OnHoverLost(HoverLostEvent e) { base.OnHoverLost(e); - hoverContainer.FadeOut(duration, Easing.OutQuint); + hoverIcon.FadeOut(duration, Easing.OutQuint); + this.FadeColour(Color4.White, duration, Easing.OutQuint); } protected override bool OnClick(ClickEvent e) { Action?.Invoke(); - return base.OnClick(e); + return true; } } } From 660c678cdcbe74b8a6b6fe55555a60b2b778f820 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 11 Sep 2019 11:40:51 +0300 Subject: [PATCH 4/5] Remove unused using directives --- osu.Game/Overlays/Rankings/HeaderFlag.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game/Overlays/Rankings/HeaderFlag.cs b/osu.Game/Overlays/Rankings/HeaderFlag.cs index 8bd4bdf13f..6f641c74a5 100644 --- a/osu.Game/Overlays/Rankings/HeaderFlag.cs +++ b/osu.Game/Overlays/Rankings/HeaderFlag.cs @@ -2,14 +2,11 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Game.Users.Drawables; using osuTK.Graphics; using osuTK; using osu.Framework.Input.Events; -using osu.Framework.Extensions.Color4Extensions; using System; namespace osu.Game.Overlays.Rankings From cafb5105bc4b4997bc0c75259c9c1ce587d0c768 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Thu, 12 Sep 2019 16:44:15 +0300 Subject: [PATCH 5/5] Rename HeaderFlag to DismissableFlag --- ...aderFlag.cs => TestSceneRankingsDismissableFlag.cs} | 10 +++++----- .../Rankings/{HeaderFlag.cs => DismissableFlag.cs} | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) rename osu.Game.Tests/Visual/Online/{TestSceneRankingsHeaderFlag.cs => TestSceneRankingsDismissableFlag.cs} (88%) rename osu.Game/Overlays/Rankings/{HeaderFlag.cs => DismissableFlag.cs} (94%) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsDismissableFlag.cs similarity index 88% rename from osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs rename to osu.Game.Tests/Visual/Online/TestSceneRankingsDismissableFlag.cs index c9531e1016..db6afa9bf3 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsDismissableFlag.cs @@ -12,16 +12,16 @@ using osuTK; namespace osu.Game.Tests.Visual.Online { - public class TestSceneRankingsHeaderFlag : OsuTestScene + public class TestSceneRankingsDismissableFlag : OsuTestScene { public override IReadOnlyList RequiredTypes => new[] { - typeof(HeaderFlag), + typeof(DismissableFlag), }; - public TestSceneRankingsHeaderFlag() + public TestSceneRankingsDismissableFlag() { - HeaderFlag flag; + DismissableFlag flag; SpriteText text; var countryA = new Country @@ -38,7 +38,7 @@ namespace osu.Game.Tests.Visual.Online AddRange(new Drawable[] { - flag = new HeaderFlag + flag = new DismissableFlag { Anchor = Anchor.Centre, Origin = Anchor.Centre, diff --git a/osu.Game/Overlays/Rankings/HeaderFlag.cs b/osu.Game/Overlays/Rankings/DismissableFlag.cs similarity index 94% rename from osu.Game/Overlays/Rankings/HeaderFlag.cs rename to osu.Game/Overlays/Rankings/DismissableFlag.cs index 6f641c74a5..7a55b0bba6 100644 --- a/osu.Game/Overlays/Rankings/HeaderFlag.cs +++ b/osu.Game/Overlays/Rankings/DismissableFlag.cs @@ -11,7 +11,7 @@ using System; namespace osu.Game.Overlays.Rankings { - public class HeaderFlag : UpdateableFlag + public class DismissableFlag : UpdateableFlag { private const int duration = 200; @@ -19,7 +19,7 @@ namespace osu.Game.Overlays.Rankings private readonly SpriteIcon hoverIcon; - public HeaderFlag() + public DismissableFlag() { AddInternal(hoverIcon = new SpriteIcon {