mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Implement basic hold note + tick input.
This commit is contained in:
@ -7,14 +7,47 @@ using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Configuration;
|
||||
using OpenTK.Input;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Rulesets.Mania.Judgements;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
||||
{
|
||||
public class DrawableHoldNote : DrawableManiaHitObject<HoldNote>
|
||||
{
|
||||
private readonly NotePiece headPiece;
|
||||
private readonly DrawableNote headNote;
|
||||
private readonly DrawableNote tailNote;
|
||||
private readonly BodyPiece bodyPiece;
|
||||
private readonly NotePiece tailPiece;
|
||||
private readonly Container<DrawableHoldNoteTick> tickContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Relative time at which the user started holding this note.
|
||||
/// </summary>
|
||||
private double holdStartTime;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the hold note has been released too early and shouldn't give full score for the release.
|
||||
/// </summary>
|
||||
private bool hasBroken;
|
||||
|
||||
private bool _holding;
|
||||
/// <summary>
|
||||
/// Whether the user is holding the hold note.
|
||||
/// </summary>
|
||||
private bool holding
|
||||
{
|
||||
get { return _holding; }
|
||||
set
|
||||
{
|
||||
if (_holding == value)
|
||||
return;
|
||||
_holding = value;
|
||||
|
||||
if (holding)
|
||||
holdStartTime = Time.Current;
|
||||
}
|
||||
}
|
||||
|
||||
public DrawableHoldNote(HoldNote hitObject, Bindable<Key> key = null)
|
||||
: base(hitObject, key)
|
||||
@ -32,17 +65,39 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
},
|
||||
headPiece = new NotePiece
|
||||
tickContainer = new Container<DrawableHoldNoteTick>
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativeCoordinateSpace = new Vector2(1, (float)HitObject.Duration)
|
||||
},
|
||||
headNote = new DrawableHoldNoteHead(this, key)
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre
|
||||
},
|
||||
tailPiece = new NotePiece
|
||||
tailNote = new DrawableHoldNoteTail(this, key)
|
||||
{
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.TopCentre
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var tick in HitObject.Ticks)
|
||||
{
|
||||
var drawableTick = new DrawableHoldNoteTick(tick)
|
||||
{
|
||||
IsHolding = () => holding,
|
||||
HoldStartTime = () => holdStartTime
|
||||
};
|
||||
|
||||
drawableTick.Y -= (float)HitObject.StartTime;
|
||||
|
||||
tickContainer.Add(drawableTick);
|
||||
AddNested(drawableTick);
|
||||
}
|
||||
|
||||
AddNested(headNote);
|
||||
AddNested(tailNote);
|
||||
}
|
||||
|
||||
public override Color4 AccentColour
|
||||
@ -54,9 +109,9 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
||||
return;
|
||||
base.AccentColour = value;
|
||||
|
||||
headPiece.AccentColour = value;
|
||||
bodyPiece.AccentColour = value;
|
||||
tailPiece.AccentColour = value;
|
||||
headNote.AccentColour = value;
|
||||
tailNote.AccentColour = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,14 +119,133 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
/// <summary>
|
||||
/// Handles key down events on the body of the hold note.
|
||||
/// </summary>
|
||||
/// <param name="state">The input state.</param>
|
||||
/// <param name="args">The key down args.</param>
|
||||
/// <returns>Whether the key press was handled.</returns>
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
if (Time.Current > HitObject.StartTime)
|
||||
headPiece.Colour = Color4.Green;
|
||||
if (Time.Current > HitObject.EndTime)
|
||||
// Make sure the keypress happened within reasonable bounds of the hold note
|
||||
if (Time.Current < HitObject.StartTime || Time.Current > HitObject.EndTime)
|
||||
return false;
|
||||
|
||||
if (args.Key != Key)
|
||||
return false;
|
||||
|
||||
if (args.Repeat)
|
||||
return false;
|
||||
|
||||
holding = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles key up events on the body of the hold note.
|
||||
/// </summary>
|
||||
/// <param name="state">The input state.</param>
|
||||
/// <param name="args">The key down args.</param>
|
||||
/// <returns>Whether the key press was handled.</returns>
|
||||
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args)
|
||||
{
|
||||
// Make sure that the user started holding the key during the hold note
|
||||
if (!holding)
|
||||
return false;
|
||||
|
||||
if (args.Key != Key)
|
||||
return false;
|
||||
|
||||
holding = false;
|
||||
|
||||
// If the key has been released too early, they should not receive full score for the release
|
||||
if (!tailNote.Judged)
|
||||
hasBroken = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private class DrawableHoldNoteHead : DrawableNote
|
||||
{
|
||||
private readonly DrawableHoldNote holdNote;
|
||||
|
||||
public DrawableHoldNoteHead(DrawableHoldNote holdNote, Bindable<Key> key = null)
|
||||
: base(holdNote.HitObject.HeadNote, key)
|
||||
{
|
||||
bodyPiece.Colour = Color4.Green;
|
||||
tailPiece.Colour = Color4.Green;
|
||||
this.holdNote = holdNote;
|
||||
|
||||
RelativePositionAxes = Axes.None;
|
||||
Y = 0;
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
if (!base.OnKeyDown(state, args))
|
||||
return false;
|
||||
|
||||
// We only want to trigger a holding state from the head if the head has received a judgement
|
||||
if (Judgement.Result == HitResult.None)
|
||||
return false;
|
||||
|
||||
// If the head has been missed, make sure the user also can't receive a full score for the release
|
||||
if (Judgement.Result == HitResult.Miss)
|
||||
holdNote.hasBroken = true;
|
||||
|
||||
holdNote.holding = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class DrawableHoldNoteTail : DrawableNote
|
||||
{
|
||||
private readonly DrawableHoldNote holdNote;
|
||||
|
||||
public DrawableHoldNoteTail(DrawableHoldNote holdNote, Bindable<Key> key = null)
|
||||
: base(holdNote.HitObject.TailNote, key)
|
||||
{
|
||||
this.holdNote = holdNote;
|
||||
|
||||
RelativePositionAxes = Axes.None;
|
||||
Y = 0;
|
||||
}
|
||||
|
||||
protected override ManiaJudgement CreateJudgement() => new HoldNoteTailJudgement();
|
||||
|
||||
protected override void CheckJudgement(bool userTriggered)
|
||||
{
|
||||
base.CheckJudgement(userTriggered);
|
||||
|
||||
var tailJudgement = Judgement as HoldNoteTailJudgement;
|
||||
if (tailJudgement == null)
|
||||
return;
|
||||
|
||||
tailJudgement.HasBroken = holdNote.hasBroken;
|
||||
}
|
||||
|
||||
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args)
|
||||
{
|
||||
// Make sure that the user started holding the key during the hold note
|
||||
if (!holdNote.holding)
|
||||
return false;
|
||||
|
||||
if (Judgement.Result != HitResult.None)
|
||||
return false;
|
||||
|
||||
if (args.Key != Key)
|
||||
return false;
|
||||
|
||||
UpdateJudgement(true);
|
||||
|
||||
// Handled by the hold note, which will set holding = false
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
// Tail doesn't handle key down
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user