Fixes UI navigation in engineering power-monitor program (#19940)

When selecting a sensor in the engineering power-monitor program, you
are not able to return to the sensor list without restarting the whole
console.
Even though the issue is known for some time now, i weren't able to find
an issue to reference in the PR.

- Fixes broken UI navigation when trying to return to the sensor list.
- Resets UI navigation state when program gets closed.
This commit is contained in:
FabianK3
2024-09-27 11:38:30 +02:00
committed by GitHub
parent f2e1df98d7
commit bc4bfcaaa0
2 changed files with 17 additions and 7 deletions
@@ -20,12 +20,10 @@
/datum/computer_file/program/power_monitor/ui_data(mob/user)
var/list/data = initial_data()
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
var/obj/machinery/power/sensor/focus // Placeholder for selected sensor, if one has been selected from the UI list
// Build list of data from sensor readings.
// Prepare list of sensors (see refresh_sensors()) and set focus to sensor based of active_sensor (see ui_act()->setsensor)
for(var/obj/machinery/power/sensor/S in grid_sensors)
sensors.Add(list(list(
"name" = S.name_tag,
@@ -34,12 +32,18 @@
if(S.name_tag == active_sensor)
focus = S
data["all_sensors"] = sensors
// Prepare return value: data["focus"] will dictate which view is visible (list or focused sensor)
data["all_sensors"] = sensors // Represents main menu list of all found sensors
if(focus)
data["focus"] = focus.return_reading_data()
data["focus"] = focus.return_reading_data() // Force view to selected sensor, include focused sensors data
else
data["focus"] = null // Force view to main menu
return data
/datum/computer_file/program/power_monitor/kill_program(forced)
..()
active_sensor = null // Reset UI navigation state
/datum/computer_file/program/power_monitor/proc/has_alarm()
for(var/obj/machinery/power/sensor/S in grid_sensors)
if(S.check_grid_warning())