From c04b09520da8115080bec4dfc4310e9f549493e3 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 19 Jun 2021 20:06:28 +0300 Subject: [PATCH] Replace spinner approach circle proxying logic with hooking up to `OnSkinChange` in mod --- osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs | 15 ++++++-- .../Objects/Drawables/DrawableSpinner.cs | 5 ++- .../Skinning/IHasSpinnerApproachCircle.cs | 18 ++++++++++ .../Skinning/IProxiesApproachCircle.cs | 12 ------- .../Skinning/Legacy/LegacySpinner.cs | 13 ++++--- .../Legacy/LegacySpinnerApproachCircle.cs | 9 +++-- .../Skinning/SkinnableSpinnerBody.cs | 34 ------------------- 7 files changed, 45 insertions(+), 61 deletions(-) create mode 100644 osu.Game.Rulesets.Osu/Skinning/IHasSpinnerApproachCircle.cs delete mode 100644 osu.Game.Rulesets.Osu/Skinning/IProxiesApproachCircle.cs delete mode 100644 osu.Game.Rulesets.Osu/Skinning/SkinnableSpinnerBody.cs diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs b/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs index d712ffd92a..071c3dc3f1 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs @@ -11,6 +11,7 @@ using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Skinning; namespace osu.Game.Rulesets.Osu.Mods { @@ -110,8 +111,8 @@ namespace osu.Game.Rulesets.Osu.Mods // hide elements we don't care about. // todo: hide background - using (spinner.BeginAbsoluteSequence(hitObject.StartTime - hitObject.TimePreempt)) - spinner.ApproachCircle.Hide(); + spinner.Body.OnSkinChanged += () => hideSpinnerApproachCircle(spinner); + hideSpinnerApproachCircle(spinner); using (spinner.BeginAbsoluteSequence(fadeStartTime)) spinner.FadeOut(fadeDuration); @@ -163,5 +164,15 @@ namespace osu.Game.Rulesets.Osu.Mods } } } + + private static void hideSpinnerApproachCircle(DrawableSpinner spinner) + { + var approachCircle = (spinner.Body.Drawable as IHasSpinnerApproachCircle)?.ApproachCircle; + if (approachCircle == null) + return; + + using (spinner.BeginAbsoluteSequence(spinner.HitObject.StartTime - spinner.HitObject.TimePreempt)) + approachCircle.Hide(); + } } } diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs index 4507b1520c..ec87d3bfdf 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs @@ -29,7 +29,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables public new OsuSpinnerJudgementResult Result => (OsuSpinnerJudgementResult)base.Result; - public SkinnableDrawable ApproachCircle { get; private set; } + public SkinnableDrawable Body { get; private set; } public SpinnerRotationTracker RotationTracker { get; private set; } @@ -88,8 +88,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables RelativeSizeAxes = Axes.Y, Children = new Drawable[] { - ApproachCircle = new SkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.SpinnerApproachCircle)), - new SkinnableSpinnerBody(ApproachCircle.CreateProxy(), _ => new DefaultSpinner()), + Body = new SkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.SpinnerBody), _ => new DefaultSpinner()), RotationTracker = new SpinnerRotationTracker(this) } }, diff --git a/osu.Game.Rulesets.Osu/Skinning/IHasSpinnerApproachCircle.cs b/osu.Game.Rulesets.Osu/Skinning/IHasSpinnerApproachCircle.cs new file mode 100644 index 0000000000..dcfc15913c --- /dev/null +++ b/osu.Game.Rulesets.Osu/Skinning/IHasSpinnerApproachCircle.cs @@ -0,0 +1,18 @@ +// 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; + +namespace osu.Game.Rulesets.Osu.Skinning +{ + /// + /// A common interface between implementations of the component that provide approach circles for the spinner. + /// + public interface IHasSpinnerApproachCircle + { + /// + /// The spinner approach circle. + /// + Drawable ApproachCircle { get; } + } +} diff --git a/osu.Game.Rulesets.Osu/Skinning/IProxiesApproachCircle.cs b/osu.Game.Rulesets.Osu/Skinning/IProxiesApproachCircle.cs deleted file mode 100644 index 3cc0026adc..0000000000 --- a/osu.Game.Rulesets.Osu/Skinning/IProxiesApproachCircle.cs +++ /dev/null @@ -1,12 +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; - -namespace osu.Game.Rulesets.Osu.Skinning -{ - public interface IProxiesApproachCircle - { - Container ApproachCircleTarget { get; } - } -} diff --git a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySpinner.cs b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySpinner.cs index efbb27bf3f..5471de22d4 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySpinner.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySpinner.cs @@ -15,7 +15,7 @@ using osuTK; namespace osu.Game.Rulesets.Osu.Skinning.Legacy { - public abstract class LegacySpinner : CompositeDrawable, IProxiesApproachCircle + public abstract class LegacySpinner : CompositeDrawable, IHasSpinnerApproachCircle { public const float SPRITE_SCALE = 0.625f; @@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy protected DrawableSpinner DrawableSpinner { get; private set; } - public Container ApproachCircleTarget { get; private set; } + public Drawable ApproachCircle { get; private set; } private Sprite spin; private Sprite clear; @@ -59,11 +59,14 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy { Depth = float.MinValue, RelativeSizeAxes = Axes.Both, - Children = new Drawable[] + Children = new[] { - ApproachCircleTarget = new Container + ApproachCircle = new LegacySpinnerApproachCircle { - RelativeSizeAxes = Axes.Both, + Anchor = Anchor.TopCentre, + Origin = Anchor.Centre, + Scale = new Vector2(SPRITE_SCALE), + Y = SPINNER_Y_CENTRE, }, spin = new Sprite { diff --git a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySpinnerApproachCircle.cs b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySpinnerApproachCircle.cs index 92454cefa3..d5e510cd69 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySpinnerApproachCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySpinnerApproachCircle.cs @@ -10,7 +10,6 @@ using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Skinning; using osuTK; -using static osu.Game.Rulesets.Osu.Skinning.Legacy.LegacySpinner; namespace osu.Game.Rulesets.Osu.Skinning.Legacy { @@ -19,7 +18,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy private DrawableSpinner drawableSpinner; [CanBeNull] - private Sprite sprite; + private Sprite approachCircle; [BackgroundDependencyLoader] private void load(DrawableHitObject drawableHitObject, ISkinSource source) @@ -35,12 +34,12 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy if (spinnerProvider is DefaultLegacySkin) return; - InternalChild = sprite = new Sprite + InternalChild = approachCircle = new Sprite { Anchor = Anchor.Centre, Origin = Anchor.Centre, Texture = source.GetTexture("spinner-approachcircle"), - Scale = new Vector2(SPRITE_SCALE * 1.86f), + Scale = new Vector2(1.86f), }; } @@ -58,7 +57,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy return; using (BeginAbsoluteSequence(spinner.HitObject.StartTime)) - sprite?.ScaleTo(SPRITE_SCALE * 0.1f, spinner.HitObject.Duration); + approachCircle?.ScaleTo(0.1f, spinner.HitObject.Duration); } } } diff --git a/osu.Game.Rulesets.Osu/Skinning/SkinnableSpinnerBody.cs b/osu.Game.Rulesets.Osu/Skinning/SkinnableSpinnerBody.cs deleted file mode 100644 index 763b9dd677..0000000000 --- a/osu.Game.Rulesets.Osu/Skinning/SkinnableSpinnerBody.cs +++ /dev/null @@ -1,34 +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 System; -using osu.Framework.Graphics; -using osu.Game.Skinning; - -namespace osu.Game.Rulesets.Osu.Skinning -{ - /// - /// A skinnable drawable of the component, with the approach circle exposed for modification. - /// - public class SkinnableSpinnerBody : SkinnableDrawable - { - private readonly Drawable approachCircleProxy; - - public SkinnableSpinnerBody(Drawable approachCircleProxy, Func defaultImplementation = null) - : base(new OsuSkinComponent(OsuSkinComponents.SpinnerBody), defaultImplementation) - { - this.approachCircleProxy = approachCircleProxy; - } - - protected override void SkinChanged(ISkinSource skin) - { - if (Drawable is IProxiesApproachCircle oldProxiesApproachCircle) - oldProxiesApproachCircle.ApproachCircleTarget.Remove(approachCircleProxy); - - base.SkinChanged(skin); - - if (Drawable is IProxiesApproachCircle newProxiesApproachCircle) - newProxiesApproachCircle.ApproachCircleTarget.Add(approachCircleProxy); - } - } -}