mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 07:12:27 +02:00
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using System;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Robust.Client.Placement.Modes
|
|
{
|
|
public sealed class SnapgridBorder : SnapgridCenter
|
|
{
|
|
public override bool HasLineMode => true;
|
|
public override bool HasGridMode => true;
|
|
|
|
public SnapgridBorder(PlacementManager pMan) : base(pMan)
|
|
{
|
|
}
|
|
|
|
|
|
public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
|
|
{
|
|
MouseCoords = ScreenToCursorGrid(mouseScreen);
|
|
|
|
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
|
|
SnapSize = 1f;
|
|
if (gridId.IsValid())
|
|
{
|
|
Grid = pManager.MapManager.GetGrid(gridId);
|
|
SnapSize = Grid.TileSize; //Find snap size for the grid.
|
|
}
|
|
else
|
|
{
|
|
Grid = null;
|
|
}
|
|
|
|
GridDistancing = SnapSize;
|
|
|
|
var mouselocal = new Vector2( //Round local coordinates onto the snap grid
|
|
MathF.Round(MouseCoords.X / SnapSize, MidpointRounding.AwayFromZero) * SnapSize,
|
|
MathF.Round(MouseCoords.Y / SnapSize, MidpointRounding.AwayFromZero) * SnapSize);
|
|
|
|
//Convert back to original world and screen coordinates after applying offset
|
|
MouseCoords =
|
|
new EntityCoordinates(
|
|
MouseCoords.EntityId, mouselocal + new Vector2(pManager.PlacementOffset.X, pManager.PlacementOffset.Y));
|
|
}
|
|
}
|
|
}
|