1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 02:27:25 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Edit/Blueprints/HoldNotePlacementBlueprint.cs

97 lines
3.0 KiB
C#
Raw Normal View History

2018-11-19 17:38:06 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2018-11-19 17:59:05 +08:00
using System;
2018-11-19 17:38:06 +08:00
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.UI;
using osuTK;
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;
private PlacementState state;
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();
switch (state)
{
case PlacementState.Start:
2018-11-19 17:59:05 +08:00
headPiece.Position = tailPiece.Position = SnappedMousePosition;
headPiece.Width = tailPiece.Width = SnappedWidth;
2018-11-19 17:38:06 +08:00
break;
case PlacementState.End:
2018-11-19 17:59:05 +08:00
tailPiece.Position = new Vector2(headPiece.Position.X, SnappedMousePosition.Y);
2018-11-19 17:38:06 +08:00
break;
}
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
}
protected override bool OnMouseDown(MouseDownEvent e)
{
Column column;
if ((column = ColumnAt(e.ScreenSpaceMousePosition)) == null)
return base.OnMouseDown(e);
HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition);
HitObject.Column = column.Index;
BeginPlacement();
state = PlacementState.End;
return true;
}
protected override bool OnMouseUp(MouseUpEvent e)
{
var endTime = TimeAt(e.ScreenSpaceMousePosition);
if (endTime < HitObject.StartTime)
{
var tmp = endTime;
endTime = HitObject.StartTime;
HitObject.StartTime = tmp;
}
HitObject.Duration = endTime - HitObject.StartTime;
EndPlacement();
return true;
}
private enum PlacementState
{
Start,
End
}
}
}