1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +08:00

Prefer [Resolved] and LoadComplete

This commit is contained in:
goodtrailer 2022-07-01 21:12:36 -07:00
parent 76d4f86ca3
commit 2e3ff2c7e0

View File

@ -1,14 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK.Graphics; using osuTK.Graphics;
@ -20,10 +18,11 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
private readonly ISkin skin; private readonly ISkin skin;
private DrawableSlider slider; [Resolved(canBeNull: true)]
private DrawableHitObject? drawableObject { get; set; }
private Sprite layerNd; private Sprite layerNd = null!;
private Sprite layerSpec; private Sprite layerSpec = null!;
public LegacySliderBall(Drawable animationContent, ISkin skin) public LegacySliderBall(Drawable animationContent, ISkin skin)
{ {
@ -36,8 +35,6 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(DrawableHitObject dho) private void load(DrawableHitObject dho)
{ {
slider = (DrawableSlider)dho;
var ballColour = skin.GetConfig<OsuSkinColour, Color4>(OsuSkinColour.SliderBall)?.Value ?? Color4.White; var ballColour = skin.GetConfig<OsuSkinColour, Color4>(OsuSkinColour.SliderBall)?.Value ?? Color4.White;
InternalChildren = new[] InternalChildren = new[]
@ -62,8 +59,17 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
Blending = BlendingParameters.Additive, Blending = BlendingParameters.Additive,
}, },
}; };
}
slider.ApplyCustomUpdateState += updateStateTransforms; protected override void LoadComplete()
{
base.LoadComplete();
if (drawableObject != null)
{
drawableObject.ApplyCustomUpdateState += updateStateTransforms;
updateStateTransforms(drawableObject, drawableObject.State.Value);
}
} }
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
@ -79,13 +85,10 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
private void updateStateTransforms(DrawableHitObject obj, ArmedState _) private void updateStateTransforms(DrawableHitObject obj, ArmedState _)
{ {
if (obj is not DrawableSlider) using (BeginAbsoluteSequence(drawableObject.AsNonNull().StateUpdateTime))
return;
using (BeginAbsoluteSequence(slider.StateUpdateTime))
this.FadeIn(); this.FadeIn();
using (BeginAbsoluteSequence(slider.HitStateUpdateTime)) using (BeginAbsoluteSequence(drawableObject.AsNonNull().HitStateUpdateTime))
this.FadeOut(); this.FadeOut();
} }
@ -93,8 +96,8 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
if (slider != null) if (drawableObject != null)
slider.ApplyCustomUpdateState -= updateStateTransforms; drawableObject.ApplyCustomUpdateState -= updateStateTransforms;
} }
} }
} }