Files
crystall-punk-14/Content.Client/GPS/UI/HandheldGpsStatusControl.cs

62 lines
1.9 KiB
C#
Raw Permalink Normal View History

using Content.Shared.GPS.Components;
2022-09-11 08:53:17 +02:00
using Content.Client.Message;
using Content.Client.Stylesheets;
using Robust.Client.GameObjects;
2022-09-11 08:53:17 +02:00
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
namespace Content.Client.GPS.UI;
public sealed class HandheldGpsStatusControl : Control
{
private readonly Entity<HandheldGPSComponent> _parent;
2022-09-11 08:53:17 +02:00
private readonly RichTextLabel _label;
private float _updateDif;
private readonly IEntityManager _entMan;
private readonly SharedTransformSystem _transform;
2022-09-11 08:53:17 +02:00
public HandheldGpsStatusControl(Entity<HandheldGPSComponent> parent)
2022-09-11 08:53:17 +02:00
{
_parent = parent;
_entMan = IoCManager.Resolve<IEntityManager>();
_transform = _entMan.System<TransformSystem>();
2022-09-11 08:53:17 +02:00
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
UpdateGpsDetails();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
// don't display the label if the gps component is being removed
if (_parent.Comp.LifeStage > ComponentLifeStage.Running)
{
_label.Visible = false;
return;
}
2022-09-11 08:53:17 +02:00
_updateDif += args.DeltaSeconds;
if (_updateDif < _parent.Comp.UpdateRate)
2022-09-11 08:53:17 +02:00
return;
_updateDif -= _parent.Comp.UpdateRate;
2022-09-11 08:53:17 +02:00
UpdateGpsDetails();
}
private void UpdateGpsDetails()
{
var posText = "Error";
if (_entMan.TryGetComponent(_parent, out TransformComponent? transComp))
2022-09-11 08:53:17 +02:00
{
var pos = _transform.GetMapCoordinates(_parent.Owner, xform: transComp);
var x = (int)pos.X;
var y = (int)pos.Y;
2022-09-11 08:53:17 +02:00
posText = $"({x}, {y})";
}
_label.SetMarkup(Loc.GetString("handheld-gps-coordinates-title", ("coordinates", posText)));
}
}