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
|
|
|
|
|
|
2017-09-11 03:22:17 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-05-04 17:02:43 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
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-09-11 03:22:17 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-08-23 12:42:11 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2017-05-04 17:02:43 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
|
|
|
|
{
|
2017-05-24 20:57:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Visualises a <see cref="HoldNote"/> hit object.
|
|
|
|
|
/// </summary>
|
2017-08-23 12:42:11 +08:00
|
|
|
|
public class DrawableHoldNote : DrawableManiaHitObject<HoldNote>, IKeyBindingHandler<ManiaAction>
|
2017-05-04 17:02:43 +08:00
|
|
|
|
{
|
2017-05-24 20:57:38 +08:00
|
|
|
|
private readonly DrawableNote head;
|
|
|
|
|
private readonly DrawableNote tail;
|
|
|
|
|
|
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;
|
2017-09-11 03:22:17 +08:00
|
|
|
|
private readonly Container glowContainer;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-05-26 17:56:21 +08:00
|
|
|
|
/// Time at which the user started holding this hold note. Null if the user is not holding this hold note.
|
2017-05-24 19:45:01 +08:00
|
|
|
|
/// </summary>
|
2017-05-26 17:56:21 +08:00
|
|
|
|
private double? holdStartTime;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the hold note has been released too early and shouldn't give full score for the release.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool hasBroken;
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
public DrawableHoldNote(HoldNote hitObject, ManiaAction action)
|
|
|
|
|
: base(hitObject, action)
|
2017-05-04 17:02:43 +08:00
|
|
|
|
{
|
2017-05-09 19:33:59 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
Height = (float)HitObject.Duration;
|
|
|
|
|
|
2017-07-11 21:58:06 +08:00
|
|
|
|
AddRange(new Drawable[]
|
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-09-11 03:21:22 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-05-04 17:02:43 +08:00
|
|
|
|
},
|
2017-05-24 19:45:01 +08:00
|
|
|
|
tickContainer = new Container<DrawableHoldNoteTick>
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-06-06 14:57:30 +08:00
|
|
|
|
RelativeChildOffset = new Vector2(0, (float)HitObject.StartTime),
|
2017-06-06 14:52:35 +08:00
|
|
|
|
RelativeChildSize = new Vector2(1, (float)HitObject.Duration)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
},
|
2017-08-23 12:42:11 +08:00
|
|
|
|
head = new DrawableHeadNote(this, action)
|
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-08-23 12:42:11 +08:00
|
|
|
|
tail = new DrawableTailNote(this, action)
|
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-09-11 03:22:17 +08:00
|
|
|
|
},
|
2017-09-11 03:29:32 +08:00
|
|
|
|
// The hit object itself cannot be used for the glow because the tail overshoots it
|
|
|
|
|
// So a specialized container that is updated to contain the tail height is used
|
2017-09-11 03:22:17 +08:00
|
|
|
|
glowContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Child = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
AlwaysPresent = true
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
HoldStartTime = () => holdStartTime
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
tickContainer.Add(drawableTick);
|
|
|
|
|
AddNested(drawableTick);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 20:57:38 +08:00
|
|
|
|
AddNested(head);
|
|
|
|
|
AddNested(tail);
|
2017-05-04 17:02:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 03:29:32 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
updateGlow();
|
|
|
|
|
}
|
|
|
|
|
|
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 20:57:38 +08:00
|
|
|
|
head.AccentColour = value;
|
|
|
|
|
tail.AccentColour = value;
|
2017-09-11 03:29:32 +08:00
|
|
|
|
|
|
|
|
|
updateGlow();
|
2017-05-04 17:02:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 03:29:32 +08:00
|
|
|
|
private void updateGlow()
|
|
|
|
|
{
|
|
|
|
|
if (!IsLoaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
glowContainer.EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Colour = AccentColour.Opacity(0.5f),
|
|
|
|
|
Radius = 10,
|
|
|
|
|
Hollow = true
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-04 17:02:43 +08:00
|
|
|
|
protected override void UpdateState(ArmedState state)
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-05-12 18:10:26 +08:00
|
|
|
|
|
2017-09-11 03:21:22 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2017-09-11 03:29:32 +08:00
|
|
|
|
// Make the body piece not lie under the head note
|
2017-09-11 03:21:22 +08:00
|
|
|
|
bodyPiece.Y = head.Height;
|
|
|
|
|
bodyPiece.Height = DrawHeight - head.Height;
|
2017-09-11 03:22:17 +08:00
|
|
|
|
|
2017-09-11 03:29:32 +08:00
|
|
|
|
// Make the glowContainer "contain" the height of the tail note, keeping in mind
|
|
|
|
|
// that the tail note overshoots the height of this hit object
|
2017-09-11 03:22:17 +08:00
|
|
|
|
glowContainer.Height = DrawHeight + tail.Height;
|
2017-09-11 03:21:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
public bool OnPressed(ManiaAction action)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
{
|
2017-08-23 12:42:11 +08:00
|
|
|
|
// Make sure the action happened within the body of the hold note
|
2017-05-24 19:45:01 +08:00
|
|
|
|
if (Time.Current < HitObject.StartTime || Time.Current > HitObject.EndTime)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
if (action != Action)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-05-26 15:10:04 +08:00
|
|
|
|
// 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.
|
2017-05-26 17:56:21 +08:00
|
|
|
|
holdStartTime = Time.Current;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
public bool OnReleased(ManiaAction action)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
{
|
|
|
|
|
// Make sure that the user started holding the key during the hold note
|
2017-05-26 17:56:21 +08:00
|
|
|
|
if (!holdStartTime.HasValue)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
if (action != Action)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-05-26 17:56:21 +08:00
|
|
|
|
holdStartTime = null;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
|
2017-05-26 15:10:04 +08:00
|
|
|
|
// If the key has been released too early, the user should not receive full score for the release
|
2017-05-24 20:57:38 +08:00
|
|
|
|
if (!tail.Judged)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
hasBroken = true;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 20:57:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The head note of a hold.
|
|
|
|
|
/// </summary>
|
2017-05-26 15:39:43 +08:00
|
|
|
|
private class DrawableHeadNote : DrawableNote
|
2017-05-24 19:45:01 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly DrawableHoldNote holdNote;
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
public DrawableHeadNote(DrawableHoldNote holdNote, ManiaAction action)
|
|
|
|
|
: base(holdNote.HitObject.Head, action)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
{
|
|
|
|
|
this.holdNote = holdNote;
|
|
|
|
|
|
|
|
|
|
RelativePositionAxes = Axes.None;
|
|
|
|
|
Y = 0;
|
2017-09-11 03:22:17 +08:00
|
|
|
|
|
2017-09-11 03:34:30 +08:00
|
|
|
|
// Life time managed by the parent DrawableHoldNote
|
|
|
|
|
LifetimeStart = double.MinValue;
|
|
|
|
|
LifetimeEnd = double.MaxValue;
|
|
|
|
|
|
2017-09-11 03:22:17 +08:00
|
|
|
|
HasOwnGlow = false;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
public override bool OnPressed(ManiaAction action)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
{
|
2017-08-23 12:42:11 +08:00
|
|
|
|
if (!base.OnPressed(action))
|
2017-05-24 19:45:01 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// We only want to trigger a holding state from the head if the head has received a judgement
|
2017-05-26 15:10:04 +08:00
|
|
|
|
if (!Judged)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-05-26 15:10:04 +08:00
|
|
|
|
// If the key has been released too early, the user should not receive full score for the release
|
2017-05-24 19:45:01 +08:00
|
|
|
|
if (Judgement.Result == HitResult.Miss)
|
|
|
|
|
holdNote.hasBroken = true;
|
|
|
|
|
|
2017-05-26 15:10:04 +08:00
|
|
|
|
// 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
|
2017-05-26 17:56:21 +08:00
|
|
|
|
holdNote.holdStartTime = Time.Current;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 20:57:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The tail note of a hold.
|
|
|
|
|
/// </summary>
|
2017-05-26 15:39:43 +08:00
|
|
|
|
private class DrawableTailNote : DrawableNote
|
2017-05-12 18:10:26 +08:00
|
|
|
|
{
|
2017-05-24 19:45:01 +08:00
|
|
|
|
private readonly DrawableHoldNote holdNote;
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
public DrawableTailNote(DrawableHoldNote holdNote, ManiaAction action)
|
|
|
|
|
: base(holdNote.HitObject.Tail, action)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
{
|
|
|
|
|
this.holdNote = holdNote;
|
|
|
|
|
|
|
|
|
|
RelativePositionAxes = Axes.None;
|
|
|
|
|
Y = 0;
|
2017-09-11 03:22:17 +08:00
|
|
|
|
|
2017-09-11 03:34:30 +08:00
|
|
|
|
// Life time managed by the parent DrawableHoldNote
|
|
|
|
|
LifetimeStart = double.MinValue;
|
|
|
|
|
LifetimeEnd = double.MaxValue;
|
|
|
|
|
|
2017-09-11 03:22:17 +08:00
|
|
|
|
HasOwnGlow = false;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
public override bool OnPressed(ManiaAction action) => false; // Tail doesn't handle key down
|
|
|
|
|
|
|
|
|
|
public override bool OnReleased(ManiaAction action)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
{
|
|
|
|
|
// Make sure that the user started holding the key during the hold note
|
2017-05-26 17:56:21 +08:00
|
|
|
|
if (!holdNote.holdStartTime.HasValue)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (Judgement.Result != HitResult.None)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
if (action != Action)
|
2017-05-24 19:45:01 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
UpdateJudgement(true);
|
|
|
|
|
|
|
|
|
|
// Handled by the hold note, which will set holding = false
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-05-12 18:10:26 +08:00
|
|
|
|
}
|
2017-05-04 17:02:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|