2020-05-29 17:58:34 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-05-29 15:40:10 +08:00
|
|
|
using System;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Input.Events;
|
2023-12-20 04:20:21 +08:00
|
|
|
using osu.Framework.Utils;
|
2020-05-29 15:40:10 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
using osu.Game.Rulesets.Taiko.Objects;
|
|
|
|
using osu.Game.Rulesets.Taiko.UI;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Edit.Blueprints
|
|
|
|
{
|
|
|
|
public partial class TaikoSpanPlacementBlueprint : PlacementBlueprint
|
|
|
|
{
|
|
|
|
private readonly HitPiece headPiece;
|
|
|
|
private readonly HitPiece tailPiece;
|
|
|
|
|
|
|
|
private readonly LengthPiece lengthPiece;
|
|
|
|
|
|
|
|
private readonly IHasDuration spanPlacementObject;
|
|
|
|
|
2023-12-20 04:20:21 +08:00
|
|
|
protected override bool IsValidForPlacement => Precision.DefinitelyBigger(spanPlacementObject.Duration, 0);
|
2023-05-12 15:00:40 +08:00
|
|
|
|
2020-05-29 15:40:10 +08:00
|
|
|
public TaikoSpanPlacementBlueprint(HitObject hitObject)
|
|
|
|
: base(hitObject)
|
|
|
|
{
|
|
|
|
spanPlacementObject = hitObject as IHasDuration;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
headPiece = new HitPiece
|
|
|
|
{
|
2024-01-20 04:48:05 +08:00
|
|
|
Size = new Vector2(TaikoHitObject.DEFAULT_SIZE * TaikoPlayfield.BASE_HEIGHT)
|
2020-05-29 15:40:10 +08:00
|
|
|
},
|
|
|
|
lengthPiece = new LengthPiece
|
|
|
|
{
|
2024-01-20 04:48:05 +08:00
|
|
|
Height = TaikoHitObject.DEFAULT_SIZE * TaikoPlayfield.BASE_HEIGHT
|
2020-05-29 15:40:10 +08:00
|
|
|
},
|
|
|
|
tailPiece = new HitPiece
|
|
|
|
{
|
2024-01-20 04:48:05 +08:00
|
|
|
Size = new Vector2(TaikoHitObject.DEFAULT_SIZE * TaikoPlayfield.BASE_HEIGHT)
|
2020-05-29 15:40:10 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private double originalStartTime;
|
2020-06-02 20:02:09 +08:00
|
|
|
private Vector2 originalPosition;
|
2020-05-29 15:40:10 +08:00
|
|
|
|
2022-10-23 00:32:22 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
BeginPlacement();
|
|
|
|
}
|
|
|
|
|
2020-05-29 15:40:10 +08:00
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
|
|
|
if (e.Button != MouseButton.Left)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
BeginPlacement(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
|
|
|
if (e.Button != MouseButton.Left)
|
|
|
|
return;
|
|
|
|
|
|
|
|
base.OnMouseUp(e);
|
2023-05-12 15:00:40 +08:00
|
|
|
EndPlacement(true);
|
2020-05-29 15:40:10 +08:00
|
|
|
}
|
|
|
|
|
2020-11-26 18:16:18 +08:00
|
|
|
public override void UpdateTimeAndPosition(SnapResult result)
|
2020-05-29 15:40:10 +08:00
|
|
|
{
|
2020-11-26 18:16:18 +08:00
|
|
|
base.UpdateTimeAndPosition(result);
|
2020-05-29 15:40:10 +08:00
|
|
|
|
2021-04-16 13:10:21 +08:00
|
|
|
if (PlacementActive == PlacementState.Active)
|
2020-05-29 15:40:10 +08:00
|
|
|
{
|
2020-06-02 20:02:09 +08:00
|
|
|
if (result.Time is double dragTime)
|
2020-05-29 15:40:10 +08:00
|
|
|
{
|
2020-06-02 20:02:09 +08:00
|
|
|
if (dragTime < originalStartTime)
|
2020-05-29 15:40:10 +08:00
|
|
|
{
|
2020-06-02 20:02:09 +08:00
|
|
|
HitObject.StartTime = dragTime;
|
|
|
|
spanPlacementObject.Duration = Math.Abs(dragTime - originalStartTime);
|
2020-05-29 15:40:10 +08:00
|
|
|
headPiece.Position = ToLocalSpace(result.ScreenSpacePosition);
|
2020-06-02 20:02:09 +08:00
|
|
|
tailPiece.Position = originalPosition;
|
2020-05-29 15:40:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-02 20:02:09 +08:00
|
|
|
HitObject.StartTime = originalStartTime;
|
|
|
|
spanPlacementObject.Duration = Math.Abs(dragTime - originalStartTime);
|
2020-05-29 15:40:10 +08:00
|
|
|
tailPiece.Position = ToLocalSpace(result.ScreenSpacePosition);
|
2020-06-02 20:02:09 +08:00
|
|
|
headPiece.Position = originalPosition;
|
2020-05-29 15:40:10 +08:00
|
|
|
}
|
2020-06-02 20:02:09 +08:00
|
|
|
|
|
|
|
lengthPiece.X = headPiece.X;
|
|
|
|
lengthPiece.Width = tailPiece.X - headPiece.X;
|
2020-05-29 15:40:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lengthPiece.Position = headPiece.Position = tailPiece.Position = ToLocalSpace(result.ScreenSpacePosition);
|
|
|
|
|
|
|
|
if (result.Time is double startTime)
|
2020-06-02 20:02:09 +08:00
|
|
|
{
|
2020-05-29 15:40:10 +08:00
|
|
|
originalStartTime = HitObject.StartTime = startTime;
|
2020-06-02 20:02:09 +08:00
|
|
|
originalPosition = ToLocalSpace(result.ScreenSpacePosition);
|
|
|
|
}
|
2020-05-29 15:40:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|