From 516f920f1e6fd191285cd1a2c60c1b2ca5202ef7 Mon Sep 17 00:00:00 2001 From: DreamySkrell <107256943+DreamySkrell@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:31:02 +0200 Subject: [PATCH] Helm Control tgui - visual bearing and direction (#16892) * a * b * c * d * e * f * g * h * data.locations * fixed * gui * red roll buttons * roll and turn switch positions * stuff * c * a * tgui lints --------- Co-authored-by: DreamySkrell <> --- code/modules/overmap/ships/computers/helm.dm | 12 +- code/modules/overmap/ships/ship.dm | 4 + .../DreamySkrell-helm-tgui-1254.yml | 41 +++++ .../DreamySkrell-helm-tgui-bear-dir.yml | 41 +++++ tgui/packages/tgui/interfaces/Helm.tsx | 161 ++++++++++++++++-- 5 files changed, 244 insertions(+), 15 deletions(-) create mode 100644 html/changelogs/DreamySkrell-helm-tgui-1254.yml create mode 100644 html/changelogs/DreamySkrell-helm-tgui-bear-dir.yml diff --git a/code/modules/overmap/ships/computers/helm.dm b/code/modules/overmap/ships/computers/helm.dm index 33207caf708..bd4be0a028d 100644 --- a/code/modules/overmap/ships/computers/helm.dm +++ b/code/modules/overmap/ships/computers/helm.dm @@ -120,14 +120,15 @@ data["sector"] = current_sector ? current_sector.name : "Deep Space" data["sector_info"] = current_sector ? current_sector.desc : "Not Available" data["landed"] = connected.get_landed_info() - data["s_x"] = connected.x - data["s_y"] = connected.y + data["ship_coord_x"] = connected.x + data["ship_coord_y"] = connected.y data["dest"] = dy && dx - data["d_x"] = dx - data["d_y"] = dy + data["autopilot_x"] = dx + data["autopilot_y"] = dy data["speedlimit"] = speedlimit ? speedlimit*1000 : "Halted" data["accel"] = get_acceleration() data["heading"] = connected.get_heading() ? dir2angle(connected.get_heading()) : 0 + data["direction"] = dir2angle(connected.dir) data["autopilot"] = autopilot data["manual_control"] = viewing_overmap(user) data["canburn"] = connected.can_burn() @@ -142,6 +143,9 @@ data["speed_slow"] = TRUE if(connected.get_speed() > SHIP_SPEED_FAST) data["speed_fast"] = TRUE + var/list/speed_xy = connected.get_speed_xy() + data["ship_speed_x"] = speed_xy[1] + data["ship_speed_y"] = speed_xy[2] data["ETAnext"] = get_eta() diff --git a/code/modules/overmap/ships/ship.dm b/code/modules/overmap/ships/ship.dm index c96f149275d..4db4cdf17c9 100644 --- a/code/modules/overmap/ships/ship.dm +++ b/code/modules/overmap/ships/ship.dm @@ -125,6 +125,10 @@ var/const/OVERMAP_SPEED_CONSTANT = (1 SECOND) /obj/effect/overmap/visitable/ship/proc/get_speed() return round(sqrt(speed[1] ** 2 + speed[2] ** 2), SHIP_MOVE_RESOLUTION) +// returns a two-item list with the speed of the ship on x and y axes +/obj/effect/overmap/visitable/ship/proc/get_speed_xy() + return list(round(speed[1], SHIP_MOVE_RESOLUTION), round(speed[2], SHIP_MOVE_RESOLUTION)) + /obj/effect/overmap/visitable/ship/proc/get_heading() var/res = 0 if(MOVING(speed[1])) diff --git a/html/changelogs/DreamySkrell-helm-tgui-1254.yml b/html/changelogs/DreamySkrell-helm-tgui-1254.yml new file mode 100644 index 00000000000..b5b8d2ba474 --- /dev/null +++ b/html/changelogs/DreamySkrell-helm-tgui-1254.yml @@ -0,0 +1,41 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# wip (For works in progress) +# tweak +# soundadd +# sounddel +# rscadd (general adding of nice things) +# rscdel (general deleting of nice things) +# imageadd +# imagedel +# maptweak +# spellcheck (typo fixes) +# experiment +# balance +# admin +# backend +# security +# refactor +################################# + +# Your name. +author: DreamySkrell + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries. +# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog. +changes: + - refactor: "Rewrites helm control from nanoui to tgui." diff --git a/html/changelogs/DreamySkrell-helm-tgui-bear-dir.yml b/html/changelogs/DreamySkrell-helm-tgui-bear-dir.yml new file mode 100644 index 00000000000..330a37a4272 --- /dev/null +++ b/html/changelogs/DreamySkrell-helm-tgui-bear-dir.yml @@ -0,0 +1,41 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# wip (For works in progress) +# tweak +# soundadd +# sounddel +# rscadd (general adding of nice things) +# rscdel (general deleting of nice things) +# imageadd +# imagedel +# maptweak +# spellcheck (typo fixes) +# experiment +# balance +# admin +# backend +# security +# refactor +################################# + +# Your name. +author: DreamySkrell + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries. +# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog. +changes: + - rscadd: "Adds a visual indication of vessel bearing and direction to helm control gui." diff --git a/tgui/packages/tgui/interfaces/Helm.tsx b/tgui/packages/tgui/interfaces/Helm.tsx index 2ad3bc0caa6..f13849546a0 100644 --- a/tgui/packages/tgui/interfaces/Helm.tsx +++ b/tgui/packages/tgui/interfaces/Helm.tsx @@ -1,20 +1,21 @@ import { BooleanLike } from '../../common/react'; import { useBackend } from '../backend'; -import { Button, Section, Table } from '../components'; +import { Box, Button, Section, Table } from '../components'; import { NtosWindow } from '../layouts'; export type HelmData = { sector: string; sector_info: string; landed: string; - s_x: number; - s_y: number; + ship_coord_x: number; + ship_coord_y: number; dest: BooleanLike; - d_x: number; - d_y: number; + autopilot_x: number; + autopilot_y: number; speedlimit: string; accel: number; heading: number; + direction: number; autopilot: BooleanLike; manual_control: BooleanLike; canburn: BooleanLike; @@ -22,6 +23,8 @@ export type HelmData = { cancombatturn: BooleanLike; accellimit: number; speed: number; + ship_speed_x: number; + ship_speed_y: number; ETAnext: number; locations: Location[]; }; @@ -33,6 +36,15 @@ type Location = { reference: string; }; +const bearing_unbounded = function (x, y) { + let res = 0; + res = Math.atan2(x, y); // radians + res = (res * 180) / 3.14; // convert to degrees + res = (res + 360.0) % 360.0; + res = Math.round(res); + return res; +}; + const FlightSection = function (act, data) { return (
@@ -51,7 +63,13 @@ const FlightSection = function (act, data) { Heading: - {data.heading}° + + {bearing_unbounded(data.ship_speed_x, data.ship_speed_y)}° + + + + Direction: + {data.direction}° Acceleration limiter: @@ -67,6 +85,124 @@ const FlightSection = function (act, data) { ); }; +const BearingsSection = function (act, data) { + return ( +
+ + + + {data.speed ? ( + + ) : ( + '' + )} + + + 0 + + + 45 + + + 90 + + + 135 + + + 180 + + + 225 + + + 270 + + + 315 + + + + + + + N + + + {data.ship_speed_y} + + + {data.ship_speed_x} E + + + S + + + {-data.ship_speed_y} + + + W {-data.ship_speed_x} + + + +
+ ); +}; + const ManualSection = function (act, data) { return (
@@ -110,7 +246,7 @@ const ManualSection = function (act, data) {