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
|
|
|
|
|
2020-08-17 23:29:00 +08:00
|
|
|
|
using System;
|
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;
|
2020-03-31 15:42:35 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2020-08-17 23:29:00 +08:00
|
|
|
|
using osuTK;
|
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
|
|
|
|
|
2020-03-31 15:42:35 +08:00
|
|
|
|
public IBindable<bool> IsHitting => isHitting;
|
|
|
|
|
|
|
|
|
|
private readonly Bindable<bool> isHitting = new Bindable<bool>();
|
|
|
|
|
|
2019-12-23 16:48:48 +08:00
|
|
|
|
public DrawableHoldNoteHead Head => headContainer.Child;
|
|
|
|
|
public DrawableHoldNoteTail Tail => tailContainer.Child;
|
2019-10-17 13:02:23 +08:00
|
|
|
|
|
2019-12-23 14:43:58 +08:00
|
|
|
|
private readonly Container<DrawableHoldNoteHead> headContainer;
|
|
|
|
|
private readonly Container<DrawableHoldNoteTail> tailContainer;
|
2019-10-17 11:37:20 +08:00
|
|
|
|
private readonly Container<DrawableHoldNoteTick> tickContainer;
|
|
|
|
|
|
2020-08-18 23:05:05 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains the maximum size/position of the body prior to any offset or size adjustments.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly Container bodyContainer;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains the offset size/position of the body such that the body extends half-way between the head and tail pieces.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly Container bodyOffsetContainer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
/// <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 17:48:14 +08:00
|
|
|
|
public double? HoldStartTime { get; private set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the hold note has been released too early and shouldn't give full score for the release.
|
|
|
|
|
/// </summary>
|
2019-12-23 17:48:14 +08:00
|
|
|
|
public bool HasBroken { get; private set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-08-17 23:29:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the hold note has been released potentially without having caused a break.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool hasReleased;
|
|
|
|
|
|
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;
|
|
|
|
|
|
2020-08-18 23:05:05 +08:00
|
|
|
|
AddRangeInternal(new[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-08-18 23:05:05 +08:00
|
|
|
|
bodyContainer = new Container
|
2020-04-23 11:53:23 +08:00
|
|
|
|
{
|
2020-08-18 23:05:05 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
2020-08-17 23:29:00 +08:00
|
|
|
|
{
|
2020-08-18 23:05:05 +08:00
|
|
|
|
bodyOffsetContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Child = new SkinnableDrawable(new ManiaSkinComponent(ManiaSkinComponents.HoldNoteBody, hitObject.Column), _ => new DefaultBodyPiece
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
// The head needs to move along with changes in the size of the body.
|
|
|
|
|
headContainer = new Container<DrawableHoldNoteHead> { RelativeSizeAxes = Axes.Both }
|
|
|
|
|
}
|
2020-03-31 15:42:35 +08:00
|
|
|
|
},
|
2019-10-17 11:37:20 +08:00
|
|
|
|
tickContainer = new Container<DrawableHoldNoteTick> { RelativeSizeAxes = Axes.Both },
|
2020-08-18 23:05:05 +08:00
|
|
|
|
headContainer.CreateProxy(),
|
2019-12-23 14:43:58 +08:00
|
|
|
|
tailContainer = new Container<DrawableHoldNoteTail> { RelativeSizeAxes = Axes.Both },
|
2019-03-25 12:47:28 +08:00
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 12:52:21 +08:00
|
|
|
|
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
2019-10-17 11:37:20 +08:00
|
|
|
|
{
|
2019-10-17 12:52:21 +08:00
|
|
|
|
base.AddNestedHitObject(hitObject);
|
2019-10-17 11:37:20 +08:00
|
|
|
|
|
2019-10-17 11:53:54 +08:00
|
|
|
|
switch (hitObject)
|
2019-10-17 11:37:20 +08:00
|
|
|
|
{
|
2019-12-23 14:43:58 +08:00
|
|
|
|
case DrawableHoldNoteHead head:
|
2019-10-17 11:37:20 +08:00
|
|
|
|
headContainer.Child = head;
|
|
|
|
|
break;
|
|
|
|
|
|
2019-12-23 14:43:58 +08:00
|
|
|
|
case DrawableHoldNoteTail tail:
|
2019-10-17 11:37:20 +08:00
|
|
|
|
tailContainer.Child = tail;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DrawableHoldNoteTick tick:
|
|
|
|
|
tickContainer.Add(tick);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 12:52:21 +08:00
|
|
|
|
protected override void ClearNestedHitObjects()
|
2019-10-17 11:37:20 +08:00
|
|
|
|
{
|
2019-10-17 12:52:21 +08:00
|
|
|
|
base.ClearNestedHitObjects();
|
2019-10-17 11:37:20 +08:00
|
|
|
|
headContainer.Clear();
|
|
|
|
|
tailContainer.Clear();
|
|
|
|
|
tickContainer.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 12:52:21 +08:00
|
|
|
|
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
|
2019-10-17 11:37:20 +08:00
|
|
|
|
{
|
|
|
|
|
switch (hitObject)
|
|
|
|
|
{
|
|
|
|
|
case TailNote _:
|
2019-12-23 14:43:58 +08:00
|
|
|
|
return new DrawableHoldNoteTail(this)
|
2019-10-17 11:37:20 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AccentColour = { BindTarget = AccentColour }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
case Note _:
|
2019-12-23 14:43:58 +08:00
|
|
|
|
return new DrawableHoldNoteHead(this)
|
2019-10-17 11:37:20 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AccentColour = { BindTarget = AccentColour }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
case HoldNoteTick tick:
|
|
|
|
|
return new DrawableHoldNoteTick(tick)
|
|
|
|
|
{
|
2019-12-23 14:43:58 +08:00
|
|
|
|
HoldStartTime = () => HoldStartTime,
|
2019-10-17 11:37:20 +08:00
|
|
|
|
AccentColour = { BindTarget = AccentColour }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 12:52:21 +08:00
|
|
|
|
return base.CreateNestedHitObject(hitObject);
|
2019-10-17 11:37:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2020-08-18 23:05:36 +08:00
|
|
|
|
// The body container is anchored from the position of the tail, since its height is changed when the hold note is being hit.
|
|
|
|
|
// The body offset container is anchored from the position of the head (inverse of the above).
|
|
|
|
|
if (e.NewValue == ScrollingDirection.Up)
|
|
|
|
|
{
|
|
|
|
|
bodyContainer.Anchor = bodyContainer.Origin = Anchor.BottomLeft;
|
|
|
|
|
bodyOffsetContainer.Anchor = bodyOffsetContainer.Origin = Anchor.TopLeft;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bodyContainer.Anchor = bodyContainer.Origin = Anchor.TopLeft;
|
|
|
|
|
bodyOffsetContainer.Anchor = bodyOffsetContainer.Origin = Anchor.BottomLeft;
|
|
|
|
|
}
|
2018-06-08 17:16:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 15:33:19 +08:00
|
|
|
|
public override void PlaySamples()
|
|
|
|
|
{
|
2020-04-21 16:20:37 +08:00
|
|
|
|
// Samples are played by the head/tail notes.
|
2020-04-21 15:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2020-08-18 23:05:05 +08:00
|
|
|
|
// Decrease the size of the body while the hold note is held and the head has been hit.
|
2020-08-17 23:29:00 +08:00
|
|
|
|
if (Head.IsHit && !hasReleased)
|
|
|
|
|
{
|
|
|
|
|
float heightDecrease = (float)(Math.Max(0, Time.Current - HitObject.StartTime) / HitObject.Duration);
|
2020-08-18 23:05:05 +08:00
|
|
|
|
bodyContainer.Height = MathHelper.Clamp(1 - heightDecrease, 0, 1);
|
2020-08-17 23:29:00 +08:00
|
|
|
|
}
|
2020-08-18 23:05:05 +08:00
|
|
|
|
|
|
|
|
|
// Offset the body to extend half-way under the head and tail.
|
|
|
|
|
bodyOffsetContainer.Y = (Direction.Value == ScrollingDirection.Up ? 1 : -1) * Head.Height / 2;
|
|
|
|
|
bodyOffsetContainer.Height = bodyContainer.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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 16:48:48 +08:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-09-06 22:49:54 +08:00
|
|
|
|
{
|
2019-12-23 16:48:48 +08:00
|
|
|
|
if (Tail.AllJudged)
|
|
|
|
|
ApplyResult(r => r.Type = HitResult.Perfect);
|
2018-09-06 22:49:54 +08:00
|
|
|
|
|
2019-12-23 16:48:48 +08:00
|
|
|
|
if (Tail.Result.Type == HitResult.Miss)
|
|
|
|
|
HasBroken = true;
|
2018-09-06 22:49:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public bool OnPressed(ManiaAction action)
|
|
|
|
|
{
|
2019-12-23 16:48:48 +08:00
|
|
|
|
if (AllJudged)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2018-07-02 11:31:41 +08:00
|
|
|
|
if (action != Action.Value)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2020-07-20 21:26:58 +08:00
|
|
|
|
// The tail has a lenience applied to it which is factored into the miss window (i.e. the miss judgement will be delayed).
|
|
|
|
|
// But the hold cannot ever be started within the late-lenience window, so we should skip trying to begin the hold during that time.
|
|
|
|
|
// Note: Unlike below, we use the tail's start time to determine the time offset.
|
|
|
|
|
if (Time.Current > Tail.HitObject.StartTime && !Tail.HitObject.HitWindows.CanBeHit(Time.Current - Tail.HitObject.StartTime))
|
|
|
|
|
return false;
|
|
|
|
|
|
2019-12-23 16:48:48 +08:00
|
|
|
|
beginHoldAt(Time.Current - Head.HitObject.StartTime);
|
|
|
|
|
Head.UpdateResult();
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 16:48:48 +08:00
|
|
|
|
private void beginHoldAt(double timeOffset)
|
|
|
|
|
{
|
|
|
|
|
if (timeOffset < -Head.HitObject.HitWindows.WindowFor(HitResult.Miss))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
HoldStartTime = Time.Current;
|
2020-03-31 15:42:35 +08:00
|
|
|
|
isHitting.Value = true;
|
2019-12-23 16:48:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 12:22:34 +08:00
|
|
|
|
public void OnReleased(ManiaAction action)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-12-23 16:48:48 +08:00
|
|
|
|
if (AllJudged)
|
2020-01-22 12:22:34 +08:00
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-02 11:31:41 +08:00
|
|
|
|
if (action != Action.Value)
|
2020-01-22 12:22:34 +08:00
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-23 16:48:48 +08:00
|
|
|
|
// Make sure a hold was started
|
|
|
|
|
if (HoldStartTime == null)
|
2020-01-22 12:22:34 +08:00
|
|
|
|
return;
|
2019-12-23 16:48:48 +08:00
|
|
|
|
|
|
|
|
|
Tail.UpdateResult();
|
|
|
|
|
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)
|
2019-12-23 14:43:58 +08:00
|
|
|
|
HasBroken = true;
|
2020-08-17 23:29:00 +08:00
|
|
|
|
|
|
|
|
|
hasReleased = true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2019-12-23 16:48:48 +08:00
|
|
|
|
|
|
|
|
|
private void endHold()
|
|
|
|
|
{
|
|
|
|
|
HoldStartTime = null;
|
2020-03-31 15:42:35 +08:00
|
|
|
|
isHitting.Value = false;
|
2019-12-23 16:48:48 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|