2019-07-24 09:50:57 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-01-24 08:43:03 +00:00
// See the LICENCE file in the repository root for full licence text.
2018-04-13 09:19:50 +00:00
2022-06-17 07:37:17 +00:00
#nullable disable
2020-03-10 06:30:24 +00:00
using System ;
2020-11-05 04:51:46 +00:00
using osu.Framework.Allocation ;
using osu.Framework.Bindables ;
2017-07-14 16:18:12 +00:00
using osu.Framework.Graphics ;
2022-04-18 04:57:13 +00:00
using osu.Framework.Graphics.Primitives ;
2018-08-02 11:36:38 +00:00
using osu.Game.Rulesets.Judgements ;
2022-09-22 05:30:01 +00:00
using osu.Game.Rulesets.Objects.Drawables ;
2018-08-02 11:36:38 +00:00
using osu.Game.Rulesets.Osu.Judgements ;
2022-10-05 05:25:04 +00:00
using osu.Game.Rulesets.Osu.Scoring ;
2020-11-05 04:51:46 +00:00
using osuTK ;
2022-10-04 08:28:15 +00:00
using osuTK.Graphics ;
2018-04-13 09:19:50 +00:00
2017-04-18 07:05:58 +00:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
2016-11-19 07:19:26 +00:00
{
2022-09-21 14:38:02 +00:00
public abstract partial class DrawableOsuHitObject : DrawableHitObject < OsuHitObject >
2016-11-19 07:19:26 +00:00
{
2020-11-05 04:51:46 +00:00
public readonly IBindable < Vector2 > PositionBindable = new Bindable < Vector2 > ( ) ;
public readonly IBindable < int > StackHeightBindable = new Bindable < int > ( ) ;
public readonly IBindable < float > ScaleBindable = new BindableFloat ( ) ;
public readonly IBindable < int > IndexInCurrentComboBindable = new Bindable < int > ( ) ;
2018-07-05 13:48:54 +00:00
2022-04-08 06:20:22 +00:00
// Must be set to update IsHovered as it's used in relax mod to detect osu hit objects.
2019-06-30 15:27:47 +00:00
public override bool HandlePositionalInput = > true ;
2022-04-18 06:18:56 +00:00
protected override float SamplePlaybackPosition = > CalculateDrawableRelativePosition ( this ) ;
2020-04-11 23:33:25 +00:00
2020-03-10 06:30:24 +00:00
/// <summary>
2020-08-31 04:33:41 +00:00
/// Whether this <see cref="DrawableOsuHitObject"/> can be hit, given a time value.
2020-03-18 10:13:25 +00:00
/// If non-null, judgements will be ignored (resulting in a shake) whilst the function returns false.
2020-03-10 06:30:24 +00:00
/// </summary>
2020-04-09 17:02:09 +00:00
public Func < DrawableHitObject , double , bool > CheckHittable ;
2020-03-10 06:30:24 +00:00
2017-03-23 06:37:16 +00:00
protected DrawableOsuHitObject ( OsuHitObject hitObject )
2016-11-26 07:51:51 +00:00
: base ( hitObject )
{
2020-11-05 04:51:46 +00:00
}
[BackgroundDependencyLoader]
private void load ( )
{
Alpha = 0 ;
2020-11-06 14:09:23 +00:00
}
2020-11-27 01:13:05 +00:00
protected override void OnApply ( )
2020-11-06 14:09:23 +00:00
{
2020-11-27 01:13:05 +00:00
base . OnApply ( ) ;
2019-07-16 04:45:59 +00:00
2020-11-05 04:51:46 +00:00
IndexInCurrentComboBindable . BindTo ( HitObject . IndexInCurrentComboBindable ) ;
PositionBindable . BindTo ( HitObject . PositionBindable ) ;
StackHeightBindable . BindTo ( HitObject . StackHeightBindable ) ;
ScaleBindable . BindTo ( HitObject . ScaleBindable ) ;
2016-11-26 07:51:51 +00:00
}
2018-04-13 09:19:50 +00:00
2020-11-27 01:13:05 +00:00
protected override void OnFree ( )
2020-11-06 15:40:26 +00:00
{
2020-11-27 01:13:05 +00:00
base . OnFree ( ) ;
2020-11-06 15:40:26 +00:00
IndexInCurrentComboBindable . UnbindFrom ( HitObject . IndexInCurrentComboBindable ) ;
PositionBindable . UnbindFrom ( HitObject . PositionBindable ) ;
StackHeightBindable . UnbindFrom ( HitObject . StackHeightBindable ) ;
ScaleBindable . UnbindFrom ( HitObject . ScaleBindable ) ;
}
2022-10-04 08:28:15 +00:00
protected override void UpdateInitialTransforms ( )
{
base . UpdateInitialTransforms ( ) ;
2022-10-05 08:48:56 +00:00
// Dim should only be applied at a top level, as it will be implicitly applied to nested objects.
if ( ParentHitObject = = null )
{
// Of note, no one noticed this was missing for years, but it definitely feels like it should still exist.
// For now this is applied across all skins, and matches stable.
// For simplicity, dim colour is applied to the DrawableHitObject itself.
// We may need to make a nested container setup if this even causes a usage conflict (ie. with a mod).
this . FadeColour ( new Color4 ( 195 , 195 , 195 , 255 ) ) ;
using ( BeginDelayedSequence ( InitialLifetimeOffset - OsuHitWindows . MISS_WINDOW ) )
this . FadeColour ( Color4 . White , 100 ) ;
}
2022-10-04 08:28:15 +00:00
}
2019-07-22 06:05:56 +00:00
protected sealed override double InitialLifetimeOffset = > HitObject . TimePreempt ;
2018-08-02 11:36:38 +00:00
2017-08-18 10:02:08 +00:00
private OsuInputManager osuActionInputManager ;
2019-11-12 10:35:08 +00:00
internal OsuInputManager OsuActionInputManager = > osuActionInputManager ? ? = GetContainingInputManager ( ) as OsuInputManager ;
2018-06-28 13:33:59 +00:00
2022-09-22 05:30:01 +00:00
/// <summary>
/// Shake the hit object in case it was clicked far too early or late (aka "note lock").
/// </summary>
public virtual void Shake ( ) { }
2018-04-13 09:19:50 +00:00
2020-03-19 10:16:24 +00:00
/// <summary>
/// Causes this <see cref="DrawableOsuHitObject"/> to get missed, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
2020-10-02 20:58:10 +00:00
public void MissForcefully ( ) = > ApplyResult ( r = > r . Type = r . Judgement . MinResult ) ;
2020-03-19 10:16:24 +00:00
2022-04-18 06:18:56 +00:00
private RectangleF parentScreenSpaceRectangle = > ( ( DrawableOsuHitObject ) ParentHitObject ) ? . parentScreenSpaceRectangle ? ? Parent . ScreenSpaceDrawQuad . AABBFloat ;
/// <summary>
/// Calculates the position of the given <paramref name="drawable"/> relative to the playfield area.
/// </summary>
/// <param name="drawable">The drawable to calculate its relative position.</param>
protected float CalculateDrawableRelativePosition ( Drawable drawable ) = > ( drawable . ScreenSpaceDrawQuad . Centre . X - parentScreenSpaceRectangle . X ) / parentScreenSpaceRectangle . Width ;
2019-09-02 08:14:40 +00:00
protected override JudgementResult CreateResult ( Judgement judgement ) = > new OsuJudgementResult ( HitObject , judgement ) ;
2016-11-19 07:19:26 +00:00
}
}