From e3a7c8a124b46fc6979c2cbc96565560a91228cb Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 26 Mar 2020 09:11:31 +0300 Subject: [PATCH 01/27] Make catcher trails colouring per container --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 73 +++++++++++++++++++++------ 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index f53e14a8c7..68280ab111 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -35,7 +35,30 @@ namespace osu.Game.Rulesets.Catch.UI public Container ExplodingFruitTarget; - public Container AdditiveTarget; + private Container additiveTarget; + private Container dashTrails; + private Container hyperDashTrails; + private Container endGlowSprites; + + public Container AdditiveTarget + { + get => additiveTarget; + set + { + if (additiveTarget == value) + return; + + additiveTarget?.RemoveRange(new[] { dashTrails, hyperDashTrails, endGlowSprites }); + + additiveTarget = value; + additiveTarget?.AddRange(new[] + { + dashTrails ??= new Container { RelativeSizeAxes = Axes.Both, Colour = Color4.White }, + hyperDashTrails ??= new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashColour }, + endGlowSprites ??= new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashEndGlowColour }, + }); + } + } public CatcherAnimationState CurrentState { get; private set; } @@ -65,7 +88,7 @@ namespace osu.Game.Rulesets.Catch.UI get => trail; set { - if (value == trail || AdditiveTarget == null) return; + if (value == trail || additiveTarget == null) return; trail = value; @@ -82,6 +105,9 @@ namespace osu.Game.Rulesets.Catch.UI private CatcherSprite currentCatcher; + private Color4 hyperDashColour = DefaultHyperDashColour; + private Color4 hyperDashEndGlowColour = DefaultHyperDashColour; + private int currentDirection; private bool dashing; @@ -213,8 +239,6 @@ namespace osu.Game.Rulesets.Catch.UI /// When this catcher crosses this position, this catcher ends hyper-dashing. public void SetHyperDashState(double modifier = 1, float targetPosition = -1) { - const float hyper_dash_transition_length = 180; - var wasHyperDashing = HyperDashing; if (modifier <= 1 || X == targetPosition) @@ -223,11 +247,7 @@ namespace osu.Game.Rulesets.Catch.UI hyperDashDirection = 0; if (wasHyperDashing) - { - this.FadeColour(Color4.White, hyper_dash_transition_length, Easing.OutQuint); - this.FadeTo(1, hyper_dash_transition_length, Easing.OutQuint); Trail &= Dashing; - } } else { @@ -237,18 +257,37 @@ namespace osu.Game.Rulesets.Catch.UI if (!wasHyperDashing) { - this.FadeColour(Color4.OrangeRed, hyper_dash_transition_length, Easing.OutQuint); - this.FadeTo(0.2f, hyper_dash_transition_length, Easing.OutQuint); Trail = true; - var hyperDashEndGlow = createAdditiveSprite(); - + var hyperDashEndGlow = createAdditiveSprite(endGlowSprites); hyperDashEndGlow.MoveToOffset(new Vector2(0, -10), 1200, Easing.In); hyperDashEndGlow.ScaleTo(hyperDashEndGlow.Scale * 0.95f).ScaleTo(hyperDashEndGlow.Scale * 1.2f, 1200, Easing.In); hyperDashEndGlow.FadeOut(1200); hyperDashEndGlow.Expire(true); } } + + updateCatcherColour(); + } + + private void updateCatcherColour() + { + const float hyper_dash_transition_length = 180; + + if (HyperDashing) + { + this.FadeColour(hyperDashColour == DefaultHyperDashColour ? Color4.OrangeRed : hyperDashColour, hyper_dash_transition_length, Easing.OutQuint); + this.FadeTo(0.2f, hyper_dash_transition_length, Easing.OutQuint); + } + else + { + this.FadeColour(Color4.White, hyper_dash_transition_length, Easing.OutQuint); + this.FadeTo(1f, hyper_dash_transition_length, Easing.OutQuint); + } + + // update hyper-dash colour of the hyper-dashing catcher sprites containers. + hyperDashTrails?.FadeColour(hyperDashColour, hyper_dash_transition_length, Easing.OutQuint); + endGlowSprites?.FadeColour(hyperDashEndGlowColour, hyper_dash_transition_length, Easing.OutQuint); } public bool OnPressed(CatchAction action) @@ -392,7 +431,7 @@ namespace osu.Game.Rulesets.Catch.UI return; } - var additive = createAdditiveSprite(); + var additive = createAdditiveSprite(HyperDashing ? hyperDashTrails : dashTrails); additive.FadeTo(0.4f).FadeOut(800, Easing.OutQuint); additive.Expire(true); @@ -409,21 +448,23 @@ namespace osu.Game.Rulesets.Catch.UI updateCatcher(); } - private CatcherTrailSprite createAdditiveSprite() + private CatcherTrailSprite createAdditiveSprite(Container target) { + if (target == null) + return null; + var tex = (currentCatcher.Drawable as TextureAnimation)?.CurrentFrame ?? ((Sprite)currentCatcher.Drawable).Texture; var sprite = new CatcherTrailSprite(tex) { Anchor = Anchor, Scale = Scale, - Colour = HyperDashing ? Color4.Red : Color4.White, Blending = BlendingParameters.Additive, RelativePositionAxes = RelativePositionAxes, Position = Position }; - AdditiveTarget?.Add(sprite); + target.Add(sprite); return sprite; } From 302fdd834a305697536ac4093b00f88d72751d80 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 26 Mar 2020 09:11:59 +0300 Subject: [PATCH 02/27] Add support for custom hyper-dash catcher colouring --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 68280ab111..b3742aa1ad 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -13,13 +13,15 @@ using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects.Drawables; +using osu.Game.Rulesets.Catch.Skinning; using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Skinning; using osuTK; using osuTK.Graphics; namespace osu.Game.Rulesets.Catch.UI { - public class Catcher : Container, IKeyBindingHandler + public class Catcher : SkinReloadableDrawable, IKeyBindingHandler { public static Color4 DefaultHyperDashColour { get; } = Color4.Red; @@ -133,7 +135,7 @@ namespace osu.Game.Rulesets.Catch.UI [BackgroundDependencyLoader] private void load() { - Children = new Drawable[] + InternalChildren = new Drawable[] { caughtFruit = new Container { @@ -184,7 +186,7 @@ namespace osu.Game.Rulesets.Catch.UI caughtFruit.Add(fruit); - Add(new HitExplosion(fruit) + AddInternal(new HitExplosion(fruit) { X = fruit.X, Scale = new Vector2(fruit.HitObject.Scale) @@ -378,6 +380,15 @@ namespace osu.Game.Rulesets.Catch.UI }); } + protected override void SkinChanged(ISkinSource skin, bool allowFallback) + { + base.SkinChanged(skin, allowFallback); + + hyperDashColour = skin.GetConfig(CatchSkinConfiguration.HyperDash)?.Value ?? DefaultHyperDashColour; + hyperDashEndGlowColour = skin.GetConfig(CatchSkinConfiguration.HyperDashAfterImage)?.Value ?? hyperDashColour; + updateCatcherColour(); + } + protected override void Update() { base.Update(); From fecafc2e48b9e45fa5a70c630832b55e7db6f396 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 26 Mar 2020 09:14:44 +0300 Subject: [PATCH 03/27] Fix additive target accidentally clears all of the added containers It sets the AdditiveTarget on the object initializer but then the catcher is set to Child which wipes up all of the existing children (containers added by Catcher through AdditiveTarget setter) --- osu.Game.Rulesets.Catch/UI/CatcherArea.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs index e0d9ff759d..37501736ff 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs @@ -33,10 +33,10 @@ namespace osu.Game.Rulesets.Catch.UI { RelativeSizeAxes = Axes.X; Height = CATCHER_SIZE; - Child = MovableCatcher = new Catcher(difficulty) - { - AdditiveTarget = this, - }; + Child = MovableCatcher = new Catcher(difficulty); + + // this property adds containers to 'this' so it must not be set in the object initializer. + MovableCatcher.AdditiveTarget = this; } public static float GetCatcherSize(BeatmapDifficulty difficulty) From 77b3011394ffdc1afb2517943a025bce713177c2 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 26 Mar 2020 09:19:00 +0300 Subject: [PATCH 04/27] Add hyper-dash catcher & trails colouring test cases --- .../TestSceneHyperDashColouring.cs | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs index 7fab961aa7..6bad45f7ba 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs @@ -28,6 +28,140 @@ namespace osu.Game.Rulesets.Catch.Tests { public class TestSceneHyperDashColouring : OsuTestScene { + [Test] + public void TestHyperDashCatcherColour() + { + CatcherArea catcherArea = null; + + AddStep("setup catcher", () => + { + Child = setupSkinHierarchy(() => + catcherArea = new CatcherArea + { + RelativePositionAxes = Axes.None, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(4f), + }, false); + }); + + AddStep("set hyper-dash", () => + { + catcherArea.MovableCatcher.SetHyperDashState(2); + catcherArea.MovableCatcher.FinishTransforms(); + }); + + AddAssert("catcher colour default-hyperdash", () => catcherArea.MovableCatcher.Colour == Color4.OrangeRed); + AddAssert("catcher trails colour default-hyperdash", () => catcherArea.OfType>().Any(c => c.Colour == Catcher.DefaultHyperDashColour)); + + AddStep("clear hyper-dash", () => + { + catcherArea.MovableCatcher.SetHyperDashState(1); + catcherArea.MovableCatcher.FinishTransforms(); + }); + + AddAssert("catcher colour white", () => catcherArea.MovableCatcher.Colour == Color4.White); + } + + [Test] + public void TestCustomHyperDashCatcherColour() + { + CatcherArea catcherArea = null; + + AddStep("setup catcher", () => + { + Child = setupSkinHierarchy(() => + catcherArea = new CatcherArea + { + RelativePositionAxes = Axes.None, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(4f), + }, true); + }); + + AddStep("set hyper-dash", () => + { + catcherArea.MovableCatcher.SetHyperDashState(2); + catcherArea.MovableCatcher.FinishTransforms(); + }); + + AddAssert("catcher colour custom-hyperdash", () => catcherArea.MovableCatcher.Colour == TestLegacySkin.CustomHyperDashColour); + AddAssert("catcher trails colour custom-hyperdash", () => catcherArea.OfType>().Any(c => c.Colour == TestLegacySkin.CustomHyperDashColour)); + + AddStep("clear hyper-dash", () => + { + catcherArea.MovableCatcher.SetHyperDashState(1); + catcherArea.MovableCatcher.FinishTransforms(); + }); + + AddAssert("catcher colour white", () => catcherArea.MovableCatcher.Colour == Color4.White); + } + + [Test] + public void TestHyperDashCatcherEndGlowColour() + { + CatcherArea catcherArea = null; + + AddStep("setup catcher", () => + { + Child = setupSkinHierarchy(() => + catcherArea = new CatcherArea + { + RelativePositionAxes = Axes.None, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(4f), + }, false, false, false); + }); + + AddStep("set hyper-dash", () => catcherArea.MovableCatcher.SetHyperDashState(2)); + AddAssert("end-glow sprite colour default-hyperdash", () => catcherArea.OfType>().Any(c => c.Colour == Catcher.DefaultHyperDashColour)); + } + + [TestCase(true)] + [TestCase(false)] + public void TestCustomHyperDashCatcherEndGlowColour(bool customHyperDashCatcherColour) + { + CatcherArea catcherArea = null; + + AddStep("setup catcher", () => + { + Child = setupSkinHierarchy(() => + catcherArea = new CatcherArea + { + RelativePositionAxes = Axes.None, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(4f), + }, customHyperDashCatcherColour, false, true); + }); + + AddStep("set hyper-dash", () => catcherArea.MovableCatcher.SetHyperDashState(2)); + AddAssert("end-glow sprite colour custom-hyperdash", () => catcherArea.OfType>().Any(c => c.Colour == TestLegacySkin.CustomHyperDashAfterColour)); + } + + [Test] + public void TestCustomHyperDashCatcherEndGlowColourFallback() + { + CatcherArea catcherArea = null; + + AddStep("setup catcher", () => + { + Child = setupSkinHierarchy(() => + catcherArea = new CatcherArea + { + RelativePositionAxes = Axes.None, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(4f), + }, true, false, false); + }); + + AddStep("set hyper-dash", () => catcherArea.MovableCatcher.SetHyperDashState(2)); + AddAssert("end-glow sprite colour catcher-custom-hyperdash", () => catcherArea.OfType>().Any(c => c.Colour == TestLegacySkin.CustomHyperDashColour)); + } + [TestCase(false)] [TestCase(true)] public void TestHyperDashFruitColour(bool legacyFruit) From f3bcb0628c828b12484c4b6f46be8b44c3599ccd Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 4 Apr 2020 19:09:52 +0300 Subject: [PATCH 05/27] Add helper methods for retrieving other skin hyper-dash colours --- osu.Game.Rulesets.Catch/Skinning/CatchSkinExtensions.cs | 7 +++++++ osu.Game.Rulesets.Catch/UI/Catcher.cs | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Skinning/CatchSkinExtensions.cs b/osu.Game.Rulesets.Catch/Skinning/CatchSkinExtensions.cs index 8fc0831918..48e11121ea 100644 --- a/osu.Game.Rulesets.Catch/Skinning/CatchSkinExtensions.cs +++ b/osu.Game.Rulesets.Catch/Skinning/CatchSkinExtensions.cs @@ -9,6 +9,13 @@ namespace osu.Game.Rulesets.Catch.Skinning { internal static class CatchSkinExtensions { + public static IBindable GetHyperDashCatcherColour(this ISkin skin) + => skin.GetConfig(CatchSkinColour.HyperDash); + + public static IBindable GetHyperDashEndGlowColour(this ISkin skin) + => skin.GetConfig(CatchSkinColour.HyperDashAfterImage) ?? + skin.GetConfig(CatchSkinColour.HyperDash); + public static IBindable GetHyperDashFruitColour(this ISkin skin) => skin.GetConfig(CatchSkinColour.HyperDashFruit) ?? skin.GetConfig(CatchSkinColour.HyperDash); diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 98cc10aa31..49c9a77277 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -389,9 +389,9 @@ namespace osu.Game.Rulesets.Catch.UI { base.SkinChanged(skin, allowFallback); - hyperDashColour = skin.GetConfig(CatchSkinColour.HyperDash)?.Value ?? DefaultHyperDashColour; - hyperDashEndGlowColour = skin.GetConfig(CatchSkinColour.HyperDashAfterImage)?.Value ?? hyperDashColour; updateCatcherColour(); + hyperDashColour = skin.GetHyperDashCatcherColour()?.Value ?? DefaultHyperDashColour; + hyperDashEndGlowColour = skin.GetHyperDashEndGlowColour()?.Value ?? DefaultHyperDashColour; } protected override void Update() From 50604dc7b22624632f015fcb55c0cb44bd3f4080 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 4 Apr 2020 19:29:06 +0300 Subject: [PATCH 06/27] Update catcher hyper-dashing colours on changing hyper-dash state only --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 49c9a77277..0b73c510d9 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -254,7 +254,10 @@ namespace osu.Game.Rulesets.Catch.UI hyperDashDirection = 0; if (wasHyperDashing) + { + updateCatcherColour(false); Trail &= Dashing; + } } else { @@ -264,6 +267,7 @@ namespace osu.Game.Rulesets.Catch.UI if (!wasHyperDashing) { + updateCatcherColour(true); Trail = true; var hyperDashEndGlow = createAdditiveSprite(endGlowSprites); @@ -273,15 +277,13 @@ namespace osu.Game.Rulesets.Catch.UI hyperDashEndGlow.Expire(true); } } - - updateCatcherColour(); } - private void updateCatcherColour() + private void updateCatcherColour(bool hyperDashing) { const float hyper_dash_transition_length = 180; - if (HyperDashing) + if (hyperDashing) { this.FadeColour(hyperDashColour == DefaultHyperDashColour ? Color4.OrangeRed : hyperDashColour, hyper_dash_transition_length, Easing.OutQuint); this.FadeTo(0.2f, hyper_dash_transition_length, Easing.OutQuint); @@ -389,9 +391,9 @@ namespace osu.Game.Rulesets.Catch.UI { base.SkinChanged(skin, allowFallback); - updateCatcherColour(); hyperDashColour = skin.GetHyperDashCatcherColour()?.Value ?? DefaultHyperDashColour; hyperDashEndGlowColour = skin.GetHyperDashEndGlowColour()?.Value ?? DefaultHyperDashColour; + updateCatcherColour(HyperDashing); } protected override void Update() From fbe95a52e3b068d37c49dafa6057a744d0d0df9c Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 4 Apr 2020 19:29:41 +0300 Subject: [PATCH 07/27] Remove unnecessary restating comment --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 0b73c510d9..1cb6987397 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -294,7 +294,6 @@ namespace osu.Game.Rulesets.Catch.UI this.FadeTo(1f, hyper_dash_transition_length, Easing.OutQuint); } - // update hyper-dash colour of the hyper-dashing catcher sprites containers. hyperDashTrails?.FadeColour(hyperDashColour, hyper_dash_transition_length, Easing.OutQuint); endGlowSprites?.FadeColour(hyperDashEndGlowColour, hyper_dash_transition_length, Easing.OutQuint); } From 19f39fe6327ffd3b3bdf27cde0da4d5b1a2801a7 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 4 Apr 2020 19:33:52 +0300 Subject: [PATCH 08/27] Change AdditiveTarget into a set method --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 39 ++++++++++++----------- osu.Game.Rulesets.Catch/UI/CatcherArea.cs | 5 ++- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 1cb6987397..0e42c19455 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -42,25 +42,6 @@ namespace osu.Game.Rulesets.Catch.UI private Container hyperDashTrails; private Container endGlowSprites; - public Container AdditiveTarget - { - get => additiveTarget; - set - { - if (additiveTarget == value) - return; - - additiveTarget?.RemoveRange(new[] { dashTrails, hyperDashTrails, endGlowSprites }); - - additiveTarget = value; - additiveTarget?.AddRange(new[] - { - dashTrails ??= new Container { RelativeSizeAxes = Axes.Both, Colour = Color4.White }, - hyperDashTrails ??= new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashColour }, - endGlowSprites ??= new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashEndGlowColour }, - }); - } - } public CatcherAnimationState CurrentState { get; private set; } @@ -167,6 +148,26 @@ namespace osu.Game.Rulesets.Catch.UI updateCatcher(); } + /// + /// Sets container target to provide catcher additive trails content in. + /// + /// The container to add catcher trails in. + public void SetAdditiveTarget(Container target) + { + if (additiveTarget == target) + return; + + additiveTarget?.RemoveRange(new[] { dashTrails, hyperDashTrails, endGlowSprites }); + + additiveTarget = target; + additiveTarget?.AddRange(new[] + { + dashTrails ??= new Container { RelativeSizeAxes = Axes.Both, Colour = Color4.White }, + hyperDashTrails ??= new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashColour }, + endGlowSprites ??= new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashEndGlowColour }, + }); + } + /// /// Add a caught fruit to the catcher's stack. /// diff --git a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs index 37501736ff..641b81599e 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs @@ -33,10 +33,9 @@ namespace osu.Game.Rulesets.Catch.UI { RelativeSizeAxes = Axes.X; Height = CATCHER_SIZE; - Child = MovableCatcher = new Catcher(difficulty); - // this property adds containers to 'this' so it must not be set in the object initializer. - MovableCatcher.AdditiveTarget = this; + Child = MovableCatcher = new Catcher(difficulty); + MovableCatcher.SetAdditiveTarget(this); } public static float GetCatcherSize(BeatmapDifficulty difficulty) From 0014a8404e17d196d3aebf386346efd20790d023 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 4 Apr 2020 23:12:42 +0300 Subject: [PATCH 09/27] GetHyperDashEndGlowColour() -> GetHyperDashCatcherAfterImageColour() --- osu.Game.Rulesets.Catch/Skinning/CatchSkinExtensions.cs | 2 +- osu.Game.Rulesets.Catch/UI/Catcher.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Skinning/CatchSkinExtensions.cs b/osu.Game.Rulesets.Catch/Skinning/CatchSkinExtensions.cs index 48e11121ea..06d21f8c5e 100644 --- a/osu.Game.Rulesets.Catch/Skinning/CatchSkinExtensions.cs +++ b/osu.Game.Rulesets.Catch/Skinning/CatchSkinExtensions.cs @@ -12,7 +12,7 @@ namespace osu.Game.Rulesets.Catch.Skinning public static IBindable GetHyperDashCatcherColour(this ISkin skin) => skin.GetConfig(CatchSkinColour.HyperDash); - public static IBindable GetHyperDashEndGlowColour(this ISkin skin) + public static IBindable GetHyperDashCatcherAfterImageColour(this ISkin skin) => skin.GetConfig(CatchSkinColour.HyperDashAfterImage) ?? skin.GetConfig(CatchSkinColour.HyperDash); diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 0e42c19455..0d5b454a9d 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -392,7 +392,7 @@ namespace osu.Game.Rulesets.Catch.UI base.SkinChanged(skin, allowFallback); hyperDashColour = skin.GetHyperDashCatcherColour()?.Value ?? DefaultHyperDashColour; - hyperDashEndGlowColour = skin.GetHyperDashEndGlowColour()?.Value ?? DefaultHyperDashColour; + hyperDashEndGlowColour = skin.GetHyperDashCatcherAfterImageColour()?.Value ?? DefaultHyperDashColour; updateCatcherColour(HyperDashing); } From 42ccee5e6c8a2eedc459a369e129cccab853133d Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 5 Apr 2020 00:15:42 +0300 Subject: [PATCH 10/27] Fix CI issue --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 0d5b454a9d..7971a17e68 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -42,7 +42,6 @@ namespace osu.Game.Rulesets.Catch.UI private Container hyperDashTrails; private Container endGlowSprites; - public CatcherAnimationState CurrentState { get; private set; } /// From 9373520bca1ebc0f38d16bca5163eb9ed2e28a5c Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 21 Apr 2020 05:59:37 +0300 Subject: [PATCH 11/27] Add constant for special colour of catcher on default skin --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index f37dae29dd..97d0fb0ada 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -25,6 +25,14 @@ namespace osu.Game.Rulesets.Catch.UI { public static readonly Color4 DEFAULT_HYPER_DASH_COLOUR = Color4.Red; + /// + /// The default colour used directly for . + /// + /// + /// This colour is only used when no skin overrides . + /// + public static readonly Color4 DEFAULT_CATCHER_HYPER_DASH_COLOUR = Color4.OrangeRed; + /// /// Whether we are hyper-dashing or not. /// @@ -285,7 +293,13 @@ namespace osu.Game.Rulesets.Catch.UI if (hyperDashing) { - this.FadeColour(hyperDashColour == DefaultHyperDashColour ? Color4.OrangeRed : hyperDashColour, hyper_dash_transition_length, Easing.OutQuint); + // special behaviour for catcher colour if no skin overrides. + var catcherColour = + hyperDashColour == DEFAULT_HYPER_DASH_COLOUR + ? DEFAULT_CATCHER_HYPER_DASH_COLOUR + : hyperDashColour; + + this.FadeColour(catcherColour, hyper_dash_transition_length, Easing.OutQuint); this.FadeTo(0.2f, hyper_dash_transition_length, Easing.OutQuint); } else From 282d1001093ac757eac1e65933577d1ac035e9d7 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 21 Apr 2020 06:09:57 +0300 Subject: [PATCH 12/27] Fix XMLDoc references --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 97d0fb0ada..056e838419 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Catch.UI public static readonly Color4 DEFAULT_HYPER_DASH_COLOUR = Color4.Red; /// - /// The default colour used directly for . + /// The default colour used directly for this 's . /// /// /// This colour is only used when no skin overrides . From a82efa626e9d95f98ccad220f14a3ab4fdb76690 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 21 Apr 2020 11:36:09 +0300 Subject: [PATCH 13/27] Add XMLDoc for default hyper-dash colour constant --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 056e838419..6f5e8be92c 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -23,6 +23,9 @@ namespace osu.Game.Rulesets.Catch.UI { public class Catcher : SkinReloadableDrawable, IKeyBindingHandler { + /// + /// The default colour used for all hyper-dashing components. (catcher drawables and fruit) + /// public static readonly Color4 DEFAULT_HYPER_DASH_COLOUR = Color4.Red; /// From ee62739b08e09feeda55b78d5a49dd68a857de0e Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 21 Apr 2020 11:41:53 +0300 Subject: [PATCH 14/27] Simplify process of adding catcher trails --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 29 +++++++---------------- osu.Game.Rulesets.Catch/UI/CatcherArea.cs | 4 +--- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 6f5e8be92c..92f2977c40 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.Catch.UI public Container ExplodingFruitTarget; - private Container additiveTarget; + private readonly Container additiveTarget; private Container dashTrails; private Container hyperDashTrails; private Container endGlowSprites; @@ -116,8 +116,10 @@ namespace osu.Game.Rulesets.Catch.UI private int hyperDashDirection; private float hyperDashTargetPosition; - public Catcher(BeatmapDifficulty difficulty = null) + public Catcher(BeatmapDifficulty difficulty = null, Container additiveTarget = null) { + this.additiveTarget = additiveTarget; + RelativePositionAxes = Axes.X; X = 0.5f; @@ -155,27 +157,14 @@ namespace osu.Game.Rulesets.Catch.UI } }; - updateCatcher(); - } - - /// - /// Sets container target to provide catcher additive trails content in. - /// - /// The container to add catcher trails in. - public void SetAdditiveTarget(Container target) - { - if (additiveTarget == target) - return; - - additiveTarget?.RemoveRange(new[] { dashTrails, hyperDashTrails, endGlowSprites }); - - additiveTarget = target; additiveTarget?.AddRange(new[] { - dashTrails ??= new Container { RelativeSizeAxes = Axes.Both, Colour = Color4.White }, - hyperDashTrails ??= new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashColour }, - endGlowSprites ??= new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashEndGlowColour }, + dashTrails = new Container { RelativeSizeAxes = Axes.Both, Colour = Color4.White }, + hyperDashTrails = new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashColour }, + endGlowSprites = new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashEndGlowColour } }); + + updateCatcher(); } /// diff --git a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs index 641b81599e..1dd94afa9e 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs @@ -33,9 +33,7 @@ namespace osu.Game.Rulesets.Catch.UI { RelativeSizeAxes = Axes.X; Height = CATCHER_SIZE; - - Child = MovableCatcher = new Catcher(difficulty); - MovableCatcher.SetAdditiveTarget(this); + Child = MovableCatcher = new Catcher(difficulty, this); } public static float GetCatcherSize(BeatmapDifficulty difficulty) From c8c2b51108a1a0b80c80d5b846c2925231e80e3a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 21 Apr 2020 11:44:10 +0300 Subject: [PATCH 15/27] Remove redundant property set Co-Authored-By: Dean Herbert --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 92f2977c40..7ecb245617 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -159,7 +159,7 @@ namespace osu.Game.Rulesets.Catch.UI additiveTarget?.AddRange(new[] { - dashTrails = new Container { RelativeSizeAxes = Axes.Both, Colour = Color4.White }, + dashTrails = new Container { RelativeSizeAxes = Axes.Both }, hyperDashTrails = new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashColour }, endGlowSprites = new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashEndGlowColour } }); From 95de2c6f7f9d82a6c8c72e94280d8b7257766ad7 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 22 Apr 2020 05:04:07 +0300 Subject: [PATCH 16/27] Mark Catcher.additiveTarget to never be null And provide empty containers instead. --- osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs | 3 ++- .../Difficulty/CatchDifficultyCalculator.cs | 3 ++- osu.Game.Rulesets.Catch/UI/Catcher.cs | 3 ++- osu.Game.Rulesets.Catch/UI/CatcherArea.cs | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs index acc5f4e428..3a3e664690 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; namespace osu.Game.Rulesets.Catch.Tests { @@ -23,7 +24,7 @@ namespace osu.Game.Rulesets.Catch.Tests [BackgroundDependencyLoader] private void load() { - SetContents(() => new Catcher + SetContents(() => new Catcher(new Container()) { RelativePositionAxes = Axes.None, Anchor = Anchor.Centre, diff --git a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs index 4d9dbbbc5f..fbdf437b7b 100644 --- a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Difficulty.Preprocessing; using osu.Game.Rulesets.Catch.Difficulty.Skills; @@ -71,7 +72,7 @@ namespace osu.Game.Rulesets.Catch.Difficulty protected override Skill[] CreateSkills(IBeatmap beatmap) { - using (var catcher = new Catcher(beatmap.BeatmapInfo.BaseDifficulty)) + using (var catcher = new Catcher(new Container(), beatmap.BeatmapInfo.BaseDifficulty)) halfCatcherWidth = catcher.CatchWidth * 0.5f; return new Skill[] diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 7ecb245617..029de2cac0 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -3,6 +3,7 @@ using System; using System.Linq; +using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Animations; @@ -116,7 +117,7 @@ namespace osu.Game.Rulesets.Catch.UI private int hyperDashDirection; private float hyperDashTargetPosition; - public Catcher(BeatmapDifficulty difficulty = null, Container additiveTarget = null) + public Catcher([NotNull] Container additiveTarget, BeatmapDifficulty difficulty = null) { this.additiveTarget = additiveTarget; diff --git a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs index 1dd94afa9e..37d177b936 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs @@ -33,7 +33,7 @@ namespace osu.Game.Rulesets.Catch.UI { RelativeSizeAxes = Axes.X; Height = CATCHER_SIZE; - Child = MovableCatcher = new Catcher(difficulty, this); + Child = MovableCatcher = new Catcher(this, difficulty); } public static float GetCatcherSize(BeatmapDifficulty difficulty) From 9ab0f6d8bc5a160f9859305a4a70e3d889f644ec Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 22 Apr 2020 05:12:29 +0300 Subject: [PATCH 17/27] Separate trail-related logic to its own container --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 120 ++++----------- .../UI/CatcherTrailDisplay.cs | 137 ++++++++++++++++++ 2 files changed, 168 insertions(+), 89 deletions(-) create mode 100644 osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 029de2cac0..e30988d8f7 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -8,7 +8,6 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Animations; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Bindings; using osu.Framework.Utils; using osu.Game.Beatmaps; @@ -37,6 +36,11 @@ namespace osu.Game.Rulesets.Catch.UI /// public static readonly Color4 DEFAULT_CATCHER_HYPER_DASH_COLOUR = Color4.OrangeRed; + /// + /// The duration between transitioning to hyper-dash state. + /// + public const double HYPER_DASH_TRANSITION_DURATION = 180; + /// /// Whether we are hyper-dashing or not. /// @@ -49,10 +53,10 @@ namespace osu.Game.Rulesets.Catch.UI public Container ExplodingFruitTarget; - private readonly Container additiveTarget; - private Container dashTrails; - private Container hyperDashTrails; - private Container endGlowSprites; + [NotNull] + private readonly Container trailsTarget; + + private CatcherTrailDisplay trails; public CatcherAnimationState CurrentState { get; private set; } @@ -66,33 +70,23 @@ namespace osu.Game.Rulesets.Catch.UI /// internal float CatchWidth => CatcherArea.CATCHER_SIZE * Math.Abs(Scale.X) * allowed_catch_range; - protected bool Dashing + /// + /// The drawable catcher for . + /// + internal Drawable CurrentDrawableCatcher => currentCatcher.Drawable; + + private bool dashing; + + public bool Dashing { get => dashing; - set + protected set { if (value == dashing) return; dashing = value; - Trail |= dashing; - } - } - - /// - /// Activate or deactivate the trail. Will be automatically deactivated when conditions to keep the trail displayed are no longer met. - /// - protected bool Trail - { - get => trail; - set - { - if (value == trail || additiveTarget == null) return; - - trail = value; - - if (Trail) - beginTrail(); + trails.DisplayTrail |= dashing; } } @@ -109,17 +103,13 @@ namespace osu.Game.Rulesets.Catch.UI private int currentDirection; - private bool dashing; - - private bool trail; - private double hyperDashModifier = 1; private int hyperDashDirection; private float hyperDashTargetPosition; - public Catcher([NotNull] Container additiveTarget, BeatmapDifficulty difficulty = null) + public Catcher([NotNull] Container trailsTarget, BeatmapDifficulty difficulty = null) { - this.additiveTarget = additiveTarget; + this.trailsTarget = trailsTarget; RelativePositionAxes = Axes.X; X = 0.5f; @@ -158,12 +148,7 @@ namespace osu.Game.Rulesets.Catch.UI } }; - additiveTarget?.AddRange(new[] - { - dashTrails = new Container { RelativeSizeAxes = Axes.Both }, - hyperDashTrails = new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashColour }, - endGlowSprites = new Container { RelativeSizeAxes = Axes.Both, Colour = hyperDashEndGlowColour } - }); + trailsTarget.Add(trails = new CatcherTrailDisplay(this)); updateCatcher(); } @@ -257,7 +242,7 @@ namespace osu.Game.Rulesets.Catch.UI if (wasHyperDashing) { updateCatcherColour(false); - Trail &= Dashing; + trails.DisplayTrail &= Dashing; } } else @@ -269,21 +254,15 @@ namespace osu.Game.Rulesets.Catch.UI if (!wasHyperDashing) { updateCatcherColour(true); - Trail = true; - var hyperDashEndGlow = createAdditiveSprite(endGlowSprites); - hyperDashEndGlow.MoveToOffset(new Vector2(0, -10), 1200, Easing.In); - hyperDashEndGlow.ScaleTo(hyperDashEndGlow.Scale * 0.95f).ScaleTo(hyperDashEndGlow.Scale * 1.2f, 1200, Easing.In); - hyperDashEndGlow.FadeOut(1200); - hyperDashEndGlow.Expire(true); + trails.DisplayTrail = true; + trails.DisplayEndGlow(); } } } private void updateCatcherColour(bool hyperDashing) { - const float hyper_dash_transition_length = 180; - if (hyperDashing) { // special behaviour for catcher colour if no skin overrides. @@ -292,17 +271,17 @@ namespace osu.Game.Rulesets.Catch.UI ? DEFAULT_CATCHER_HYPER_DASH_COLOUR : hyperDashColour; - this.FadeColour(catcherColour, hyper_dash_transition_length, Easing.OutQuint); - this.FadeTo(0.2f, hyper_dash_transition_length, Easing.OutQuint); + this.FadeColour(catcherColour, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); + this.FadeTo(0.2f, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); } else { - this.FadeColour(Color4.White, hyper_dash_transition_length, Easing.OutQuint); - this.FadeTo(1f, hyper_dash_transition_length, Easing.OutQuint); + this.FadeColour(Color4.White, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); + this.FadeTo(1f, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); } - hyperDashTrails?.FadeColour(hyperDashColour, hyper_dash_transition_length, Easing.OutQuint); - endGlowSprites?.FadeColour(hyperDashEndGlowColour, hyper_dash_transition_length, Easing.OutQuint); + trails.HyperDashTrailsColour = hyperDashColour; + trails.EndGlowSpritesColour = hyperDashEndGlowColour; } public bool OnPressed(CatchAction action) @@ -453,22 +432,6 @@ namespace osu.Game.Rulesets.Catch.UI (currentCatcher.Drawable as IFramedAnimation)?.GotoFrame(0); } - private void beginTrail() - { - if (!dashing && !HyperDashing) - { - Trail = false; - return; - } - - var additive = createAdditiveSprite(HyperDashing ? hyperDashTrails : dashTrails); - - additive.FadeTo(0.4f).FadeOut(800, Easing.OutQuint); - additive.Expire(true); - - Scheduler.AddDelayed(beginTrail, HyperDashing ? 25 : 50); - } - private void updateState(CatcherAnimationState state) { if (CurrentState == state) @@ -478,27 +441,6 @@ namespace osu.Game.Rulesets.Catch.UI updateCatcher(); } - private CatcherTrailSprite createAdditiveSprite(Container target) - { - if (target == null) - return null; - - var tex = (currentCatcher.Drawable as TextureAnimation)?.CurrentFrame ?? ((Sprite)currentCatcher.Drawable).Texture; - - var sprite = new CatcherTrailSprite(tex) - { - Anchor = Anchor, - Scale = Scale, - Blending = BlendingParameters.Additive, - RelativePositionAxes = RelativePositionAxes, - Position = Position - }; - - target.Add(sprite); - - return sprite; - } - private void removeFromPlateWithTransform(DrawableHitObject fruit, Action action) { if (ExplodingFruitTarget != null) diff --git a/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs b/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs new file mode 100644 index 0000000000..afbfac9a51 --- /dev/null +++ b/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs @@ -0,0 +1,137 @@ +// 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 osu.Framework.Graphics; +using osu.Framework.Graphics.Animations; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Rulesets.Catch.UI +{ + /// + /// Represents a component responsible for displaying + /// the appropriate catcher trails when requested to. + /// + public class CatcherTrailDisplay : CompositeDrawable + { + private readonly Catcher catcher; + + private readonly Container dashTrails; + private readonly Container hyperDashTrails; + private readonly Container endGlowSprites; + + private Color4 hyperDashTrailsColour; + + public Color4 HyperDashTrailsColour + { + get => hyperDashTrailsColour; + set + { + if (hyperDashTrailsColour == value) + return; + + hyperDashTrailsColour = value; + hyperDashTrails.FadeColour(hyperDashTrailsColour, Catcher.HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); + } + } + + private Color4 endGlowSpritesColour; + + public Color4 EndGlowSpritesColour + { + get => endGlowSpritesColour; + set + { + if (endGlowSpritesColour == value) + return; + + endGlowSpritesColour = value; + endGlowSprites.FadeColour(endGlowSpritesColour, Catcher.HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); + } + } + + private bool trail; + + /// + /// Whether to start displaying trails following the catcher. + /// + public bool DisplayTrail + { + get => trail; + set + { + if (trail == value) + return; + + trail = value; + + if (trail) + displayTrail(); + } + } + + public CatcherTrailDisplay(Catcher catcher) + { + this.catcher = catcher ?? throw new ArgumentNullException(nameof(catcher)); + + RelativeSizeAxes = Axes.Both; + + InternalChildren = new[] + { + dashTrails = new Container { RelativeSizeAxes = Axes.Both }, + hyperDashTrails = new Container { RelativeSizeAxes = Axes.Both, Colour = Catcher.DEFAULT_HYPER_DASH_COLOUR }, + endGlowSprites = new Container { RelativeSizeAxes = Axes.Both, Colour = Catcher.DEFAULT_HYPER_DASH_COLOUR }, + }; + } + + /// + /// Displays a single end-glow catcher sprite. + /// + public void DisplayEndGlow() + { + var endGlow = createTrailSprite(endGlowSprites); + + endGlow.MoveToOffset(new Vector2(0, -10), 1200, Easing.In); + endGlow.ScaleTo(endGlow.Scale * 0.95f).ScaleTo(endGlow.Scale * 1.2f, 1200, Easing.In); + endGlow.FadeOut(1200); + endGlow.Expire(true); + } + + private void displayTrail() + { + if (!catcher.Dashing && !catcher.HyperDashing) + { + DisplayTrail = false; + return; + } + + var sprite = createTrailSprite(catcher.HyperDashing ? hyperDashTrails : dashTrails); + + sprite.FadeTo(0.4f).FadeOut(800, Easing.OutQuint); + sprite.Expire(true); + + Scheduler.AddDelayed(displayTrail, catcher.HyperDashing ? 25 : 50); + } + + private CatcherTrailSprite createTrailSprite(Container target) + { + var texture = (catcher.CurrentDrawableCatcher as TextureAnimation)?.CurrentFrame ?? ((Sprite)catcher.CurrentDrawableCatcher).Texture; + + var sprite = new CatcherTrailSprite(texture) + { + Anchor = catcher.Anchor, + Scale = catcher.Scale, + Blending = BlendingParameters.Additive, + RelativePositionAxes = catcher.RelativePositionAxes, + Position = catcher.Position + }; + + target.Add(sprite); + + return sprite; + } + } +} From 5d3475a5ed32b45c6b3fca5fdd823fab0e2141f9 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 22 Apr 2020 05:12:51 +0300 Subject: [PATCH 18/27] Retrieve CatcherTrailDisplay for asserting colours set correctly --- .../TestSceneHyperDashColouring.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs index 347b71f3ff..0c8ade9018 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs @@ -113,6 +113,7 @@ namespace osu.Game.Rulesets.Catch.Tests private void checkHyperDashCatcherColour(ISkin skin, Color4 expectedCatcherColour, Color4? expectedEndGlowColour = null) { CatcherArea catcherArea = null; + CatcherTrailDisplay trails = null; AddStep("create hyper-dashing catcher", () => { @@ -123,6 +124,7 @@ namespace osu.Game.Rulesets.Catch.Tests Scale = new Vector2(4f), }, skin); + trails = catcherArea.OfType().Single(); catcherArea.MovableCatcher.SetHyperDashState(2); catcherArea.MovableCatcher.FinishTransforms(); }); @@ -132,8 +134,8 @@ namespace osu.Game.Rulesets.Catch.Tests ? catcherArea.MovableCatcher.Colour == Catcher.DEFAULT_CATCHER_HYPER_DASH_COLOUR : catcherArea.MovableCatcher.Colour == expectedCatcherColour); - AddAssert("catcher trails colours are correct", () => catcherArea.OfType>().Any(c => c.Colour == expectedCatcherColour)); - AddAssert("catcher end-glow colours are correct", () => catcherArea.OfType>().Any(c => c.Colour == (expectedEndGlowColour ?? expectedCatcherColour))); + AddAssert("catcher trails colours are correct", () => trails.HyperDashTrailsColour == expectedCatcherColour); + AddAssert("catcher end-glow colours are correct", () => trails.EndGlowSpritesColour == (expectedEndGlowColour ?? expectedCatcherColour)); AddStep("finish hyper-dashing", () => { From 2d4077e71313c8fdb2c03bddd65db9b0a9555ae5 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 22 Apr 2020 05:25:40 +0300 Subject: [PATCH 19/27] Reword special default hyper-dash colour constant a bit --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index e30988d8f7..08e438db56 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -29,7 +29,8 @@ namespace osu.Game.Rulesets.Catch.UI public static readonly Color4 DEFAULT_HYPER_DASH_COLOUR = Color4.Red; /// - /// The default colour used directly for this 's . + /// The default hyper-dash colour used directly for this + /// 's . /// /// /// This colour is only used when no skin overrides . From 730b5ea1a986a6772520d8babd185ede3543c2ab Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 22 Apr 2020 10:40:21 +0300 Subject: [PATCH 20/27] Make the Catcher.Colour assertion read better --- .../TestSceneHyperDashColouring.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs index 0c8ade9018..1e1746efb3 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs @@ -130,9 +130,16 @@ namespace osu.Game.Rulesets.Catch.Tests }); AddAssert("catcher colour is correct", () => - expectedCatcherColour == Catcher.DEFAULT_HYPER_DASH_COLOUR - ? catcherArea.MovableCatcher.Colour == Catcher.DEFAULT_CATCHER_HYPER_DASH_COLOUR - : catcherArea.MovableCatcher.Colour == expectedCatcherColour); + { + var expected = expectedCatcherColour; + + if (expected == Catcher.DEFAULT_HYPER_DASH_COLOUR) + // The expected colour for Catcher.Colour is another colour + // for the default skin, assert with that instead. + expected = Catcher.DEFAULT_CATCHER_HYPER_DASH_COLOUR; + + return catcherArea.MovableCatcher.Colour == expected; + }); AddAssert("catcher trails colours are correct", () => trails.HyperDashTrailsColour == expectedCatcherColour); AddAssert("catcher end-glow colours are correct", () => trails.EndGlowSpritesColour == (expectedEndGlowColour ?? expectedCatcherColour)); From bffe6742e0cde53ce1ce4c6f76546e79eca41abd Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 22 Apr 2020 10:43:49 +0300 Subject: [PATCH 21/27] Replace finishing catcher transforms with until-true step --- osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs index 1e1746efb3..589bafe400 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs @@ -126,10 +126,9 @@ namespace osu.Game.Rulesets.Catch.Tests trails = catcherArea.OfType().Single(); catcherArea.MovableCatcher.SetHyperDashState(2); - catcherArea.MovableCatcher.FinishTransforms(); }); - AddAssert("catcher colour is correct", () => + AddUntilStep("catcher colour is correct", () => { var expected = expectedCatcherColour; From 6376128bde406d3340feb7f9dd946d8bdae77225 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 23 Apr 2020 05:33:28 +0300 Subject: [PATCH 22/27] Remove unnecessary using directive --- osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs index 57930a21fa..d99325ff87 100644 --- a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Difficulty.Preprocessing; using osu.Game.Rulesets.Catch.Difficulty.Skills; From ed83ac188e20c2b9e6e00de7083b90e1974dc9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 6 May 2020 23:25:25 +0200 Subject: [PATCH 23/27] Remove special case for moving catcher sprite --- .../TestSceneHyperDashColouring.cs | 12 +----------- osu.Game.Rulesets.Catch/UI/Catcher.cs | 17 +---------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs index 589bafe400..1e708cce4b 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs @@ -128,17 +128,7 @@ namespace osu.Game.Rulesets.Catch.Tests catcherArea.MovableCatcher.SetHyperDashState(2); }); - AddUntilStep("catcher colour is correct", () => - { - var expected = expectedCatcherColour; - - if (expected == Catcher.DEFAULT_HYPER_DASH_COLOUR) - // The expected colour for Catcher.Colour is another colour - // for the default skin, assert with that instead. - expected = Catcher.DEFAULT_CATCHER_HYPER_DASH_COLOUR; - - return catcherArea.MovableCatcher.Colour == expected; - }); + AddUntilStep("catcher colour is correct", () => catcherArea.MovableCatcher.Colour == expectedCatcherColour); AddAssert("catcher trails colours are correct", () => trails.HyperDashTrailsColour == expectedCatcherColour); AddAssert("catcher end-glow colours are correct", () => trails.EndGlowSpritesColour == (expectedEndGlowColour ?? expectedCatcherColour)); diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 2022cffb40..520cfeee70 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -28,15 +28,6 @@ namespace osu.Game.Rulesets.Catch.UI /// public static readonly Color4 DEFAULT_HYPER_DASH_COLOUR = Color4.Red; - /// - /// The default hyper-dash colour used directly for this - /// 's . - /// - /// - /// This colour is only used when no skin overrides . - /// - public static readonly Color4 DEFAULT_CATCHER_HYPER_DASH_COLOUR = Color4.OrangeRed; - /// /// The duration between transitioning to hyper-dash state. /// @@ -288,13 +279,7 @@ namespace osu.Game.Rulesets.Catch.UI { if (hyperDashing) { - // special behaviour for catcher colour if no skin overrides. - var catcherColour = - hyperDashColour == DEFAULT_HYPER_DASH_COLOUR - ? DEFAULT_CATCHER_HYPER_DASH_COLOUR - : hyperDashColour; - - this.FadeColour(catcherColour, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); + this.FadeColour(hyperDashColour, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); this.FadeTo(0.2f, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); } else From 52d1e2b5f889dd193aad2c10b0f3b40f87e24f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 6 May 2020 23:27:01 +0200 Subject: [PATCH 24/27] Improve xmldoc --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 520cfeee70..40c7d6a9b5 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -24,7 +24,8 @@ namespace osu.Game.Rulesets.Catch.UI public class Catcher : SkinReloadableDrawable, IKeyBindingHandler { /// - /// The default colour used for all hyper-dashing components. (catcher drawables and fruit) + /// The default colour used to tint hyper-dash fruit, along with the moving catcher, its trail + /// and end glow/after-image during a hyper-dash. /// public static readonly Color4 DEFAULT_HYPER_DASH_COLOUR = Color4.Red; From 25f73c0b9f30d2c3dc129d02f0bd8a61e738374c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 6 May 2020 23:40:36 +0200 Subject: [PATCH 25/27] Add [NotNull] annotation --- osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs b/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs index afbfac9a51..64fb4b2196 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using JetBrains.Annotations; using osu.Framework.Graphics; using osu.Framework.Graphics.Animations; using osu.Framework.Graphics.Containers; @@ -73,7 +74,7 @@ namespace osu.Game.Rulesets.Catch.UI } } - public CatcherTrailDisplay(Catcher catcher) + public CatcherTrailDisplay([NotNull] Catcher catcher) { this.catcher = catcher ?? throw new ArgumentNullException(nameof(catcher)); From b44a70ef9ab7240d3a9a285654996889e8e67910 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 7 May 2020 01:46:37 +0300 Subject: [PATCH 26/27] Let the catcher be responsible for stopping the trails --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 2 +- osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 40c7d6a9b5..558555af96 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -74,7 +74,7 @@ namespace osu.Game.Rulesets.Catch.UI dashing = value; - trails.DisplayTrail |= dashing; + trails.DisplayTrail = value || HyperDashing; } } diff --git a/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs b/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs index 64fb4b2196..bab3cb748b 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs @@ -103,11 +103,8 @@ namespace osu.Game.Rulesets.Catch.UI private void displayTrail() { - if (!catcher.Dashing && !catcher.HyperDashing) - { - DisplayTrail = false; + if (!DisplayTrail) return; - } var sprite = createTrailSprite(catcher.HyperDashing ? hyperDashTrails : dashTrails); From 5bab53b04ce53325aab9991f2b811034580ef957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 10 May 2020 17:05:30 +0200 Subject: [PATCH 27/27] Centralise trail visibility state management --- osu.Game.Rulesets.Catch/UI/Catcher.cs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 558555af96..9cce46d730 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -74,7 +74,7 @@ namespace osu.Game.Rulesets.Catch.UI dashing = value; - trails.DisplayTrail = value || HyperDashing; + updateTrailVisibility(); } } @@ -255,10 +255,7 @@ namespace osu.Game.Rulesets.Catch.UI hyperDashDirection = 0; if (wasHyperDashing) - { - updateCatcherColour(false); - trails.DisplayTrail &= Dashing; - } + runHyperDashStateTransition(false); } else { @@ -268,16 +265,18 @@ namespace osu.Game.Rulesets.Catch.UI if (!wasHyperDashing) { - updateCatcherColour(true); - - trails.DisplayTrail = true; trails.DisplayEndGlow(); + runHyperDashStateTransition(true); } } } - private void updateCatcherColour(bool hyperDashing) + private void runHyperDashStateTransition(bool hyperDashing) { + trails.HyperDashTrailsColour = hyperDashColour; + trails.EndGlowSpritesColour = hyperDashEndGlowColour; + updateTrailVisibility(); + if (hyperDashing) { this.FadeColour(hyperDashColour, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); @@ -288,11 +287,10 @@ namespace osu.Game.Rulesets.Catch.UI this.FadeColour(Color4.White, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); this.FadeTo(1f, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint); } - - trails.HyperDashTrailsColour = hyperDashColour; - trails.EndGlowSpritesColour = hyperDashEndGlowColour; } + private void updateTrailVisibility() => trails.DisplayTrail = Dashing || HyperDashing; + public bool OnPressed(CatchAction action) { switch (action) @@ -393,7 +391,7 @@ namespace osu.Game.Rulesets.Catch.UI skin.GetConfig(CatchSkinColour.HyperDashAfterImage)?.Value ?? hyperDashColour; - updateCatcherColour(HyperDashing); + runHyperDashStateTransition(HyperDashing); } protected override void Update()