2019-01-24 08:43:03 +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.
2018-04-13 09:19:50 +00:00
2022-06-17 07:37:17 +00:00
#nullable disable
2020-08-27 11:24:08 +00:00
using System ;
2018-07-02 03:31:41 +00:00
using JetBrains.Annotations ;
2018-06-08 11:13:24 +00:00
using osu.Framework.Allocation ;
2019-02-21 10:04:31 +00:00
using osu.Framework.Bindables ;
2018-01-10 10:17:43 +00:00
using osu.Framework.Graphics ;
2017-05-03 06:50:42 +00:00
using osu.Game.Rulesets.Objects.Drawables ;
2018-06-08 06:16:45 +00:00
using osu.Game.Rulesets.UI.Scrolling ;
2020-04-11 23:33:25 +00:00
using osu.Game.Rulesets.Mania.UI ;
2018-04-13 09:19:50 +00:00
2017-05-03 06:50:42 +00:00
namespace osu.Game.Rulesets.Mania.Objects.Drawables
{
2018-07-02 03:31:41 +00:00
public abstract partial class DrawableManiaHitObject : DrawableHitObject < ManiaHitObject >
2017-05-03 06:50:42 +00:00
{
2017-05-22 06:27:38 +00:00
/// <summary>
2018-07-02 03:31:41 +00:00
/// The <see cref="ManiaAction"/> which causes this <see cref="DrawableManiaHitObject{TObject}"/> to be hit.
2017-05-22 06:27:38 +00:00
/// </summary>
2018-07-02 03:31:41 +00:00
protected readonly IBindable < ManiaAction > Action = new Bindable < ManiaAction > ( ) ;
2018-04-13 09:19:50 +00:00
2018-06-08 12:41:20 +00:00
protected readonly IBindable < ScrollingDirection > Direction = new Bindable < ScrollingDirection > ( ) ;
2020-04-13 04:01:27 +00:00
[Resolved(canBeNull: true)]
2020-04-13 04:42:21 +00:00
private ManiaPlayfield playfield { get ; set ; }
2020-04-13 04:01:27 +00:00
2020-04-13 04:00:03 +00:00
protected override float SamplePlaybackPosition
2020-04-11 23:33:25 +00:00
{
get
{
2020-04-13 04:42:21 +00:00
if ( playfield = = null )
2020-04-13 04:01:27 +00:00
return base . SamplePlaybackPosition ;
2020-04-11 23:33:25 +00:00
2020-04-13 04:42:21 +00:00
return ( float ) HitObject . Column / playfield . TotalColumns ;
2020-04-11 23:33:25 +00:00
}
}
2020-08-31 04:33:41 +00:00
/// <summary>
/// Whether this <see cref="DrawableManiaHitObject"/> can be hit, given a time value.
2020-08-31 10:02:02 +00:00
/// If non-null, judgements will be ignored whilst the function returns false.
2020-08-31 04:33:41 +00:00
/// </summary>
2020-08-27 11:24:08 +00:00
public Func < DrawableHitObject , double , bool > CheckHittable ;
2018-07-02 03:31:41 +00:00
protected DrawableManiaHitObject ( ManiaHitObject hitObject )
2017-05-03 06:50:42 +00:00
: base ( hitObject )
{
2021-05-12 07:35:05 +00:00
RelativeSizeAxes = Axes . X ;
2017-05-03 06:50:42 +00:00
}
2018-06-07 05:27:59 +00:00
2018-07-02 03:31:41 +00:00
[BackgroundDependencyLoader(true)]
private void load ( [ CanBeNull ] IBindable < ManiaAction > action , [ NotNull ] IScrollingInfo scrollingInfo )
2018-06-08 12:41:20 +00:00
{
2018-07-02 03:31:41 +00:00
if ( action ! = null )
Action . BindTo ( action ) ;
2018-06-08 12:41:20 +00:00
Direction . BindTo ( scrollingInfo . Direction ) ;
2021-05-12 07:40:46 +00:00
}
protected override void LoadComplete ( )
{
base . LoadComplete ( ) ;
2018-06-08 12:41:20 +00:00
Direction . BindValueChanged ( OnDirectionChanged , true ) ;
}
2019-02-21 09:56:34 +00:00
protected virtual void OnDirectionChanged ( ValueChangedEvent < ScrollingDirection > e )
2018-06-08 11:13:24 +00:00
{
2019-02-21 09:56:34 +00:00
Anchor = Origin = e . NewValue = = ScrollingDirection . Up ? Anchor . TopCentre : Anchor . BottomCentre ;
2018-06-08 11:13:24 +00:00
}
2019-07-22 06:55:38 +00:00
2020-11-04 07:19:07 +00:00
protected override void UpdateHitStateTransforms ( ArmedState state )
2018-06-07 05:27:59 +00:00
{
switch ( state )
{
case ArmedState . Miss :
2019-09-12 10:29:08 +00:00
this . FadeOut ( 150 , Easing . In ) ;
2018-06-07 05:27:59 +00:00
break ;
2019-04-01 03:44:46 +00:00
2018-06-07 05:27:59 +00:00
case ArmedState . Hit :
2020-08-21 14:56:27 +00:00
this . FadeOut ( ) ;
2018-06-07 05:27:59 +00:00
break ;
}
}
2020-08-27 11:24:08 +00:00
/// <summary>
/// Causes this <see cref="DrawableManiaHitObject"/> to get missed, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
2024-02-05 12:21:01 +00:00
public virtual void MissForcefully ( ) = > ApplyMinResult ( ) ;
2017-05-03 06:50:42 +00:00
}
2019-08-26 19:06:30 +00:00
public abstract partial class DrawableManiaHitObject < TObject > : DrawableManiaHitObject
where TObject : ManiaHitObject
{
2021-05-12 07:35:05 +00:00
public new TObject HitObject = > ( TObject ) base . HitObject ;
2019-08-26 19:06:30 +00:00
protected DrawableManiaHitObject ( TObject hitObject )
: base ( hitObject )
{
}
}
2017-05-03 06:50:42 +00:00
}