// Copyright (c) 2007-2017 ppy Pty Ltd . // 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 { /// /// A list of keys which can result in hits for this HitObject. /// protected abstract List HitKeys { get; } /// /// 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. /// private readonly List validKeys = new List(new[] { Key.D, Key.F, Key.J, Key.K }); private readonly Hit hit; /// /// Whether the last key pressed is a valid hit key. /// 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); } } }