mirror of
https://github.com/ppy/osu
synced 2024-12-13 18:37:04 +00:00
93 lines
3.1 KiB
C#
93 lines
3.1 KiB
C#
// 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.
|
|
|
|
using System;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Input.Events;
|
|
using osu.Game.Rulesets.Edit;
|
|
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
using osuTK;
|
|
using osuTK.Input;
|
|
|
|
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
|
{
|
|
public class HoldNotePlacementBlueprint : ManiaPlacementBlueprint<HoldNote>
|
|
{
|
|
private readonly EditBodyPiece bodyPiece;
|
|
private readonly EditNotePiece headPiece;
|
|
private readonly EditNotePiece tailPiece;
|
|
|
|
[Resolved]
|
|
private IManiaHitObjectComposer composer { get; set; }
|
|
|
|
public HoldNotePlacementBlueprint()
|
|
: base(new HoldNote())
|
|
{
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
InternalChildren = new Drawable[]
|
|
{
|
|
bodyPiece = new EditBodyPiece { Origin = Anchor.TopCentre },
|
|
headPiece = new EditNotePiece { Origin = Anchor.Centre },
|
|
tailPiece = new EditNotePiece { Origin = Anchor.Centre }
|
|
};
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
|
|
if (Column != null)
|
|
{
|
|
headPiece.Y = Parent.ToLocalSpace(Column.ScreenSpacePositionAtTime(HitObject.StartTime, Column)).Y;
|
|
tailPiece.Y = Parent.ToLocalSpace(Column.ScreenSpacePositionAtTime(HitObject.EndTime, Column)).Y;
|
|
}
|
|
|
|
var topPosition = new Vector2(headPiece.DrawPosition.X, Math.Min(headPiece.DrawPosition.Y, tailPiece.DrawPosition.Y));
|
|
var bottomPosition = new Vector2(headPiece.DrawPosition.X, Math.Max(headPiece.DrawPosition.Y, tailPiece.DrawPosition.Y));
|
|
|
|
bodyPiece.Position = topPosition;
|
|
bodyPiece.Width = headPiece.Width;
|
|
bodyPiece.Height = (bottomPosition - topPosition).Y;
|
|
}
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
{
|
|
if (e.Button != MouseButton.Left)
|
|
return;
|
|
|
|
base.OnMouseUp(e);
|
|
EndPlacement(true);
|
|
}
|
|
|
|
private double originalStartTime;
|
|
|
|
public override void UpdatePosition(SnapResult result)
|
|
{
|
|
base.UpdatePosition(result);
|
|
|
|
if (PlacementActive)
|
|
{
|
|
if (result.Time is double endTime)
|
|
{
|
|
HitObject.StartTime = endTime < originalStartTime ? endTime : originalStartTime;
|
|
HitObject.Duration = Math.Abs(endTime - originalStartTime);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (result is ManiaSnapResult maniaResult)
|
|
{
|
|
headPiece.Width = tailPiece.Width = maniaResult.Column.DrawWidth;
|
|
headPiece.X = tailPiece.X = ToLocalSpace(result.ScreenSpacePosition).X;
|
|
}
|
|
|
|
if (result.Time is double startTime)
|
|
originalStartTime = HitObject.StartTime = startTime;
|
|
}
|
|
}
|
|
}
|
|
}
|