2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-09-02 17:31:33 +08:00
|
|
|
|
using System.Diagnostics;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input.Bindings;
|
2019-10-17 11:37:20 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2019-08-27 11:59:57 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2018-06-08 17:16:55 +08:00
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Visualises a <see cref="HoldNote"/> hit object.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DrawableHoldNote : DrawableManiaHitObject<HoldNote>, IKeyBindingHandler<ManiaAction>
|
|
|
|
|
{
|
2018-08-06 10:31:46 +08:00
|
|
|
|
public override bool DisplayResult => false;
|
2018-05-28 17:12:49 +08:00
|
|
|
|
|
2019-10-17 11:37:20 +08:00
|
|
|
|
private readonly Container<DrawableHeadNote> headContainer;
|
|
|
|
|
private readonly Container<DrawableTailNote> tailContainer;
|
|
|
|
|
private readonly Container<DrawableHoldNoteTick> tickContainer;
|
|
|
|
|
|
|
|
|
|
public DrawableNote Head { get; private set; }
|
|
|
|
|
public DrawableNote Tail { get; private set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private readonly BodyPiece bodyPiece;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Time at which the user started holding this hold note. Null if the user is not holding this hold 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;
|
|
|
|
|
|
2018-07-02 11:31:41 +08:00
|
|
|
|
public DrawableHoldNote(HoldNote hitObject)
|
|
|
|
|
: base(hitObject)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
2019-03-25 12:47:28 +08:00
|
|
|
|
AddRangeInternal(new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-10-17 11:37:20 +08:00
|
|
|
|
bodyPiece = new BodyPiece { RelativeSizeAxes = Axes.X },
|
|
|
|
|
tickContainer = new Container<DrawableHoldNoteTick> { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
headContainer = new Container<DrawableHeadNote> { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
tailContainer = new Container<DrawableTailNote> { RelativeSizeAxes = Axes.Both },
|
2019-03-25 12:47:28 +08:00
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-07-22 13:45:25 +08:00
|
|
|
|
AccentColour.BindValueChanged(colour =>
|
|
|
|
|
{
|
|
|
|
|
bodyPiece.AccentColour = colour.NewValue;
|
|
|
|
|
}, true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 11:37:20 +08:00
|
|
|
|
protected override void AddNested(DrawableHitObject h)
|
|
|
|
|
{
|
|
|
|
|
base.AddNested(h);
|
|
|
|
|
|
|
|
|
|
switch (h)
|
|
|
|
|
{
|
|
|
|
|
case DrawableHeadNote head:
|
|
|
|
|
headContainer.Child = head;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DrawableTailNote tail:
|
|
|
|
|
tailContainer.Child = tail;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DrawableHoldNoteTick tick:
|
|
|
|
|
tickContainer.Add(tick);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ClearNested()
|
|
|
|
|
{
|
|
|
|
|
base.ClearNested();
|
|
|
|
|
headContainer.Clear();
|
|
|
|
|
tailContainer.Clear();
|
|
|
|
|
tickContainer.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override DrawableHitObject CreateNested(HitObject hitObject)
|
|
|
|
|
{
|
|
|
|
|
switch (hitObject)
|
|
|
|
|
{
|
|
|
|
|
case TailNote _:
|
|
|
|
|
return Tail = new DrawableTailNote(this)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AccentColour = { BindTarget = AccentColour }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
case Note _:
|
|
|
|
|
return Head = new DrawableHeadNote(this)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AccentColour = { BindTarget = AccentColour }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
case HoldNoteTick tick:
|
|
|
|
|
return new DrawableHoldNoteTick(tick)
|
|
|
|
|
{
|
|
|
|
|
HoldStartTime = () => holdStartTime,
|
|
|
|
|
AccentColour = { BindTarget = AccentColour }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.CreateNested(hitObject);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
protected override void OnDirectionChanged(ValueChangedEvent<ScrollingDirection> e)
|
2018-06-08 17:16:55 +08:00
|
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
|
base.OnDirectionChanged(e);
|
2018-06-08 17:16:55 +08:00
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
bodyPiece.Anchor = bodyPiece.Origin = e.NewValue == ScrollingDirection.Up ? Anchor.TopLeft : Anchor.BottomLeft;
|
2018-06-08 17:16:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 10:31:46 +08:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-05-16 18:43:01 +08:00
|
|
|
|
{
|
2018-05-20 18:22:42 +08:00
|
|
|
|
if (Tail.AllJudged)
|
2018-08-03 14:38:48 +08:00
|
|
|
|
ApplyResult(r => r.Type = HitResult.Perfect);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
// Make the body piece not lie under the head note
|
2018-07-17 12:13:57 +08:00
|
|
|
|
bodyPiece.Y = (Direction.Value == ScrollingDirection.Up ? 1 : -1) * Head.Height / 2;
|
2018-06-07 18:19:20 +08:00
|
|
|
|
bodyPiece.Height = DrawHeight - Head.Height / 2 + Tail.Height / 2;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 11:59:57 +08:00
|
|
|
|
protected override void UpdateStateTransforms(ArmedState state)
|
|
|
|
|
{
|
|
|
|
|
using (BeginDelayedSequence(HitObject.Duration, true))
|
|
|
|
|
base.UpdateStateTransforms(state);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 22:49:54 +08:00
|
|
|
|
protected void BeginHold()
|
|
|
|
|
{
|
|
|
|
|
holdStartTime = Time.Current;
|
|
|
|
|
bodyPiece.Hitting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void EndHold()
|
|
|
|
|
{
|
|
|
|
|
holdStartTime = null;
|
|
|
|
|
bodyPiece.Hitting = false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public bool OnPressed(ManiaAction action)
|
|
|
|
|
{
|
|
|
|
|
// Make sure the action happened within the body of the hold note
|
|
|
|
|
if (Time.Current < HitObject.StartTime || Time.Current > HitObject.EndTime)
|
|
|
|
|
return false;
|
|
|
|
|
|
2018-07-02 11:31:41 +08:00
|
|
|
|
if (action != Action.Value)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// The user has pressed during the body of the hold note, after the head note and its hit windows have passed
|
|
|
|
|
// and within the limited range of the above if-statement. This state will be managed by the head note if the
|
|
|
|
|
// user has pressed during the hit windows of the head note.
|
2018-09-06 22:49:54 +08:00
|
|
|
|
BeginHold();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnReleased(ManiaAction action)
|
|
|
|
|
{
|
|
|
|
|
// Make sure that the user started holding the key during the hold note
|
|
|
|
|
if (!holdStartTime.HasValue)
|
|
|
|
|
return false;
|
|
|
|
|
|
2018-07-02 11:31:41 +08:00
|
|
|
|
if (action != Action.Value)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2018-09-06 22:49:54 +08:00
|
|
|
|
EndHold();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
// If the key has been released too early, the user should not receive full score for the release
|
2018-05-20 18:22:42 +08:00
|
|
|
|
if (!Tail.IsHit)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
hasBroken = true;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The head note of a hold.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private class DrawableHeadNote : DrawableNote
|
|
|
|
|
{
|
|
|
|
|
private readonly DrawableHoldNote holdNote;
|
|
|
|
|
|
2018-07-02 11:31:41 +08:00
|
|
|
|
public DrawableHeadNote(DrawableHoldNote holdNote)
|
|
|
|
|
: base(holdNote.HitObject.Head)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
this.holdNote = holdNote;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool OnPressed(ManiaAction action)
|
|
|
|
|
{
|
|
|
|
|
if (!base.OnPressed(action))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// If the key has been released too early, the user should not receive full score for the release
|
2018-08-03 14:38:48 +08:00
|
|
|
|
if (Result.Type == HitResult.Miss)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
holdNote.hasBroken = true;
|
|
|
|
|
|
|
|
|
|
// The head note also handles early hits before the body, but we want accurate early hits to count as the body being held
|
|
|
|
|
// The body doesn't handle these early early hits, so we have to explicitly set the holding state here
|
2018-09-06 22:49:54 +08:00
|
|
|
|
holdNote.BeginHold();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The tail note of a hold.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private class DrawableTailNote : DrawableNote
|
|
|
|
|
{
|
2018-05-17 12:59:04 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Lenience of release hit windows. This is to make cases where the hold note release
|
|
|
|
|
/// is timed alongside presses of other hit objects less awkward.
|
|
|
|
|
/// Todo: This shouldn't exist for non-LegacyBeatmapDecoder beatmaps
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const double release_window_lenience = 1.5;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly DrawableHoldNote holdNote;
|
|
|
|
|
|
2018-07-02 11:31:41 +08:00
|
|
|
|
public DrawableTailNote(DrawableHoldNote holdNote)
|
|
|
|
|
: base(holdNote.HitObject.Tail)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
this.holdNote = holdNote;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 10:31:46 +08:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-09-02 17:31:33 +08:00
|
|
|
|
Debug.Assert(HitObject.HitWindows != null);
|
|
|
|
|
|
2018-05-17 12:59:04 +08:00
|
|
|
|
// Factor in the release lenience
|
|
|
|
|
timeOffset /= release_window_lenience;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (!userTriggered)
|
|
|
|
|
{
|
|
|
|
|
if (!HitObject.HitWindows.CanBeHit(timeOffset))
|
2018-08-03 14:38:48 +08:00
|
|
|
|
ApplyResult(r => r.Type = HitResult.Miss);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = HitObject.HitWindows.ResultFor(timeOffset);
|
|
|
|
|
if (result == HitResult.None)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-08-03 14:38:48 +08:00
|
|
|
|
ApplyResult(r =>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-08-02 19:36:54 +08:00
|
|
|
|
if (holdNote.hasBroken && (result == HitResult.Perfect || result == HitResult.Perfect))
|
|
|
|
|
result = HitResult.Good;
|
|
|
|
|
|
|
|
|
|
r.Type = result;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool OnPressed(ManiaAction action) => false; // Tail doesn't handle key down
|
|
|
|
|
|
|
|
|
|
public override bool OnReleased(ManiaAction action)
|
|
|
|
|
{
|
|
|
|
|
// Make sure that the user started holding the key during the hold note
|
|
|
|
|
if (!holdNote.holdStartTime.HasValue)
|
|
|
|
|
return false;
|
|
|
|
|
|
2018-07-02 11:31:41 +08:00
|
|
|
|
if (action != Action.Value)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2018-08-06 10:31:46 +08:00
|
|
|
|
UpdateResult(true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
// Handled by the hold note, which will set holding = false
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|