diff --git a/osu.Game.Rulesets.Mania/UI/DrawableManiaJudgement.cs b/osu.Game.Rulesets.Mania/UI/DrawableManiaJudgement.cs index d99f6cb8d3..c53ab4a717 100644 --- a/osu.Game.Rulesets.Mania/UI/DrawableManiaJudgement.cs +++ b/osu.Game.Rulesets.Mania/UI/DrawableManiaJudgement.cs @@ -1,10 +1,10 @@ // 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.Allocation; using osu.Framework.Graphics; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Mania.UI { @@ -19,13 +19,6 @@ namespace osu.Game.Rulesets.Mania.UI { } - [BackgroundDependencyLoader] - private void load() - { - if (JudgementText != null) - JudgementText.Font = JudgementText.Font.With(size: 25); - } - protected override double FadeInDuration => 50; protected override void ApplyHitAnimations() @@ -36,5 +29,17 @@ namespace osu.Game.Rulesets.Mania.UI JudgementBody.Delay(FadeInDuration).ScaleTo(0.75f, 250); this.Delay(FadeInDuration).FadeOut(200); } + + protected override Drawable CreateDefaultJudgement(HitResult type) + => new ManiaJudgementPiece(); + + private class ManiaJudgementPiece : DefaultJudgementPiece + { + protected override void LoadComplete() + { + base.LoadComplete(); + JudgementText.Font = JudgementText.Font.With(size: 25); + } + } } } diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuJudgement.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuJudgement.cs index d89a613e0f..a96ec53e28 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuJudgement.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuJudgement.cs @@ -4,9 +4,9 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Configuration; -using osuTK; using osu.Game.Rulesets.Judgements; -using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Scoring; +using osuTK; namespace osu.Game.Rulesets.Osu.Objects.Drawables { @@ -65,8 +65,20 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables fadeOutDelay = hitLightingEnabled ? 1400 : base.FadeOutDelay; - JudgementText?.TransformSpacingTo(Vector2.Zero).Then().TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint); base.ApplyHitAnimations(); } + + protected override Drawable CreateDefaultJudgement(HitResult type) => new OsuJudgementPiece(); + + private class OsuJudgementPiece : DefaultJudgementPiece + { + public override void PlayAnimation(HitResult resultType) + { + base.PlayAnimation(resultType); + + if (resultType != HitResult.Miss) + JudgementText.TransformSpacingTo(Vector2.Zero).Then().TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint); + } + } } } diff --git a/osu.Game/Rulesets/Judgements/DefaultJudgementPiece.cs b/osu.Game/Rulesets/Judgements/DefaultJudgementPiece.cs new file mode 100644 index 0000000000..051cd755d6 --- /dev/null +++ b/osu.Game/Rulesets/Judgements/DefaultJudgementPiece.cs @@ -0,0 +1,65 @@ +// 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.Allocation; +using osu.Framework.Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Rulesets.Scoring; +using osuTK; + +namespace osu.Game.Rulesets.Judgements +{ + public class DefaultJudgementPiece : CompositeDrawable, IAnimatableJudgement + { + protected SpriteText JudgementText { get; } + + [Resolved] + private OsuColour colours { get; set; } + + public DefaultJudgementPiece() + { + Origin = Anchor.Centre; + + AutoSizeAxes = Axes.Both; + + InternalChildren = new Drawable[] + { + JudgementText = new OsuSpriteText + { + Font = OsuFont.Numeric.With(size: 20), + Scale = new Vector2(0.85f, 1), + } + }; + } + + public virtual void PlayAnimation(HitResult result) + { + JudgementText.Text = result.GetDescription().ToUpperInvariant(); + JudgementText.Colour = colours.ForHitResult(result); + + this.RotateTo(0); + this.MoveTo(Vector2.Zero); + + switch (result) + { + case HitResult.Miss: + this.ScaleTo(1.6f); + this.ScaleTo(1, 100, Easing.In); + + this.MoveToOffset(new Vector2(0, 100), 800, Easing.InQuint); + + this.RotateTo(40, 800, Easing.InQuint); + break; + + default: + this.ScaleTo(0.9f); + this.ScaleTo(1, 500, Easing.OutElastic); + break; + } + } + } +} diff --git a/osu.Game/Rulesets/Judgements/DrawableJudgement.cs b/osu.Game/Rulesets/Judgements/DrawableJudgement.cs index 5c617aaa98..a73b422ccf 100644 --- a/osu.Game/Rulesets/Judgements/DrawableJudgement.cs +++ b/osu.Game/Rulesets/Judgements/DrawableJudgement.cs @@ -3,18 +3,14 @@ using System.Diagnostics; using JetBrains.Annotations; -using osuTK; using osu.Framework.Allocation; -using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Pooling; -using osu.Framework.Graphics.Sprites; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Scoring; using osu.Game.Skinning; +using osuTK; namespace osu.Game.Rulesets.Judgements { @@ -25,16 +21,13 @@ namespace osu.Game.Rulesets.Judgements { private const float judgement_size = 128; - [Resolved] - private OsuColour colours { get; set; } - public JudgementResult Result { get; private set; } + public DrawableHitObject JudgedObject { get; private set; } protected Container JudgementBody { get; private set; } - protected SpriteText JudgementText { get; private set; } - private SkinnableDrawable bodyDrawable; + private SkinnableDrawable skinnableJudgement; /// /// Duration of initial fade in. @@ -69,14 +62,34 @@ namespace osu.Game.Rulesets.Judgements prepareDrawables(); } + /// + /// Apply top-level animations to the current judgement when successfully hit. + /// Generally used for fading, defaulting to a simple fade out based on . + /// This will be used to calculate the lifetime of the judgement. + /// + /// + /// For animating the actual "default skin" judgement itself, it is recommended to use . + /// This allows applying animations which don't affect custom skins. + /// protected virtual void ApplyHitAnimations() { - JudgementBody.ScaleTo(0.9f); - JudgementBody.ScaleTo(1, 500, Easing.OutElastic); - this.Delay(FadeOutDelay).FadeOut(400); } + /// + /// Apply top-level animations to the current judgement when missed. + /// Generally used for fading, defaulting to a simple fade out based on . + /// This will be used to calculate the lifetime of the judgement. + /// + /// + /// For animating the actual "default skin" judgement itself, it is recommended to use . + /// This allows applying animations which don't affect custom skins. + /// + protected virtual void ApplyMissAnimations() + { + this.Delay(600).FadeOut(200); + } + public void Apply([NotNull] JudgementResult result, [CanBeNull] DrawableHitObject judgedObject) { Result = result; @@ -91,12 +104,9 @@ namespace osu.Game.Rulesets.Judgements prepareDrawables(); - bodyDrawable.ResetAnimation(); + skinnableJudgement.ResetAnimation(); this.FadeInFromZero(FadeInDuration, Easing.OutQuint); - JudgementBody.ScaleTo(1); - JudgementBody.RotateTo(0); - JudgementBody.MoveTo(Vector2.Zero); switch (Result.Type) { @@ -104,13 +114,7 @@ namespace osu.Game.Rulesets.Judgements break; case HitResult.Miss: - JudgementBody.ScaleTo(1.6f); - JudgementBody.ScaleTo(1, 100, Easing.In); - - JudgementBody.MoveToOffset(new Vector2(0, 100), 800, Easing.InQuint); - JudgementBody.RotateTo(40, 800, Easing.InQuint); - - this.Delay(600).FadeOut(200); + ApplyMissAnimations(); break; default: @@ -118,6 +122,12 @@ namespace osu.Game.Rulesets.Judgements break; } + if (skinnableJudgement.Drawable is IAnimatableJudgement animatable) + { + using (BeginAbsoluteSequence(Result.TimeAbsolute)) + animatable.PlayAnimation(Result.Type); + } + Expire(true); } @@ -139,16 +149,13 @@ namespace osu.Game.Rulesets.Judgements Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativeSizeAxes = Axes.Both, - Child = bodyDrawable = new SkinnableDrawable(new GameplaySkinComponent(type), _ => JudgementText = new OsuSpriteText - { - Text = type.GetDescription().ToUpperInvariant(), - Font = OsuFont.Numeric.With(size: 20), - Colour = colours.ForHitResult(type), - Scale = new Vector2(0.85f, 1), - }, confineMode: ConfineMode.NoScaling) + Child = skinnableJudgement = new SkinnableDrawable(new GameplaySkinComponent(type), _ => + CreateDefaultJudgement(type), confineMode: ConfineMode.NoScaling) }); currentDrawableType = type; } + + protected virtual Drawable CreateDefaultJudgement(HitResult type) => new DefaultJudgementPiece(); } } diff --git a/osu.Game/Rulesets/Judgements/IAnimatableJudgement.cs b/osu.Game/Rulesets/Judgements/IAnimatableJudgement.cs new file mode 100644 index 0000000000..3f84e6f83c --- /dev/null +++ b/osu.Game/Rulesets/Judgements/IAnimatableJudgement.cs @@ -0,0 +1,15 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Rulesets.Scoring; + +namespace osu.Game.Rulesets.Judgements +{ + /// + /// A skinnable judgement element which supports playing an animation from the current point in time. + /// + public interface IAnimatableJudgement + { + void PlayAnimation(HitResult result); + } +}