From 13e3dc7a70f780c3e1f2fa445676243d5b6456ff Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Fri, 10 Jul 2020 22:18:21 +1000 Subject: [PATCH] Fix mob panel debug (#1334) The panel was staying when an individual part was toggled. I also removed some other redundant code. Co-authored-by: Metal Gear Sloth --- .../EntitySystems/AI/ClientAiDebugSystem.cs | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/Content.Client/GameObjects/EntitySystems/AI/ClientAiDebugSystem.cs b/Content.Client/GameObjects/EntitySystems/AI/ClientAiDebugSystem.cs index 9e24a58c66..e0071b5116 100644 --- a/Content.Client/GameObjects/EntitySystems/AI/ClientAiDebugSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/AI/ClientAiDebugSystem.cs @@ -15,6 +15,10 @@ namespace Content.Client.GameObjects.EntitySystems.AI #if DEBUG public class ClientAiDebugSystem : EntitySystem { +#pragma warning disable 649 + [Dependency] private IEyeManager _eyeManager; +#pragma restore disable 649 + private AiDebugMode _tooltips = AiDebugMode.None; private readonly Dictionary _aiBoxes = new Dictionary(); @@ -23,26 +27,44 @@ namespace Content.Client.GameObjects.EntitySystems.AI base.Update(frameTime); if (_tooltips == 0) { + if (_aiBoxes.Count > 0) + { + foreach (var (_, panel) in _aiBoxes) + { + panel.Dispose(); + } + + _aiBoxes.Clear(); + } return; } - var eyeManager = IoCManager.Resolve(); + var deletedEntities = new List(0); foreach (var (entity, panel) in _aiBoxes) { - if (entity == null) continue; + if (entity.Deleted) + { + deletedEntities.Add(entity); + continue; + } - if (!eyeManager.GetWorldViewport().Contains(entity.Transform.WorldPosition)) + if (!_eyeManager.GetWorldViewport().Contains(entity.Transform.WorldPosition)) { panel.Visible = false; continue; } - var (x, y) = eyeManager.WorldToScreen(entity.Transform.GridPosition).Position; + var (x, y) = _eyeManager.WorldToScreen(entity.Transform.GridPosition).Position; var offsetPosition = new Vector2(x - panel.Width / 2, y - panel.Height - 50f); panel.Visible = true; LayoutContainer.SetPosition(panel, offsetPosition); } + + foreach (var entity in deletedEntities) + { + _aiBoxes.Remove(entity); + } } public override void Initialize() @@ -60,11 +82,6 @@ namespace Content.Client.GameObjects.EntitySystems.AI // I guess if it's out of range we don't know about it? var entityManager = IoCManager.Resolve(); var entity = entityManager.GetEntity(message.EntityUid); - if (entity == null) - { - return; - } - TryCreatePanel(entity); // Probably shouldn't access by index but it's a debugging tool so eh @@ -82,11 +99,6 @@ namespace Content.Client.GameObjects.EntitySystems.AI { var entityManager = IoCManager.Resolve(); var entity = entityManager.GetEntity(message.EntityUid); - if (entity == null) - { - return; - } - TryCreatePanel(entity); var label = (Label) _aiBoxes[entity].GetChild(0).GetChild(1); @@ -102,11 +114,6 @@ namespace Content.Client.GameObjects.EntitySystems.AI { var entityManager = IoCManager.Resolve(); var entity = entityManager.GetEntity(message.EntityUid); - if (entity == null) - { - return; - } - TryCreatePanel(entity); var label = (Label) _aiBoxes[entity].GetChild(0).GetChild(1);