2019-07-24 18:50:57 +09:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-01-24 17:43:03 +09:00
// See the LICENCE file in the repository root for full licence text.
2018-04-13 18:19:50 +09:00
2020-03-10 15:30:24 +09:00
using System ;
2018-04-13 18:19:50 +09:00
using osu.Game.Rulesets.Objects.Drawables ;
using osu.Framework.Graphics ;
2018-08-02 20:36:38 +09:00
using osu.Game.Rulesets.Judgements ;
using osu.Game.Rulesets.Osu.Judgements ;
2018-07-05 15:48:54 +02:00
using osu.Game.Graphics.Containers ;
2020-04-13 13:00:03 +09:00
using osu.Game.Rulesets.Osu.UI ;
2020-03-19 19:16:24 +09:00
using osu.Game.Rulesets.Scoring ;
2018-04-13 18:19:50 +09:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public class DrawableOsuHitObject : DrawableHitObject < OsuHitObject >
{
2018-07-05 15:48:54 +02:00
private readonly ShakeContainer shakeContainer ;
2019-06-30 18:28:20 +03:00
// Must be set to update IsHovered as it's used in relax mdo to detect osu hit objects.
2019-06-30 18:27:47 +03:00
public override bool HandlePositionalInput = > true ;
2020-04-13 13:00:03 +09:00
protected override float SamplePlaybackPosition = > HitObject . X / OsuPlayfield . BASE_SIZE . X ;
2020-04-12 01:33:25 +02:00
2020-03-10 15:30:24 +09:00
/// <summary>
2020-08-31 13:33:41 +09:00
/// Whether this <see cref="DrawableOsuHitObject"/> can be hit, given a time value.
2020-03-18 19:13:25 +09:00
/// If non-null, judgements will be ignored (resulting in a shake) whilst the function returns false.
2020-03-10 15:30:24 +09:00
/// </summary>
2020-04-10 02:02:09 +09:00
public Func < DrawableHitObject , double , bool > CheckHittable ;
2020-03-10 15:30:24 +09:00
2018-04-13 18:19:50 +09:00
protected DrawableOsuHitObject ( OsuHitObject hitObject )
: base ( hitObject )
{
2018-12-04 20:33:29 +09:00
base . AddInternal ( shakeContainer = new ShakeContainer
{
ShakeDuration = 30 ,
RelativeSizeAxes = Axes . Both
} ) ;
2019-07-16 13:45:59 +09:00
2018-04-13 18:19:50 +09:00
Alpha = 0 ;
}
2018-07-06 13:02:00 +09:00
// Forward all internal management to shakeContainer.
// This is a bit ugly but we don't have the concept of InternalContent so it'll have to do for now. (https://github.com/ppy/osu-framework/issues/1690)
2018-07-05 15:48:54 +02:00
protected override void AddInternal ( Drawable drawable ) = > shakeContainer . Add ( drawable ) ;
protected override void ClearInternal ( bool disposeChildren = true ) = > shakeContainer . Clear ( disposeChildren ) ;
protected override bool RemoveInternal ( Drawable drawable ) = > shakeContainer . Remove ( drawable ) ;
2019-07-22 15:05:56 +09:00
protected sealed override double InitialLifetimeOffset = > HitObject . TimePreempt ;
2018-08-02 20:36:38 +09:00
2018-04-13 18:19:50 +09:00
private OsuInputManager osuActionInputManager ;
2019-11-12 18:35:08 +08:00
internal OsuInputManager OsuActionInputManager = > osuActionInputManager ? ? = GetContainingInputManager ( ) as OsuInputManager ;
2018-06-28 15:33:59 +02:00
2018-07-06 17:24:30 +09:00
protected virtual void Shake ( double maximumLength ) = > shakeContainer . Shake ( maximumLength ) ;
2018-04-13 18:19:50 +09:00
2019-09-13 18:49:21 +09:00
protected override void UpdateStateTransforms ( ArmedState state )
2019-09-12 19:29:08 +09:00
{
2019-09-13 18:49:21 +09:00
base . UpdateStateTransforms ( state ) ;
2019-09-12 19:29:08 +09:00
2019-09-13 18:49:21 +09:00
switch ( state )
{
case ArmedState . Idle :
// Manually set to reduce the number of future alive objects to a bare minimum.
LifetimeStart = HitObject . StartTime - HitObject . TimePreempt ;
break ;
}
2019-09-12 19:29:08 +09:00
}
2020-03-19 19:16:24 +09:00
/// <summary>
/// Causes this <see cref="DrawableOsuHitObject"/> to get missed, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
public void MissForcefully ( ) = > ApplyResult ( r = > r . Type = HitResult . Miss ) ;
2019-09-02 17:14:40 +09:00
protected override JudgementResult CreateResult ( Judgement judgement ) = > new OsuJudgementResult ( HitObject , judgement ) ;
2018-04-13 18:19:50 +09:00
}
}