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
|
|
|
|
|
|
2018-08-03 07:56:46 +00:00
|
|
|
|
using System;
|
2019-09-02 09:31:33 +00:00
|
|
|
|
using System.Diagnostics;
|
2017-04-04 03:38:55 +00:00
|
|
|
|
using System.Linq;
|
2020-12-14 21:53:46 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2020-05-26 05:43:38 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-03-28 01:33:23 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-09-16 09:26:12 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2017-04-18 07:05:58 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2017-12-30 20:23:18 +00:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2020-12-07 03:30:25 +00:00
|
|
|
|
using osu.Game.Rulesets.Taiko.Skinning.Default;
|
2020-04-27 07:13:28 +00:00
|
|
|
|
using osu.Game.Skinning;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-18 07:05:58 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
2017-03-17 07:55:57 +00:00
|
|
|
|
{
|
2020-12-14 20:47:31 +00:00
|
|
|
|
public partial class DrawableHit : DrawableTaikoStrongableHitObject<Hit, Hit.StrongNestedHit>
|
2017-03-17 07:55:57 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A list of keys which can result in hits for this HitObject.
|
|
|
|
|
/// </summary>
|
2020-05-26 05:43:38 +00:00
|
|
|
|
public TaikoAction[] HitActions { get; private set; }
|
2018-08-02 11:36:08 +00:00
|
|
|
|
|
2017-03-17 07:55:57 +00:00
|
|
|
|
/// <summary>
|
2018-08-03 07:12:38 +00:00
|
|
|
|
/// The action that caused this <see cref="DrawableHit"/> to be hit.
|
2017-03-17 07:55:57 +00:00
|
|
|
|
/// </summary>
|
2020-04-27 07:13:28 +00:00
|
|
|
|
public TaikoAction? HitAction
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
2018-08-03 07:12:38 +00:00
|
|
|
|
|
|
|
|
|
private bool validActionPressed;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-28 08:18:34 +00:00
|
|
|
|
private bool pressHandledThisFrame;
|
2018-09-25 09:37:25 +00:00
|
|
|
|
|
2020-12-14 21:53:46 +00:00
|
|
|
|
private readonly Bindable<HitType> type = new Bindable<HitType>();
|
2020-05-26 05:43:38 +00:00
|
|
|
|
|
2020-12-14 21:53:46 +00:00
|
|
|
|
public DrawableHit()
|
|
|
|
|
: this(null)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DrawableHit([CanBeNull] Hit hit)
|
2017-03-24 05:59:59 +00:00
|
|
|
|
: base(hit)
|
2017-03-17 07:55:57 +00:00
|
|
|
|
{
|
2017-08-03 04:24:13 +00:00
|
|
|
|
FillMode = FillMode.Fit;
|
2020-05-26 05:43:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 21:53:46 +00:00
|
|
|
|
protected override void OnApply()
|
2020-05-26 05:43:38 +00:00
|
|
|
|
{
|
2020-12-14 21:53:46 +00:00
|
|
|
|
type.BindTo(HitObject.TypeBindable);
|
2021-05-21 07:10:48 +00:00
|
|
|
|
// this doesn't need to be run inline as RecreatePieces is called by the base call below.
|
2021-05-21 07:45:28 +00:00
|
|
|
|
type.BindValueChanged(_ => Scheduler.AddOnce(RecreatePieces));
|
2020-12-14 21:53:46 +00:00
|
|
|
|
|
|
|
|
|
base.OnApply();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-21 07:10:48 +00:00
|
|
|
|
protected override void RecreatePieces()
|
|
|
|
|
{
|
|
|
|
|
updateActionsFromType();
|
|
|
|
|
base.RecreatePieces();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 21:53:46 +00:00
|
|
|
|
protected override void OnFree()
|
|
|
|
|
{
|
|
|
|
|
base.OnFree();
|
|
|
|
|
|
|
|
|
|
type.UnbindFrom(HitObject.TypeBindable);
|
|
|
|
|
type.UnbindEvents();
|
|
|
|
|
|
|
|
|
|
UnproxyContent();
|
|
|
|
|
|
|
|
|
|
HitActions = null;
|
|
|
|
|
HitAction = null;
|
|
|
|
|
validActionPressed = pressHandledThisFrame = false;
|
2020-09-23 08:57:57 +00:00
|
|
|
|
}
|
2020-04-27 07:13:28 +00:00
|
|
|
|
|
2020-09-23 08:57:57 +00:00
|
|
|
|
private void updateActionsFromType()
|
2020-05-26 05:43:38 +00:00
|
|
|
|
{
|
2020-04-27 07:13:28 +00:00
|
|
|
|
HitActions =
|
|
|
|
|
HitObject.Type == HitType.Centre
|
|
|
|
|
? new[] { TaikoAction.LeftCentre, TaikoAction.RightCentre }
|
|
|
|
|
: new[] { TaikoAction.LeftRim, TaikoAction.RightRim };
|
2017-03-17 07:55:57 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-04-27 07:13:28 +00:00
|
|
|
|
protected override SkinnableDrawable CreateMainPiece() => HitObject.Type == HitType.Centre
|
2022-11-09 07:04:56 +00:00
|
|
|
|
? new SkinnableDrawable(new TaikoSkinComponentLookup(TaikoSkinComponents.CentreHit), _ => new CentreHitCirclePiece(), confineMode: ConfineMode.ScaleToFit)
|
|
|
|
|
: new SkinnableDrawable(new TaikoSkinComponentLookup(TaikoSkinComponents.RimHit), _ => new RimHitCirclePiece(), confineMode: ConfineMode.ScaleToFit);
|
2020-04-27 07:13:28 +00:00
|
|
|
|
|
2018-08-06 02:31:46 +00:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2017-03-17 07:55:57 +00:00
|
|
|
|
{
|
2019-09-02 09:31:33 +00:00
|
|
|
|
Debug.Assert(HitObject.HitWindows != null);
|
|
|
|
|
|
2017-03-17 07:55:57 +00:00
|
|
|
|
if (!userTriggered)
|
|
|
|
|
{
|
2018-02-02 09:53:30 +00:00
|
|
|
|
if (!HitObject.HitWindows.CanBeHit(timeOffset))
|
2020-10-02 20:58:10 +00:00
|
|
|
|
ApplyResult(r => r.Type = r.Judgement.MinResult);
|
2017-03-17 07:55:57 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-02-08 05:15:47 +00:00
|
|
|
|
var result = HitObject.HitWindows.ResultFor(timeOffset);
|
2018-12-06 12:04:54 +00:00
|
|
|
|
if (result == HitResult.None)
|
2017-03-17 07:55:57 +00:00
|
|
|
|
return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-08-03 07:12:38 +00:00
|
|
|
|
if (!validActionPressed)
|
2020-10-02 20:58:10 +00:00
|
|
|
|
ApplyResult(r => r.Type = r.Judgement.MinResult);
|
2018-02-02 09:53:30 +00:00
|
|
|
|
else
|
2018-08-03 07:12:38 +00:00
|
|
|
|
ApplyResult(r => r.Type = result);
|
2017-03-17 07:55:57 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public override bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
|
2017-03-17 07:55:57 +00:00
|
|
|
|
{
|
2018-09-28 08:18:34 +00:00
|
|
|
|
if (pressHandledThisFrame)
|
2018-09-25 09:37:25 +00:00
|
|
|
|
return true;
|
2018-08-03 07:12:38 +00:00
|
|
|
|
if (Judged)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
validActionPressed = HitActions.Contains(e.Action);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-12-08 08:42:10 +00:00
|
|
|
|
// Only count this as handled if the new judgement is a hit
|
2021-10-27 04:04:41 +00:00
|
|
|
|
bool result = UpdateResult(true);
|
2018-08-03 07:12:38 +00:00
|
|
|
|
if (IsHit)
|
2021-09-16 09:26:12 +00:00
|
|
|
|
HitAction = e.Action;
|
2018-08-03 07:12:38 +00:00
|
|
|
|
|
2018-09-25 09:37:25 +00:00
|
|
|
|
// Regardless of whether we've hit or not, any secondary key presses in the same frame should be discarded
|
|
|
|
|
// E.g. hitting a non-strong centre as a strong should not fall through and perform a hit on the next note
|
2018-09-28 08:18:34 +00:00
|
|
|
|
pressHandledThisFrame = true;
|
2018-08-03 07:12:38 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public override void OnReleased(KeyBindingReleaseEvent<TaikoAction> e)
|
2018-08-03 07:12:38 +00:00
|
|
|
|
{
|
2021-09-16 09:26:12 +00:00
|
|
|
|
if (e.Action == HitAction)
|
2018-08-03 07:12:38 +00:00
|
|
|
|
HitAction = null;
|
2021-09-16 09:26:12 +00:00
|
|
|
|
base.OnReleased(e);
|
2017-03-17 07:55:57 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-08-22 11:51:53 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-25 09:37:25 +00:00
|
|
|
|
// The input manager processes all input prior to us updating, so this is the perfect time
|
|
|
|
|
// for us to remove the extra press blocking, before input is handled in the next frame
|
2018-09-28 08:18:34 +00:00
|
|
|
|
pressHandledThisFrame = false;
|
2017-08-22 11:51:53 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-11-04 07:19:07 +00:00
|
|
|
|
protected override void UpdateHitStateTransforms(ArmedState state)
|
2017-03-28 01:33:23 +00:00
|
|
|
|
{
|
2019-09-02 09:31:33 +00:00
|
|
|
|
Debug.Assert(HitObject.HitWindows != null);
|
|
|
|
|
|
2019-08-27 02:03:56 +00:00
|
|
|
|
switch (state)
|
2017-03-28 01:33:23 +00:00
|
|
|
|
{
|
2019-08-27 02:03:56 +00:00
|
|
|
|
case ArmedState.Idle:
|
|
|
|
|
validActionPressed = false;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2019-08-27 02:03:56 +00:00
|
|
|
|
UnproxyContent();
|
|
|
|
|
break;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2019-08-27 02:03:56 +00:00
|
|
|
|
case ArmedState.Miss:
|
2019-09-12 10:29:08 +00:00
|
|
|
|
this.FadeOut(100);
|
2019-08-27 02:03:56 +00:00
|
|
|
|
break;
|
2018-06-11 12:45:19 +00:00
|
|
|
|
|
2019-08-27 02:03:56 +00:00
|
|
|
|
case ArmedState.Hit:
|
2022-11-08 06:19:08 +00:00
|
|
|
|
// If we're far enough away from the left stage, we should bring ourselves in front of it
|
2019-08-27 02:03:56 +00:00
|
|
|
|
ProxyContent();
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2019-08-27 02:03:56 +00:00
|
|
|
|
const float gravity_time = 300;
|
|
|
|
|
const float gravity_travel_height = 200;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-02-09 08:57:51 +00:00
|
|
|
|
if (SnapJudgementLocation)
|
|
|
|
|
MainPiece.MoveToX(-X);
|
2023-02-06 13:34:54 +00:00
|
|
|
|
|
2019-08-27 02:03:56 +00:00
|
|
|
|
this.ScaleTo(0.8f, gravity_time * 2, Easing.OutQuad);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-08-27 02:03:56 +00:00
|
|
|
|
this.MoveToY(-gravity_travel_height, gravity_time, Easing.Out)
|
|
|
|
|
.Then()
|
|
|
|
|
.MoveToY(gravity_travel_height * 2, gravity_time * 2, Easing.In);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-09-12 10:29:08 +00:00
|
|
|
|
this.FadeOut(800);
|
2019-08-27 02:03:56 +00:00
|
|
|
|
break;
|
2017-03-28 01:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 07:12:38 +00:00
|
|
|
|
|
2020-12-14 22:21:19 +00:00
|
|
|
|
protected override DrawableStrongNestedHit CreateStrongNestedHit(Hit.StrongNestedHit hitObject) => new StrongNestedHit(hitObject);
|
2018-08-03 07:56:46 +00:00
|
|
|
|
|
2020-12-20 17:02:31 +00:00
|
|
|
|
public partial class StrongNestedHit : DrawableStrongNestedHit
|
2018-08-03 07:56:46 +00:00
|
|
|
|
{
|
2020-12-14 22:21:19 +00:00
|
|
|
|
public new DrawableHit ParentHitObject => (DrawableHit)base.ParentHitObject;
|
|
|
|
|
|
2018-08-03 07:56:46 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The lenience for the second key press.
|
|
|
|
|
/// This does not adjust by map difficulty in ScoreV2 yet.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const double second_hit_window = 30;
|
|
|
|
|
|
2020-12-14 22:21:19 +00:00
|
|
|
|
public StrongNestedHit()
|
|
|
|
|
: this(null)
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-08-03 07:56:46 +00:00
|
|
|
|
|
2020-12-14 22:21:19 +00:00
|
|
|
|
public StrongNestedHit([CanBeNull] Hit.StrongNestedHit nestedHit)
|
|
|
|
|
: base(nestedHit)
|
2018-08-03 07:56:46 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 02:31:46 +00:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-08-03 07:56:46 +00:00
|
|
|
|
{
|
2020-12-14 22:21:19 +00:00
|
|
|
|
if (!ParentHitObject.Result.HasResult)
|
2018-08-03 07:56:46 +00:00
|
|
|
|
{
|
2018-08-06 02:31:46 +00:00
|
|
|
|
base.CheckForResult(userTriggered, timeOffset);
|
2018-08-03 07:56:46 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 22:21:19 +00:00
|
|
|
|
if (!ParentHitObject.Result.IsHit)
|
2018-08-03 07:56:46 +00:00
|
|
|
|
{
|
2020-09-29 06:13:11 +00:00
|
|
|
|
ApplyResult(r => r.Type = r.Judgement.MinResult);
|
2018-08-03 07:56:46 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-11-29 02:06:40 +00:00
|
|
|
|
|
2018-08-03 07:56:46 +00:00
|
|
|
|
if (!userTriggered)
|
|
|
|
|
{
|
2020-12-14 22:21:19 +00:00
|
|
|
|
if (timeOffset - ParentHitObject.Result.TimeOffset > second_hit_window)
|
2020-09-29 06:13:11 +00:00
|
|
|
|
ApplyResult(r => r.Type = r.Judgement.MinResult);
|
2018-08-03 07:56:46 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 22:21:19 +00:00
|
|
|
|
if (Math.Abs(timeOffset - ParentHitObject.Result.TimeOffset) <= second_hit_window)
|
2020-09-29 06:13:11 +00:00
|
|
|
|
ApplyResult(r => r.Type = r.Judgement.MaxResult);
|
2018-08-03 07:56:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public override bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
|
2018-08-03 07:56:46 +00:00
|
|
|
|
{
|
|
|
|
|
// Don't process actions until the main hitobject is hit
|
2020-12-14 22:21:19 +00:00
|
|
|
|
if (!ParentHitObject.IsHit)
|
2018-08-03 07:56:46 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Don't process actions if the pressed button was released
|
2020-12-14 22:21:19 +00:00
|
|
|
|
if (ParentHitObject.HitAction == null)
|
2018-08-03 07:56:46 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Don't handle invalid hit action presses
|
2021-09-16 09:26:12 +00:00
|
|
|
|
if (!ParentHitObject.HitActions.Contains(e.Action))
|
2018-08-03 07:56:46 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2018-08-06 02:31:46 +00:00
|
|
|
|
return UpdateResult(true);
|
2018-08-03 07:56:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-17 07:55:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|