1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 12:42:54 +08:00

Merge pull request #10878 from peppy/fix-judgement-transform-logic

Add ability for skins to have more control over judgement transforms
This commit is contained in:
Bartłomiej Dach 2020-11-18 20:33:29 +01:00 committed by GitHub
commit e7c0cf093b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 257 additions and 97 deletions

View File

@ -1,10 +1,10 @@
// 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.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,22 @@ namespace osu.Game.Rulesets.Mania.UI
JudgementBody.Delay(FadeInDuration).ScaleTo(0.75f, 250);
this.Delay(FadeInDuration).FadeOut(200);
}
protected override Drawable CreateDefaultJudgement(HitResult result) => new ManiaJudgementPiece(result);
private class ManiaJudgementPiece : DefaultJudgementPiece
{
public ManiaJudgementPiece(HitResult result)
: base(result)
{
}
protected override void LoadComplete()
{
base.LoadComplete();
JudgementText.Font = JudgementText.Font.With(size: 25);
}
}
}
}

View File

@ -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
{
@ -17,15 +17,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
[Resolved]
private OsuConfigManager config { get; set; }
public DrawableOsuJudgement(JudgementResult result, DrawableHitObject judgedObject)
: base(result, judgedObject)
{
}
public DrawableOsuJudgement()
{
}
[BackgroundDependencyLoader]
private void load()
{
@ -39,23 +30,18 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
});
}
public override void Apply(JudgementResult result, DrawableHitObject judgedObject)
{
base.Apply(result, judgedObject);
if (judgedObject?.HitObject is OsuHitObject osuObject)
{
Position = osuObject.StackedPosition;
Scale = new Vector2(osuObject.Scale);
}
}
protected override void PrepareForUse()
{
base.PrepareForUse();
Lighting.ResetAnimation();
Lighting.SetColourFrom(JudgedObject, Result);
if (JudgedObject?.HitObject is OsuHitObject osuObject)
{
Position = osuObject.StackedPosition;
Scale = new Vector2(osuObject.Scale);
}
}
private double fadeOutDelay;
@ -79,8 +65,25 @@ 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 result) => new OsuJudgementPiece(result);
private class OsuJudgementPiece : DefaultJudgementPiece
{
public OsuJudgementPiece(HitResult result)
: base(result)
{
}
public override void PlayAnimation()
{
base.PlayAnimation();
if (Result != HitResult.Miss)
JudgementText.TransformSpacingTo(Vector2.Zero).Then().TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint);
}
}
}
}

View File

@ -1,12 +1,9 @@
// 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.Game.Rulesets.Objects.Drawables;
using osu.Framework.Allocation;
using osu.Game.Graphics;
using osu.Game.Rulesets.Judgements;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables;
namespace osu.Game.Rulesets.Taiko.UI
{
@ -25,21 +22,6 @@ namespace osu.Game.Rulesets.Taiko.UI
{
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
switch (Result.Type)
{
case HitResult.Ok:
JudgementBody.Colour = colours.GreenLight;
break;
case HitResult.Great:
JudgementBody.Colour = colours.BlueLight;
break;
}
}
protected override void ApplyHitAnimations()
{
this.MoveToY(-100, 500);

View File

@ -0,0 +1,71 @@
// 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.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 readonly HitResult Result;
protected SpriteText JudgementText { get; private set; }
[Resolved]
private OsuColour colours { get; set; }
public DefaultJudgementPiece(HitResult result)
{
Result = result;
Origin = Anchor.Centre;
}
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
JudgementText = new OsuSpriteText
{
Text = Result.GetDescription().ToUpperInvariant(),
Colour = colours.ForHitResult(Result),
Font = OsuFont.Numeric.With(size: 20),
Scale = new Vector2(0.85f, 1),
}
};
}
public virtual void PlayAnimation()
{
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;
}
}
}
}

View File

@ -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;
/// <summary>
/// Duration of initial fade in.
@ -69,15 +62,40 @@ namespace osu.Game.Rulesets.Judgements
prepareDrawables();
}
/// <summary>
/// Apply top-level animations to the current judgement when successfully hit.
/// Generally used for fading, defaulting to a simple fade out based on <see cref="FadeOutDelay"/>.
/// This will be used to calculate the lifetime of the judgement.
/// </summary>
/// <remarks>
/// For animating the actual "default skin" judgement itself, it is recommended to use <see cref="CreateDefaultJudgement"/>.
/// This allows applying animations which don't affect custom skins.
/// </remarks>
protected virtual void ApplyHitAnimations()
{
JudgementBody.ScaleTo(0.9f);
JudgementBody.ScaleTo(1, 500, Easing.OutElastic);
this.Delay(FadeOutDelay).FadeOut(400);
}
public virtual void Apply([NotNull] JudgementResult result, [CanBeNull] DrawableHitObject judgedObject)
/// <summary>
/// Apply top-level animations to the current judgement when missed.
/// Generally used for fading, defaulting to a simple fade out based on <see cref="FadeOutDelay"/>.
/// This will be used to calculate the lifetime of the judgement.
/// </summary>
/// <remarks>
/// For animating the actual "default skin" judgement itself, it is recommended to use <see cref="CreateDefaultJudgement"/>.
/// This allows applying animations which don't affect custom skins.
/// </remarks>
protected virtual void ApplyMissAnimations()
{
this.Delay(600).FadeOut(200);
}
/// <summary>
/// Associate a new result / object with this judgement. Should be called when retrieving a judgement from a pool.
/// </summary>
/// <param name="result">The applicable judgement.</param>
/// <param name="judgedObject">The drawable object.</param>
public void Apply([NotNull] JudgementResult result, [CanBeNull] DrawableHitObject judgedObject)
{
Result = result;
JudgedObject = judgedObject;
@ -91,12 +109,10 @@ namespace osu.Game.Rulesets.Judgements
prepareDrawables();
bodyDrawable.ResetAnimation();
// not sure if this should remain going forward.
skinnableJudgement.ResetAnimation();
this.FadeInFromZero(FadeInDuration, Easing.OutQuint);
JudgementBody.ScaleTo(1);
JudgementBody.RotateTo(0);
JudgementBody.MoveTo(Vector2.Zero);
switch (Result.Type)
{
@ -104,13 +120,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 +128,12 @@ namespace osu.Game.Rulesets.Judgements
break;
}
if (skinnableJudgement.Drawable is IAnimatableJudgement animatable)
{
using (BeginAbsoluteSequence(Result.TimeAbsolute))
animatable.PlayAnimation();
}
Expire(true);
}
@ -127,6 +143,7 @@ namespace osu.Game.Rulesets.Judgements
{
var type = Result?.Type ?? HitResult.Perfect; //TODO: better default type from ruleset
// todo: this should be removed once judgements are always pooled.
if (type == currentDrawableType)
return;
@ -139,16 +156,13 @@ namespace osu.Game.Rulesets.Judgements
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Child = bodyDrawable = new SkinnableDrawable(new GameplaySkinComponent<HitResult>(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<HitResult>(type), _ =>
CreateDefaultJudgement(type), confineMode: ConfineMode.NoScaling)
});
currentDrawableType = type;
}
protected virtual Drawable CreateDefaultJudgement(HitResult result) => new DefaultJudgementPiece(result);
}
}

View File

@ -0,0 +1,13 @@
// 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.
namespace osu.Game.Rulesets.Judgements
{
/// <summary>
/// A skinnable judgement element which supports playing an animation from the current point in time.
/// </summary>
public interface IAnimatableJudgement
{
void PlayAnimation();
}
}

View File

@ -0,0 +1,58 @@
// 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;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osuTK;
namespace osu.Game.Skinning
{
public class LegacyJudgementPiece : CompositeDrawable, IAnimatableJudgement
{
private readonly HitResult result;
public LegacyJudgementPiece(HitResult result, Drawable drawable)
{
this.result = result;
AutoSizeAxes = Axes.Both;
Origin = Anchor.Centre;
InternalChild = drawable;
}
public virtual void PlayAnimation()
{
var animation = InternalChild as IFramedAnimation;
animation?.GotoFrame(0);
this.RotateTo(0);
this.MoveTo(Vector2.Zero);
// legacy judgements don't play any transforms if they are an animation.
if (animation?.FrameCount > 1)
return;
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;
}
}
}
}

View File

@ -371,20 +371,9 @@ namespace osu.Game.Skinning
}
case GameplaySkinComponent<HitResult> resultComponent:
switch (resultComponent.Component)
{
case HitResult.Miss:
return this.GetAnimation("hit0", true, false);
case HitResult.Meh:
return this.GetAnimation("hit50", true, false);
case HitResult.Ok:
return this.GetAnimation("hit100", true, false);
case HitResult.Great:
return this.GetAnimation("hit300", true, false);
}
var drawable = getJudgementAnimation(resultComponent.Component);
if (drawable != null)
return new LegacyJudgementPiece(resultComponent.Component, drawable);
break;
}
@ -392,6 +381,26 @@ namespace osu.Game.Skinning
return this.GetAnimation(component.LookupName, false, false);
}
private Drawable getJudgementAnimation(HitResult result)
{
switch (result)
{
case HitResult.Miss:
return this.GetAnimation("hit0", true, false);
case HitResult.Meh:
return this.GetAnimation("hit50", true, false);
case HitResult.Ok:
return this.GetAnimation("hit100", true, false);
case HitResult.Great:
return this.GetAnimation("hit300", true, false);
}
return null;
}
public override Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
{
foreach (var name in getFallbackNames(componentName))