2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00: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 03:37:20 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2019-08-27 03:59:57 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2018-06-08 09:16:55 +00:00
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2018-04-13 09:19:50 +00: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 02:31:46 +00:00
|
|
|
|
public override bool DisplayResult => false;
|
2018-05-28 09:12:49 +00:00
|
|
|
|
|
2019-10-17 05:02:23 +00:00
|
|
|
|
public DrawableNote Head => headContainer.Child;
|
|
|
|
|
public DrawableNote Tail => tailContainer.Child;
|
|
|
|
|
|
2019-12-23 06:43:58 +00:00
|
|
|
|
private readonly Container<DrawableHoldNoteHead> headContainer;
|
|
|
|
|
private readonly Container<DrawableHoldNoteTail> tailContainer;
|
2019-10-17 03:37:20 +00:00
|
|
|
|
private readonly Container<DrawableHoldNoteTick> tickContainer;
|
|
|
|
|
|
2018-04-13 09:19:50 +00: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>
|
2019-12-23 06:43:58 +00:00
|
|
|
|
internal double? HoldStartTime;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the hold note has been released too early and shouldn't give full score for the release.
|
|
|
|
|
/// </summary>
|
2019-12-23 06:43:58 +00:00
|
|
|
|
internal bool HasBroken;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-02 03:31:41 +00:00
|
|
|
|
public DrawableHoldNote(HoldNote hitObject)
|
|
|
|
|
: base(hitObject)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
2019-03-25 04:47:28 +00:00
|
|
|
|
AddRangeInternal(new Drawable[]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-10-17 03:37:20 +00:00
|
|
|
|
bodyPiece = new BodyPiece { RelativeSizeAxes = Axes.X },
|
|
|
|
|
tickContainer = new Container<DrawableHoldNoteTick> { RelativeSizeAxes = Axes.Both },
|
2019-12-23 06:43:58 +00:00
|
|
|
|
headContainer = new Container<DrawableHoldNoteHead> { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
tailContainer = new Container<DrawableHoldNoteTail> { RelativeSizeAxes = Axes.Both },
|
2019-03-25 04:47:28 +00:00
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-22 05:45:25 +00:00
|
|
|
|
AccentColour.BindValueChanged(colour =>
|
|
|
|
|
{
|
|
|
|
|
bodyPiece.AccentColour = colour.NewValue;
|
|
|
|
|
}, true);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 04:52:21 +00:00
|
|
|
|
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
2019-10-17 03:37:20 +00:00
|
|
|
|
{
|
2019-10-17 04:52:21 +00:00
|
|
|
|
base.AddNestedHitObject(hitObject);
|
2019-10-17 03:37:20 +00:00
|
|
|
|
|
2019-10-17 03:53:54 +00:00
|
|
|
|
switch (hitObject)
|
2019-10-17 03:37:20 +00:00
|
|
|
|
{
|
2019-12-23 06:43:58 +00:00
|
|
|
|
case DrawableHoldNoteHead head:
|
2019-10-17 03:37:20 +00:00
|
|
|
|
headContainer.Child = head;
|
|
|
|
|
break;
|
|
|
|
|
|
2019-12-23 06:43:58 +00:00
|
|
|
|
case DrawableHoldNoteTail tail:
|
2019-10-17 03:37:20 +00:00
|
|
|
|
tailContainer.Child = tail;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DrawableHoldNoteTick tick:
|
|
|
|
|
tickContainer.Add(tick);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 04:52:21 +00:00
|
|
|
|
protected override void ClearNestedHitObjects()
|
2019-10-17 03:37:20 +00:00
|
|
|
|
{
|
2019-10-17 04:52:21 +00:00
|
|
|
|
base.ClearNestedHitObjects();
|
2019-10-17 03:37:20 +00:00
|
|
|
|
headContainer.Clear();
|
|
|
|
|
tailContainer.Clear();
|
|
|
|
|
tickContainer.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 04:52:21 +00:00
|
|
|
|
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
|
2019-10-17 03:37:20 +00:00
|
|
|
|
{
|
|
|
|
|
switch (hitObject)
|
|
|
|
|
{
|
|
|
|
|
case TailNote _:
|
2019-12-23 06:43:58 +00:00
|
|
|
|
return new DrawableHoldNoteTail(this)
|
2019-10-17 03:37:20 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AccentColour = { BindTarget = AccentColour }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
case Note _:
|
2019-12-23 06:43:58 +00:00
|
|
|
|
return new DrawableHoldNoteHead(this)
|
2019-10-17 03:37:20 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AccentColour = { BindTarget = AccentColour }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
case HoldNoteTick tick:
|
|
|
|
|
return new DrawableHoldNoteTick(tick)
|
|
|
|
|
{
|
2019-12-23 06:43:58 +00:00
|
|
|
|
HoldStartTime = () => HoldStartTime,
|
2019-10-17 03:37:20 +00:00
|
|
|
|
AccentColour = { BindTarget = AccentColour }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 04:52:21 +00:00
|
|
|
|
return base.CreateNestedHitObject(hitObject);
|
2019-10-17 03:37:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
protected override void OnDirectionChanged(ValueChangedEvent<ScrollingDirection> e)
|
2018-06-08 09:16:55 +00:00
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
|
base.OnDirectionChanged(e);
|
2018-06-08 09:16:55 +00:00
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
bodyPiece.Anchor = bodyPiece.Origin = e.NewValue == ScrollingDirection.Up ? Anchor.TopLeft : Anchor.BottomLeft;
|
2018-06-08 09:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 02:31:46 +00:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-05-16 10:43:01 +00:00
|
|
|
|
{
|
2018-05-20 10:22:42 +00:00
|
|
|
|
if (Tail.AllJudged)
|
2018-08-03 06:38:48 +00:00
|
|
|
|
ApplyResult(r => r.Type = HitResult.Perfect);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
// Make the body piece not lie under the head note
|
2018-07-17 04:13:57 +00:00
|
|
|
|
bodyPiece.Y = (Direction.Value == ScrollingDirection.Up ? 1 : -1) * Head.Height / 2;
|
2018-06-07 10:19:20 +00:00
|
|
|
|
bodyPiece.Height = DrawHeight - Head.Height / 2 + Tail.Height / 2;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 03:59:57 +00:00
|
|
|
|
protected override void UpdateStateTransforms(ArmedState state)
|
|
|
|
|
{
|
|
|
|
|
using (BeginDelayedSequence(HitObject.Duration, true))
|
|
|
|
|
base.UpdateStateTransforms(state);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 06:43:58 +00:00
|
|
|
|
internal void BeginHold()
|
2018-09-06 14:49:54 +00:00
|
|
|
|
{
|
2019-12-23 06:43:58 +00:00
|
|
|
|
HoldStartTime = Time.Current;
|
2018-09-06 14:49:54 +00:00
|
|
|
|
bodyPiece.Hitting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void EndHold()
|
|
|
|
|
{
|
2019-12-23 06:43:58 +00:00
|
|
|
|
HoldStartTime = null;
|
2018-09-06 14:49:54 +00:00
|
|
|
|
bodyPiece.Hitting = false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00: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 03:31:41 +00:00
|
|
|
|
if (action != Action.Value)
|
2018-04-13 09:19:50 +00: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 14:49:54 +00:00
|
|
|
|
BeginHold();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnReleased(ManiaAction action)
|
|
|
|
|
{
|
|
|
|
|
// Make sure that the user started holding the key during the hold note
|
2019-12-23 06:43:58 +00:00
|
|
|
|
if (!HoldStartTime.HasValue)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2018-07-02 03:31:41 +00:00
|
|
|
|
if (action != Action.Value)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2018-09-06 14:49:54 +00:00
|
|
|
|
EndHold();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
// If the key has been released too early, the user should not receive full score for the release
|
2018-05-20 10:22:42 +00:00
|
|
|
|
if (!Tail.IsHit)
|
2019-12-23 06:43:58 +00:00
|
|
|
|
HasBroken = true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|