From 296ec8bab869a586b2d318f06b74a882106dc3da Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Fri, 29 Mar 2019 17:23:47 +0200 Subject: [PATCH] (d95fc9893) Fixed crashing when dragging waypoints in the sub editor due to waypoints not being assigned a prefab --- .../BarotraumaClient/Source/Map/MapEntity.cs | 4 ++-- .../Source/Map/MapEntityPrefab.cs | 2 +- .../BarotraumaShared/Source/Map/WayPoint.cs | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs index cd6f5624a..a49b60add 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs @@ -504,12 +504,12 @@ namespace Barotrauma { foreach (MapEntity e in selectedList) { - e.prefab.DrawPlacing(spriteBatch, + e.prefab?.DrawPlacing(spriteBatch, new Rectangle(e.WorldRect.Location + new Point((int)moveAmount.X, (int)-moveAmount.Y), e.WorldRect.Size)); GUI.DrawRectangle(spriteBatch, new Vector2(e.WorldRect.X, -e.WorldRect.Y) + moveAmount, new Vector2(e.rect.Width, e.rect.Height), - Color.DarkRed, false, 0, (int)Math.Max(1.5f / GameScreen.Selected.Cam.Zoom, 1.0f)); + Color.White, false, 0, (int)Math.Max(3.0f / GameScreen.Selected.Cam.Zoom, 2.0f)); } //stop dragging the "selection rectangle" diff --git a/Barotrauma/BarotraumaClient/Source/Map/MapEntityPrefab.cs b/Barotrauma/BarotraumaClient/Source/Map/MapEntityPrefab.cs index f8ab3faa8..2d2a03e2b 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/MapEntityPrefab.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/MapEntityPrefab.cs @@ -44,7 +44,7 @@ namespace Barotrauma drawRect.Location -= Submarine.MainSub.Position.ToPoint(); } drawRect.Y = -drawRect.Y; - GUI.DrawRectangle(spriteBatch, drawRect, Color.DarkBlue); + GUI.DrawRectangle(spriteBatch, drawRect, Color.White); } public void DrawListLine(SpriteBatch spriteBatch, Vector2 pos, Color color) { diff --git a/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs b/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs index 6072beef8..f932497b4 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs @@ -101,8 +101,14 @@ namespace Barotrauma } } + public WayPoint(Rectangle newRect, Submarine submarine) - : base (null, submarine) + : this (MapEntityPrefab.Find(null, "waypoint"), newRect, submarine) + { + } + + public WayPoint(MapEntityPrefab prefab, Rectangle newRect, Submarine submarine) + : base (prefab, submarine) { rect = newRect; linkedTo = new ObservableCollection(); @@ -602,11 +608,14 @@ namespace Barotrauma int.Parse(element.Attribute("y").Value), (int)Submarine.GridSize.X, (int)Submarine.GridSize.Y); - WayPoint w = new WayPoint(rect, submarine); - w.ID = (ushort)int.Parse(element.Attribute("ID").Value); + Enum.TryParse(element.GetAttributeString("spawn", "Path"), out SpawnType spawnType); + WayPoint w = new WayPoint(MapEntityPrefab.Find(null, spawnType == SpawnType.Path ? "waypoint" : "spawnpoint"), rect, submarine) + { + ID = (ushort)int.Parse(element.Attribute("ID").Value) + }; - Enum.TryParse(element.GetAttributeString("spawn", "Path"), out w.spawnType); + w.spawnType = spawnType; string idCardDescString = element.GetAttributeString("idcarddesc", ""); if (!string.IsNullOrWhiteSpace(idCardDescString))