Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions Robust.Client/Placement/PlacementManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private set
/// <summary>
/// Holds the selection rectangle for the eraser
/// </summary>
public Box2? EraserRect { get; set; }
public Box2Rotated? EraserRect { get; set; }

/// <summary>
/// Drawing shader for drawing without being affected by lighting
Expand Down Expand Up @@ -482,12 +482,16 @@ public void HandleDeletion(EntityUid entity)
_networkManager.ClientSendMessage(msg);
}

public void HandleRectDeletion(EntityCoordinates start, Box2 rect)
public void HandleRectDeletion(EntityCoordinates start, Box2Rotated rect)
{
var msg = new MsgPlacement();
msg.PlaceType = PlacementManagerMessage.RequestRectRemove;
msg.NetCoordinates = new NetCoordinates(EntityManager.GetNetEntity(StartPoint.EntityId), rect.BottomLeft);
msg.RectSize = rect.Size;
var centerCoords = XformSystem.ToCoordinates(new MapCoordinates(rect.Origin, XformSystem.GetMapId(start)));
var msg = new MsgPlacement
{
PlaceType = PlacementManagerMessage.RequestRectRemove,
NetCoordinates = EntityManager.GetNetCoordinates(centerCoords),
RectSize = rect.Box.Size,
RectRotation = (float)rect.Rotation.Theta
};
_networkManager.ClientSendMessage(msg);
}

Expand Down Expand Up @@ -595,28 +599,15 @@ public void FrameUpdate(FrameEventArgs e)
{
if (!CurrentEraserMouseCoordinates(out EntityCoordinates end))
return;
float b, l, t, r;
if (StartPoint.X < end.X)
{
l = StartPoint.X;
r = end.X;
}
else
{
l = end.X;
r = StartPoint.X;
}
if (StartPoint.Y < end.Y)
{
b = StartPoint.Y;
t = end.Y;
}
else
{
b = end.Y;
t = StartPoint.Y;
}
EraserRect = new Box2(l, b, r, t);

var startPos = XformSystem.ToWorldPosition(StartPoint);
var endPos = XformSystem.ToWorldPosition(end);
var eyeRot = _eyeManager.CurrentEye.Rotation;

var diff = eyeRot.RotateVec(endPos - startPos);
var size = new Vector2(MathF.Abs(diff.X), MathF.Abs(diff.Y));
var centerPos = (startPos + endPos) / 2f;
EraserRect = new Box2Rotated(Box2.CenteredAround(centerPos, size), -eyeRot, centerPos);
}
return;
}
Expand Down Expand Up @@ -665,7 +656,9 @@ private void EraseRectMode()
return;

StartPoint = coordinates;
EraserRect = new Box2(coordinates.Position, Vector2.Zero);
var startPos = XformSystem.ToWorldPosition(coordinates);
var eyeRot = _eyeManager.CurrentEye.Rotation;
EraserRect = new Box2Rotated(new Box2(startPos, startPos), -eyeRot, startPos);
}

private bool DeactivateSpecialPlacement()
Expand Down
9 changes: 6 additions & 3 deletions Robust.Server/Placement/PlacementManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,13 @@ private void HandleEntRemoveReq(MsgPlacement msg)
/// <param name="msg"></param>
private void HandleRectRemoveReq(MsgPlacement msg)
{
var start = _entityManager.GetCoordinates(msg.NetCoordinates);
var rectSize = msg.RectSize;
var centerCoords = _xformSystem.ToMapCoordinates(msg.NetCoordinates);
var centerPos = centerCoords.Position;

foreach (var entity in _lookup.GetEntitiesIntersecting(_xformSystem.GetMapId(start), new Box2(start.Position, start.Position + rectSize)))
var box = Box2.CenteredAround(centerPos, msg.RectSize);
var boxRotated = new Box2Rotated(box, msg.RectRotation, centerPos);

foreach (var entity in _lookup.GetEntitiesIntersecting(centerCoords.MapId, boxRotated))
{
if (_entityManager.Deleted(entity)
|| _entityManager.HasComponent<MapGridComponent>(entity)
Expand Down
3 changes: 3 additions & 0 deletions Robust.Shared/Network/Messages/MsgPlacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public sealed class MsgPlacement : NetMessage
public string ObjType { get; set; }
public string AlignOption { get; set; }
public Vector2 RectSize { get; set; }
public float RectRotation { get; set; }

/// <summary>
/// Used to determine tile sprite mirroring
Expand Down Expand Up @@ -71,6 +72,7 @@ public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer
case PlacementManagerMessage.RequestRectRemove:
NetCoordinates = buffer.ReadNetCoordinates();
RectSize = buffer.ReadVector2();
RectRotation = buffer.ReadFloat();
break;
}
}
Expand Down Expand Up @@ -107,6 +109,7 @@ public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer
case PlacementManagerMessage.RequestRectRemove:
buffer.Write(NetCoordinates);
buffer.Write(RectSize);
buffer.Write(RectRotation);
break;
}
}
Expand Down
Loading