[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
🆑

qol: Gives Health sensor assemblies a UI so its easier to use.

/🆑

* Makes Health Sensor assemblies a bit nicer to use

---------

Co-authored-by: starrm4nn <139372157+starrm4nn@users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-05-15 01:33:06 +02:00
committed by GitHub
parent 144c9b903c
commit 1d7dfbf584
2 changed files with 92 additions and 18 deletions
+37 -18
View File
@@ -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
@@ -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<Data>();
const { health, scanning, target } = data;
return (
<Window width={360} height={115}>
<Window.Content>
<Section
title="Health Sensor"
buttons={
<>
<Button
icon={scanning ? 'power-off' : 'times'}
content={scanning ? 'On' : 'Off'}
selected={scanning}
onClick={() => act('scanning')}
/>
<Button
icon={target ? 'skull' : 'heartbeat'}
color="red"
content={target ? 'Checking for Death' : 'Checking for Crit'}
onClick={() => act('target')}
/>
</>
}
>
{health !== undefined && (
<ProgressBar
value={scanning ? health / 100 : 0}
ranges={{
good: [0.5, Infinity],
average: [0.2, 0.5],
bad: [-Infinity, 0.2],
}}
>
{scanning ? <AnimatedNumber value={health} /> : 'Off'}
</ProgressBar>
)}
</Section>
</Window.Content>
</Window>
);
};