]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Improve access overlay (#26667)
authorWrexbe (Josh) <81056464+wrexbe@users.noreply.github.com>
Tue, 9 Apr 2024 22:16:42 +0000 (15:16 -0700)
committerGitHub <noreply@github.com>
Tue, 9 Apr 2024 22:16:42 +0000 (18:16 -0400)
* Improve access overlay

* review changes

---------

Co-authored-by: wrexbe <wrexbe@protonmail.com>
Content.Client/Access/AccessOverlay.cs
Content.Client/Access/Commands/ShowAccessReadersCommand.cs

index 2be3d07e90d50de224eefae304c7529961f967a5..59c9441036d8fb9ea5b2255937d958db1fe7e428 100644 (file)
@@ -9,20 +9,20 @@ namespace Content.Client.Access;
 
 public sealed class AccessOverlay : Overlay
 {
+    private const string TextFontPath = "/Fonts/NotoSans/NotoSans-Regular.ttf";
+    private const int TextFontSize = 12;
+
     private readonly IEntityManager _entityManager;
-    private readonly EntityLookupSystem _lookup;
-    private readonly SharedTransformSystem _xform;
+    private readonly SharedTransformSystem _transformSystem;
     private readonly Font _font;
 
     public override OverlaySpace Space => OverlaySpace.ScreenSpace;
 
-    public AccessOverlay(IEntityManager entManager, IResourceCache cache, EntityLookupSystem lookup, SharedTransformSystem xform)
+    public AccessOverlay(IEntityManager entityManager, IResourceCache resourceCache, SharedTransformSystem transformSystem)
     {
-        _entityManager = entManager;
-        _lookup = lookup;
-        _xform = xform;
-
-        _font = cache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 12);
+        _entityManager = entityManager;
+        _transformSystem = transformSystem;
+        _font = resourceCache.GetFont(TextFontPath, TextFontSize);
     }
 
     protected override void Draw(in OverlayDrawArgs args)
@@ -30,52 +30,65 @@ public sealed class AccessOverlay : Overlay
         if (args.ViewportControl == null)
             return;
 
-        var readerQuery = _entityManager.GetEntityQuery<AccessReaderComponent>();
-        var xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
-
-        foreach (var ent in _lookup.GetEntitiesIntersecting(args.MapId, args.WorldAABB,
-                         LookupFlags.Static | LookupFlags.Approximate))
+        var textBuffer = new StringBuilder();
+        var query = _entityManager.EntityQueryEnumerator<AccessReaderComponent, TransformComponent>();
+        while (query.MoveNext(out var uid, out var accessReader, out var transform))
         {
-            if (!readerQuery.TryGetComponent(ent, out var reader) ||
-                !xformQuery.TryGetComponent(ent, out var xform))
+            textBuffer.Clear();
+
+            var entityName = _entityManager.ToPrettyString(uid);
+            textBuffer.AppendLine(entityName.Prototype);
+            textBuffer.Append("UID: ");
+            textBuffer.Append(entityName.Uid.Id);
+            textBuffer.Append(", NUID: ");
+            textBuffer.Append(entityName.Nuid.Id);
+            textBuffer.AppendLine();
+
+            if (!accessReader.Enabled)
             {
+                textBuffer.AppendLine("-Disabled");
                 continue;
             }
 
-            var text = new StringBuilder();
-            var index = 0;
-            var a = $"{_entityManager.ToPrettyString(ent)}";
-            text.Append(a);
-
-            foreach (var list in reader.AccessLists)
+            if (accessReader.AccessLists.Count > 0)
             {
-                a = $"Tag {index}";
-                text.AppendLine(a);
-
-                foreach (var entry in list)
+                var groupNumber = 0;
+                foreach (var accessList in accessReader.AccessLists)
                 {
-                    a = $"- {entry}";
-                    text.AppendLine(a);
+                    groupNumber++;
+                    foreach (var entry in accessList)
+                    {
+                        textBuffer.Append("+Set ");
+                        textBuffer.Append(groupNumber);
+                        textBuffer.Append(": ");
+                        textBuffer.Append(entry.Id);
+                        textBuffer.AppendLine();
+                    }
                 }
-
-                index++;
             }
-
-            string textStr;
-
-            if (text.Length >= 2)
+            else
             {
-                textStr = text.ToString();
-                textStr = textStr[..^2];
+                textBuffer.AppendLine("+Unrestricted");
             }
-            else
+
+            foreach (var key in accessReader.AccessKeys)
             {
-                textStr = "";
+                textBuffer.Append("+Key ");
+                textBuffer.Append(key.OriginStation);
+                textBuffer.Append(": ");
+                textBuffer.Append(key.Id);
+                textBuffer.AppendLine();
             }
 
-            var screenPos = args.ViewportControl.WorldToScreen(_xform.GetWorldPosition(xform));
+            foreach (var tag in accessReader.DenyTags)
+            {
+                textBuffer.Append("-Tag ");
+                textBuffer.AppendLine(tag.Id);
+            }
 
-            args.ScreenHandle.DrawString(_font, screenPos, textStr, Color.Gold);
+            var accessInfoText = textBuffer.ToString();
+            var screenPos = args.ViewportControl.WorldToScreen(_transformSystem.GetWorldPosition(transform));
+            args.ScreenHandle.DrawString(_font, screenPos, accessInfoText, Color.Gold);
         }
     }
 }
index 7c804dd969801bc9efb38b1d1dd7276fbcf2ba8f..cb6cb6cf6bb0148e2176261071e78c12401a27c9 100644 (file)
@@ -7,8 +7,16 @@ namespace Content.Client.Access.Commands;
 public sealed class ShowAccessReadersCommand : IConsoleCommand
 {
     public string Command => "showaccessreaders";
-    public string Description => "Shows all access readers in the viewport";
-    public string Help => $"{Command}";
+
+    public string Description => "Toggles showing access reader permissions on the map";
+    public string Help => """
+        Overlay Info:
+        -Disabled | The access reader is disabled
+        +Unrestricted | The access reader has no restrictions
+        +Set [Index]: [Tag Name]| A tag in an access set (accessor needs all tags in the set to be allowed by the set)
+        +Key [StationUid]: [StationRecordKeyId] | A StationRecordKey that is allowed
+        -Tag [Tag Name] | A tag that is not allowed (takes priority over other allows)
+        """;
     public void Execute(IConsoleShell shell, string argStr, string[] args)
     {
         var collection = IoCManager.Instance;
@@ -26,10 +34,9 @@ public sealed class ShowAccessReadersCommand : IConsoleCommand
 
         var entManager = collection.Resolve<IEntityManager>();
         var cache = collection.Resolve<IResourceCache>();
-        var lookup = entManager.System<EntityLookupSystem>();
         var xform = entManager.System<SharedTransformSystem>();
 
-        overlay.AddOverlay(new AccessOverlay(entManager, cache, lookup, xform));
+        overlay.AddOverlay(new AccessOverlay(entManager, cache, xform));
         shell.WriteLine($"Set access reader debug overlay to true");
     }
 }