1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 09:32:53 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Edit/Blueprints/TaikoSpanPlacementBlueprint.cs

102 lines
3.2 KiB
C#
Raw Normal View History

2020-05-29 15:40:10 +08:00
using System;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
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 class TaikoSpanPlacementBlueprint : PlacementBlueprint
{
private readonly HitPiece headPiece;
private readonly HitPiece tailPiece;
private readonly LengthPiece lengthPiece;
private readonly IHasDuration spanPlacementObject;
public TaikoSpanPlacementBlueprint(HitObject hitObject)
: base(hitObject)
{
spanPlacementObject = hitObject as IHasDuration;
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
headPiece = new HitPiece
{
Size = new Vector2(TaikoHitObject.DEFAULT_SIZE * TaikoPlayfield.DEFAULT_HEIGHT)
},
lengthPiece = new LengthPiece
{
Height = TaikoHitObject.DEFAULT_SIZE * TaikoPlayfield.DEFAULT_HEIGHT
},
tailPiece = new HitPiece
{
Size = new Vector2(TaikoHitObject.DEFAULT_SIZE * TaikoPlayfield.DEFAULT_HEIGHT)
}
};
}
private double originalStartTime;
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);
EndPlacement(true);
}
public override void UpdatePosition(SnapResult result)
{
base.UpdatePosition(result);
if (PlacementActive)
{
if (result.Time is double endTime)
{
if (endTime < originalStartTime)
{
HitObject.StartTime = endTime;
spanPlacementObject.Duration = Math.Abs(endTime - originalStartTime);
headPiece.Position = ToLocalSpace(result.ScreenSpacePosition);
lengthPiece.X = headPiece.X;
lengthPiece.Width = tailPiece.X - headPiece.X;
}
else
{
spanPlacementObject.Duration = Math.Abs(endTime - originalStartTime);
tailPiece.Position = ToLocalSpace(result.ScreenSpacePosition);
lengthPiece.Width = tailPiece.X - headPiece.X;
}
}
}
else
{
lengthPiece.Position = headPiece.Position = tailPiece.Position = ToLocalSpace(result.ScreenSpacePosition);
if (result.Time is double startTime)
originalStartTime = HitObject.StartTime = startTime;
}
}
}
}