From 989a6ab02be514a04c270c07247652b1065e6866 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Sat, 25 Mar 2017 23:43:41 +0900 Subject: [PATCH] Move validKeys to DrawableTaikoHitObject. Cleanup + reword comments. --- .../Objects/Drawable/DrawableAccentedHit.cs | 33 +++++++++++-------- .../Objects/Drawable/DrawableHit.cs | 23 +------------ .../Drawable/DrawableTaikoHitObject.cs | 25 ++++++++++++++ 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableAccentedHit.cs b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableAccentedHit.cs index e251daae7d..9d9c67a7f4 100644 --- a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableAccentedHit.cs +++ b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableAccentedHit.cs @@ -17,6 +17,7 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable private const double second_hit_window = 30; private double firstHitTime; + private bool firstKeyHeld; private Key firstHitKey; protected DrawableAccentedHit(Hit hit) @@ -41,40 +42,44 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable Judgement.SecondHit = true; } - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + protected override bool HandleKeyPress(Key key) { - // Check if we've handled the initial key + // Check if we've handled the first key if (!Judgement.Result.HasValue) { - bool result = base.OnKeyDown(state, args); + // First key hasn't been handled yet, attempt to handle it + bool handled = base.HandleKeyPress(key); - if (result) + if (handled) { firstHitTime = Time.Current; - firstHitKey = args.Key; + firstHitKey = key; } - return result; + return handled; } // 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) + // Don't handle represses of the first key + if (firstHitKey == key) return false; // Don't handle invalid hit key presses - if (!HitKeys.Contains(args.Key)) + if (!HitKeys.Contains(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; + // Assume the intention was to hit the accented hit with both keys only if the first key is still being held down + return firstKeyHeld && UpdateJudgement(true); + } - return UpdateJudgement(true); + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + firstKeyHeld = state.Keyboard.Keys.Contains(firstHitKey); + + return base.OnKeyDown(state, args); } } } diff --git a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs index cc017ab376..a3ea9e36b9 100644 --- a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs +++ b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs @@ -2,7 +2,6 @@ // 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; @@ -17,12 +16,6 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable /// 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; /// @@ -61,7 +54,7 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable Judgement.Result = HitResult.Miss; } - protected virtual bool HandleKeyPress(Key key) + protected override bool HandleKeyPress(Key key) { if (Judgement.Result.HasValue) return false; @@ -70,19 +63,5 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable 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); - } } } diff --git a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableTaikoHitObject.cs b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableTaikoHitObject.cs index e165f40442..bb6ca627da 100644 --- a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableTaikoHitObject.cs +++ b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableTaikoHitObject.cs @@ -1,15 +1,24 @@ // 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.Graphics; using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Taiko.Judgements; using osu.Game.Modes.Taiko.Objects.Drawable.Pieces; +using System.Collections.Generic; +using osu.Framework.Input; namespace osu.Game.Modes.Taiko.Objects.Drawable { public abstract class DrawableTaikoHitObject : DrawableHitObject { + /// + /// 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 }); + protected DrawableTaikoHitObject(TaikoHitObject hitObject) : base(hitObject) { @@ -49,6 +58,22 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable UpdateScrollPosition(Time.Current); } + protected virtual bool HandleKeyPress(Key key) { return false; } + + 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); + } + protected abstract CirclePiece CreateCircle(); } }