]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Navmap UI enhancements (#23777)
authorErrant <35878406+Errant-4@users.noreply.github.com>
Sun, 14 Jan 2024 05:08:43 +0000 (06:08 +0100)
committerGitHub <noreply@github.com>
Sun, 14 Jan 2024 05:08:43 +0000 (16:08 +1100)
* label scaling wip

* beacon toggle, cleanup

* weh

* caw

* Smooth scaling, almost-selectable font size, Magnification count, zoom scale accuracy change, opacity

* never asked for individual font sizes

* zoom

* format

* Fixes CrewMonitor and PowerMonitor using the default tile color as text background instead of their custom tile colors

* font customisation, needs UI elements

* Station map rightclick now works

* UI scale will keep the local systems in line

* adjusting font size to UI scale

* typo

* fix RT version

* putting cache back in its place

* toggle labels moved to Examine

Content.Client/Medical/CrewMonitoring/CrewMonitoringNavMapControl.cs
Content.Client/Pinpointer/UI/NavMapControl.cs
Content.Client/Power/PowerMonitoringConsoleNavMapControl.cs
Resources/Locale/en-US/medical/components/crew-monitoring-component.ftl
Resources/Locale/en-US/ui/navmap.ftl

index e6adf13bed4abe37d12342639099891e22d5d7f9..fcecbad465aca3fcfc0c184c83f1f939c4420b63 100644 (file)
@@ -9,7 +9,6 @@ public sealed partial class CrewMonitoringNavMapControl : NavMapControl
     public NetEntity? Focus;
     public Dictionary<NetEntity, string> LocalizedNames = new();
 
-    private Color _backgroundColor;
     private Label _trackedEntityLabel;
     private PanelContainer _trackedEntityPanel;
 
@@ -17,8 +16,7 @@ public sealed partial class CrewMonitoringNavMapControl : NavMapControl
     {
         WallColor = new Color(192, 122, 196);
         TileColor = new(71, 42, 72);
-
-        _backgroundColor = Color.FromSrgb(TileColor.WithAlpha(0.8f));
+        _backgroundColor = Color.FromSrgb(TileColor.WithAlpha(_backgroundOpacity));
 
         _trackedEntityLabel = new Label
         {
index d3c505e49f3a97bcbb0ee1b57fc0ea15786090c8..320c5f899aca9f60a35a201fd5aadf04e73384ae 100644 (file)
@@ -1,5 +1,6 @@
 using Content.Client.Stylesheets;
 using Content.Client.UserInterface.Controls;
+using Content.Shared.Input;
 using Content.Shared.Pinpointer;
 using Robust.Client.Graphics;
 using Robust.Client.ResourceManagement;
@@ -48,16 +49,21 @@ public partial class NavMapControl : MapGridControl
     protected float MaxSelectableDistance = 10f;
     protected float RecenterMinimum = 0.05f;
     protected float MinDragDistance = 5f;
+    protected static float MinDisplayedRange = 8f;
+    protected static float MaxDisplayedRange = 128f;
+    protected static float DefaultDisplayedRange = 48f;
 
     // Local variables
     private Vector2 _offset;
     private bool _draggin;
     private Vector2 _startDragPosition = default!;
     private bool _recentering = false;
-    private readonly Font _font;
     private float _updateTimer = 0.25f;
     private Dictionary<Color, Color> _sRGBLookUp = new Dictionary<Color, Color>();
-    private Color _beaconColor;
+    public Color _backgroundColor;
+    public float _backgroundOpacity = 0.9f;
+    private int _targetFontsize = 8;
+    private IResourceCache _cache;
 
     // Components
     private NavMapComponent? _navMap;
@@ -91,14 +97,13 @@ public partial class NavMapControl : MapGridControl
         Pressed = false,
     };
 
-    public NavMapControl() : base(8f, 128f, 48f)
+    public NavMapControl() : base(MinDisplayedRange, MaxDisplayedRange, DefaultDisplayedRange)
     {
         IoCManager.InjectDependencies(this);
-        var cache = IoCManager.Resolve<IResourceCache>();
+        _cache = IoCManager.Resolve<IResourceCache>();
 
         _transformSystem = _entManager.System<SharedTransformSystem>();
-        _font = new VectorFont(cache.GetResource<FontResource>("/EngineFonts/NotoSans/NotoSans-Regular.ttf"), 12);
-        _beaconColor = Color.FromSrgb(TileColor.WithAlpha(0.8f));
+        _backgroundColor = Color.FromSrgb(TileColor.WithAlpha(_backgroundOpacity));
 
         RectClipContent = true;
         HorizontalExpand = true;
@@ -185,11 +190,11 @@ public partial class NavMapControl : MapGridControl
         if (args.Function == EngineKeyFunctions.Use)
             _draggin = false;
 
-        if (TrackedEntitySelectedAction == null)
-            return;
-
-        if (args.Function == EngineKeyFunctions.Use)
+        if (args.Function == EngineKeyFunctions.UIClick)
         {
+            if (TrackedEntitySelectedAction == null)
+                return;
+
             if (_xform == null || _physics == null || TrackedEntities.Count == 0)
                 return;
 
@@ -234,6 +239,12 @@ public partial class NavMapControl : MapGridControl
             // Clear current selection with right click
             TrackedEntitySelectedAction?.Invoke(null);
         }
+
+        else if (args.Function == ContentKeyFunctions.ExamineEntity)
+        {
+            // Toggle beacon labels
+            _beacons.Pressed = !_beacons.Pressed;
+        }
     }
 
     protected override void MouseMove(GUIMouseMoveEventArgs args)
@@ -282,7 +293,7 @@ public partial class NavMapControl : MapGridControl
             }
         }
 
-        _zoom.Text = Loc.GetString("navmap-zoom", ("value", $"{(WorldRange / WorldMaxRange * 100f):0.00}"));
+        _zoom.Text = Loc.GetString("navmap-zoom", ("value", $"{(DefaultDisplayedRange / WorldRange ):0.0}"));
 
         if (_navMap == null || _xform == null)
             return;
@@ -400,14 +411,18 @@ public partial class NavMapControl : MapGridControl
         {
             var rectBuffer = new Vector2(5f, 3f);
 
+            // Calculate font size for current zoom level
+            var fontSize = (int) Math.Round(1 / WorldRange * DefaultDisplayedRange * UIScale * _targetFontsize , 0);
+            var font = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Bold.ttf"), fontSize);
+
             foreach (var beacon in _navMap.Beacons)
             {
                 var position = beacon.Position - offset;
                 position = Scale(position with { Y = -position.Y });
 
-                var textDimensions = handle.GetDimensions(_font, beacon.Text, 1f);
-                handle.DrawRect(new UIBox2(position - textDimensions / 2 - rectBuffer, position + textDimensions / 2 + rectBuffer), _beaconColor);
-                handle.DrawString(_font, position - textDimensions / 2, beacon.Text, beacon.Color);
+                var textDimensions = handle.GetDimensions(font, beacon.Text, 1f);
+                handle.DrawRect(new UIBox2(position - textDimensions / 2 - rectBuffer, position + textDimensions / 2 + rectBuffer), _backgroundColor);
+                handle.DrawString(font, position - textDimensions / 2, beacon.Text, beacon.Color);
             }
         }
 
index ac2700564d6f6309019ba0c4e6d4dcf13232daba..9f537f38587496d8bc9a709d6f21bc8648ba4e4d 100644 (file)
@@ -33,6 +33,7 @@ public sealed partial class PowerMonitoringConsoleNavMapControl : NavMapControl
         // Set colors
         TileColor = new Color(30, 57, 67);
         WallColor = new Color(102, 164, 217);
+        _backgroundColor = Color.FromSrgb(TileColor.WithAlpha(_backgroundOpacity));
 
         PostWallDrawingAction += DrawAllCableNetworks;
     }
index f77f334c7e2e73598b3aed03ba8823ef024d1eab..7fd7f4608e16e989a5c75e713ee7b8758c0fd343 100644 (file)
@@ -15,5 +15,5 @@ crew-monitoring-user-interface-no-server = Server not found
 
 crew-monitoring-user-interface-no-department = Unknown
 
-crew-monitoring-user-interface-flavor-left = In case of an emergancy, contact station medical staff immediately
-crew-monitoring-user-interface-flavor-right = v1.7
\ No newline at end of file
+crew-monitoring-user-interface-flavor-left = In case of an emergency, contact station medical staff immediately
+crew-monitoring-user-interface-flavor-right = v1.7
index e600e7a1f22ef3292f9d44f8f769bb46dc51980b..3c2aad12718ad6b269fd825ab0c5d688f178d6a7 100644 (file)
@@ -1,3 +1,3 @@
-navmap-zoom = Zoom: {$value}%
+navmap-zoom = Zoom: {$value}x
 navmap-recenter = Recenter
-navmap-toggle-beacons = Show departments
\ No newline at end of file
+navmap-toggle-beacons = Show departments