From bf162f148e320f93cc85456ee780383c030878a2 Mon Sep 17 00:00:00 2001 From: mcendu Date: Sat, 28 Dec 2019 13:48:10 +0800 Subject: [PATCH 1/6] Move mania stage hint to its own class --- .../UI/Components/ColumnHitObjectArea.cs | 108 ++++++++++++------ .../UI/Components/StageHint.cs | 14 +++ 2 files changed, 90 insertions(+), 32 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/UI/Components/StageHint.cs diff --git a/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs b/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs index 386bcbb724..dde718d5ba 100644 --- a/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs +++ b/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs @@ -22,26 +22,15 @@ namespace osu.Game.Rulesets.Mania.UI.Components private readonly IBindable direction = new Bindable(); - private readonly Container hitTargetLine; - private readonly Drawable hitTargetBar; + private readonly Drawable stageHint; public ColumnHitObjectArea(HitObjectContainer hitObjectContainer) { - InternalChildren = new[] + InternalChildren = new Drawable[] { - hitTargetBar = new Box + stageHint = new DefaultStageHint { RelativeSizeAxes = Axes.X, - Height = NotePiece.NOTE_HEIGHT, - Alpha = 0.6f, - Colour = Color4.Black - }, - hitTargetLine = new Container - { - RelativeSizeAxes = Axes.X, - Height = hit_target_bar_height, - Masking = true, - Child = new Box { RelativeSizeAxes = Axes.Both } }, hitObjectContainer }; @@ -55,17 +44,10 @@ namespace osu.Game.Rulesets.Mania.UI.Components { Anchor anchor = dir.NewValue == ScrollingDirection.Up ? Anchor.TopLeft : Anchor.BottomLeft; - hitTargetBar.Anchor = hitTargetBar.Origin = anchor; - hitTargetLine.Anchor = hitTargetLine.Origin = anchor; + stageHint.Anchor = stageHint.Origin = anchor; }, true); } - protected override void LoadComplete() - { - base.LoadComplete(); - updateColours(); - } - private Color4 accentColour; public Color4 AccentColour @@ -77,22 +59,84 @@ namespace osu.Game.Rulesets.Mania.UI.Components return; accentColour = value; - - updateColours(); } } - private void updateColours() + private class DefaultStageHint : StageHint { - if (!IsLoaded) - return; + private readonly IBindable direction = new Bindable(); - hitTargetLine.EdgeEffect = new EdgeEffectParameters + private readonly Container hitTargetLine; + private readonly Drawable hitTargetBar; + + public DefaultStageHint() { - Type = EdgeEffectType.Glow, - Radius = 5, - Colour = accentColour.Opacity(0.5f), - }; + InternalChildren = new[] + { + hitTargetBar = new Box + { + RelativeSizeAxes = Axes.X, + Height = NotePiece.NOTE_HEIGHT, + Alpha = 0.6f, + Colour = Color4.Black + }, + hitTargetLine = new Container + { + RelativeSizeAxes = Axes.X, + Height = hit_target_bar_height, + Masking = true, + Child = new Box { RelativeSizeAxes = Axes.Both } + }, + }; + } + + [BackgroundDependencyLoader] + private void load(IScrollingInfo scrollingInfo) + { + direction.BindTo(scrollingInfo.Direction); + direction.BindValueChanged(dir => + { + Anchor anchor = dir.NewValue == ScrollingDirection.Up ? Anchor.TopLeft : Anchor.BottomLeft; + + hitTargetBar.Anchor = hitTargetBar.Origin = anchor; + hitTargetLine.Anchor = hitTargetLine.Origin = anchor; + }, true); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + updateColours(); + } + + private Color4 accentColour; + + public override Color4 AccentColour + { + get => accentColour; + set + { + if (accentColour == value) + return; + + accentColour = value; + + updateColours(); + } + } + + private void updateColours() + { + if (!IsLoaded) + return; + + hitTargetLine.EdgeEffect = new EdgeEffectParameters + { + Type = EdgeEffectType.Glow, + Radius = 5, + Colour = accentColour.Opacity(0.5f), + }; + } } } } diff --git a/osu.Game.Rulesets.Mania/UI/Components/StageHint.cs b/osu.Game.Rulesets.Mania/UI/Components/StageHint.cs new file mode 100644 index 0000000000..9574f77eb5 --- /dev/null +++ b/osu.Game.Rulesets.Mania/UI/Components/StageHint.cs @@ -0,0 +1,14 @@ +// 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.Containers; +using osu.Game.Graphics; +using osuTK.Graphics; + +namespace osu.Game.Rulesets.Mania.UI.Components +{ + public abstract class StageHint : CompositeDrawable, IHasAccentColour + { + public abstract Color4 AccentColour { get; set; } + } +} From 5d2b5cc950b5608cdf369c1d3e226733a7648689 Mon Sep 17 00:00:00 2001 From: mcendu Date: Sat, 28 Dec 2019 14:05:46 +0800 Subject: [PATCH 2/6] correct type of field stageHint --- osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs b/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs index dde718d5ba..6bfb2b89aa 100644 --- a/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs +++ b/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs @@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Mania.UI.Components private readonly IBindable direction = new Bindable(); - private readonly Drawable stageHint; + private readonly StageHint stageHint; public ColumnHitObjectArea(HitObjectContainer hitObjectContainer) { @@ -59,6 +59,8 @@ namespace osu.Game.Rulesets.Mania.UI.Components return; accentColour = value; + + stageHint.AccentColour = accentColour; } } From cdfbe96e9bdceecc7f04ff2262e23b4e207720e7 Mon Sep 17 00:00:00 2001 From: mcendu Date: Sun, 29 Dec 2019 14:52:51 +0800 Subject: [PATCH 3/6] Make AccentColour of StageHint virtual --- osu.Game.Rulesets.Mania/UI/Components/StageHint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/UI/Components/StageHint.cs b/osu.Game.Rulesets.Mania/UI/Components/StageHint.cs index 9574f77eb5..813a6928c9 100644 --- a/osu.Game.Rulesets.Mania/UI/Components/StageHint.cs +++ b/osu.Game.Rulesets.Mania/UI/Components/StageHint.cs @@ -9,6 +9,6 @@ namespace osu.Game.Rulesets.Mania.UI.Components { public abstract class StageHint : CompositeDrawable, IHasAccentColour { - public abstract Color4 AccentColour { get; set; } + public virtual Color4 AccentColour { get; set; } } } From 61fb9f5613dc47c07a96b88eba4f40f23efeb0c2 Mon Sep 17 00:00:00 2001 From: mcendu Date: Sun, 29 Dec 2019 23:18:50 +0800 Subject: [PATCH 4/6] Remove class StageHint and usage --- .../UI/Components/ColumnHitObjectArea.cs | 9 +++++---- osu.Game.Rulesets.Mania/UI/Components/StageHint.cs | 14 -------------- 2 files changed, 5 insertions(+), 18 deletions(-) delete mode 100644 osu.Game.Rulesets.Mania/UI/Components/StageHint.cs diff --git a/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs b/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs index 6bfb2b89aa..494da6c61b 100644 --- a/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs +++ b/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs @@ -22,11 +22,11 @@ namespace osu.Game.Rulesets.Mania.UI.Components private readonly IBindable direction = new Bindable(); - private readonly StageHint stageHint; + private readonly Drawable stageHint; public ColumnHitObjectArea(HitObjectContainer hitObjectContainer) { - InternalChildren = new Drawable[] + InternalChildren = new[] { stageHint = new DefaultStageHint { @@ -60,11 +60,12 @@ namespace osu.Game.Rulesets.Mania.UI.Components accentColour = value; - stageHint.AccentColour = accentColour; + if (stageHint is IHasAccentColour colouredHitTarget) + colouredHitTarget.AccentColour = accentColour; } } - private class DefaultStageHint : StageHint + private class DefaultStageHint : CompositeDrawable, IHasAccentColour { private readonly IBindable direction = new Bindable(); diff --git a/osu.Game.Rulesets.Mania/UI/Components/StageHint.cs b/osu.Game.Rulesets.Mania/UI/Components/StageHint.cs deleted file mode 100644 index 813a6928c9..0000000000 --- a/osu.Game.Rulesets.Mania/UI/Components/StageHint.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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.Containers; -using osu.Game.Graphics; -using osuTK.Graphics; - -namespace osu.Game.Rulesets.Mania.UI.Components -{ - public abstract class StageHint : CompositeDrawable, IHasAccentColour - { - public virtual Color4 AccentColour { get; set; } - } -} From 51000765ddca9c9f4b4a60605e10bd554e74c111 Mon Sep 17 00:00:00 2001 From: mcendu Date: Sun, 29 Dec 2019 23:29:00 +0800 Subject: [PATCH 5/6] remove override --- osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs b/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs index 494da6c61b..c78023a58b 100644 --- a/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs +++ b/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs @@ -114,7 +114,7 @@ namespace osu.Game.Rulesets.Mania.UI.Components private Color4 accentColour; - public override Color4 AccentColour + public Color4 AccentColour { get => accentColour; set From 20c5748342efacb4d36c6d971d9e9bcdf689d650 Mon Sep 17 00:00:00 2001 From: mcendu Date: Sun, 29 Dec 2019 23:37:28 +0800 Subject: [PATCH 6/6] Use hitTarget in place of stageHint --- .../UI/Components/ColumnHitObjectArea.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs b/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs index c78023a58b..ee2cec1bbd 100644 --- a/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs +++ b/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs @@ -22,13 +22,13 @@ namespace osu.Game.Rulesets.Mania.UI.Components private readonly IBindable direction = new Bindable(); - private readonly Drawable stageHint; + private readonly Drawable hitTarget; public ColumnHitObjectArea(HitObjectContainer hitObjectContainer) { InternalChildren = new[] { - stageHint = new DefaultStageHint + hitTarget = new DefaultHitTarget { RelativeSizeAxes = Axes.X, }, @@ -44,7 +44,7 @@ namespace osu.Game.Rulesets.Mania.UI.Components { Anchor anchor = dir.NewValue == ScrollingDirection.Up ? Anchor.TopLeft : Anchor.BottomLeft; - stageHint.Anchor = stageHint.Origin = anchor; + hitTarget.Anchor = hitTarget.Origin = anchor; }, true); } @@ -60,19 +60,19 @@ namespace osu.Game.Rulesets.Mania.UI.Components accentColour = value; - if (stageHint is IHasAccentColour colouredHitTarget) + if (hitTarget is IHasAccentColour colouredHitTarget) colouredHitTarget.AccentColour = accentColour; } } - private class DefaultStageHint : CompositeDrawable, IHasAccentColour + private class DefaultHitTarget : CompositeDrawable, IHasAccentColour { private readonly IBindable direction = new Bindable(); private readonly Container hitTargetLine; private readonly Drawable hitTargetBar; - public DefaultStageHint() + public DefaultHitTarget() { InternalChildren = new[] {