2020-11-18 06:38:26 +00:00
// 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 System ;
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Animations ;
using osu.Framework.Graphics.Containers ;
2020-11-19 06:47:02 +00:00
using osu.Framework.Graphics.Textures ;
2020-11-18 08:15:45 +00:00
using osu.Framework.Utils ;
2020-11-19 06:47:02 +00:00
using osu.Game.Graphics ;
2020-11-18 06:38:26 +00:00
using osu.Game.Rulesets.Judgements ;
using osu.Game.Rulesets.Scoring ;
using osuTK ;
namespace osu.Game.Skinning
{
public partial class LegacyJudgementPieceNew : CompositeDrawable , IAnimatableJudgement
{
private readonly HitResult result ;
2022-11-09 04:44:59 +00:00
private readonly LegacyJudgementPieceOld ? temporaryOldStyle ;
2020-11-18 06:38:26 +00:00
private readonly Drawable mainPiece ;
2022-11-09 04:44:59 +00:00
private readonly ParticleExplosion ? particles ;
2020-11-19 06:47:02 +00:00
2022-11-09 04:44:59 +00:00
public LegacyJudgementPieceNew ( HitResult result , Func < Drawable > createMainDrawable , Texture ? particleTexture )
2020-11-18 06:38:26 +00:00
{
this . result = result ;
AutoSizeAxes = Axes . Both ;
Origin = Anchor . Centre ;
InternalChildren = new [ ]
{
mainPiece = createMainDrawable ( ) . With ( d = >
{
d . Anchor = Anchor . Centre ;
d . Origin = Anchor . Centre ;
} )
} ;
2020-11-19 06:47:02 +00:00
if ( particleTexture ! = null )
{
AddInternal ( particles = new ParticleExplosion ( particleTexture , 150 , 1600 )
{
Size = new Vector2 ( 140 ) ,
Depth = float . MaxValue ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
} ) ;
}
2020-11-18 06:38:26 +00:00
if ( result ! = HitResult . Miss )
{
//new judgement shows old as a temporary effect
2022-09-12 09:53:37 +00:00
AddInternal ( temporaryOldStyle = new LegacyJudgementPieceOld ( result , createMainDrawable , 1.05f , true )
2020-11-18 06:38:26 +00:00
{
Blending = BlendingParameters . Additive ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
} ) ;
}
}
public void PlayAnimation ( )
{
var animation = mainPiece as IFramedAnimation ;
animation ? . GotoFrame ( 0 ) ;
2020-11-19 06:47:02 +00:00
if ( particles ! = null )
{
// start the particles already some way into their animation to break cluster away from centre.
2021-07-05 15:52:39 +00:00
using ( particles . BeginDelayedSequence ( - 100 ) )
2020-11-19 06:47:02 +00:00
particles . Restart ( ) ;
}
2020-11-18 08:15:45 +00:00
const double fade_in_length = 120 ;
const double fade_out_delay = 500 ;
const double fade_out_length = 600 ;
2020-11-18 06:38:26 +00:00
2020-11-18 08:15:45 +00:00
this . FadeInFromZero ( fade_in_length ) ;
this . Delay ( fade_out_delay ) . FadeOut ( fade_out_length ) ;
// new style non-miss judgements show the original style temporarily, with additive colour.
2020-11-18 06:38:26 +00:00
if ( temporaryOldStyle ! = null )
{
temporaryOldStyle . PlayAnimation ( ) ;
temporaryOldStyle . Hide ( ) ;
temporaryOldStyle . Delay ( - 16 )
. FadeTo ( 0.5f , 56 , Easing . Out ) . Then ( )
. FadeOut ( 300 ) ;
}
// legacy judgements don't play any transforms if they are an animation.
if ( animation ? . FrameCount > 1 )
return ;
switch ( result )
{
case HitResult . Miss :
2020-11-18 08:15:45 +00:00
this . ScaleTo ( 1.6f ) ;
this . ScaleTo ( 1 , 100 , Easing . In ) ;
//todo: this only applies to osu! ruleset apparently.
this . MoveTo ( new Vector2 ( 0 , - 2 ) ) ;
this . MoveToOffset ( new Vector2 ( 0 , 20 ) , fade_out_delay + fade_out_length , Easing . In ) ;
2020-11-18 06:38:26 +00:00
2020-11-18 08:15:45 +00:00
float rotation = RNG . NextSingle ( - 8.6f , 8.6f ) ;
2020-11-18 06:38:26 +00:00
2020-11-18 08:15:45 +00:00
this . RotateTo ( 0 ) ;
this . RotateTo ( rotation , fade_in_length )
. Then ( ) . RotateTo ( rotation * 2 , fade_out_delay + fade_out_length - fade_in_length , Easing . In ) ;
2020-11-18 06:38:26 +00:00
break ;
default :
mainPiece . ScaleTo ( 0.9f ) ;
2020-11-18 08:15:45 +00:00
mainPiece . ScaleTo ( 1.05f , fade_out_delay + fade_out_length ) ;
2020-11-18 06:38:26 +00:00
break ;
}
}
2020-11-20 07:14:38 +00:00
2022-11-09 04:44:59 +00:00
public Drawable ? GetAboveHitObjectsProxiedContent ( ) = > temporaryOldStyle ? . CreateProxy ( ) ; // for new style judgements, only the old style temporary display is in front of objects.
2020-11-18 06:38:26 +00:00
}
}