From 6b7379dad0fad176f29445c1fb527e893ee942b0 Mon Sep 17 00:00:00 2001 From: Fishfish458 <47410468+Fishfish458@users.noreply.github.com> Date: Fri, 25 Feb 2022 23:59:20 -0600 Subject: [PATCH] Add basic handheld GPS (#6896) Co-authored-by: fishfish458 --- Content.Client/GPS/HandheldGPSComponent.cs | 65 ++++++++++++++++++ Content.Server/Entry/IgnoredComponents.cs | 1 + .../Components/SharedHandheldGPSComponent.cs | 9 +++ Resources/Locale/en-US/GPS/handheld-gps.ftl | 1 + .../Prototypes/Entities/Objects/Tools/gps.yml | 16 +++++ .../Entities/Structures/Machines/lathe.yml | 1 + Resources/Prototypes/Recipes/Lathes/tools.yml | 9 +++ .../Objects/Devices/gps.rsi/active.png | Bin 0 -> 385 bytes .../Textures/Objects/Devices/gps.rsi/icon.png | Bin 0 -> 351 bytes .../Objects/Devices/gps.rsi/meta.json | 33 +++++++++ 10 files changed, 135 insertions(+) create mode 100644 Content.Client/GPS/HandheldGPSComponent.cs create mode 100644 Content.Shared/Tools/Components/SharedHandheldGPSComponent.cs create mode 100644 Resources/Locale/en-US/GPS/handheld-gps.ftl create mode 100644 Resources/Prototypes/Entities/Objects/Tools/gps.yml create mode 100644 Resources/Textures/Objects/Devices/gps.rsi/active.png create mode 100644 Resources/Textures/Objects/Devices/gps.rsi/icon.png create mode 100644 Resources/Textures/Objects/Devices/gps.rsi/meta.json diff --git a/Content.Client/GPS/HandheldGPSComponent.cs b/Content.Client/GPS/HandheldGPSComponent.cs new file mode 100644 index 0000000000..3d216d4d4c --- /dev/null +++ b/Content.Client/GPS/HandheldGPSComponent.cs @@ -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(); + _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(_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))); + } + } + } +} diff --git a/Content.Server/Entry/IgnoredComponents.cs b/Content.Server/Entry/IgnoredComponents.cs index 1b5280cc6c..16c1ebbcbd 100644 --- a/Content.Server/Entry/IgnoredComponents.cs +++ b/Content.Server/Entry/IgnoredComponents.cs @@ -17,6 +17,7 @@ namespace Content.Server.Entry "ClientEntitySpawner", "CharacterInfo", "ItemCabinetVisuals", + "HandheldGPS" }; } } diff --git a/Content.Shared/Tools/Components/SharedHandheldGPSComponent.cs b/Content.Shared/Tools/Components/SharedHandheldGPSComponent.cs new file mode 100644 index 0000000000..0535201792 --- /dev/null +++ b/Content.Shared/Tools/Components/SharedHandheldGPSComponent.cs @@ -0,0 +1,9 @@ + +namespace Content.Shared.GPS +{ + public abstract class SharedHandheldGPSComponent : Component + { + [DataField("updateRate")] + public float UpdateRate = 1.5f; + } +} diff --git a/Resources/Locale/en-US/GPS/handheld-gps.ftl b/Resources/Locale/en-US/GPS/handheld-gps.ftl new file mode 100644 index 0000000000..e852f80832 --- /dev/null +++ b/Resources/Locale/en-US/GPS/handheld-gps.ftl @@ -0,0 +1 @@ +handheld-gps-coordinates-title = Coords: {$coordinates} diff --git a/Resources/Prototypes/Entities/Objects/Tools/gps.yml b/Resources/Prototypes/Entities/Objects/Tools/gps.yml new file mode 100644 index 0000000000..ee84fa3e5a --- /dev/null +++ b/Resources/Prototypes/Entities/Objects/Tools/gps.yml @@ -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 diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index 80c0025d0b..8fe43b7940 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -64,6 +64,7 @@ - Shovel - Spade - CableStack + - HandheldGPSBasic - type: Appearance visuals: - type: AutolatheVisualizer diff --git a/Resources/Prototypes/Recipes/Lathes/tools.yml b/Resources/Prototypes/Recipes/Lathes/tools.yml index efe10304c6..9a7e4b1866 100644 --- a/Resources/Prototypes/Recipes/Lathes/tools.yml +++ b/Resources/Prototypes/Recipes/Lathes/tools.yml @@ -134,3 +134,12 @@ materials: Steel: 500 Plastic: 250 + +- type: latheRecipe + id: HandheldGPSBasic + icon: Objects/Devices/gps.rsi/icon.png + result: HandheldGPSBasic + completetime: 2000 + materials: + Steel: 800 + Glass: 300 diff --git a/Resources/Textures/Objects/Devices/gps.rsi/active.png b/Resources/Textures/Objects/Devices/gps.rsi/active.png new file mode 100644 index 0000000000000000000000000000000000000000..1dfcedc6c7fa44789bf31384c531f137ed5107ff GIT binary patch literal 385 zcmeAS@N?(olHy`uVBq!ia0vp^4M3d0!3HF+R#ka2Ffe*}x;TbZ%z1lvW9}gb5w-`@ zHMV%1SSs$&<5+f*>&yYJo2rt^pO`cQRc?ta>Ch2$7umV_57WPWmri`2zg9TpzcLfh zC|Zd`||JO&)2_}ZJqH%^@P0s|9xe~ci%Y|IKAPX)J>U1MsD{11JlJ3;(Gc>C`Hao| znubGvrZ0DPInrPD?#g-l9QN~Bb`J5L=hrMv55Ii;M7_q|jr{B0E}wqtlp-#$UE6&)jRo)7IzOITc#} z*e~%||H|=G=QF(KpJ#s|eY-xemSNpq`Fii4s_YwnFr<9H{B$-y)Vu?(@y2g%#NUxP QkpU9%boFyt=akR{0E8{3y#N3J literal 0 HcmV?d00001 diff --git a/Resources/Textures/Objects/Devices/gps.rsi/icon.png b/Resources/Textures/Objects/Devices/gps.rsi/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a8796cd6fe2605207ee20aeb3fd70938d1d8e6e1 GIT binary patch literal 351 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=hEVFsgaFIEGZrNluVpU7R4oW00T{ zzPM%5zj}$^NB4I3yr@Y!o2Yc1(SCnzT1BG3u@9ebr?06=VvJN&&{+6o{)AcI_1_7m znsKk3w%a@FfBCyP2M+*2z_y11F?+NR@SV%k?^eHMGii}SfD>n)7bc~sp48bS^l)+OLLUG7|BoH$7i*i8BX)CVLsY^6S%)yG z1R$6orlPxU(=1b#H*!XN+7t69t1bI{{pD+n2HZ~`g$Jt& oPKuEZ+N>r63XvWrHXvY_u_U)}#>td!V8AhWy85}Sb4q9e0N2@(-T(jq literal 0 HcmV?d00001 diff --git a/Resources/Textures/Objects/Devices/gps.rsi/meta.json b/Resources/Textures/Objects/Devices/gps.rsi/meta.json new file mode 100644 index 0000000000..a59c0b0012 --- /dev/null +++ b/Resources/Textures/Objects/Devices/gps.rsi/meta.json @@ -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 + ] + ] + } + ] +}