// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using osu.Framework.Graphics; using osu.Framework.Input.Events; using osu.Game.Rulesets.Mania.Edit.Blueprints.Components; using osu.Game.Rulesets.Mania.Objects; using osuTK; namespace osu.Game.Rulesets.Mania.Edit.Blueprints { public class HoldNotePlacementBlueprint : ManiaPlacementBlueprint { private readonly EditBodyPiece bodyPiece; private readonly EditNotePiece headPiece; private readonly EditNotePiece tailPiece; 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 = PositionAt(HitObject.StartTime); tailPiece.Y = PositionAt(HitObject.EndTime); } 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; } private double originalStartTime; protected override bool OnMouseMove(MouseMoveEvent e) { base.OnMouseMove(e); if (PlacementBegun) { var endTime = TimeAt(e.ScreenSpaceMousePosition); HitObject.StartTime = endTime < originalStartTime ? endTime : originalStartTime; HitObject.Duration = Math.Abs(endTime - originalStartTime); } else { headPiece.Width = tailPiece.Width = SnappedWidth; headPiece.X = tailPiece.X = SnappedMousePosition.X; originalStartTime = HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition); } return true; } } }