1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 18:32:56 +08:00

Replace spinner approach circle proxying logic with hooking up to OnSkinChange in mod

This commit is contained in:
Salman Ahmed 2021-06-19 20:06:28 +03:00
parent d6b9436151
commit c04b09520d
7 changed files with 45 additions and 61 deletions

View File

@ -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();
}
}
}

View File

@ -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)
}
},

View File

@ -0,0 +1,18 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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
{
/// <summary>
/// A common interface between implementations of the <see cref="OsuSkinComponents.SpinnerBody"/> component that provide approach circles for the spinner.
/// </summary>
public interface IHasSpinnerApproachCircle
{
/// <summary>
/// The spinner approach circle.
/// </summary>
Drawable ApproachCircle { get; }
}
}

View File

@ -1,12 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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; }
}
}

View File

@ -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
{

View File

@ -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);
}
}
}

View File

@ -1,34 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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
{
/// <summary>
/// A skinnable drawable of the <see cref="OsuSkinComponents.SpinnerBody"/> component, with the approach circle exposed for modification.
/// </summary>
public class SkinnableSpinnerBody : SkinnableDrawable
{
private readonly Drawable approachCircleProxy;
public SkinnableSpinnerBody(Drawable approachCircleProxy, Func<ISkinComponent, Drawable> 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);
}
}
}