mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 09:05:59 +08:00
Merge pull request #515 from smoogipooo/taiko_hit_drawables
Drawable Hit Implementation (Input only)
This commit is contained in:
commit
f150c0828c
80
osu.Game.Modes.Taiko/Objects/Drawable/DrawableAccentedHit.cs
Normal file
80
osu.Game.Modes.Taiko/Objects/Drawable/DrawableAccentedHit.cs
Normal file
@ -0,0 +1,80 @@
|
||||
// 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;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Input;
|
||||
|
||||
namespace osu.Game.Modes.Taiko.Objects.Drawable
|
||||
{
|
||||
public abstract class DrawableAccentedHit : DrawableHit
|
||||
{
|
||||
/// <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;
|
||||
|
||||
private double firstHitTime;
|
||||
private Key firstHitKey;
|
||||
|
||||
protected DrawableAccentedHit(Hit hit)
|
||||
: base(hit)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void CheckJudgement(bool userTriggered)
|
||||
{
|
||||
if (!Judgement.Result.HasValue)
|
||||
{
|
||||
base.CheckJudgement(userTriggered);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!userTriggered)
|
||||
return;
|
||||
|
||||
// If we get here, we're assured that the key pressed is the correct secondary key
|
||||
|
||||
if (Math.Abs(firstHitTime - Time.Current) < second_hit_window)
|
||||
Judgement.SecondHit = true;
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
// Check if we've handled the initial key
|
||||
if (!Judgement.Result.HasValue)
|
||||
{
|
||||
bool result = base.OnKeyDown(state, args);
|
||||
|
||||
if (result)
|
||||
{
|
||||
firstHitTime = Time.Current;
|
||||
firstHitKey = args.Key;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// If we've already hit the second key, don't handle this object any further
|
||||
if (Judgement.SecondHit)
|
||||
return false;
|
||||
|
||||
// Don't handle represses of the same key
|
||||
if (firstHitKey == args.Key)
|
||||
return false;
|
||||
|
||||
// Don't handle invalid hit key presses
|
||||
if (!HitKeys.Contains(args.Key))
|
||||
return false;
|
||||
|
||||
// If we're not holding the first key down still, assume the intention
|
||||
// was not to hit the accented hit with both keys simultaneously
|
||||
if (!state.Keyboard.Keys.Contains(firstHitKey))
|
||||
return false;
|
||||
|
||||
return UpdateJudgement(true);
|
||||
}
|
||||
}
|
||||
}
|
88
osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs
Normal file
88
osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs
Normal file
@ -0,0 +1,88 @@
|
||||
// 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;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Modes.Objects.Drawables;
|
||||
using osu.Game.Modes.Taiko.Judgements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Modes.Taiko.Objects.Drawable
|
||||
{
|
||||
public abstract class DrawableHit : DrawableTaikoHitObject
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of keys which can result in hits for this HitObject.
|
||||
/// </summary>
|
||||
protected abstract List<Key> HitKeys { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A list of keys which this hit object will accept. These are the standard Taiko keys for now.
|
||||
/// These should be moved to bindings later.
|
||||
/// </summary>
|
||||
private readonly List<Key> validKeys = new List<Key>(new[] { Key.D, Key.F, Key.J, Key.K });
|
||||
|
||||
private readonly Hit hit;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the last key pressed is a valid hit key.
|
||||
/// </summary>
|
||||
private bool validKeyPressed;
|
||||
|
||||
protected DrawableHit(Hit hit)
|
||||
: base(hit)
|
||||
{
|
||||
this.hit = hit;
|
||||
}
|
||||
|
||||
protected override void CheckJudgement(bool userTriggered)
|
||||
{
|
||||
if (!userTriggered)
|
||||
{
|
||||
if (Judgement.TimeOffset > hit.HitWindowGood)
|
||||
Judgement.Result = HitResult.Miss;
|
||||
return;
|
||||
}
|
||||
|
||||
double hitOffset = Math.Abs(Judgement.TimeOffset);
|
||||
|
||||
if (hitOffset > hit.HitWindowMiss)
|
||||
return;
|
||||
|
||||
if (!validKeyPressed)
|
||||
Judgement.Result = HitResult.Miss;
|
||||
else if (hitOffset < hit.HitWindowGood)
|
||||
{
|
||||
Judgement.Result = HitResult.Hit;
|
||||
Judgement.TaikoResult = hitOffset < hit.HitWindowGreat ? TaikoHitResult.Great : TaikoHitResult.Good;
|
||||
}
|
||||
else
|
||||
Judgement.Result = HitResult.Miss;
|
||||
}
|
||||
|
||||
protected virtual bool HandleKeyPress(Key key)
|
||||
{
|
||||
if (Judgement.Result.HasValue)
|
||||
return false;
|
||||
|
||||
validKeyPressed = HitKeys.Contains(key);
|
||||
|
||||
return UpdateJudgement(true);
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
// Make sure we don't handle held-down keys
|
||||
if (args.Repeat)
|
||||
return false;
|
||||
|
||||
// Check if we've pressed a valid taiko key
|
||||
if (!validKeys.Contains(args.Key))
|
||||
return false;
|
||||
|
||||
// Handle it!
|
||||
return HandleKeyPress(args.Key);
|
||||
}
|
||||
}
|
||||
}
|
@ -52,6 +52,8 @@
|
||||
<Compile Include="Judgements\TaikoDrumRollTickJudgement.cs" />
|
||||
<Compile Include="Judgements\TaikoJudgement.cs" />
|
||||
<Compile Include="Judgements\TaikoHitResult.cs" />
|
||||
<Compile Include="Objects\Drawable\DrawableHit.cs" />
|
||||
<Compile Include="Objects\Drawable\DrawableAccentedHit.cs" />
|
||||
<Compile Include="Objects\Drawable\DrawableTaikoHitObject.cs" />
|
||||
<Compile Include="Objects\Bash.cs" />
|
||||
<Compile Include="Objects\Drawable\Pieces\AccentedCirclePiece.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user