Station maps (#13027)
This commit is contained in:
@@ -7,15 +7,25 @@ namespace Content.Client.Medical.CrewMonitoring
|
||||
{
|
||||
public sealed class CrewMonitoringBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
private readonly IEntityManager _entManager;
|
||||
private CrewMonitoringWindow? _menu;
|
||||
|
||||
public CrewMonitoringBoundUserInterface([NotNull] ClientUserInterfaceComponent owner, [NotNull] Enum uiKey) : base(owner, uiKey)
|
||||
public CrewMonitoringBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
_entManager = IoCManager.Resolve<IEntityManager>();
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
_menu = new CrewMonitoringWindow();
|
||||
EntityUid? gridUid = null;
|
||||
|
||||
if (_entManager.TryGetComponent<TransformComponent>(Owner.Owner, out var xform))
|
||||
{
|
||||
gridUid = xform.GridUid;
|
||||
}
|
||||
|
||||
_menu = new CrewMonitoringWindow(gridUid);
|
||||
|
||||
_menu.OpenCentered();
|
||||
_menu.OnClose += Close;
|
||||
}
|
||||
@@ -27,7 +37,15 @@ namespace Content.Client.Medical.CrewMonitoring
|
||||
switch (state)
|
||||
{
|
||||
case CrewMonitoringState st:
|
||||
_menu?.ShowSensors(st.Sensors, st.WorldPosition, st.Snap, st.Precision);
|
||||
_entManager.TryGetComponent<TransformComponent>(Owner.Owner, out var xform);
|
||||
Vector2 localPosition = Vector2.Zero;
|
||||
|
||||
if (_entManager.TryGetComponent<TransformComponent>(xform?.GridUid, out var gridXform))
|
||||
{
|
||||
localPosition = gridXform.InvWorldMatrix.Transform(xform.WorldPosition);
|
||||
}
|
||||
|
||||
_menu?.ShowSensors(st.Sensors, localPosition, st.Snap, st.Precision);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
Title="{Loc 'crew-monitoring-user-interface-title'}"
|
||||
SetSize="775 400">
|
||||
<ScrollContainer HorizontalExpand="True" VerticalExpand="True" Margin="5">
|
||||
<GridContainer Name="SensorsTable" HorizontalExpand="True" VerticalExpand="True" HSeparationOverride="5" VSeparationOverride="20" Columns="4">
|
||||
<!-- Category Headers -->
|
||||
<Label Text="{Loc 'crew-monitoring-user-interface-name'}" StyleClasses="LabelHeading"/>
|
||||
<Label Text="{Loc 'crew-monitoring-user-interface-job'}" StyleClasses="LabelHeading"/>
|
||||
<Label Text="{Loc 'crew-monitoring-user-interface-status'}" StyleClasses="LabelHeading"/>
|
||||
<Label Text="{Loc 'crew-monitoring-user-interface-location'}" StyleClasses="LabelHeading"/>
|
||||
xmlns:ui="clr-namespace:Content.Client.Pinpointer.UI"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
Title="{Loc 'crew-monitoring-user-interface-title'}"
|
||||
SetSize="1130 700"
|
||||
MinSize="1130 700">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<ScrollContainer HorizontalExpand="True"
|
||||
VerticalExpand="True"
|
||||
Margin="0, 0, 8, 0">
|
||||
<GridContainer Name="SensorsTable"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True"
|
||||
HSeparationOverride="5"
|
||||
VSeparationOverride="20"
|
||||
Columns="4">
|
||||
<!-- Table header -->
|
||||
<Label Text="{Loc 'crew-monitoring-user-interface-name'}"
|
||||
StyleClasses="LabelHeading"/>
|
||||
<Label Text="{Loc 'crew-monitoring-user-interface-job'}"
|
||||
StyleClasses="LabelHeading"/>
|
||||
<Label Text="{Loc 'crew-monitoring-user-interface-status'}"
|
||||
StyleClasses="LabelHeading"/>
|
||||
<Label Text="{Loc 'crew-monitoring-user-interface-location'}"
|
||||
StyleClasses="LabelHeading"/>
|
||||
|
||||
<!-- Additional table rows are filled by code -->
|
||||
</GridContainer>
|
||||
</ScrollContainer>
|
||||
<!-- Table rows are filled by code -->
|
||||
</GridContainer>
|
||||
</ScrollContainer>
|
||||
<ui:NavMapControl Name="NavMap"
|
||||
Margin="5 5"/>
|
||||
</BoxContainer>
|
||||
</controls:FancyWindow>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user