From 1d7dfbf58446faba732d091ac49ccbf4e4b43f9b Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 15 May 2024 01:33:06 +0200 Subject: [PATCH] [MIRROR] Makes Health Sensor assemblies a bit nicer to use (#27689) * Makes Health Sensor assemblies a bit nicer to use (#83183) ## About The Pull Request Gives health sensors a UI to change their settings ![sensor-off](https://github.com/tgstation/tgstation/assets/139372157/06eb1756-23ff-4d8a-b305-e847430f6982) ![sensor-on](https://github.com/tgstation/tgstation/assets/139372157/466f21d2-8369-4e04-9197-d606063aa715) ![checking-for-death](https://github.com/tgstation/tgstation/assets/139372157/25d7bc84-246b-4997-9684-e899a6700b5b) ## Why It's Good For The Game Makes the assemblies less annoying to use ## Changelog :cl: qol: Gives Health sensor assemblies a UI so its easier to use. /:cl: * Makes Health Sensor assemblies a bit nicer to use --------- Co-authored-by: starrm4nn <139372157+starrm4nn@users.noreply.github.com> --- code/modules/assembly/health.dm | 55 +++++++++++++------ .../packages/tgui/interfaces/HealthSensor.tsx | 55 +++++++++++++++++++ 2 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 tgui/packages/tgui/interfaces/HealthSensor.tsx diff --git a/code/modules/assembly/health.dm b/code/modules/assembly/health.dm index 28ab16f63d7..20316ebfd66 100644 --- a/code/modules/assembly/health.dm +++ b/code/modules/assembly/health.dm @@ -7,11 +7,10 @@ var/scanning = FALSE var/health_scan - var/alarm_health = HEALTH_THRESHOLD_CRIT + var/health_target = HEALTH_THRESHOLD_CRIT /obj/item/assembly/health/examine(mob/user) . = ..() - . += "Use it in hand to turn it off/on and Alt-click to swap between \"detect death\" mode and \"detect critical state\" mode." . += "[src.scanning ? "The sensor is on and you can see [health_scan] displayed on the screen" : "The sensor is off"]." /obj/item/assembly/health/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change) @@ -37,15 +36,6 @@ update_appearance() return secured -/obj/item/assembly/health/click_alt(mob/living/user) - if(alarm_health == HEALTH_THRESHOLD_CRIT) - alarm_health = HEALTH_THRESHOLD_DEAD - to_chat(user, span_notice("You toggle [src] to \"detect death\" mode.")) - else - alarm_health = HEALTH_THRESHOLD_CRIT - to_chat(user, span_notice("You toggle [src] to \"detect critical state\" mode.")) - return CLICK_ACTION_SUCCESS - /obj/item/assembly/health/process() //not ready yet if(!scanning || !secured) @@ -63,7 +53,7 @@ //only do the pulse if we are within alarm thresholds var/mob/living/target_mob = object health_scan = target_mob.health - if(health_scan > alarm_health) + if(health_scan > health_target) return //do the pulse & the scan @@ -82,14 +72,43 @@ STOP_PROCESSING(SSobj, src) return -/obj/item/assembly/health/attack_self(mob/user) - . = ..() - if (secured) - balloon_alert(user, "scanning [scanning ? "disabled" : "enabled"]") +/obj/item/assembly/health/proc/toggle_target() + if(health_target == HEALTH_THRESHOLD_CRIT) + health_target = HEALTH_THRESHOLD_DEAD else - balloon_alert(user, "secure it first!") - toggle_scan() + health_target = HEALTH_THRESHOLD_CRIT + return /obj/item/assembly/health/proc/get_status_tab_item(mob/living/carbon/source, list/items) SIGNAL_HANDLER items += "Health: [round((source.health / source.maxHealth) * 100)]%" + + +/obj/item/assembly/health/ui_status(mob/user, datum/ui_state/state) + return is_secured(user) ? ..() : UI_CLOSE + +/obj/item/assembly/health/ui_interact(mob/user, datum/tgui/ui) + ui = SStgui.try_update_ui(user, src, ui) + if(!ui) + ui = new(user, src, "HealthSensor", name) + ui.open() + +/obj/item/assembly/health/ui_data(mob/user) + var/list/data = list() + data["health"] = health_scan + data["scanning"] = scanning + data["target"] = health_target + return data + +/obj/item/assembly/health/ui_act(action, params) + . = ..() + if(.) + return . + + switch(action) + if("scanning") + toggle_scan() + return TRUE + if("target") + toggle_target() + return TRUE diff --git a/tgui/packages/tgui/interfaces/HealthSensor.tsx b/tgui/packages/tgui/interfaces/HealthSensor.tsx new file mode 100644 index 00000000000..fbff3aaa1ea --- /dev/null +++ b/tgui/packages/tgui/interfaces/HealthSensor.tsx @@ -0,0 +1,55 @@ +import { BooleanLike } from 'common/react'; + +import { useBackend } from '../backend'; +import { AnimatedNumber, Button, ProgressBar, Section } from '../components'; +import { Window } from '../layouts'; + +type Data = { + health: number; + scanning: BooleanLike; + target: BooleanLike; +}; + +export const HealthSensor = (props) => { + const { act, data } = useBackend(); + const { health, scanning, target } = data; + + return ( + + +
+
+
+
+ ); +};