diff --git a/Barotrauma/BarotraumaClient/Source/Map/WayPoint.cs b/Barotrauma/BarotraumaClient/Source/Map/WayPoint.cs index 0754e07da..27c059ccf 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/WayPoint.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/WayPoint.cs @@ -1,6 +1,9 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using System.Collections.Generic; +using Barotrauma.Items.Components; +using System.Linq; namespace Barotrauma { @@ -48,6 +51,10 @@ namespace Barotrauma { iconSize = (int)(iconSize * 1.5f); } + if (Stairs != null) + { + iconSize = (int)(iconSize * 1.5f); + } spriteBatch.Draw(iconTexture, new Rectangle((int)(drawPos.X - iconSize / 2), (int)(drawPos.Y - iconSize / 2), iconSize, iconSize), @@ -90,10 +97,49 @@ namespace Barotrauma editingHUD = CreateEditingHUD(); } - if (PlayerInput.LeftButtonClicked()) + if (IsSelected && PlayerInput.LeftButtonClicked()) { Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition); + // Update gaps, ladders, and stairs + UpdateLinkedEntity(position, Gap.GapList, gap => ConnectedGap = gap, gap => + { + if (ConnectedGap == gap) + { + ConnectedGap = null; + } + }); + UpdateLinkedEntity(position, Item.ItemList, i => + { + var ladder = i?.GetComponent(); + if (ladder != null) + { + Ladders = ladder; + } + }, i => + { + var ladder = i?.GetComponent(); + if (ladder != null) + { + if (Ladders == ladder) + { + Ladders = null; + } + } + }, inflate: 5); + // TODO: Cannot check the rectangle, since the rectangle is not rotated -> Need to use the collider. + //var stairList = mapEntityList.Where(me => me is Structure s && s.StairDirection != Direction.None).Select(me => me as Structure); + //UpdateLinkedEntity(position, stairList, s => + //{ + // Stairs = s; + //}, s => + //{ + // if (Stairs == s) + // { + // Stairs = null; + // } + //}); + foreach (MapEntity e in mapEntityList) { if (e.GetType() != typeof(WayPoint)) continue; @@ -107,6 +153,23 @@ namespace Barotrauma } } + private void UpdateLinkedEntity(Vector2 worldPos, IEnumerable list, Action match, Action noMatch, int inflate = 0) where T : MapEntity + { + foreach (var entity in list) + { + var rect = entity.WorldRect; + rect.Inflate(inflate, inflate); + if (Submarine.RectContains(rect, worldPos)) + { + match(entity); + } + else + { + noMatch(entity); + } + } + } + private bool ChangeSpawnType(GUIButton button, object obj) { GUITextBlock spawnTypeText = button.Parent.GetChildByUserData("spawntypetext") as GUITextBlock;