Navmap UI enhancements (#23777)

* 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
This commit is contained in:
Errant
2024-01-14 06:08:43 +01:00
committed by GitHub
parent c41bf7e27e
commit 40db236b82
5 changed files with 35 additions and 21 deletions

View File

@@ -9,7 +9,6 @@ public sealed partial class CrewMonitoringNavMapControl : NavMapControl
public NetEntity? Focus; public NetEntity? Focus;
public Dictionary<NetEntity, string> LocalizedNames = new(); public Dictionary<NetEntity, string> LocalizedNames = new();
private Color _backgroundColor;
private Label _trackedEntityLabel; private Label _trackedEntityLabel;
private PanelContainer _trackedEntityPanel; private PanelContainer _trackedEntityPanel;
@@ -17,8 +16,7 @@ public sealed partial class CrewMonitoringNavMapControl : NavMapControl
{ {
WallColor = new Color(192, 122, 196); WallColor = new Color(192, 122, 196);
TileColor = new(71, 42, 72); TileColor = new(71, 42, 72);
_backgroundColor = Color.FromSrgb(TileColor.WithAlpha(_backgroundOpacity));
_backgroundColor = Color.FromSrgb(TileColor.WithAlpha(0.8f));
_trackedEntityLabel = new Label _trackedEntityLabel = new Label
{ {

View File

@@ -1,5 +1,6 @@
using Content.Client.Stylesheets; using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Shared.Input;
using Content.Shared.Pinpointer; using Content.Shared.Pinpointer;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
@@ -48,16 +49,21 @@ public partial class NavMapControl : MapGridControl
protected float MaxSelectableDistance = 10f; protected float MaxSelectableDistance = 10f;
protected float RecenterMinimum = 0.05f; protected float RecenterMinimum = 0.05f;
protected float MinDragDistance = 5f; protected float MinDragDistance = 5f;
protected static float MinDisplayedRange = 8f;
protected static float MaxDisplayedRange = 128f;
protected static float DefaultDisplayedRange = 48f;
// Local variables // Local variables
private Vector2 _offset; private Vector2 _offset;
private bool _draggin; private bool _draggin;
private Vector2 _startDragPosition = default!; private Vector2 _startDragPosition = default!;
private bool _recentering = false; private bool _recentering = false;
private readonly Font _font;
private float _updateTimer = 0.25f; private float _updateTimer = 0.25f;
private Dictionary<Color, Color> _sRGBLookUp = new Dictionary<Color, Color>(); 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 // Components
private NavMapComponent? _navMap; private NavMapComponent? _navMap;
@@ -91,14 +97,13 @@ public partial class NavMapControl : MapGridControl
Pressed = false, Pressed = false,
}; };
public NavMapControl() : base(8f, 128f, 48f) public NavMapControl() : base(MinDisplayedRange, MaxDisplayedRange, DefaultDisplayedRange)
{ {
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
var cache = IoCManager.Resolve<IResourceCache>(); _cache = IoCManager.Resolve<IResourceCache>();
_transformSystem = _entManager.System<SharedTransformSystem>(); _transformSystem = _entManager.System<SharedTransformSystem>();
_font = new VectorFont(cache.GetResource<FontResource>("/EngineFonts/NotoSans/NotoSans-Regular.ttf"), 12); _backgroundColor = Color.FromSrgb(TileColor.WithAlpha(_backgroundOpacity));
_beaconColor = Color.FromSrgb(TileColor.WithAlpha(0.8f));
RectClipContent = true; RectClipContent = true;
HorizontalExpand = true; HorizontalExpand = true;
@@ -185,11 +190,11 @@ public partial class NavMapControl : MapGridControl
if (args.Function == EngineKeyFunctions.Use) if (args.Function == EngineKeyFunctions.Use)
_draggin = false; _draggin = false;
if (TrackedEntitySelectedAction == null) if (args.Function == EngineKeyFunctions.UIClick)
return;
if (args.Function == EngineKeyFunctions.Use)
{ {
if (TrackedEntitySelectedAction == null)
return;
if (_xform == null || _physics == null || TrackedEntities.Count == 0) if (_xform == null || _physics == null || TrackedEntities.Count == 0)
return; return;
@@ -234,6 +239,12 @@ public partial class NavMapControl : MapGridControl
// Clear current selection with right click // Clear current selection with right click
TrackedEntitySelectedAction?.Invoke(null); TrackedEntitySelectedAction?.Invoke(null);
} }
else if (args.Function == ContentKeyFunctions.ExamineEntity)
{
// Toggle beacon labels
_beacons.Pressed = !_beacons.Pressed;
}
} }
protected override void MouseMove(GUIMouseMoveEventArgs args) 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) if (_navMap == null || _xform == null)
return; return;
@@ -400,14 +411,18 @@ public partial class NavMapControl : MapGridControl
{ {
var rectBuffer = new Vector2(5f, 3f); 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) foreach (var beacon in _navMap.Beacons)
{ {
var position = beacon.Position - offset; var position = beacon.Position - offset;
position = Scale(position with { Y = -position.Y }); position = Scale(position with { Y = -position.Y });
var textDimensions = handle.GetDimensions(_font, beacon.Text, 1f); var textDimensions = handle.GetDimensions(font, beacon.Text, 1f);
handle.DrawRect(new UIBox2(position - textDimensions / 2 - rectBuffer, position + textDimensions / 2 + rectBuffer), _beaconColor); handle.DrawRect(new UIBox2(position - textDimensions / 2 - rectBuffer, position + textDimensions / 2 + rectBuffer), _backgroundColor);
handle.DrawString(_font, position - textDimensions / 2, beacon.Text, beacon.Color); handle.DrawString(font, position - textDimensions / 2, beacon.Text, beacon.Color);
} }
} }

View File

@@ -33,6 +33,7 @@ public sealed partial class PowerMonitoringConsoleNavMapControl : NavMapControl
// Set colors // Set colors
TileColor = new Color(30, 57, 67); TileColor = new Color(30, 57, 67);
WallColor = new Color(102, 164, 217); WallColor = new Color(102, 164, 217);
_backgroundColor = Color.FromSrgb(TileColor.WithAlpha(_backgroundOpacity));
PostWallDrawingAction += DrawAllCableNetworks; PostWallDrawingAction += DrawAllCableNetworks;
} }

View 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-no-department = Unknown
crew-monitoring-user-interface-flavor-left = In case of an emergancy, contact station medical staff immediately crew-monitoring-user-interface-flavor-left = In case of an emergency, contact station medical staff immediately
crew-monitoring-user-interface-flavor-right = v1.7 crew-monitoring-user-interface-flavor-right = v1.7

View File

@@ -1,3 +1,3 @@
navmap-zoom = Zoom: {$value}% navmap-zoom = Zoom: {$value}x
navmap-recenter = Recenter navmap-recenter = Recenter
navmap-toggle-beacons = Show departments navmap-toggle-beacons = Show departments