1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 00:52:56 +08:00

Add action support to taiko

This commit is contained in:
Dean Herbert 2017-08-20 21:18:21 +09:00
parent a2c184ea43
commit ff84eb219b
10 changed files with 50 additions and 61 deletions

View File

@ -4,13 +4,12 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using OpenTK.Input;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
public class DrawableCentreHit : DrawableHit public class DrawableCentreHit : DrawableHit
{ {
protected override Key[] HitKeys { get; } = { Key.F, Key.J }; protected override TaikoAction[] HitActions { get; } = { TaikoAction.LeftCentre, TaikoAction.RightCentre };
public DrawableCentreHit(Hit hit) public DrawableCentreHit(Hit hit)
: base(hit) : base(hit)

View File

@ -4,13 +4,12 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using OpenTK.Input;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
public class DrawableCentreHitStrong : DrawableHitStrong public class DrawableCentreHitStrong : DrawableHitStrong
{ {
protected override Key[] HitKeys { get; } = { Key.F, Key.J }; protected override TaikoAction[] HitActions { get; } = { TaikoAction.LeftCentre, TaikoAction.RightCentre };
public DrawableCentreHitStrong(Hit hit) public DrawableCentreHitStrong(Hit hit)
: base(hit) : base(hit)

View File

@ -56,6 +56,8 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
protected override TaikoPiece CreateMainPiece() => new ElongatedCirclePiece(); protected override TaikoPiece CreateMainPiece() => new ElongatedCirclePiece();
public override bool OnPressed(TaikoAction action) => false;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {

View File

@ -5,7 +5,6 @@ using System;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Judgements; using osu.Game.Rulesets.Taiko.Judgements;
using OpenTK.Input;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
@ -59,7 +58,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
} }
} }
protected override bool HandleKeyPress(Key key) public override bool OnPressed(TaikoAction action)
{ {
return Judgement.Result == HitResult.None && UpdateJudgement(true); return Judgement.Result == HitResult.None && UpdateJudgement(true);
} }

View File

@ -7,7 +7,6 @@ using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Judgements; using osu.Game.Rulesets.Taiko.Judgements;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using OpenTK.Input;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
@ -16,7 +15,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
/// <summary> /// <summary>
/// A list of keys which can result in hits for this HitObject. /// A list of keys which can result in hits for this HitObject.
/// </summary> /// </summary>
protected abstract Key[] HitKeys { get; } protected abstract TaikoAction[] HitActions { get; }
/// <summary> /// <summary>
/// Whether the last key pressed is a valid hit key. /// Whether the last key pressed is a valid hit key.
@ -62,12 +61,12 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
Judgement.Result = HitResult.Miss; Judgement.Result = HitResult.Miss;
} }
protected override bool HandleKeyPress(Key key) public override bool OnPressed(TaikoAction action)
{ {
if (Judgement.Result != HitResult.None) if (Judgement.Result != HitResult.None)
return false; return false;
validKeyPressed = HitKeys.Contains(key); validKeyPressed = HitActions.Contains(action);
return UpdateJudgement(true); return UpdateJudgement(true);
} }

View File

@ -6,7 +6,6 @@ using System.Linq;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Judgements; using osu.Game.Rulesets.Taiko.Judgements;
using OpenTK.Input;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
@ -20,7 +19,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
private double firstHitTime; private double firstHitTime;
private bool firstKeyHeld; private bool firstKeyHeld;
private Key firstHitKey; private TaikoAction firstHitAction;
protected DrawableHitStrong(Hit hit) protected DrawableHitStrong(Hit hit)
: base(hit) : base(hit)
@ -46,18 +45,26 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
Judgement.SecondHit = true; Judgement.SecondHit = true;
} }
protected override bool HandleKeyPress(Key key) public override bool OnReleased(TaikoAction action)
{
if (action == firstHitAction)
firstKeyHeld = false;
return base.OnReleased(action);
}
public override bool OnPressed(TaikoAction action)
{ {
// Check if we've handled the first key // Check if we've handled the first key
if (Judgement.Result == HitResult.None) if (Judgement.Result == HitResult.None)
{ {
// First key hasn't been handled yet, attempt to handle it // First key hasn't been handled yet, attempt to handle it
bool handled = base.HandleKeyPress(key); bool handled = base.OnPressed(action);
if (handled) if (handled)
{ {
firstHitTime = Time.Current; firstHitTime = Time.Current;
firstHitKey = key; firstHitAction = action;
firstKeyHeld = true;
} }
return handled; return handled;
@ -68,22 +75,15 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
return false; return false;
// Don't handle represses of the first key // Don't handle represses of the first key
if (firstHitKey == key) if (firstHitAction == action)
return false; return false;
// Don't handle invalid hit key presses // Don't handle invalid hit action presses
if (!HitKeys.Contains(key)) if (!HitActions.Contains(action))
return false; return false;
// Assume the intention was to hit the strong hit with both keys only if the first key is still being held down // Assume the intention was to hit the strong hit with both keys only if the first key is still being held down
return firstKeyHeld && UpdateJudgement(true); return firstKeyHeld && UpdateJudgement(true);
} }
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
firstKeyHeld = state.Keyboard.Keys.Contains(firstHitKey);
return base.OnKeyDown(state, args);
}
} }
} }

View File

@ -4,13 +4,12 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using OpenTK.Input;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
public class DrawableRimHit : DrawableHit public class DrawableRimHit : DrawableHit
{ {
protected override Key[] HitKeys { get; } = { Key.D, Key.K }; protected override TaikoAction[] HitActions { get; } = { TaikoAction.LeftRim, TaikoAction.RightRim };
public DrawableRimHit(Hit hit) public DrawableRimHit(Hit hit)
: base(hit) : base(hit)

View File

@ -4,13 +4,12 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using OpenTK.Input;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
public class DrawableRimHitStrong : DrawableHitStrong public class DrawableRimHitStrong : DrawableHitStrong
{ {
protected override Key[] HitKeys { get; } = { Key.D, Key.K }; protected override TaikoAction[] HitActions { get; } = { TaikoAction.LeftRim, TaikoAction.RightRim };
public DrawableRimHitStrong(Hit hit) public DrawableRimHitStrong(Hit hit)
: base(hit) : base(hit)

View File

@ -13,7 +13,6 @@ using osu.Game.Rulesets.Taiko.Judgements;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
@ -35,9 +34,9 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
private readonly CircularContainer targetRing; private readonly CircularContainer targetRing;
private readonly CircularContainer expandingRing; private readonly CircularContainer expandingRing;
private readonly Key[] rimKeys = { Key.D, Key.K }; private readonly TaikoAction[] rimActions = { TaikoAction.LeftRim, TaikoAction.RightRim };
private readonly Key[] centreKeys = { Key.F, Key.J }; private readonly TaikoAction[] centreActions = { TaikoAction.LeftCentre, TaikoAction.RightCentre };
private Key[] lastKeySet; private TaikoAction[] lastAction;
/// <summary> /// <summary>
/// The amount of times the user has hit this swell. /// The amount of times the user has hit this swell.
@ -211,8 +210,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
} }
} }
public override bool OnPressed(TaikoAction action)
protected override bool HandleKeyPress(Key key)
{ {
if (Judgement.Result != HitResult.None) if (Judgement.Result != HitResult.None)
return false; return false;
@ -222,12 +220,12 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
return false; return false;
// Find the keyset which this key corresponds to // Find the keyset which this key corresponds to
var keySet = rimKeys.Contains(key) ? rimKeys : centreKeys; var keySet = rimActions.Contains(action) ? rimActions : centreActions;
// Ensure alternating keysets // Ensure alternating keysets
if (keySet == lastKeySet) if (keySet == lastAction)
return false; return false;
lastKeySet = keySet; lastAction = keySet;
UpdateJudgement(true); UpdateJudgement(true);

View File

@ -1,26 +1,21 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic; using System.ComponentModel;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input; using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Judgements; using osu.Game.Rulesets.Taiko.Judgements;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using OpenTK; using OpenTK;
using OpenTK.Input;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
public abstract class DrawableTaikoHitObject<TaikoHitType> : DrawableScrollingHitObject<TaikoHitObject, TaikoJudgement> public abstract class DrawableTaikoHitObject<TaikoHitType> :
DrawableScrollingHitObject<TaikoHitObject, TaikoJudgement>,
IKeyBindingHandler<TaikoAction>
where TaikoHitType : TaikoHitObject where TaikoHitType : TaikoHitObject
{ {
/// <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 });
public override Vector2 OriginPosition => new Vector2(DrawHeight / 2); public override Vector2 OriginPosition => new Vector2(DrawHeight / 2);
protected readonly TaikoPiece MainPiece; protected readonly TaikoPiece MainPiece;
@ -46,20 +41,20 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
protected virtual TaikoPiece CreateMainPiece() => new CirclePiece(); protected virtual TaikoPiece CreateMainPiece() => new CirclePiece();
protected virtual bool HandleKeyPress(Key key) => false; public abstract bool OnPressed(TaikoAction action);
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) public virtual bool OnReleased(TaikoAction action) => false;
{
// 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);
} }
public enum TaikoAction
{
[Description("Left (Rim)")]
LeftRim,
[Description("Left (Centre)")]
LeftCentre,
[Description("Right (Centre)")]
RightCentre,
[Description("Right (Rim)")]
RightRim
} }
} }