2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
2018-08-03 15:56:46 +08:00
|
|
|
|
using System;
|
2020-05-11 11:53:54 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-09-02 17:31:33 +08:00
|
|
|
|
using System.Diagnostics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Graphics;
|
2020-05-11 11:53:54 +08:00
|
|
|
|
using osu.Game.Audio;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
|
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
|
2020-04-27 15:13:28 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|
|
|
|
{
|
2020-04-27 15:13:28 +08:00
|
|
|
|
public class DrawableHit : DrawableTaikoHitObject<Hit>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A list of keys which can result in hits for this HitObject.
|
|
|
|
|
/// </summary>
|
2020-04-27 15:13:28 +08:00
|
|
|
|
public TaikoAction[] HitActions { get; }
|
2018-08-02 19:36:08 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// <summary>
|
2018-08-03 15:12:38 +08:00
|
|
|
|
/// The action that caused this <see cref="DrawableHit"/> to be hit.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// </summary>
|
2020-04-27 15:13:28 +08:00
|
|
|
|
public TaikoAction? HitAction
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
2018-08-03 15:12:38 +08:00
|
|
|
|
|
|
|
|
|
private bool validActionPressed;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-28 16:18:34 +08:00
|
|
|
|
private bool pressHandledThisFrame;
|
2018-09-25 17:37:25 +08:00
|
|
|
|
|
2020-04-27 15:13:28 +08:00
|
|
|
|
public DrawableHit(Hit hit)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
: base(hit)
|
|
|
|
|
{
|
|
|
|
|
FillMode = FillMode.Fit;
|
2020-04-27 15:13:28 +08:00
|
|
|
|
|
|
|
|
|
HitActions =
|
|
|
|
|
HitObject.Type == HitType.Centre
|
|
|
|
|
? new[] { TaikoAction.LeftCentre, TaikoAction.RightCentre }
|
|
|
|
|
: new[] { TaikoAction.LeftRim, TaikoAction.RightRim };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 15:13:28 +08:00
|
|
|
|
protected override SkinnableDrawable CreateMainPiece() => HitObject.Type == HitType.Centre
|
|
|
|
|
? new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.CentreHit), _ => new CentreHitCirclePiece(), confineMode: ConfineMode.ScaleToFit)
|
|
|
|
|
: new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.RimHit), _ => new RimHitCirclePiece(), confineMode: ConfineMode.ScaleToFit);
|
|
|
|
|
|
2020-05-11 11:53:54 +08:00
|
|
|
|
protected override IEnumerable<HitSampleInfo> GetSamples()
|
|
|
|
|
{
|
|
|
|
|
// normal and claps are always handled by the drum (see DrumSampleMapping).
|
|
|
|
|
return HitObject.Samples.Where(s => s.Name != HitSampleInfo.HIT_NORMAL && s.Name != HitSampleInfo.HIT_CLAP);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 10:31:46 +08:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-09-02 17:31:33 +08:00
|
|
|
|
Debug.Assert(HitObject.HitWindows != null);
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (!userTriggered)
|
|
|
|
|
{
|
|
|
|
|
if (!HitObject.HitWindows.CanBeHit(timeOffset))
|
2018-08-03 15:12:38 +08:00
|
|
|
|
ApplyResult(r => r.Type = HitResult.Miss);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = HitObject.HitWindows.ResultFor(timeOffset);
|
2018-12-06 20:04:54 +08:00
|
|
|
|
if (result == HitResult.None)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2018-08-03 15:12:38 +08:00
|
|
|
|
if (!validActionPressed)
|
|
|
|
|
ApplyResult(r => r.Type = HitResult.Miss);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
else
|
2018-08-03 15:12:38 +08:00
|
|
|
|
ApplyResult(r => r.Type = result);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool OnPressed(TaikoAction action)
|
|
|
|
|
{
|
2018-09-28 16:18:34 +08:00
|
|
|
|
if (pressHandledThisFrame)
|
2018-09-25 17:37:25 +08:00
|
|
|
|
return true;
|
2018-08-03 15:12:38 +08:00
|
|
|
|
if (Judged)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
validActionPressed = HitActions.Contains(action);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
// Only count this as handled if the new judgement is a hit
|
2018-08-06 10:31:46 +08:00
|
|
|
|
var result = UpdateResult(true);
|
2018-08-03 15:12:38 +08:00
|
|
|
|
if (IsHit)
|
|
|
|
|
HitAction = action;
|
|
|
|
|
|
2018-09-25 17:37:25 +08: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 16:18:34 +08:00
|
|
|
|
pressHandledThisFrame = true;
|
2018-08-03 15:12:38 +08:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 12:22:34 +08:00
|
|
|
|
public override void OnReleased(TaikoAction action)
|
2018-08-03 15:12:38 +08:00
|
|
|
|
{
|
|
|
|
|
if (action == HitAction)
|
|
|
|
|
HitAction = null;
|
2020-01-22 12:22:34 +08:00
|
|
|
|
base.OnReleased(action);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2018-09-25 17:37:25 +08: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 16:18:34 +08:00
|
|
|
|
pressHandledThisFrame = false;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 10:03:56 +08:00
|
|
|
|
protected override void UpdateStateTransforms(ArmedState state)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-09-02 17:31:33 +08:00
|
|
|
|
Debug.Assert(HitObject.HitWindows != null);
|
|
|
|
|
|
2019-08-27 10:03:56 +08:00
|
|
|
|
switch (state)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-08-27 10:03:56 +08:00
|
|
|
|
case ArmedState.Idle:
|
|
|
|
|
validActionPressed = false;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2019-08-27 10:03:56 +08:00
|
|
|
|
UnproxyContent();
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2019-08-27 10:03:56 +08:00
|
|
|
|
case ArmedState.Miss:
|
2019-09-12 18:29:08 +08:00
|
|
|
|
this.FadeOut(100);
|
2019-08-27 10:03:56 +08:00
|
|
|
|
break;
|
2018-06-11 20:45:19 +08:00
|
|
|
|
|
2019-08-27 10:03:56 +08:00
|
|
|
|
case ArmedState.Hit:
|
|
|
|
|
// If we're far enough away from the left stage, we should bring outselves in front of it
|
|
|
|
|
ProxyContent();
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2020-04-15 15:54:50 +08:00
|
|
|
|
var flash = (MainPiece.Drawable as CirclePiece)?.FlashBox;
|
2019-08-27 10:03:56 +08:00
|
|
|
|
flash?.FadeTo(0.9f).FadeOut(300);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-08-27 10:03:56 +08:00
|
|
|
|
const float gravity_time = 300;
|
|
|
|
|
const float gravity_travel_height = 200;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-08-27 10:03:56 +08:00
|
|
|
|
this.ScaleTo(0.8f, gravity_time * 2, Easing.OutQuad);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-08-27 10:03:56 +08:00
|
|
|
|
this.MoveToY(-gravity_travel_height, gravity_time, Easing.Out)
|
|
|
|
|
.Then()
|
|
|
|
|
.MoveToY(gravity_travel_height * 2, gravity_time * 2, Easing.In);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-09-12 18:29:08 +08:00
|
|
|
|
this.FadeOut(800);
|
2019-08-27 10:03:56 +08:00
|
|
|
|
break;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 15:12:38 +08:00
|
|
|
|
|
2018-08-14 13:28:05 +08:00
|
|
|
|
protected override DrawableStrongNestedHit CreateStrongHit(StrongHitObject hitObject) => new StrongNestedHit(hitObject, this);
|
2018-08-03 15:56:46 +08:00
|
|
|
|
|
2018-08-14 13:28:05 +08:00
|
|
|
|
private class StrongNestedHit : DrawableStrongNestedHit
|
2018-08-03 15:56:46 +08: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;
|
|
|
|
|
|
|
|
|
|
public new DrawableHit MainObject => (DrawableHit)base.MainObject;
|
|
|
|
|
|
2018-08-14 13:28:05 +08:00
|
|
|
|
public StrongNestedHit(StrongHitObject strong, DrawableHit hit)
|
2018-08-03 15:56:46 +08:00
|
|
|
|
: base(strong, hit)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 10:31:46 +08:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-08-03 15:56:46 +08:00
|
|
|
|
{
|
|
|
|
|
if (!MainObject.Result.HasResult)
|
|
|
|
|
{
|
2018-08-06 10:31:46 +08:00
|
|
|
|
base.CheckForResult(userTriggered, timeOffset);
|
2018-08-03 15:56:46 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!MainObject.Result.IsHit)
|
|
|
|
|
{
|
|
|
|
|
ApplyResult(r => r.Type = HitResult.Miss);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-11-29 10:06:40 +08:00
|
|
|
|
|
2018-08-03 15:56:46 +08:00
|
|
|
|
if (!userTriggered)
|
|
|
|
|
{
|
2018-12-06 20:04:54 +08:00
|
|
|
|
if (timeOffset - MainObject.Result.TimeOffset > second_hit_window)
|
2018-08-03 15:56:46 +08:00
|
|
|
|
ApplyResult(r => r.Type = HitResult.Miss);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 20:04:54 +08:00
|
|
|
|
if (Math.Abs(timeOffset - MainObject.Result.TimeOffset) <= second_hit_window)
|
2018-11-29 09:56:19 +08:00
|
|
|
|
ApplyResult(r => r.Type = MainObject.Result.Type);
|
2018-08-03 15:56:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool OnPressed(TaikoAction action)
|
|
|
|
|
{
|
|
|
|
|
// Don't process actions until the main hitobject is hit
|
|
|
|
|
if (!MainObject.IsHit)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Don't process actions if the pressed button was released
|
|
|
|
|
if (MainObject.HitAction == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Don't handle invalid hit action presses
|
|
|
|
|
if (!MainObject.HitActions.Contains(action))
|
|
|
|
|
return false;
|
|
|
|
|
|
2018-08-06 10:31:46 +08:00
|
|
|
|
return UpdateResult(true);
|
2018-08-03 15:56:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|