2017-05-04 17:02:43 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-05-22 14:27:38 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using OpenTK.Input;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Rulesets.Mania.Judgements;
|
2017-05-24 20:24:18 +08:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2017-05-04 17:02:43 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
|
|
|
|
{
|
|
|
|
|
public class DrawableHoldNote : DrawableManiaHitObject<HoldNote>
|
|
|
|
|
{
|
2017-05-24 19:45:01 +08:00
|
|
|
|
private readonly DrawableNote headNote;
|
|
|
|
|
private readonly DrawableNote tailNote;
|
2017-05-11 13:11:52 +08:00
|
|
|
|
private readonly BodyPiece bodyPiece;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-04 17:02:43 +08:00
|
|
|
|
|
2017-05-22 14:27:38 +08:00
|
|
|
|
public DrawableHoldNote(HoldNote hitObject, Bindable<Key> key = null)
|
|
|
|
|
: base(hitObject, key)
|
2017-05-04 17:02:43 +08:00
|
|
|
|
{
|
2017-05-09 19:33:59 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
Height = (float)HitObject.Duration;
|
|
|
|
|
|
|
|
|
|
Add(new Drawable[]
|
2017-05-04 17:02:43 +08:00
|
|
|
|
{
|
2017-05-09 19:55:20 +08:00
|
|
|
|
// For now the body piece covers the entire height of the container
|
|
|
|
|
// whereas possibly in the future we don't want to extend under the head/tail.
|
|
|
|
|
// This will be fixed when new designs are given or the current design is finalized.
|
2017-05-04 17:02:43 +08:00
|
|
|
|
bodyPiece = new BodyPiece
|
|
|
|
|
{
|
2017-05-16 16:34:41 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-05-04 17:02:43 +08:00
|
|
|
|
},
|
2017-05-24 19:45:01 +08:00
|
|
|
|
tickContainer = new Container<DrawableHoldNoteTick>
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
RelativeCoordinateSpace = new Vector2(1, (float)HitObject.Duration)
|
|
|
|
|
},
|
|
|
|
|
headNote = new DrawableHoldNoteHead(this, key)
|
2017-05-04 17:02:43 +08:00
|
|
|
|
{
|
2017-05-16 16:34:41 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre
|
2017-05-09 19:33:59 +08:00
|
|
|
|
},
|
2017-05-24 19:45:01 +08:00
|
|
|
|
tailNote = new DrawableHoldNoteTail(this, key)
|
2017-05-09 19:33:59 +08:00
|
|
|
|
{
|
2017-05-16 16:34:41 +08:00
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2017-05-17 12:20:33 +08:00
|
|
|
|
Origin = Anchor.TopCentre
|
2017-05-04 17:02:43 +08:00
|
|
|
|
}
|
2017-05-09 19:33:59 +08:00
|
|
|
|
});
|
2017-05-24 19:45:01 +08:00
|
|
|
|
|
|
|
|
|
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);
|
2017-05-04 17:02:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Color4 AccentColour
|
|
|
|
|
{
|
2017-05-11 13:11:52 +08:00
|
|
|
|
get { return base.AccentColour; }
|
2017-05-04 17:02:43 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (base.AccentColour == value)
|
|
|
|
|
return;
|
|
|
|
|
base.AccentColour = value;
|
|
|
|
|
|
2017-05-24 20:24:18 +08:00
|
|
|
|
tickContainer.Children.ForEach(t => t.AccentColour = value);
|
|
|
|
|
|
2017-05-04 17:02:43 +08:00
|
|
|
|
bodyPiece.AccentColour = value;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
headNote.AccentColour = value;
|
|
|
|
|
tailNote.AccentColour = value;
|
2017-05-04 17:02:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateState(ArmedState state)
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-05-12 18:10:26 +08:00
|
|
|
|
|
2017-05-24 19:45:01 +08:00
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
|
|
|
|
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
|
2017-05-12 18:10:26 +08:00
|
|
|
|
{
|
2017-05-24 19:45:01 +08:00
|
|
|
|
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)
|
2017-05-12 18:10:26 +08:00
|
|
|
|
{
|
2017-05-24 19:45:01 +08:00
|
|
|
|
// Tail doesn't handle key down
|
|
|
|
|
return false;
|
2017-05-12 18:10:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-04 17:02:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|