Add basic handheld GPS (#6896)

Co-authored-by: fishfish458 <fishfish458>
This commit is contained in:
Fishfish458
2022-02-25 23:59:20 -06:00
committed by GitHub
parent 44d5d41d60
commit 6b7379dad0
10 changed files with 135 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
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

@@ -17,6 +17,7 @@ namespace Content.Server.Entry
"ClientEntitySpawner", "ClientEntitySpawner",
"CharacterInfo", "CharacterInfo",
"ItemCabinetVisuals", "ItemCabinetVisuals",
"HandheldGPS"
}; };
} }
} }

View File

@@ -0,0 +1,9 @@
namespace Content.Shared.GPS
{
public abstract class SharedHandheldGPSComponent : Component
{
[DataField("updateRate")]
public float UpdateRate = 1.5f;
}
}

View File

@@ -0,0 +1 @@
handheld-gps-coordinates-title = Coords: {$coordinates}

View File

@@ -0,0 +1,16 @@
- type: entity
name: global positioning system
parent: BaseItem
id: HandheldGPSBasic
description: Helping lost spacemen find their way through the planets since 2016.
components:
- type: Sprite
sprite: Objects/Devices/gps.rsi
netsync: false
layers:
- state: icon
- state: active
- type: Item
sprite: Objects/Devices/gps.rsi
state: icon
- type: HandheldGPS

View File

@@ -64,6 +64,7 @@
- Shovel - Shovel
- Spade - Spade
- CableStack - CableStack
- HandheldGPSBasic
- type: Appearance - type: Appearance
visuals: visuals:
- type: AutolatheVisualizer - type: AutolatheVisualizer

View File

@@ -134,3 +134,12 @@
materials: materials:
Steel: 500 Steel: 500
Plastic: 250 Plastic: 250
- type: latheRecipe
id: HandheldGPSBasic
icon: Objects/Devices/gps.rsi/icon.png
result: HandheldGPSBasic
completetime: 2000
materials:
Steel: 800
Glass: 300

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

View File

@@ -0,0 +1,33 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "tgstation at 3ddd840268e33bbcf316f242e6a972b84e6b773c",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "icon"
},
{
"name": "active",
"delays": [
[
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1
]
]
}
]
}