2019-01-24 08:43:03 +00: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.
|
2018-11-19 09:38:06 +00:00
|
|
|
|
2018-11-19 09:59:05 +00:00
|
|
|
using System;
|
2020-05-20 10:52:57 +00:00
|
|
|
using osu.Framework.Allocation;
|
2018-11-19 09:38:06 +00:00
|
|
|
using osu.Framework.Graphics;
|
2020-04-24 04:20:41 +00:00
|
|
|
using osu.Framework.Input.Events;
|
2020-05-20 10:05:03 +00:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2018-11-19 09:38:06 +00:00
|
|
|
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
2020-05-25 11:21:06 +00:00
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2018-11-29 06:14:07 +00:00
|
|
|
using osuTK;
|
2020-05-13 05:43:50 +00:00
|
|
|
using osuTK.Input;
|
2018-11-19 09:38:06 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
|
|
|
{
|
|
|
|
public class HoldNotePlacementBlueprint : ManiaPlacementBlueprint<HoldNote>
|
|
|
|
{
|
2018-11-19 09:59:05 +00:00
|
|
|
private readonly EditBodyPiece bodyPiece;
|
2018-11-19 09:38:06 +00:00
|
|
|
private readonly EditNotePiece headPiece;
|
|
|
|
private readonly EditNotePiece tailPiece;
|
|
|
|
|
2020-05-25 11:21:06 +00:00
|
|
|
[Resolved]
|
|
|
|
private IScrollingInfo scrollingInfo { get; set; }
|
|
|
|
|
2018-11-19 09:38:06 +00:00
|
|
|
public HoldNotePlacementBlueprint()
|
|
|
|
: base(new HoldNote())
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2018-11-19 09:59:05 +00:00
|
|
|
InternalChildren = new Drawable[]
|
2018-11-19 09:38:06 +00:00
|
|
|
{
|
2018-11-19 09:59:05 +00:00
|
|
|
bodyPiece = new EditBodyPiece { Origin = Anchor.TopCentre },
|
2018-11-19 09:38:06 +00:00
|
|
|
headPiece = new EditNotePiece { Origin = Anchor.Centre },
|
|
|
|
tailPiece = new EditNotePiece { Origin = Anchor.Centre }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2018-11-29 10:29:36 +00:00
|
|
|
if (Column != null)
|
2018-11-19 09:38:06 +00:00
|
|
|
{
|
2020-05-21 06:16:30 +00:00
|
|
|
headPiece.Y = Parent.ToLocalSpace(Column.ScreenSpacePositionAtTime(HitObject.StartTime)).Y;
|
|
|
|
tailPiece.Y = Parent.ToLocalSpace(Column.ScreenSpacePositionAtTime(HitObject.EndTime)).Y;
|
2020-05-25 11:21:06 +00:00
|
|
|
|
|
|
|
switch (scrollingInfo.Direction.Value)
|
|
|
|
{
|
|
|
|
case ScrollingDirection.Down:
|
|
|
|
headPiece.Y -= headPiece.DrawHeight / 2;
|
|
|
|
tailPiece.Y -= tailPiece.DrawHeight / 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ScrollingDirection.Up:
|
|
|
|
headPiece.Y += headPiece.DrawHeight / 2;
|
|
|
|
tailPiece.Y += tailPiece.DrawHeight / 2;
|
|
|
|
break;
|
|
|
|
}
|
2018-11-19 09:38:06 +00:00
|
|
|
}
|
2018-11-19 09:59:05 +00: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 09:38:06 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 04:20:41 +00:00
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
2020-05-13 05:43:50 +00:00
|
|
|
if (e.Button != MouseButton.Left)
|
|
|
|
return;
|
|
|
|
|
2020-04-24 04:20:41 +00:00
|
|
|
base.OnMouseUp(e);
|
2021-04-22 05:59:57 +00:00
|
|
|
EndPlacement(HitObject.Duration > 0);
|
2020-04-24 04:20:41 +00:00
|
|
|
}
|
|
|
|
|
2018-11-29 10:29:36 +00:00
|
|
|
private double originalStartTime;
|
2018-11-19 09:38:06 +00:00
|
|
|
|
2020-11-26 10:16:18 +00:00
|
|
|
public override void UpdateTimeAndPosition(SnapResult result)
|
2018-11-19 09:38:06 +00:00
|
|
|
{
|
2020-11-26 10:16:18 +00:00
|
|
|
base.UpdateTimeAndPosition(result);
|
2018-11-29 10:29:36 +00:00
|
|
|
|
2021-04-16 05:10:21 +00:00
|
|
|
if (PlacementActive == PlacementState.Active)
|
2018-11-19 09:38:06 +00:00
|
|
|
{
|
2020-05-20 10:05:03 +00:00
|
|
|
if (result.Time is double endTime)
|
|
|
|
{
|
|
|
|
HitObject.StartTime = endTime < originalStartTime ? endTime : originalStartTime;
|
|
|
|
HitObject.Duration = Math.Abs(endTime - originalStartTime);
|
|
|
|
}
|
2018-11-19 09:38:06 +00:00
|
|
|
}
|
2018-11-29 10:29:36 +00:00
|
|
|
else
|
|
|
|
{
|
2020-05-25 10:21:53 +00:00
|
|
|
if (result.Playfield != null)
|
2020-05-20 10:23:17 +00:00
|
|
|
{
|
2020-05-25 10:21:53 +00:00
|
|
|
headPiece.Width = tailPiece.Width = result.Playfield.DrawWidth;
|
2020-05-20 10:23:17 +00:00
|
|
|
headPiece.X = tailPiece.X = ToLocalSpace(result.ScreenSpacePosition).X;
|
|
|
|
}
|
2018-11-19 09:38:06 +00:00
|
|
|
|
2020-05-20 10:05:03 +00:00
|
|
|
if (result.Time is double startTime)
|
|
|
|
originalStartTime = HitObject.StartTime = startTime;
|
2018-11-29 10:29:36 +00:00
|
|
|
}
|
2018-11-19 09:38:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|