1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 02:07:24 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Edit/Blueprints/HoldNotePlacementBlueprint.cs

93 lines
3.1 KiB
C#
Raw Normal View History

// 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.
2018-11-19 17:38:06 +08:00
2018-11-19 17:59:05 +08:00
using System;
using osu.Framework.Allocation;
2018-11-19 17:38:06 +08:00
using osu.Framework.Graphics;
2020-04-24 12:20:41 +08:00
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
2018-11-19 17:38:06 +08:00
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
using osu.Game.Rulesets.Mania.Objects;
using osuTK;
using osuTK.Input;
2018-11-19 17:38:06 +08:00
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
public class HoldNotePlacementBlueprint : ManiaPlacementBlueprint<HoldNote>
{
2018-11-19 17:59:05 +08:00
private readonly EditBodyPiece bodyPiece;
2018-11-19 17:38:06 +08:00
private readonly EditNotePiece headPiece;
private readonly EditNotePiece tailPiece;
[Resolved]
private IManiaHitObjectComposer composer { get; set; }
2018-11-19 17:38:06 +08:00
public HoldNotePlacementBlueprint()
: base(new HoldNote())
{
RelativeSizeAxes = Axes.Both;
2018-11-19 17:59:05 +08:00
InternalChildren = new Drawable[]
2018-11-19 17:38:06 +08:00
{
2018-11-19 17:59:05 +08:00
bodyPiece = new EditBodyPiece { Origin = Anchor.TopCentre },
2018-11-19 17:38:06 +08:00
headPiece = new EditNotePiece { Origin = Anchor.Centre },
tailPiece = new EditNotePiece { Origin = Anchor.Centre }
};
}
protected override void Update()
{
base.Update();
2018-11-29 18:29:36 +08:00
if (Column != null)
2018-11-19 17:38:06 +08:00
{
headPiece.Y = Parent.ToLocalSpace(Column.ScreenSpacePositionAtTime(HitObject.StartTime)).Y;
tailPiece.Y = Parent.ToLocalSpace(Column.ScreenSpacePositionAtTime(HitObject.EndTime)).Y;
2018-11-19 17:38:06 +08:00
}
2018-11-19 17:59:05 +08:00
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;
2018-11-19 17:38:06 +08:00
}
2020-04-24 12:20:41 +08:00
protected override void OnMouseUp(MouseUpEvent e)
{
if (e.Button != MouseButton.Left)
return;
2020-04-24 12:20:41 +08:00
base.OnMouseUp(e);
EndPlacement(true);
}
2018-11-29 18:29:36 +08:00
private double originalStartTime;
2018-11-19 17:38:06 +08:00
public override void UpdatePosition(SnapResult result)
2018-11-19 17:38:06 +08:00
{
base.UpdatePosition(result);
2018-11-29 18:29:36 +08:00
if (PlacementActive)
2018-11-19 17:38:06 +08:00
{
if (result.Time is double endTime)
{
HitObject.StartTime = endTime < originalStartTime ? endTime : originalStartTime;
HitObject.Duration = Math.Abs(endTime - originalStartTime);
}
2018-11-19 17:38:06 +08:00
}
2018-11-29 18:29:36 +08:00
else
{
if (result is ManiaSnapResult maniaResult)
{
headPiece.Width = tailPiece.Width = maniaResult.Column.DrawWidth;
headPiece.X = tailPiece.X = ToLocalSpace(result.ScreenSpacePosition).X;
}
2018-11-19 17:38:06 +08:00
if (result.Time is double startTime)
originalStartTime = HitObject.StartTime = startTime;
2018-11-29 18:29:36 +08:00
}
2018-11-19 17:38:06 +08:00
}
}
}