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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.6 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using osu.Framework.Graphics;
2018-11-13 13:13:29 +08:00
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Skinning.Default;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.UI.Scrolling;
using osuTK;
using osuTK.Input;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
public abstract class ManiaPlacementBlueprint<T> : PlacementBlueprint
where T : ManiaHitObject
{
protected new T HitObject => (T)base.HitObject;
2020-05-20 20:13:08 +08:00
private Column column;
public Column Column
{
get => column;
set
{
if (value == column)
return;
column = value;
HitObject.Column = column.Index;
}
}
2018-11-29 18:29:36 +08:00
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)
2020-05-20 20:13:08 +08:00
return false;
2018-11-29 18:29:36 +08:00
BeginPlacement(true);
2018-11-29 18:29:36 +08:00
return true;
}
public override void UpdateTimeAndPosition(SnapResult result)
2018-11-13 13:13:29 +08:00
{
base.UpdateTimeAndPosition(result);
if (result.Playfield is Column col)
{
// Apply an offset to better align with the visual grid.
// This should only be applied during placement, as during selection / drag operations the movement is relative
// to the initial point of interaction rather than the grid.
switch (col.ScrollingInfo.Direction.Value)
{
case ScrollingDirection.Down:
result.ScreenSpacePosition -= new Vector2(0, getNoteHeight(col) / 2);
break;
case ScrollingDirection.Up:
result.ScreenSpacePosition += new Vector2(0, getNoteHeight(col) / 2);
break;
}
if (PlacementActive == PlacementState.Waiting)
Column = col;
}
}
private float getNoteHeight(Column resultPlayfield) =>
resultPlayfield.ToScreenSpace(new Vector2(DefaultNotePiece.NOTE_HEIGHT)).Y -
resultPlayfield.ToScreenSpace(Vector2.Zero).Y;
}
}