Station maps (#13027)

This commit is contained in:
metalgearsloth
2023-04-13 16:21:24 +10:00
committed by GitHub
parent fc94d5245e
commit be4e69b0c0
45 changed files with 1210 additions and 153 deletions

View File

@@ -1,11 +1,11 @@
using System.Linq;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls;
using Content.Shared.Medical.SuitSensor;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Map;
using Robust.Shared.Timing;
@@ -18,19 +18,32 @@ namespace Content.Client.Medical.CrewMonitoring
{
private List<Control> _rowsContent = new();
private List<(DirectionIcon Icon, Vector2 Position)> _directionIcons = new();
private readonly IEntityManager _entManager;
private readonly IEyeManager _eye;
private readonly IEntityManager _entityManager;
private EntityUid? _stationUid;
public static int IconSize = 16; // XAML has a `VSeparationOverride` of 20 for each row.
public CrewMonitoringWindow()
public CrewMonitoringWindow(EntityUid? mapUid)
{
RobustXamlLoader.Load(this);
_eye = IoCManager.Resolve<IEyeManager>();
_entityManager = IoCManager.Resolve<IEntityManager>();
_entManager = IoCManager.Resolve<IEntityManager>();
_stationUid = mapUid;
if (_entManager.TryGetComponent<TransformComponent>(mapUid, out var xform))
{
NavMap.MapUid = xform.GridUid;
}
else
{
NavMap.Visible = false;
SetSize = new Vector2(775, 400);
MinSize = SetSize;
}
}
public void ShowSensors(List<SuitSensorStatus> stSensors, Vector2 worldPosition, bool snap, float precision)
public void ShowSensors(List<SuitSensorStatus> stSensors, Vector2 localPosition, bool snap, float precision)
{
ClearAllSensors();
@@ -43,13 +56,21 @@ namespace Content.Client.Medical.CrewMonitoring
{
// add users name
// format: UserName
var nameLabel = new Label()
var nameLabel = new PanelContainer()
{
Text = sensor.Name,
HorizontalExpand = true
PanelOverride = new StyleBoxFlat()
{
BackgroundColor = StyleNano.ButtonColorDisabled,
},
Children =
{
new Label()
{
Text = sensor.Name,
Margin = new Thickness(5f, 5f),
}
}
};
SensorsTable.AddChild(nameLabel);
_rowsContent.Add(nameLabel);
// add users job
// format: JobName
@@ -58,6 +79,9 @@ namespace Content.Client.Medical.CrewMonitoring
Text = sensor.Job,
HorizontalExpand = true
};
SensorsTable.AddChild(nameLabel);
_rowsContent.Add(nameLabel);
SensorsTable.AddChild(jobLabel);
_rowsContent.Add(jobLabel);
@@ -79,9 +103,36 @@ namespace Content.Client.Medical.CrewMonitoring
// add users positions
// format: (x, y)
var box = GetPositionBox(sensor.Coordinates, worldPosition, snap, precision);
var box = GetPositionBox(sensor.Coordinates, localPosition, snap, precision);
SensorsTable.AddChild(box);
_rowsContent.Add(box);
if (sensor.Coordinates != null && NavMap.Visible)
{
NavMap.TrackedCoordinates.Add(sensor.Coordinates.Value, (true, Color.FromHex("#B02E26")));
nameLabel.MouseFilter = MouseFilterMode.Stop;
// Hide all others upon mouseover.
nameLabel.OnMouseEntered += args =>
{
foreach (var (coord, value) in NavMap.TrackedCoordinates)
{
if (coord == sensor.Coordinates)
continue;
NavMap.TrackedCoordinates[coord] = (false, value.Color);
}
};
nameLabel.OnMouseExited += args =>
{
foreach (var (coord, value) in NavMap.TrackedCoordinates)
{
NavMap.TrackedCoordinates[coord] = (true, value.Color);
}
};
}
}
}
@@ -89,7 +140,7 @@ namespace Content.Client.Medical.CrewMonitoring
{
var box = new BoxContainer() { Orientation = LayoutOrientation.Horizontal };
if (coordinates == null)
if (coordinates == null || !_entManager.TryGetComponent<TransformComponent>(_stationUid, out var xform))
{
var dirIcon = new DirectionIcon()
{
@@ -101,17 +152,18 @@ namespace Content.Client.Medical.CrewMonitoring
}
else
{
// todo: add locations names (kitchen, bridge, etc)
var pos = (Vector2i) coordinates.Value.Position;
var mapCoords = coordinates.Value.ToMap(_entityManager).Position;
var position = coordinates.Value.ToMapPos(_entManager);
var local = xform.InvWorldMatrix.Transform(position);
var displayPos = local.Floored();
var dirIcon = new DirectionIcon(snap, precision)
{
SetSize = (IconSize, IconSize),
Margin = new(0, 0, 4, 0)
};
box.AddChild(dirIcon);
box.AddChild(new Label() { Text = pos.ToString() });
_directionIcons.Add((dirIcon, mapCoords - sensorPosition));
box.AddChild(new Label() { Text = displayPos.ToString() });
_directionIcons.Add((dirIcon, local - sensorPosition));
}
return box;
@@ -134,7 +186,9 @@ namespace Content.Client.Medical.CrewMonitoring
{
SensorsTable.RemoveChild(child);
}
_rowsContent.Clear();
NavMap.TrackedCoordinates.Clear();
}
}
}