Files

86 lines
2.3 KiB
Plaintext

/datum/tgui_module_old/power_monitor
name = "Power Monitor"
tgui_id = "PowerMonitor"
var/list/grid_sensors
var/active_sensor = null //name_tag of the currently selected sensor
/datum/tgui_module_old/power_monitor/New()
. = ..()
refresh_sensors()
/datum/tgui_module_old/power_monitor/ui_data(mob/user, datum/tgui/ui)
var/list/data = list()
var/list/sensors = list()
// Focus: If it remains null if no sensor is selected and UI will display sensor list, otherwise it will display sensor reading.
var/obj/machinery/power/sensor/focus = null
var/z = get_z(user)
var/list/map_levels = (LEGACY_MAP_DATUM).get_map_levels(z)
// Build list of data from sensor readings.
for(var/obj/machinery/power/sensor/S in grid_sensors)
if(!(S.z in map_levels))
continue
sensors.Add(list(list(
"name" = S.name_tag,
"alarm" = S.check_grid_warning()
)))
if(S.name_tag == active_sensor)
focus = S
data["all_sensors"] = sensors
if(focus)
data["focus"] = focus.ui_data(user)
else
data["focus"] = null
return data
/datum/tgui_module_old/power_monitor/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state, datum/event_args/actor/actor)
if(..())
return TRUE
switch(action)
if("clear")
active_sensor = null
. = TRUE
if("refresh")
refresh_sensors()
. = TRUE
if("setsensor")
active_sensor = params["id"]
. = TRUE
/datum/tgui_module_old/power_monitor/proc/has_alarm()
for(var/obj/machinery/power/sensor/S in grid_sensors)
if(S.check_grid_warning())
return TRUE
return FALSE
/datum/tgui_module_old/power_monitor/proc/refresh_sensors()
grid_sensors = list()
// Handle ultranested programs
var/turf/T = get_turf(ui_host())
var/list/levels = list()
if(!T) // Safety check
return
if(T)
levels += (LEGACY_MAP_DATUM).get_map_levels(T.z, FALSE)
for(var/obj/machinery/power/sensor/S in GLOB.machines)
if(T && (S.loc.z == T.z) || (S.loc.z in levels) || (S.long_range)) // Consoles have range on their Z-Level. Sensors with long_range var will work between Z levels.
if(S.name_tag == "#UNKN#") // Default name. Shouldn't happen!
warning("Powernet sensor with unset ID Tag! [S.x]X [S.y]Y [S.z]Z")
else
grid_sensors += S
/datum/tgui_module_old/power_monitor/ntos
ntos = TRUE
// Subtype for self_state
/datum/tgui_module_old/power_monitor/robot
/datum/tgui_module_old/power_monitor/robot/ui_state()
return GLOB.self_state