From 54fe039c8a9a17ffab59c9d84aa87476c5badaca Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 12 Jun 2019 16:43:13 +0300 Subject: [PATCH] (5b697f37f) Link the door and the gap even more strictly. It shouldn't be possible to destroy or move the other without moving the other. Fixes #1528. --- .../BarotraumaClient/Source/Map/MapEntity.cs | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs index 91dd8e015..215e2db4d 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs @@ -483,6 +483,26 @@ namespace Barotrauma { if (selectedList.Contains(entity)) { return; } selectedList.Add(entity); + HandleDoorGapLinks(entity, + onGapFound: (door, gap) => + { + door.RefreshLinkedGap(); + if (!selectedList.Contains(gap)) + { + selectedList.Add(gap); + } + }, + onDoorFound: (door, gap) => + { + if (!selectedList.Contains(door.Item)) + { + selectedList.Add(door.Item); + } + }); + } + + private static void HandleDoorGapLinks(MapEntity entity, Action onGapFound, Action onDoorFound) + { if (entity is Item i) { var door = i.GetComponent(); @@ -491,31 +511,26 @@ namespace Barotrauma var gap = door.LinkedGap; if (gap != null) { - door.RefreshLinkedGap(); - if (!selectedList.Contains(gap)) - { - selectedList.Add(gap); - } + onGapFound(door, gap); } } } + else if (entity is Gap gap) + { + var door = gap.ConnectedDoor; + if (door != null) + { + onDoorFound(door, gap); + } + } } public static void RemoveSelection(MapEntity entity) { selectedList.Remove(entity); - if (entity is Item i) - { - var door = i.GetComponent(); - if (door != null) - { - var gap = door.LinkedGap; - if (gap != null) - { - selectedList.Remove(gap); - } - } - } + HandleDoorGapLinks(entity, + onGapFound: (door, gap) => selectedList.Remove(gap), + onDoorFound: (door, gap) => selectedList.Remove(door.Item)); } static partial void UpdateAllProjSpecific(float deltaTime) @@ -585,12 +600,11 @@ namespace Barotrauma public static void UpdateEditor(Camera cam) { - FilteredSelectedList.Clear(); if (highlightedListBox != null) highlightedListBox.UpdateManually((float)Timing.Step); if (editingHUD != null) { - if (selectedList.Count == 0 || editingHUD.UserData != selectedList[0]) + if (FilteredSelectedList.Count == 0 || editingHUD.UserData != FilteredSelectedList[0]) { foreach (GUIComponent component in editingHUD.Children) { @@ -601,7 +615,7 @@ namespace Barotrauma editingHUD = null; } } - + FilteredSelectedList.Clear(); if (selectedList.Count == 0) return; foreach (var e in selectedList) {