Improve access overlay (#26667)
* Improve access overlay * review changes --------- Co-authored-by: wrexbe <wrexbe@protonmail.com>
This commit is contained in:
@@ -9,20 +9,20 @@ namespace Content.Client.Access;
|
|||||||
|
|
||||||
public sealed class AccessOverlay : Overlay
|
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 IEntityManager _entityManager;
|
||||||
private readonly EntityLookupSystem _lookup;
|
private readonly SharedTransformSystem _transformSystem;
|
||||||
private readonly SharedTransformSystem _xform;
|
|
||||||
private readonly Font _font;
|
private readonly Font _font;
|
||||||
|
|
||||||
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
|
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;
|
_entityManager = entityManager;
|
||||||
_lookup = lookup;
|
_transformSystem = transformSystem;
|
||||||
_xform = xform;
|
_font = resourceCache.GetFont(TextFontPath, TextFontSize);
|
||||||
|
|
||||||
_font = cache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 12);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Draw(in OverlayDrawArgs args)
|
protected override void Draw(in OverlayDrawArgs args)
|
||||||
@@ -30,52 +30,65 @@ public sealed class AccessOverlay : Overlay
|
|||||||
if (args.ViewportControl == null)
|
if (args.ViewportControl == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var readerQuery = _entityManager.GetEntityQuery<AccessReaderComponent>();
|
var textBuffer = new StringBuilder();
|
||||||
var xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
|
var query = _entityManager.EntityQueryEnumerator<AccessReaderComponent, TransformComponent>();
|
||||||
|
while (query.MoveNext(out var uid, out var accessReader, out var transform))
|
||||||
|
{
|
||||||
|
textBuffer.Clear();
|
||||||
|
|
||||||
foreach (var ent in _lookup.GetEntitiesIntersecting(args.MapId, args.WorldAABB,
|
var entityName = _entityManager.ToPrettyString(uid);
|
||||||
LookupFlags.Static | LookupFlags.Approximate))
|
textBuffer.AppendLine(entityName.Prototype);
|
||||||
{
|
textBuffer.Append("UID: ");
|
||||||
if (!readerQuery.TryGetComponent(ent, out var reader) ||
|
textBuffer.Append(entityName.Uid.Id);
|
||||||
!xformQuery.TryGetComponent(ent, out var xform))
|
textBuffer.Append(", NUID: ");
|
||||||
|
textBuffer.Append(entityName.Nuid.Id);
|
||||||
|
textBuffer.AppendLine();
|
||||||
|
|
||||||
|
if (!accessReader.Enabled)
|
||||||
{
|
{
|
||||||
|
textBuffer.AppendLine("-Disabled");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var text = new StringBuilder();
|
if (accessReader.AccessLists.Count > 0)
|
||||||
var index = 0;
|
|
||||||
var a = $"{_entityManager.ToPrettyString(ent)}";
|
|
||||||
text.Append(a);
|
|
||||||
|
|
||||||
foreach (var list in reader.AccessLists)
|
|
||||||
{
|
{
|
||||||
a = $"Tag {index}";
|
var groupNumber = 0;
|
||||||
text.AppendLine(a);
|
foreach (var accessList in accessReader.AccessLists)
|
||||||
|
|
||||||
foreach (var entry in list)
|
|
||||||
{
|
{
|
||||||
a = $"- {entry}";
|
groupNumber++;
|
||||||
text.AppendLine(a);
|
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)
|
|
||||||
{
|
|
||||||
textStr = text.ToString();
|
|
||||||
textStr = textStr[..^2];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
textStr = "";
|
textBuffer.AppendLine("+Unrestricted");
|
||||||
}
|
}
|
||||||
|
|
||||||
var screenPos = args.ViewportControl.WorldToScreen(_xform.GetWorldPosition(xform));
|
foreach (var key in accessReader.AccessKeys)
|
||||||
|
{
|
||||||
|
textBuffer.Append("+Key ");
|
||||||
|
textBuffer.Append(key.OriginStation);
|
||||||
|
textBuffer.Append(": ");
|
||||||
|
textBuffer.Append(key.Id);
|
||||||
|
textBuffer.AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
args.ScreenHandle.DrawString(_font, screenPos, textStr, Color.Gold);
|
foreach (var tag in accessReader.DenyTags)
|
||||||
|
{
|
||||||
|
textBuffer.Append("-Tag ");
|
||||||
|
textBuffer.AppendLine(tag.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
var accessInfoText = textBuffer.ToString();
|
||||||
|
var screenPos = args.ViewportControl.WorldToScreen(_transformSystem.GetWorldPosition(transform));
|
||||||
|
args.ScreenHandle.DrawString(_font, screenPos, accessInfoText, Color.Gold);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,16 @@ namespace Content.Client.Access.Commands;
|
|||||||
public sealed class ShowAccessReadersCommand : IConsoleCommand
|
public sealed class ShowAccessReadersCommand : IConsoleCommand
|
||||||
{
|
{
|
||||||
public string Command => "showaccessreaders";
|
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)
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
{
|
{
|
||||||
var collection = IoCManager.Instance;
|
var collection = IoCManager.Instance;
|
||||||
@@ -26,10 +34,9 @@ public sealed class ShowAccessReadersCommand : IConsoleCommand
|
|||||||
|
|
||||||
var entManager = collection.Resolve<IEntityManager>();
|
var entManager = collection.Resolve<IEntityManager>();
|
||||||
var cache = collection.Resolve<IResourceCache>();
|
var cache = collection.Resolve<IResourceCache>();
|
||||||
var lookup = entManager.System<EntityLookupSystem>();
|
|
||||||
var xform = entManager.System<SharedTransformSystem>();
|
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");
|
shell.WriteLine($"Set access reader debug overlay to true");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user