1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 23:52:57 +08:00

Merge pull request #10951 from peppy/fix-drawable-judgement-animation-loss

Fix DrawableJudgement not always animating correctly on skin change
This commit is contained in:
Dan Balasescu 2020-11-30 16:36:09 +09:00 committed by GitHub
commit d9edd4e7de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,9 +32,6 @@ namespace osu.Game.Rulesets.Judgements
private readonly Container aboveHitObjectsContent; private readonly Container aboveHitObjectsContent;
[Resolved]
private ISkinSource skinSource { get; set; }
/// <summary> /// <summary>
/// Duration of initial fade in. /// Duration of initial fade in.
/// </summary> /// </summary>
@ -78,29 +75,6 @@ namespace osu.Game.Rulesets.Judgements
public Drawable GetProxyAboveHitObjectsContent() => aboveHitObjectsContent.CreateProxy(); public Drawable GetProxyAboveHitObjectsContent() => aboveHitObjectsContent.CreateProxy();
protected override void LoadComplete()
{
base.LoadComplete();
skinSource.SourceChanged += onSkinChanged;
}
private void onSkinChanged()
{
// on a skin change, the child component will update but not get correctly triggered to play its animation.
// we need to trigger a reinitialisation to make things right.
currentDrawableType = null;
PrepareForUse();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (skinSource != null)
skinSource.SourceChanged -= onSkinChanged;
}
/// <summary> /// <summary>
/// Apply top-level animations to the current judgement when successfully hit. /// Apply top-level animations to the current judgement when successfully hit.
/// If displaying components which require lifetime extensions, manually adjusting <see cref="Drawable.LifetimeEnd"/> is required. /// If displaying components which require lifetime extensions, manually adjusting <see cref="Drawable.LifetimeEnd"/> is required.
@ -142,13 +116,14 @@ namespace osu.Game.Rulesets.Judgements
Debug.Assert(Result != null); Debug.Assert(Result != null);
prepareDrawables();
runAnimation(); runAnimation();
} }
private void runAnimation() private void runAnimation()
{ {
// is a no-op if the drawables are already in a correct state.
prepareDrawables();
// undo any transforms applies in ApplyMissAnimations/ApplyHitAnimations to get a sane initial state. // undo any transforms applies in ApplyMissAnimations/ApplyHitAnimations to get a sane initial state.
ApplyTransformsAt(double.MinValue, true); ApplyTransformsAt(double.MinValue, true);
ClearTransforms(true); ClearTransforms(true);
@ -203,7 +178,6 @@ namespace osu.Game.Rulesets.Judgements
if (JudgementBody != null) if (JudgementBody != null)
RemoveInternal(JudgementBody); RemoveInternal(JudgementBody);
aboveHitObjectsContent.Clear();
AddInternal(JudgementBody = new SkinnableDrawable(new GameplaySkinComponent<HitResult>(type), _ => AddInternal(JudgementBody = new SkinnableDrawable(new GameplaySkinComponent<HitResult>(type), _ =>
CreateDefaultJudgement(type), confineMode: ConfineMode.NoScaling) CreateDefaultJudgement(type), confineMode: ConfineMode.NoScaling)
{ {
@ -211,14 +185,29 @@ namespace osu.Game.Rulesets.Judgements
Origin = Anchor.Centre, Origin = Anchor.Centre,
}); });
if (JudgementBody.Drawable is IAnimatableJudgement animatable) JudgementBody.OnSkinChanged += () =>
{ {
var proxiedContent = animatable.GetAboveHitObjectsProxiedContent(); // on a skin change, the child component will update but not get correctly triggered to play its animation (or proxy the newly created content).
if (proxiedContent != null) // we need to trigger a reinitialisation to make things right.
aboveHitObjectsContent.Add(proxiedContent); proxyContent();
} runAnimation();
};
proxyContent();
currentDrawableType = type; currentDrawableType = type;
void proxyContent()
{
aboveHitObjectsContent.Clear();
if (JudgementBody.Drawable is IAnimatableJudgement animatable)
{
var proxiedContent = animatable.GetAboveHitObjectsProxiedContent();
if (proxiedContent != null)
aboveHitObjectsContent.Add(proxiedContent);
}
}
} }
protected virtual Drawable CreateDefaultJudgement(HitResult result) => new DefaultJudgementPiece(result); protected virtual Drawable CreateDefaultJudgement(HitResult result) => new DefaultJudgementPiece(result);