Sub editor doesn't allow creating structures with zero width/height, fixed null exceptions when trying to remove a structure without wall sections

This commit is contained in:
Regalis
2017-04-20 18:02:20 +03:00
parent acaa8697c8
commit a5d605e29b
2 changed files with 16 additions and 13 deletions
+8 -4
View File
@@ -469,14 +469,18 @@ namespace Barotrauma
GameMain.World.RemoveBody(b); GameMain.World.RemoveBody(b);
} }
foreach (WallSection s in sections) if (sections != null)
{ {
if (s.gap != null) foreach (WallSection s in sections)
{ {
s.gap.Remove(); if (s.gap != null)
s.gap = null; {
s.gap.Remove();
s.gap = null;
}
} }
} }
if (convexHulls != null) convexHulls.ForEach(x => x.Remove()); if (convexHulls != null) convexHulls.ForEach(x => x.Remove());
} }
+7 -8
View File
@@ -152,11 +152,8 @@ namespace Barotrauma
public override void UpdatePlacing(Camera cam) public override void UpdatePlacing(Camera cam)
{ {
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub); Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
//Vector2 placeSize = size;
Rectangle newRect = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y); Rectangle newRect = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
if (placePosition == Vector2.Zero) if (placePosition == Vector2.Zero)
{ {
if (PlayerInput.LeftButtonHeld()) if (PlayerInput.LeftButtonHeld())
@@ -164,8 +161,6 @@ namespace Barotrauma
newRect.X = (int)position.X; newRect.X = (int)position.X;
newRect.Y = (int)position.Y; newRect.Y = (int)position.Y;
//sprite.Draw(spriteBatch, new Vector2(position.X, -position.Y), placeSize, Color.White);
} }
else else
{ {
@@ -177,10 +172,14 @@ namespace Barotrauma
if (PlayerInput.LeftButtonReleased()) if (PlayerInput.LeftButtonReleased())
{ {
newRect.Location -= Submarine.MainSub.Position.ToPoint(); //don't allow resizing width/height to zero
if ((!resizeHorizontal || placeSize.X != 0.0f) && (!resizeVertical || placeSize.Y != 0.0f))
{
newRect.Location -= Submarine.MainSub.Position.ToPoint();
var structure = new Structure(newRect, this, Submarine.MainSub); var structure = new Structure(newRect, this, Submarine.MainSub);
structure.Submarine = Submarine.MainSub; structure.Submarine = Submarine.MainSub;
}
selected = null; selected = null;
return; return;