Add directional icons to crew monitors (#7404)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Medical.CrewMonitoring;
|
||||
using Content.Shared.Medical.CrewMonitoring;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -27,7 +27,7 @@ namespace Content.Client.Medical.CrewMonitoring
|
||||
switch (state)
|
||||
{
|
||||
case CrewMonitoringState st:
|
||||
_menu?.ShowSensors(st.Sensors);
|
||||
_menu?.ShowSensors(st.Sensors, st.WorldPosition, st.WorldRotation, st.Snap, st.Precision);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
Title="{Loc 'crew-monitoring-user-interface-title'}"
|
||||
MinSize="450 400">
|
||||
SetSize="450 400">
|
||||
<ScrollContainer HorizontalExpand="True"
|
||||
VerticalExpand="True">
|
||||
<GridContainer Name="SensorsTable"
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.Medical.SuitSensor;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Medical.CrewMonitoring
|
||||
{
|
||||
@@ -14,15 +15,21 @@ namespace Content.Client.Medical.CrewMonitoring
|
||||
{
|
||||
private List<Control> _rowsContent = new();
|
||||
|
||||
public static int IconSize = 16; // XAML has a `VSeparationOverride` of 20 for each row.
|
||||
|
||||
public CrewMonitoringWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public void ShowSensors(List<SuitSensorStatus> stSensors)
|
||||
public void ShowSensors(List<SuitSensorStatus> stSensors, Vector2 worldPosition, Angle worldRotation, bool snap, float precision)
|
||||
{
|
||||
ClearAllSensors();
|
||||
|
||||
// TODO scroll container
|
||||
// TODO filter by name & occupation
|
||||
// TODO make each row a xaml-control. Get rid of some of this c# control creation.
|
||||
|
||||
// add a row for each sensor
|
||||
foreach (var sensor in stSensors)
|
||||
{
|
||||
@@ -53,28 +60,43 @@ namespace Content.Client.Medical.CrewMonitoring
|
||||
|
||||
// add users positions
|
||||
// format: (x, y)
|
||||
string posText;
|
||||
if (sensor.Coordinates != null)
|
||||
{
|
||||
// todo: add locations names (kitchen, bridge, etc)
|
||||
var pos = sensor.Coordinates.Value.Position;
|
||||
var x = (int) pos.X;
|
||||
var y = (int) pos.Y;
|
||||
posText = $"({x}, {y})";
|
||||
}
|
||||
else
|
||||
{
|
||||
posText = Loc.GetString("crew-monitoring-user-interface-no-info");
|
||||
}
|
||||
var posLabel = new Label()
|
||||
{
|
||||
Text = posText
|
||||
};
|
||||
SensorsTable.AddChild(posLabel);
|
||||
_rowsContent.Add(posLabel);
|
||||
var box = GetPositionBox(sensor.Coordinates, worldPosition, worldRotation, snap, precision);
|
||||
SensorsTable.AddChild(box);
|
||||
_rowsContent.Add(box);
|
||||
}
|
||||
}
|
||||
|
||||
private BoxContainer GetPositionBox(MapCoordinates? coordinates, Vector2 sensorPosition, Angle sensorRotation, bool snap, float precision)
|
||||
{
|
||||
var box = new BoxContainer() { Orientation = LayoutOrientation.Horizontal };
|
||||
|
||||
if (coordinates == null)
|
||||
{
|
||||
var dirIcon = new DirectionIcon()
|
||||
{
|
||||
SetSize = (IconSize, IconSize),
|
||||
Margin = new(0, 0, 4, 0)
|
||||
};
|
||||
box.AddChild(dirIcon);
|
||||
box.AddChild(new Label() { Text = Loc.GetString("crew-monitoring-user-interface-no-info") });
|
||||
}
|
||||
else
|
||||
{
|
||||
// todo: add locations names (kitchen, bridge, etc)
|
||||
var pos = (Vector2i) coordinates.Value.Position;
|
||||
var relPos = coordinates.Value.Position - sensorPosition;
|
||||
var dirIcon = new DirectionIcon(relPos, sensorRotation, snap, minDistance: precision)
|
||||
{
|
||||
SetSize = (IconSize, IconSize),
|
||||
Margin = new(0, 0, 4, 0)
|
||||
};
|
||||
box.AddChild(dirIcon);
|
||||
box.AddChild(new Label() { Text = pos.ToString() });
|
||||
}
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
private void ClearAllSensors()
|
||||
{
|
||||
foreach (var child in _rowsContent)
|
||||
|
||||
@@ -457,6 +457,11 @@ namespace Content.Client.Stylesheets
|
||||
var contextMenuExpansionTexture = resCache.GetTexture("/Textures/Interface/VerbIcons/group.svg.192dpi.png");
|
||||
var verbMenuConfirmationTexture = resCache.GetTexture("/Textures/Interface/VerbIcons/group.svg.192dpi.png");
|
||||
|
||||
// south-facing arrow:
|
||||
var directionIconArrowTex = resCache.GetTexture("/Textures/Interface/VerbIcons/drop.svg.192dpi.png");
|
||||
var directionIconQuestionTex = resCache.GetTexture("/Textures/Interface/VerbIcons/information.svg.192dpi.png");
|
||||
var directionIconHereTex = resCache.GetTexture("/Textures/Interface/VerbIcons/dot.svg.192dpi.png");
|
||||
|
||||
Stylesheet = new Stylesheet(BaseRules.Concat(new[]
|
||||
{
|
||||
// Window title.
|
||||
@@ -680,6 +685,16 @@ namespace Content.Client.Stylesheets
|
||||
.Pseudo(ContainerButton.StylePseudoClassDisabled)
|
||||
.Prop(Control.StylePropertyModulateSelf, ExamineButtonColorContextDisabled),
|
||||
|
||||
// Direction / arrow icon
|
||||
Element<DirectionIcon>().Class(DirectionIcon.StyleClassDirectionIconArrow)
|
||||
.Prop(TextureRect.StylePropertyTexture, directionIconArrowTex),
|
||||
|
||||
Element<DirectionIcon>().Class(DirectionIcon.StyleClassDirectionIconUnknown)
|
||||
.Prop(TextureRect.StylePropertyTexture, directionIconQuestionTex),
|
||||
|
||||
Element<DirectionIcon>().Class(DirectionIcon.StyleClassDirectionIconHere)
|
||||
.Prop(TextureRect.StylePropertyTexture, directionIconHereTex),
|
||||
|
||||
// Thin buttons (No padding nor vertical margin)
|
||||
Element<EntityContainerButton>().Class(StyleClassStorageButton)
|
||||
.Prop(ContainerButton.StylePropertyStyleBox, buttonStorage),
|
||||
|
||||
70
Content.Client/UserInterface/Controls/DirectionIcon.cs
Normal file
70
Content.Client/UserInterface/Controls/DirectionIcon.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
|
||||
namespace Content.Client.UserInterface.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Simple control that shows an arrow pointing in some direction.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The actual arrow and other icons are defined in the style sheet.
|
||||
/// </remarks>
|
||||
public sealed class DirectionIcon : TextureRect
|
||||
{
|
||||
public static string StyleClassDirectionIconArrow = "direction-icon-arrow"; // south pointing arrow
|
||||
public static string StyleClassDirectionIconHere = "direction-icon-here"; // "you have reached your destination"
|
||||
public static string StyleClassDirectionIconUnknown = "direction-icon-unknown"; // unknown direction / error
|
||||
|
||||
private Angle? _rotation;
|
||||
|
||||
public Angle? Rotation
|
||||
{
|
||||
get => _rotation;
|
||||
set
|
||||
{
|
||||
_rotation = value;
|
||||
SetOnlyStyleClass(value == null ? StyleClassDirectionIconUnknown : StyleClassDirectionIconArrow);
|
||||
}
|
||||
}
|
||||
|
||||
public DirectionIcon()
|
||||
{
|
||||
Stretch = StretchMode.KeepAspectCentered;
|
||||
SetOnlyStyleClass(StyleClassDirectionIconUnknown);
|
||||
}
|
||||
|
||||
public DirectionIcon(Direction direction) : this()
|
||||
{
|
||||
Rotation = direction.ToAngle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an icon with an arrow pointing in some direction.
|
||||
/// </summary>
|
||||
/// <param name="direction">The direction</param>
|
||||
/// <param name="relativeAngle">The relative angle. This may be the players eye rotation, the grid rotation, or
|
||||
/// maybe the world rotation of the entity that owns some BUI</param>
|
||||
/// <param name="snap">If true, will snap the nearest cardinal or diagonal direction</param>
|
||||
/// <param name="minDistance">If the distance is less than this, the arrow icon will be replaced by some other indicator</param>
|
||||
public DirectionIcon(Vector2 direction, Angle relativeAngle, bool snap, float minDistance = 0.1f) : this()
|
||||
{
|
||||
if (direction.EqualsApprox(Vector2.Zero, minDistance))
|
||||
{
|
||||
SetOnlyStyleClass(StyleClassDirectionIconHere);
|
||||
return;
|
||||
}
|
||||
|
||||
var rotation = direction.ToWorldAngle() - relativeAngle;
|
||||
Rotation = snap ? rotation.GetDir().ToAngle() : rotation;
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
if (_rotation != null)
|
||||
{
|
||||
var offset = (-_rotation.Value).RotateVec(Size * UIScale / 2) - Size * UIScale / 2;
|
||||
handle.SetTransform(Matrix3.CreateTransform(GlobalPixelPosition - offset, -_rotation.Value));
|
||||
}
|
||||
base.Draw(handle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user