2018-11-12 17:32:44 +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
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
2018-11-13 13:13:29 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2018-11-12 17:32:44 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
2018-11-19 17:40:16 +08:00
|
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
|
2018-11-12 17:32:44 +08:00
|
|
|
using osu.Game.Rulesets.Mania.UI;
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
|
|
|
{
|
2018-11-19 16:59:52 +08:00
|
|
|
public abstract class ManiaPlacementBlueprint<T> : PlacementBlueprint
|
2018-11-12 17:32:44 +08:00
|
|
|
where T : ManiaHitObject
|
|
|
|
{
|
|
|
|
protected new T HitObject => (T)base.HitObject;
|
|
|
|
|
2018-11-13 13:13:29 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The current mouse position, snapped to the closest column.
|
|
|
|
/// </summary>
|
|
|
|
protected Vector2 SnappedMousePosition { get; private set; }
|
|
|
|
|
2018-11-19 17:40:16 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The width of the closest column to the current mouse position.
|
|
|
|
/// </summary>
|
|
|
|
protected float SnappedWidth { get; private set; }
|
|
|
|
|
2018-11-12 17:32:44 +08:00
|
|
|
[Resolved]
|
2018-11-12 18:41:06 +08:00
|
|
|
private IManiaHitObjectComposer composer { get; set; }
|
2018-11-12 17:32:44 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IScrollingInfo scrollingInfo { get; set; }
|
|
|
|
|
2018-11-19 16:59:52 +08:00
|
|
|
protected ManiaPlacementBlueprint(T hitObject)
|
2018-11-12 17:32:44 +08:00
|
|
|
: base(hitObject)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.None;
|
|
|
|
}
|
|
|
|
|
2018-11-13 13:13:29 +08:00
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
|
|
|
{
|
2018-11-19 16:59:52 +08:00
|
|
|
Column column = ColumnAt(e.ScreenSpaceMousePosition);
|
2018-11-19 17:02:01 +08:00
|
|
|
|
2018-11-19 16:59:52 +08:00
|
|
|
if (column == null)
|
|
|
|
SnappedMousePosition = e.MousePosition;
|
|
|
|
else
|
2018-11-13 13:13:29 +08:00
|
|
|
{
|
2018-11-19 17:40:16 +08:00
|
|
|
SnappedWidth = column.DrawWidth;
|
2018-11-19 17:05:21 +08:00
|
|
|
|
2018-11-19 16:59:52 +08:00
|
|
|
// Snap to the column
|
|
|
|
var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0)));
|
|
|
|
SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-11-13 13:13:29 +08:00
|
|
|
}
|
|
|
|
|
2018-11-12 17:32:44 +08:00
|
|
|
protected double TimeAt(Vector2 screenSpacePosition)
|
|
|
|
{
|
|
|
|
var column = ColumnAt(screenSpacePosition);
|
|
|
|
if (column == null)
|
|
|
|
return 0;
|
|
|
|
|
2018-11-12 18:40:57 +08:00
|
|
|
var hitObjectContainer = column.HitObjectContainer;
|
|
|
|
|
|
|
|
// If we're scrolling downwards, a position of 0 is actually further away from the hit target
|
|
|
|
// so we need to flip the vertical coordinate in the hitobject container's space
|
|
|
|
var hitObjectPos = column.HitObjectContainer.ToLocalSpace(applyPositionOffset(screenSpacePosition)).Y;
|
|
|
|
if (scrollingInfo.Direction.Value == ScrollingDirection.Down)
|
|
|
|
hitObjectPos = hitObjectContainer.DrawHeight - hitObjectPos;
|
|
|
|
|
|
|
|
return scrollingInfo.Algorithm.TimeAt(hitObjectPos,
|
2018-11-12 17:32:44 +08:00
|
|
|
EditorClock.CurrentTime,
|
|
|
|
scrollingInfo.TimeRange.Value,
|
2018-11-12 18:40:57 +08:00
|
|
|
hitObjectContainer.DrawHeight);
|
2018-11-12 17:32:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected Column ColumnAt(Vector2 screenSpacePosition)
|
|
|
|
=> composer.ColumnAt(applyPositionOffset(screenSpacePosition));
|
|
|
|
|
|
|
|
private Vector2 applyPositionOffset(Vector2 position)
|
|
|
|
{
|
|
|
|
switch (scrollingInfo.Direction.Value)
|
|
|
|
{
|
|
|
|
case ScrollingDirection.Up:
|
2018-11-19 17:40:16 +08:00
|
|
|
position.Y -= NotePiece.NOTE_HEIGHT / 2;
|
2018-11-12 17:32:44 +08:00
|
|
|
break;
|
|
|
|
case ScrollingDirection.Down:
|
2018-11-19 17:40:16 +08:00
|
|
|
position.Y += NotePiece.NOTE_HEIGHT / 2;
|
2018-11-12 17:32:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|