1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 01:47:24 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Edit/Blueprints/TaikoSpanPlacementBlueprint.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

122 lines
3.9 KiB
C#
Raw Normal View History

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;
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;
protected override bool IsValidForPlacement => Precision.DefinitelyBigger(spanPlacementObject.Duration, 0);
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
{
Size = new Vector2(TaikoHitObject.DEFAULT_SIZE * TaikoPlayfield.BASE_HEIGHT)
2020-05-29 15:40:10 +08:00
},
lengthPiece = new LengthPiece
{
Height = TaikoHitObject.DEFAULT_SIZE * TaikoPlayfield.BASE_HEIGHT
2020-05-29 15:40:10 +08:00
},
tailPiece = new HitPiece
{
Size = new Vector2(TaikoHitObject.DEFAULT_SIZE * TaikoPlayfield.BASE_HEIGHT)
2020-05-29 15:40:10 +08:00
}
};
}
private double originalStartTime;
private Vector2 originalPosition;
2020-05-29 15:40:10 +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);
EndPlacement(true);
2020-05-29 15:40:10 +08:00
}
public override void UpdateTimeAndPosition(SnapResult result)
2020-05-29 15:40:10 +08:00
{
base.UpdateTimeAndPosition(result);
2020-05-29 15:40:10 +08:00
if (PlacementActive == PlacementState.Active)
2020-05-29 15:40:10 +08:00
{
if (result.Time is double dragTime)
2020-05-29 15:40:10 +08:00
{
if (dragTime < originalStartTime)
2020-05-29 15:40:10 +08:00
{
HitObject.StartTime = dragTime;
spanPlacementObject.Duration = Math.Abs(dragTime - originalStartTime);
2020-05-29 15:40:10 +08:00
headPiece.Position = ToLocalSpace(result.ScreenSpacePosition);
tailPiece.Position = originalPosition;
2020-05-29 15:40:10 +08:00
}
else
{
HitObject.StartTime = originalStartTime;
spanPlacementObject.Duration = Math.Abs(dragTime - originalStartTime);
2020-05-29 15:40:10 +08:00
tailPiece.Position = ToLocalSpace(result.ScreenSpacePosition);
headPiece.Position = originalPosition;
2020-05-29 15:40:10 +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-05-29 15:40:10 +08:00
originalStartTime = HitObject.StartTime = startTime;
originalPosition = ToLocalSpace(result.ScreenSpacePosition);
}
2020-05-29 15:40:10 +08:00
}
}
}
}