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>
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using Robust.Shared.Map;
|
|
|
|
namespace Robust.Client.Placement.Modes
|
|
{
|
|
public sealed class AlignTileAny : PlacementMode
|
|
{
|
|
public override bool HasLineMode => true;
|
|
public override bool HasGridMode => true;
|
|
|
|
public AlignTileAny(PlacementManager pMan) : base(pMan) { }
|
|
|
|
public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
|
|
{
|
|
// Go over diagonal size so when placing in a line it doesn't stop snapping.
|
|
const float SearchBoxSize = 2f; // size of search box in meters
|
|
|
|
MouseCoords = ScreenToCursorGrid(mouseScreen).AlignWithClosestGridTile(SearchBoxSize, pManager.EntityManager, pManager.MapManager);
|
|
|
|
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
|
|
|
|
if (!pManager.MapManager.TryGetGrid(gridId, out var mapGrid))
|
|
return;
|
|
|
|
CurrentTile = mapGrid.GetTileRef(MouseCoords);
|
|
float tileSize = mapGrid.TileSize; //convert from ushort to float
|
|
GridDistancing = tileSize;
|
|
|
|
if (pManager.CurrentPermission!.IsTile)
|
|
{
|
|
MouseCoords = new EntityCoordinates(MouseCoords.EntityId, (CurrentTile.X + tileSize / 2,
|
|
CurrentTile.Y + tileSize / 2));
|
|
}
|
|
else
|
|
{
|
|
MouseCoords = new EntityCoordinates(MouseCoords.EntityId, (CurrentTile.X + tileSize / 2 + pManager.PlacementOffset.X,
|
|
CurrentTile.Y + tileSize / 2 + pManager.PlacementOffset.Y));
|
|
}
|
|
}
|
|
|
|
public override bool IsValidPosition(EntityCoordinates position)
|
|
{
|
|
if (!RangeCheck(position))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|