]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add doors to the station map (#23639)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Thu, 11 Jan 2024 13:14:20 +0000 (08:14 -0500)
committerGitHub <noreply@github.com>
Thu, 11 Jan 2024 13:14:20 +0000 (00:14 +1100)
* Add doors to the navmap

* tweaksies

* gah

* draw primitive

* draw primitive? at least take me out to dinner first!

* Update Content.Client/Pinpointer/UI/NavMapControl.cs

* casualties

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
12 files changed:
Content.Client/Pinpointer/NavMapSystem.cs
Content.Client/Pinpointer/UI/NavMapControl.cs
Content.Server/Pinpointer/NavMapSystem.cs
Content.Shared/Pinpointer/NavMapComponent.cs
Content.Shared/Pinpointer/NavMapDoorComponent.cs [new file with mode: 0644]
Content.Shared/Pinpointer/SharedNavMapSystem.cs
Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml
Resources/Prototypes/Entities/Structures/Doors/Airlocks/highsec.yml
Resources/Prototypes/Entities/Structures/Doors/MaterialDoors/material_doors.yml
Resources/Prototypes/Entities/Structures/Doors/SecretDoor/secret_door.yml
Resources/Prototypes/Entities/Structures/Doors/Shutter/shutters.yml
Resources/Prototypes/Entities/Structures/Doors/Windoors/base_structurewindoors.yml

index d346d90904a393430e6f0e3bb40afe371fa6c8e4..bd7dfc1117fb6c5e9b37432602cfc2381e9f48ce 100644 (file)
@@ -33,6 +33,9 @@ public sealed class NavMapSystem : SharedNavMapSystem
 
         component.Beacons.Clear();
         component.Beacons.AddRange(state.Beacons);
+
+        component.Airlocks.Clear();
+        component.Airlocks.AddRange(state.Airlocks);
     }
 }
 
index a748dc4a6d54a39851902653d03a5f40da635ac8..d3c505e49f3a97bcbb0ee1b57fc0ea15786090c8 100644 (file)
@@ -25,7 +25,7 @@ namespace Content.Client.Pinpointer.UI;
 public partial class NavMapControl : MapGridControl
 {
     [Dependency] private readonly IEntityManager _entManager = default!;
-    private readonly SharedTransformSystem _transformSystem = default!;
+    private readonly SharedTransformSystem _transformSystem;
 
     public EntityUid? Owner;
     public EntityUid? MapUid;
@@ -37,7 +37,7 @@ public partial class NavMapControl : MapGridControl
     // Tracked data
     public Dictionary<EntityCoordinates, (bool Visible, Color Color)> TrackedCoordinates = new();
     public Dictionary<NetEntity, NavMapBlip> TrackedEntities = new();
-    public Dictionary<Vector2i, List<NavMapLine>> TileGrid = default!;
+    public Dictionary<Vector2i, List<NavMapLine>>? TileGrid = default!;
 
     // Default colors
     public Color WallColor = new(102, 217, 102);
@@ -207,7 +207,6 @@ public partial class NavMapControl : MapGridControl
 
             // Find closest tracked entity in range
             var closestEntity = NetEntity.Invalid;
-            var closestCoords = new EntityCoordinates();
             var closestDistance = float.PositiveInfinity;
 
             foreach ((var currentEntity, var blip) in TrackedEntities)
@@ -221,7 +220,6 @@ public partial class NavMapControl : MapGridControl
                     continue;
 
                 closestEntity = currentEntity;
-                closestCoords = blip.Coordinates;
                 closestDistance = currentDistance;
             }
 
@@ -234,8 +232,7 @@ public partial class NavMapControl : MapGridControl
         else if (args.Function == EngineKeyFunctions.UIRightClick)
         {
             // Clear current selection with right click
-            if (TrackedEntitySelectedAction != null)
-                TrackedEntitySelectedAction.Invoke(null);
+            TrackedEntitySelectedAction?.Invoke(null);
         }
     }
 
@@ -260,7 +257,7 @@ public partial class NavMapControl : MapGridControl
     {
         base.Draw(handle);
 
-        // Get the components necessary for drawing the navmap 
+        // Get the components necessary for drawing the navmap
         _entManager.TryGetComponent(MapUid, out _navMap);
         _entManager.TryGetComponent(MapUid, out _grid);
         _entManager.TryGetComponent(MapUid, out _xform);
@@ -318,7 +315,7 @@ public partial class NavMapControl : MapGridControl
 
         var area = new Box2(-WorldRange, -WorldRange, WorldRange + 1f, WorldRange + 1f).Translated(offset);
 
-        // Drawing lines can be rather expensive due to the number of neighbors that need to be checked in order  
+        // Drawing lines can be rather expensive due to the number of neighbors that need to be checked in order
         // to figure out where they should be drawn. However, we don't *need* to do check these every frame.
         // Instead, lets periodically update where to draw each line and then store these points in a list.
         // Then we can just run through the list each frame and draw the lines without any extra computation.
@@ -360,6 +357,41 @@ public partial class NavMapControl : MapGridControl
             }
         }
 
+        var airlockBuffer = Vector2.One * (MinimapScale / 2.25f) * 0.75f;
+        var airlockLines = new ValueList<Vector2>();
+        var foobarVec = new Vector2(1, -1);
+
+        foreach (var airlock in _navMap.Airlocks)
+        {
+            var position = airlock.Position - offset;
+            position = Scale(position with { Y = -position.Y });
+            airlockLines.Add(position + airlockBuffer);
+            airlockLines.Add(position - airlockBuffer * foobarVec);
+
+            airlockLines.Add(position + airlockBuffer);
+            airlockLines.Add(position + airlockBuffer * foobarVec);
+
+            airlockLines.Add(position - airlockBuffer);
+            airlockLines.Add(position + airlockBuffer * foobarVec);
+
+            airlockLines.Add(position - airlockBuffer);
+            airlockLines.Add(position - airlockBuffer * foobarVec);
+
+            airlockLines.Add(position + airlockBuffer * -Vector2.UnitY);
+            airlockLines.Add(position - airlockBuffer * -Vector2.UnitY);
+        }
+
+        if (airlockLines.Count > 0)
+        {
+            if (!_sRGBLookUp.TryGetValue(WallColor, out var sRGB))
+            {
+                sRGB = Color.ToSrgb(WallColor);
+                _sRGBLookUp[WallColor] = sRGB;
+            }
+
+            handle.DrawPrimitives(DrawPrimitiveTopology.LineList, airlockLines.Span, sRGB);
+        }
+
         if (PostWallDrawingAction != null)
             PostWallDrawingAction.Invoke(handle);
 
index 567175abc516f2cb4febdc61c3eadd86b0282528..f2a23693a882cc2d4df52550aa67c42d02f5d26b 100644 (file)
@@ -5,6 +5,7 @@ using Content.Shared.Database;
 using Content.Shared.Examine;
 using Content.Shared.Pinpointer;
 using Content.Shared.Tag;
+using Robust.Server.GameObjects;
 using Robust.Shared.GameStates;
 using Robust.Shared.Map.Components;
 using Robust.Shared.Physics;
@@ -20,6 +21,7 @@ public sealed class NavMapSystem : SharedNavMapSystem
     [Dependency] private readonly IAdminLogManager _adminLog = default!;
     [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private readonly TagSystem _tags = default!;
+    [Dependency] private readonly MapSystem _map = default!;
 
     private EntityQuery<PhysicsComponent> _physicsQuery;
     private EntityQuery<TagComponent> _tagQuery;
@@ -41,6 +43,9 @@ public sealed class NavMapSystem : SharedNavMapSystem
         SubscribeLocalEvent<NavMapBeaconComponent, ComponentStartup>(OnNavMapBeaconStartup);
         SubscribeLocalEvent<NavMapBeaconComponent, AnchorStateChangedEvent>(OnNavMapBeaconAnchor);
 
+        SubscribeLocalEvent<NavMapDoorComponent, ComponentStartup>(OnNavMapDoorStartup);
+        SubscribeLocalEvent<NavMapDoorComponent, AnchorStateChangedEvent>(OnNavMapDoorAnchor);
+
         SubscribeLocalEvent<ConfigurableNavMapBeaconComponent, NavMapBeaconConfigureBuiMessage>(OnConfigureMessage);
         SubscribeLocalEvent<ConfigurableNavMapBeaconComponent, MapInitEvent>(OnConfigurableMapInit);
         SubscribeLocalEvent<ConfigurableNavMapBeaconComponent, ExaminedEvent>(OnConfigurableExamined);
@@ -63,6 +68,16 @@ public sealed class NavMapSystem : SharedNavMapSystem
         RefreshNavGrid(uid);
     }
 
+    private void OnNavMapDoorStartup(Entity<NavMapDoorComponent> ent, ref ComponentStartup args)
+    {
+        RefreshNavGrid(ent);
+    }
+
+    private void OnNavMapDoorAnchor(Entity<NavMapDoorComponent> ent, ref AnchorStateChangedEvent args)
+    {
+        RefreshNavGrid(ent);
+    }
+
     private void OnConfigureMessage(Entity<ConfigurableNavMapBeaconComponent> ent, ref NavMapBeaconConfigureBuiMessage args)
     {
         if (args.Session.AttachedEntity is not { } user)
@@ -190,6 +205,9 @@ public sealed class NavMapSystem : SharedNavMapSystem
 
     private void OnGetState(EntityUid uid, NavMapComponent component, ref ComponentGetState args)
     {
+        if (!TryComp<MapGridComponent>(uid, out var mapGrid))
+            return;
+
         var data = new Dictionary<Vector2i, int>(component.Chunks.Count);
         foreach (var (index, chunk) in component.Chunks)
         {
@@ -222,11 +240,45 @@ public sealed class NavMapSystem : SharedNavMapSystem
             beacons.Add(new NavMapBeacon(beacon.Color, name, xform.LocalPosition));
         }
 
+        var airlockQuery = EntityQueryEnumerator<NavMapDoorComponent, TransformComponent>();
+        var airlocks = new List<NavMapAirlock>();
+        while (airlockQuery.MoveNext(out _, out _, out var xform))
+        {
+            if (xform.GridUid != uid || !xform.Anchored)
+                continue;
+
+            var pos = _map.TileIndicesFor(uid, mapGrid, xform.Coordinates);
+            var enumerator = _map.GetAnchoredEntitiesEnumerator(uid, mapGrid, pos);
+
+            var wallPresent = false;
+            while (enumerator.MoveNext(out var ent))
+            {
+                if (!_physicsQuery.TryGetComponent(ent, out var body) ||
+                    !body.CanCollide ||
+                    !body.Hard ||
+                    body.BodyType != BodyType.Static ||
+                    !_tags.HasTag(ent.Value, "Wall", _tagQuery) &&
+                    !_tags.HasTag(ent.Value, "Window", _tagQuery))
+                {
+                    continue;
+                }
+
+                wallPresent = true;
+                break;
+            }
+
+            if (wallPresent)
+                continue;
+
+            airlocks.Add(new NavMapAirlock(xform.LocalPosition));
+        }
+
         // TODO: Diffs
         args.State = new NavMapComponentState()
         {
             TileData = data,
             Beacons = beacons,
+            Airlocks = airlocks
         };
     }
 
@@ -286,8 +338,8 @@ public sealed class NavMapSystem : SharedNavMapSystem
                 !body.CanCollide ||
                 !body.Hard ||
                 body.BodyType != BodyType.Static ||
-                (!_tags.HasTag(ent.Value, "Wall", _tagQuery) &&
-                 !_tags.HasTag(ent.Value, "Window", _tagQuery)))
+                !_tags.HasTag(ent.Value, "Wall", _tagQuery) &&
+                !_tags.HasTag(ent.Value, "Window", _tagQuery))
             {
                 continue;
             }
index 57f2d004d5573b0ba166648ef2e5f522085012fc..8c9979ba25a818097b9d1e3894e23ec5bb3609f2 100644 (file)
@@ -16,6 +16,8 @@ public sealed partial class NavMapComponent : Component
     public readonly Dictionary<Vector2i, NavMapChunk> Chunks = new();
 
     [ViewVariables] public readonly List<SharedNavMapSystem.NavMapBeacon> Beacons = new();
+
+    [ViewVariables] public readonly List<SharedNavMapSystem.NavMapAirlock> Airlocks = new();
 }
 
 public sealed class NavMapChunk
diff --git a/Content.Shared/Pinpointer/NavMapDoorComponent.cs b/Content.Shared/Pinpointer/NavMapDoorComponent.cs
new file mode 100644 (file)
index 0000000..914f88c
--- /dev/null
@@ -0,0 +1,13 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Pinpointer;
+
+/// <summary>
+/// This is used for objects which appear as doors on the navmap.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+[Access(typeof(SharedNavMapSystem))]
+public sealed partial class NavMapDoorComponent : Component
+{
+
+}
index 3f01934a24e3a5c1de5304a4dd8116ae13eb4bf3..17f86ac7e6807210a1a75d3b9e92c660114f4318 100644 (file)
@@ -37,8 +37,13 @@ public abstract class SharedNavMapSystem : EntitySystem
         public Dictionary<Vector2i, int> TileData = new();
 
         public List<NavMapBeacon> Beacons = new();
+
+        public List<NavMapAirlock> Airlocks = new();
     }
 
     [Serializable, NetSerializable]
     public readonly record struct NavMapBeacon(Color Color, string Text, Vector2 Position);
+
+    [Serializable, NetSerializable]
+    public readonly record struct NavMapAirlock(Vector2 Position);
 }
index bbb85f335e38267d057a86eb79901bf3b349b10e..22770ffc185943f8e5b1f6ade7f16cd79d3bbf9b 100644 (file)
@@ -64,6 +64,7 @@
   - type: Weldable
     time: 3
   - type: Airlock
+  - type: NavMapDoor
   - type: DoorBolt
   - type: Appearance
   - type: WiresVisuals
index 2ed1c60d37bbd658a409996378f4791fbd23ec63..d799558df75367d8f84e8eca3448188045004582 100644 (file)
@@ -57,6 +57,7 @@
   - type: Weldable\r
     time: 10\r
   - type: Airlock\r
+  - type: NavMapDoor\r
   - type: DoorBolt\r
   - type: AccessReader\r
   - type: Appearance\r
index 176eaf76511943d89ae8eb0fc2f0dc2023cb155f..f661b507bd701ebeace3846f3895cbb4c1fbc388 100644 (file)
     mode: NoSprite
   - type: Occluder
 
+- type: entity
+  parent: BaseMaterialDoor
+  id: BaseMaterialDoorNavMap
+  abstract: true
+  components:
+  - type: NavMapDoor
+
 - type: entity
   id: MetalDoor
   name: metal door
-  parent: BaseMaterialDoor
+  parent: BaseMaterialDoorNavMap
   components:
   - type: Construction
     graph: DoorGraph
@@ -69,7 +76,7 @@
 - type: entity
   id: WoodDoor
   name: wooden door
-  parent: BaseMaterialDoor
+  parent: BaseMaterialDoorNavMap
   description: A door, where will it lead?
   components:
   - type: Sprite
 - type: entity
   id: PaperDoor
   name: paper door
-  parent: WoodDoor
+  parent: BaseMaterialDoorNavMap
   description: A door, where will it lead?
   components:
   - type: Sprite
 - type: entity
   id: PlasmaDoor
   name: plasma door
-  parent: BaseMaterialDoor
+  parent: BaseMaterialDoorNavMap
   description: A door, where will it lead?
   components:
   - type: Sprite
 - type: entity
   id: GoldDoor
   name: gold door
-  parent: BaseMaterialDoor
+  parent: BaseMaterialDoorNavMap
   description: A door, where will it lead?
   components:
   - type: Sprite
 - type: entity
   id: SilverDoor
   name: silver door
-  parent: BaseMaterialDoor
+  parent: BaseMaterialDoorNavMap
   description: A door, where will it lead?
   components:
   - type: Sprite
 - type: entity
   id: BananiumDoor
   name: bananium door
-  parent: BaseMaterialDoor
+  parent: BaseMaterialDoorNavMap
   description: A door, where will it lead?
   components:
   - type: Sprite
 - type: entity
   id: WebDoor
   name: web door
-  parent: BaseMaterialDoor
+  parent: BaseMaterialDoorNavMap
   description: A door, leading to the lands of the spiders... or a spaced room.
   components:
   - type: Sprite
index cafaea3a2269a355f92fd9468f8f4a8f04f29a01..154467213a74c9b95ff5d47d7a41fc05b4a21961 100644 (file)
   - type: ContainerFill
     containers:
       battery-container: [ PowerCellMedium ]
+  - type: Tag
+    tags:
+    - Structure
+    - Wall
   - type: ContainerContainer
     containers:
       battery-container: !type:Container
index 876e4d0ef4d36e4d53c890721df890e0382e676f..f4a5debeac9d6ce836443e2cf236910d1daaeb96 100644 (file)
@@ -32,6 +32,7 @@
   - type: ContainerContainer
     containers:
       board: !type:Container
+  - type: NavMapDoor
   - type: Door
     openDrawDepth: BlastDoors
     closedDrawDepth: BlastDoors
index 60d03e0091f3cbdd304746eb6ec1b828124ddc63..e3fab04da889cf92789a1a837348d82b9f2896f1 100644 (file)
     openUnlitVisible: true
     # needed so that windoors will close regardless of whether there are people in it; it doesn't crush after all
     safety: false
+  - type: NavMapDoor
   - type: DoorBolt
   - type: Electrified
     enabled: false