1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-30 07:47:35 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs

89 lines
2.9 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.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
2018-11-29 18:29:36 +08:00
using osu.Framework.Input;
2018-11-13 13:13:29 +08:00
using osu.Framework.Input.Events;
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;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.UI.Scrolling;
2018-11-26 09:44:48 +08:00
using osuTK;
using osuTK.Input;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
2018-11-29 18:29:36 +08:00
public abstract class ManiaPlacementBlueprint<T> : PlacementBlueprint,
IRequireHighFrequencyMousePosition // the playfield could be moving behind us
where T : ManiaHitObject
{
protected new T HitObject => (T)base.HitObject;
2018-11-29 18:29:36 +08:00
protected Column Column;
[Resolved]
private IScrollingInfo scrollingInfo { get; set; }
2018-11-19 16:59:52 +08:00
protected ManiaPlacementBlueprint(T hitObject)
: base(hitObject)
{
RelativeSizeAxes = Axes.None;
}
2018-11-29 18:29:36 +08:00
protected override bool OnMouseDown(MouseDownEvent e)
{
if (e.Button != MouseButton.Left)
return false;
2018-11-29 18:29:36 +08:00
if (Column == null)
return base.OnMouseDown(e);
HitObject.Column = Column.Index;
BeginPlacement(true);
2018-11-29 18:29:36 +08:00
return true;
}
public override void UpdatePosition(SnapResult result)
2018-11-13 13:13:29 +08:00
{
if (!PlacementActive)
2020-05-20 18:09:04 +08:00
Column = (result as ManiaSnapResult)?.Column;
}
2018-11-29 18:29:36 +08:00
protected float PositionAt(double time)
{
var pos = scrollingInfo.Algorithm.PositionAt(time,
EditorClock.CurrentTime,
scrollingInfo.TimeRange.Value,
Column.HitObjectContainer.DrawHeight);
if (scrollingInfo.Direction.Value == ScrollingDirection.Down)
pos = Column.HitObjectContainer.DrawHeight - pos;
return hitObjectToMousePosition(Column.HitObjectContainer.ToSpaceOfOtherDrawable(new Vector2(0, pos), Parent)).Y;
2018-11-29 18:29:36 +08:00
}
/// <summary>
/// Converts a hitobject position to a mouse position.
/// </summary>
/// <param name="hitObjectPosition">The hitobject position.</param>
/// <returns>The resulting mouse position, anchored at the centre of the hitobject.</returns>
private Vector2 hitObjectToMousePosition(Vector2 hitObjectPosition)
{
switch (scrollingInfo.Direction.Value)
{
case ScrollingDirection.Up:
2020-03-31 14:29:25 +08:00
hitObjectPosition.Y += DefaultNotePiece.NOTE_HEIGHT / 2;
break;
case ScrollingDirection.Down:
2020-03-31 14:29:25 +08:00
hitObjectPosition.Y -= DefaultNotePiece.NOTE_HEIGHT / 2;
break;
}
return hitObjectPosition;
}
}
}