2017-03-20 17:25:12 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using OpenTK.Input;
|
2017-03-28 09:33:23 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-03-17 15:55:57 +08:00
|
|
|
|
using osu.Game.Modes.Objects.Drawables;
|
|
|
|
|
using osu.Game.Modes.Taiko.Judgements;
|
2017-04-03 13:39:56 +08:00
|
|
|
|
using osu.Game.Modes.Taiko.Objects.Drawable.Pieces;
|
2017-03-17 15:55:57 +08:00
|
|
|
|
using System;
|
2017-03-29 14:35:22 +08:00
|
|
|
|
using System.Linq;
|
2017-03-17 15:55:57 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Modes.Taiko.Objects.Drawable
|
|
|
|
|
{
|
2017-03-17 18:24:39 +08:00
|
|
|
|
public abstract class DrawableHit : DrawableTaikoHitObject
|
2017-03-17 15:55:57 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A list of keys which can result in hits for this HitObject.
|
|
|
|
|
/// </summary>
|
2017-03-29 14:35:22 +08:00
|
|
|
|
protected abstract Key[] HitKeys { get; }
|
2017-03-17 15:55:57 +08:00
|
|
|
|
|
2017-03-28 09:33:23 +08:00
|
|
|
|
protected override Container<Framework.Graphics.Drawable> Content => bodyContainer;
|
|
|
|
|
|
2017-04-03 13:39:56 +08:00
|
|
|
|
protected readonly CirclePiece Circle;
|
|
|
|
|
|
2017-03-24 13:59:59 +08:00
|
|
|
|
private readonly Hit hit;
|
2017-03-17 15:55:57 +08:00
|
|
|
|
|
2017-04-03 13:39:56 +08:00
|
|
|
|
private readonly Container bodyContainer;
|
|
|
|
|
|
2017-03-17 15:55:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the last key pressed is a valid hit key.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool validKeyPressed;
|
|
|
|
|
|
2017-03-24 13:59:59 +08:00
|
|
|
|
protected DrawableHit(Hit hit)
|
|
|
|
|
: base(hit)
|
2017-03-17 15:55:57 +08:00
|
|
|
|
{
|
2017-03-24 13:59:59 +08:00
|
|
|
|
this.hit = hit;
|
2017-03-28 09:33:23 +08:00
|
|
|
|
|
|
|
|
|
AddInternal(bodyContainer = new Container
|
|
|
|
|
{
|
2017-03-29 12:07:36 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2017-04-03 13:39:56 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
Circle = CreateCirclePiece()
|
|
|
|
|
}
|
2017-03-28 09:33:23 +08:00
|
|
|
|
});
|
2017-04-03 13:40:12 +08:00
|
|
|
|
|
|
|
|
|
Circle.KiaiMode = HitObject.Kiai;
|
2017-03-17 15:55:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void CheckJudgement(bool userTriggered)
|
|
|
|
|
{
|
|
|
|
|
if (!userTriggered)
|
|
|
|
|
{
|
2017-03-24 13:59:59 +08:00
|
|
|
|
if (Judgement.TimeOffset > hit.HitWindowGood)
|
2017-03-17 15:55:57 +08:00
|
|
|
|
Judgement.Result = HitResult.Miss;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double hitOffset = Math.Abs(Judgement.TimeOffset);
|
|
|
|
|
|
2017-03-24 13:59:59 +08:00
|
|
|
|
if (hitOffset > hit.HitWindowMiss)
|
2017-03-17 15:55:57 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!validKeyPressed)
|
|
|
|
|
Judgement.Result = HitResult.Miss;
|
2017-03-24 13:59:59 +08:00
|
|
|
|
else if (hitOffset < hit.HitWindowGood)
|
2017-03-17 15:55:57 +08:00
|
|
|
|
{
|
|
|
|
|
Judgement.Result = HitResult.Hit;
|
2017-03-24 13:59:59 +08:00
|
|
|
|
Judgement.TaikoResult = hitOffset < hit.HitWindowGreat ? TaikoHitResult.Great : TaikoHitResult.Good;
|
2017-03-17 15:55:57 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Judgement.Result = HitResult.Miss;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-25 22:43:41 +08:00
|
|
|
|
protected override bool HandleKeyPress(Key key)
|
2017-03-17 15:55:57 +08:00
|
|
|
|
{
|
2017-03-29 16:57:36 +08:00
|
|
|
|
if (Judgement.Result != HitResult.None)
|
2017-03-17 15:55:57 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
validKeyPressed = HitKeys.Contains(key);
|
|
|
|
|
|
|
|
|
|
return UpdateJudgement(true);
|
|
|
|
|
}
|
2017-03-28 09:33:23 +08:00
|
|
|
|
|
|
|
|
|
protected override void UpdateState(ArmedState state)
|
|
|
|
|
{
|
2017-03-29 12:19:48 +08:00
|
|
|
|
Delay(HitObject.StartTime - Time.Current + Judgement.TimeOffset, true);
|
|
|
|
|
|
2017-03-28 09:33:23 +08:00
|
|
|
|
switch (State)
|
|
|
|
|
{
|
|
|
|
|
case ArmedState.Idle:
|
2017-03-29 12:19:48 +08:00
|
|
|
|
Delay(hit.HitWindowMiss);
|
2017-03-28 09:33:23 +08:00
|
|
|
|
break;
|
|
|
|
|
case ArmedState.Miss:
|
2017-03-29 08:11:07 +08:00
|
|
|
|
FadeOut(100);
|
2017-03-28 09:33:23 +08:00
|
|
|
|
break;
|
|
|
|
|
case ArmedState.Hit:
|
|
|
|
|
bodyContainer.ScaleTo(0.8f, 400, EasingTypes.OutQuad);
|
|
|
|
|
bodyContainer.MoveToY(-200, 250, EasingTypes.Out);
|
|
|
|
|
bodyContainer.Delay(250);
|
|
|
|
|
bodyContainer.MoveToY(0, 500, EasingTypes.In);
|
2017-03-29 08:11:07 +08:00
|
|
|
|
|
|
|
|
|
FadeOut(600);
|
2017-03-28 09:33:23 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-03-29 12:19:48 +08:00
|
|
|
|
|
|
|
|
|
Expire();
|
2017-03-28 09:33:23 +08:00
|
|
|
|
}
|
2017-04-03 13:39:56 +08:00
|
|
|
|
|
|
|
|
|
protected abstract CirclePiece CreateCirclePiece();
|
2017-03-17 15:55:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|