1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Move shared followcircle code into abstract base class

This commit is contained in:
Alden Wu 2022-07-14 16:52:45 -07:00
parent 0bc42ef67d
commit 66932f1af6
3 changed files with 92 additions and 109 deletions

View File

@ -1,27 +1,19 @@
// 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Skinning.Default
{
public class DefaultFollowCircle : CompositeDrawable
public class DefaultFollowCircle : FollowCircle
{
[Resolved(canBeNull: true)]
private DrawableHitObject? parentObject { get; set; }
public DefaultFollowCircle()
{
Alpha = 0f;
RelativeSizeAxes = Axes.Both;
InternalChild = new CircularContainer
{
RelativeSizeAxes = Axes.Both,
@ -38,28 +30,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
};
}
[BackgroundDependencyLoader]
private void load()
{
if (parentObject != null)
{
var slider = (DrawableSlider)parentObject;
slider.Tracking.BindValueChanged(trackingChanged, true);
}
}
protected override void LoadComplete()
{
base.LoadComplete();
if (parentObject != null)
{
parentObject.ApplyCustomUpdateState += updateStateTransforms;
updateStateTransforms(parentObject, parentObject.State.Value);
}
}
private void trackingChanged(ValueChangedEvent<bool> tracking)
protected override void OnTrackingChanged(ValueChangedEvent<bool> tracking)
{
const float scale_duration = 300f;
const float fade_duration = 300f;
@ -68,25 +39,12 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
.FadeTo(tracking.NewValue ? 1f : 0, fade_duration, Easing.OutQuint);
}
private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState state)
protected override void OnSliderEnd()
{
// see comment in LegacySliderBall.updateStateTransforms
if (drawableObject is not DrawableSlider)
return;
const float fade_duration = 450f;
// intentionally pile on an extra FadeOut to make it happen much faster
using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime))
this.FadeOut(fade_duration / 4, Easing.Out);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (parentObject != null)
parentObject.ApplyCustomUpdateState -= updateStateTransforms;
}
}
}

View File

@ -0,0 +1,79 @@
// 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables;
namespace osu.Game.Rulesets.Osu.Skinning
{
public abstract class FollowCircle : CompositeDrawable
{
[Resolved(canBeNull: true)]
protected DrawableHitObject? ParentObject { get; private set; }
public FollowCircle()
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
if (ParentObject != null)
{
var slider = (DrawableSlider)ParentObject;
slider.Tracking.BindValueChanged(OnTrackingChanged, true);
}
}
protected override void LoadComplete()
{
base.LoadComplete();
if (ParentObject != null)
{
ParentObject.HitObjectApplied += onHitObjectApplied;
onHitObjectApplied(ParentObject);
ParentObject.ApplyCustomUpdateState += updateStateTransforms;
updateStateTransforms(ParentObject, ParentObject.State.Value);
}
}
private void onHitObjectApplied(DrawableHitObject drawableObject)
{
this.ScaleTo(1f)
.FadeOut();
}
private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState state)
{
// Gets called by slider ticks, tails, etc., leading to duplicated
// animations which may negatively affect performance
if (drawableObject is not DrawableSlider)
return;
using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime))
OnSliderEnd();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (ParentObject != null)
{
ParentObject.HitObjectApplied -= onHitObjectApplied;
ParentObject.ApplyCustomUpdateState -= updateStateTransforms;
}
}
protected abstract void OnTrackingChanged(ValueChangedEvent<bool> tracking);
protected abstract void OnSliderEnd();
}
}

View File

@ -2,20 +2,14 @@
// See the LICENCE file in the repository root for full licence text.
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables;
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
public class LegacyFollowCircle : CompositeDrawable
public class LegacyFollowCircle : FollowCircle
{
[Resolved(canBeNull: true)]
private DrawableHitObject? parentObject { get; set; }
public LegacyFollowCircle(Drawable animationContent)
{
// follow circles are 2x the hitcircle resolution in legacy skins (since they are scaled down from >1x
@ -27,41 +21,17 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
InternalChild = animationContent;
}
[BackgroundDependencyLoader]
private void load()
protected override void OnTrackingChanged(ValueChangedEvent<bool> tracking)
{
if (parentObject != null)
{
var slider = (DrawableSlider)parentObject;
slider.Tracking.BindValueChanged(trackingChanged, true);
}
}
Debug.Assert(ParentObject != null);
protected override void LoadComplete()
{
base.LoadComplete();
if (parentObject != null)
{
parentObject.HitObjectApplied += onHitObjectApplied;
onHitObjectApplied(parentObject);
parentObject.ApplyCustomUpdateState += updateStateTransforms;
updateStateTransforms(parentObject, parentObject.State.Value);
}
}
private void trackingChanged(ValueChangedEvent<bool> tracking)
{
Debug.Assert(parentObject != null);
if (parentObject.Judged)
if (ParentObject.Judged)
return;
const float scale_duration = 180f;
const float fade_duration = 90f;
double maxScaleDuration = parentObject.HitStateUpdateTime - Time.Current;
double maxScaleDuration = ParentObject.HitStateUpdateTime - Time.Current;
double realScaleDuration = scale_duration;
if (tracking.NewValue && maxScaleDuration < realScaleDuration && maxScaleDuration >= 0)
realScaleDuration = maxScaleDuration;
@ -71,39 +41,15 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
.FadeTo(tracking.NewValue ? 1f : 0f, realFadeDuration, Easing.OutQuad);
}
private void onHitObjectApplied(DrawableHitObject drawableObject)
protected override void OnSliderEnd()
{
this.ScaleTo(1f)
.FadeOut();
}
private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState state)
{
// see comment in LegacySliderBall.updateStateTransforms
if (drawableObject is not DrawableSlider)
return;
const float shrink_duration = 200f;
const float fade_delay = 175f;
const float fade_duration = 35f;
using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime))
{
this.ScaleTo(DrawableSliderBall.FOLLOW_AREA * 0.75f, shrink_duration, Easing.OutQuad)
.Delay(fade_delay)
.FadeOut(fade_duration);
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (parentObject != null)
{
parentObject.HitObjectApplied -= onHitObjectApplied;
parentObject.ApplyCustomUpdateState -= updateStateTransforms;
}
}
}
}