Remove IItemStatus (#11055)

This commit is contained in:
Alex Evgrashin
2022-09-11 08:53:17 +02:00
committed by GitHub
parent 61655c18b2
commit 385a52c390
18 changed files with 357 additions and 355 deletions

View File

@@ -0,0 +1,9 @@
using Content.Shared.GPS;
namespace Content.Client.GPS.Components
{
[RegisterComponent]
public sealed class HandheldGPSComponent : SharedHandheldGPSComponent
{
}
}

View File

@@ -1,65 +0,0 @@
using Content.Client.Items.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
using Content.Shared.GPS;
namespace Content.Client.GPS
{
[RegisterComponent]
internal sealed class HandheldGPSComponent : SharedHandheldGPSComponent, IItemStatus
{
Control IItemStatus.MakeControl()
{
return new StatusControl(this);
}
private sealed class StatusControl : Control
{
private readonly HandheldGPSComponent _parent;
private readonly RichTextLabel _label;
private float UpdateDif;
private readonly IEntityManager _entMan = default!;
public StatusControl(HandheldGPSComponent parent)
{
_parent = parent;
_entMan = IoCManager.Resolve<IEntityManager>();
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
UpdateGPSDetails();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
UpdateDif += args.DeltaSeconds;
if (UpdateDif < _parent.UpdateRate)
return;
UpdateDif -= _parent.UpdateRate;
UpdateGPSDetails();
}
public void UpdateGPSDetails()
{
string posText = "Error";
if (_entMan.TryGetComponent<TransformComponent>(_parent.Owner, out TransformComponent? transComp))
{
if (transComp.Coordinates != null)
{
var pos = transComp.MapPosition;
var x = (int) pos.X;
var y = (int) pos.Y;
posText = $"({x}, {y})";
}
}
_label.SetMarkup(Loc.GetString("handheld-gps-coordinates-title", ("coordinates", posText)));
}
}
}
}

View File

@@ -0,0 +1,19 @@
using Content.Client.GPS.Components;
using Content.Client.GPS.UI;
using Content.Client.Items;
namespace Content.Client.GPS.Systems;
public sealed class HandheldGpsSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HandheldGPSComponent, ItemStatusCollectMessage>(OnItemStatus);
}
private void OnItemStatus(EntityUid uid, HandheldGPSComponent component, ItemStatusCollectMessage args)
{
args.Controls.Add(new HandheldGpsStatusControl(component));
}
}

View File

@@ -0,0 +1,51 @@
using Content.Client.GPS.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
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 HandheldGPSComponent _parent;
private readonly RichTextLabel _label;
private float _updateDif;
private readonly IEntityManager _entMan;
public HandheldGpsStatusControl(HandheldGPSComponent parent)
{
_parent = parent;
_entMan = IoCManager.Resolve<IEntityManager>();
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
UpdateGpsDetails();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
_updateDif += args.DeltaSeconds;
if (_updateDif < _parent.UpdateRate)
return;
_updateDif -= _parent.UpdateRate;
UpdateGpsDetails();
}
private void UpdateGpsDetails()
{
var posText = "Error";
if (_entMan.TryGetComponent(_parent.Owner, out TransformComponent? transComp))
{
var pos = transComp.MapPosition;
var x = (int) pos.X;
var y = (int) pos.Y;
posText = $"({x}, {y})";
}
_label.SetMarkup(Loc.GetString("handheld-gps-coordinates-title", ("coordinates", posText)));
}
}