VueUI Conversions and Style Tweaks (#11523)

This commit is contained in:
MarinaGryphon
2021-03-25 17:18:44 +01:00
committed by GitHub
parent 1e1c25baa5
commit d29806094a
21 changed files with 679 additions and 580 deletions
+87 -109
View File
@@ -127,7 +127,6 @@
var/obj/item/cell/cell
var/chargelevel = 0.0005 // Cap for how fast APC cells charge, as a percentage-per-tick (0.01 means cellcharge is capped to 1% per second)
var/cellused = 0
var/initalchargelevel = 0.0005 // Cap for how fast APC cells charge, as a percentage-per-tick (0.01 means cellcharge is capped to 1% per second)
var/start_charge = 90 // initial cell charge %
var/cell_type = /obj/item/cell/apc
var/opened = COVER_CLOSED
@@ -139,7 +138,7 @@
var/infected = FALSE
var/operating = TRUE
var/charging = CHARGING_OFF
var/chargemode = CHARGE_MODE_DISCHARGE
var/chargemode = TRUE // whether we're trying to charge
var/chargecount = 0
var/locked = TRUE
var/coverlocked = TRUE
@@ -177,7 +176,7 @@
var/emergency_lights = FALSE
var/time = 0
var/charge_mode = CHARGE_MODE_CHARGE
var/charge_mode = CHARGE_MODE_CHARGE // if we're actually able to charge
var/last_time = 1
/obj/machinery/power/apc/updateDialog()
@@ -537,6 +536,7 @@
//to_chat(user, "You remove the power cell.")
charging = CHARGING_OFF
update_icon()
SSvueui.check_uis_for_change(src)
return
else if (istype(W, /obj/item/cell) && opened != COVER_CLOSED) // trying to put a cell inside
if(cell)
@@ -556,6 +556,7 @@
SPAN_NOTICE("You insert \the [cell]."))
chargecount = 0
update_icon()
SSvueui.check_uis_for_change(src)
else if (W.isscrewdriver()) // haxing
if(opened != COVER_CLOSED)
if (cell)
@@ -587,7 +588,7 @@
else if(opened != COVER_CLOSED)
to_chat(user, "You must close the cover to swipe an ID card.")
else if(wiresexposed)
to_chat(user, "You must close the panel")
to_chat(user, "You must close the wiring panel to swipe an ID card.")
else if(stat & (BROKEN|MAINT))
to_chat(user, "Nothing happens.")
else if(hacker)
@@ -596,6 +597,7 @@
if(allowed(usr) && !isWireCut(APC_WIRE_IDSCAN))
locked = !locked
to_chat(user, "You [ locked ? "lock" : "unlock"] the APC interface.")
SSvueui.check_uis_for_change(src)
update_icon()
else
to_chat(user, SPAN_WARNING("Access denied."))
@@ -730,6 +732,7 @@
emagged = FALSE
if(infected)
infected = FALSE
SSvueui.check_uis_for_change(src)
else
to_chat(user, SPAN_NOTICE("There has been a connection issue."))
return
@@ -789,6 +792,7 @@
to_chat(user, SPAN_NOTICE("You hack the charging slot. The next IPC that charges from this APC will be hacked and slaved to you."))
infected = TRUE
hacker = user
SSvueui.check_uis_for_change(src)
if(!(emagged || hacker)) // trying to unlock with an emag card
if(opened != COVER_CLOSED)
to_chat(user, "You must close the cover to swipe an ID card.")
@@ -804,6 +808,7 @@
locked = FALSE
to_chat(user, SPAN_NOTICE("You hack the APC interface open."))
update_icon()
SSvueui.check_uis_for_change(src)
else
to_chat(user, SPAN_WARNING("You fail to [ locked ? "unlock" : "lock"] the APC interface."))
return TRUE
@@ -887,6 +892,7 @@
SPAN_NOTICE("You remove the power cell."))
charging = CHARGING_ON
update_icon()
SSvueui.check_uis_for_change(src)
return
if(stat & (BROKEN|MAINT))
return
@@ -902,67 +908,49 @@
return ui_interact(user)
/obj/machinery/power/apc/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
if(!user)
return
/obj/machinery/power/apc/vueui_data_change(list/data, mob/user, datum/vueui/ui)
var/list/monitordata = ..()
data = list()
if(monitordata)
data = monitordata
var/isAdmin = isobserver(user) && check_rights(R_ADMIN, FALSE, user)
var/list/data = list(
"locked" = (locked && !emagged) ? TRUE : FALSE,
"isOperating" = operating,
"externalPower" = main_status,
"powerCellStatus" = cell ? cell.percent() : null,
"chargeMode" = chargemode,
"lightingMode" = night_mode,
"chargingStatus" = charging,
"totalLoad" = round(lastused_total),
"totalCharging" = round(lastused_charging),
"coverLocked" = coverlocked,
"failTime" = failure_timer * 2,
"siliconUser" = isAdmin || issilicon(user),
"emergencyMode" = !emergency_lights,
"time" = time,
"charge_mode" = charge_mode,
"powerChannels" = list(
list(
"title" = "Equipment",
"powerLoad" = lastused_equip,
"status" = equipment,
"topicParams" = list(
"auto" = list("eqp" = 3),
"on" = list("eqp" = 2),
"off" = list("eqp" = 1)
)
),
list(
"title" = "Lighting",
"powerLoad" = round(lastused_light),
"status" = lighting,
"topicParams" = list(
"auto" = list("lgt" = 3),
"on" = list("lgt" = 2),
"off" = list("lgt" = 1)
)
),
list(
"title" = "Environment",
"powerLoad" = round(lastused_environ),
"status" = environ,
"topicParams" = list(
"auto" = list("env" = 3),
"on" = list("env" = 2),
"off" = list("env" = 1)
)
)
data["locked"] = (locked && !emagged)
data["powerCellStatus"] = cell?.percent()
data["failTime"] = failure_timer * 2
data["siliconUser"] = isAdmin || issilicon(user)
data["totalLoad"] = round(lastused_total)
data["totalCharging"] = round(lastused_charging)
data["isOperating"] = operating
data["chargeMode"] = chargemode
data["externalPower"] = main_status
data["lightingMode"] = night_mode
data["chargingStatus"] = charging
data["coverLocked"] = coverlocked
data["emergencyMode"] = !emergency_lights
data["time"] = time
data["charge_mode"] = charge_mode
data["powerChannels"] = list(\
"Equipment" = list(\
"powerLoad" = lastused_equip,\
"status" = equipment
),
"Lighting" = list(
"powerLoad" = round(lastused_light),
"status" = lighting
),
"Environment" = list(
"powerLoad" = round(lastused_environ),
"status" = environ
)
)
return data
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
/obj/machinery/power/apc/ui_interact(mob/user)
var/datum/vueui/ui = SSvueui.get_open_ui(user, src)
if (!ui)
ui = new(user, src, ui_key, "apc.tmpl", "[area.name] - APC", 665, data["siliconUser"] ? 540 : 480)
ui.set_initial_data(data)
ui = new(user, src, "machinery-power-apc", 665, (isobserver(user) && check_rights(R_ADMIN, FALSE, user) || issilicon(user)) ? 540 : 480, "[area.name] - APC")
ui.open()
ui.set_auto_update(TRUE)
ui.auto_update_content = TRUE
/obj/machinery/power/apc/proc/report()
return "[area.name] : [equipment]/[lighting]/[environ] ([lastused_equip+lastused_light+lastused_environ]) : [cell? cell.percent() : "N/C"] ([charging])"
@@ -977,6 +965,7 @@
area.power_equip = FALSE
area.power_environ = FALSE
area.power_change()
SSvueui.check_uis_for_change(src)
/obj/machinery/power/apc/proc/isWireCut(var/wireIndex)
return wires.IsIndexCut(wireIndex)
@@ -984,15 +973,14 @@
/obj/machinery/power/apc/proc/can_use(mob/user, var/loud = 0) //used by attack_hand() and Topic()
if(inoperable())
return FALSE
var/use_flags = issilicon(user) && USE_ALLOW_NON_ADJACENT // AIs and borgs can use it at range
use_flags |= (check_rights(R_ADMIN, FALSE, user) && USE_ALLOW_NONLIVING) // admins can use the UI when ghosting
if(use_check(user, use_flags, show_messages = TRUE))
return FALSE
if(isobserver(user))
return check_rights(R_ADMIN, FALSE, user) // admins can use the UI when ghosting
if(user.stat)
to_chat(user, SPAN_WARNING("You must be conscious to use [src]!"))
return FALSE
return check_rights(R_ADMIN, FALSE, user)
if(!user.client)
return FALSE
if(!user.IsAdvancedToolUser())
return FALSE
if(user.restrained())
to_chat(user, SPAN_WARNING("You must have free hands to use [src]."))
return FALSE
@@ -1002,20 +990,13 @@
if (issilicon(user))
var/permit = FALSE // Malfunction variable. If AI hacks APC it can control it even without AI control wire.
var/mob/living/silicon/ai/AI = user
var/mob/living/silicon/robot/robot = user
if(hacker)
if(hacker == AI)
permit = TRUE
else if(istype(robot) && robot.connected_ai && robot.connected_ai == hacker) // Cyborgs can use APCs hacked by their AI
permit = TRUE
if(hacker == user || hacker == robot.connected_ai) // Cyborgs can use APCs hacked by their AI
permit = TRUE
if(aidisabled && !permit)
if(!loud)
to_chat(user, SPAN_DANGER("\The [src] have AI control disabled!"))
return FALSE
else
if (!in_range(src, user) || !isturf(loc))
to_chat(user, SPAN_DANGER("[src] has AI control disabled!"))
return FALSE
var/mob/living/carbon/human/H = user
@@ -1031,30 +1012,31 @@
/obj/machinery/power/apc/Topic(href, href_list)
if(..())
return TRUE
return TOPIC_NOACTION
if(!can_use(usr, 1))
return TRUE
return TOPIC_NOACTION
if (href_list["lmode"])
toggle_nightlight(href_list["lmode"])
update_icon()
return TRUE
SSvueui.check_uis_for_change(src)
return TOPIC_REFRESH
var/isAdmin = isobserver(usr) && check_rights(R_ADMIN, FALSE)
if(!issilicon(usr) && !isAdmin && locked && !emagged)
// Shouldn't happen, this is here to prevent href exploits
to_chat(usr, "You must unlock the panel to use this!")
return TRUE
return TOPIC_NOACTION
if (href_list["emergency_lights"])
emergency_lights = href_list["emergency_lights"] != "off"
emergency_lights = !emergency_lights
for (var/obj/machinery/light/L in area)
if (!initial(L.no_emergency))
L.no_emergency = emergency_lights //If there was an override set on creation, keep that override
INVOKE_ASYNC(L, /obj/machinery/light/.proc/update, FALSE)
CHECK_TICK
return TRUE
return TOPIC_REFRESH
if (href_list["lock"])
coverlocked = !coverlocked
@@ -1072,22 +1054,17 @@
if(!chargemode)
charging = CHARGING_OFF
update_icon()
SSvueui.check_uis_for_change(src)
else if (href_list["eqp"])
var/val = text2num(href_list["eqp"])
equipment = setsubsystem(val)
update_icon()
update()
else if (href_list["lgt"])
var/val = text2num(href_list["lgt"])
lighting = setsubsystem(val)
update_icon()
update()
else if (href_list["env"])
var/val = text2num(href_list["env"])
environ = setsubsystem(val)
else if (href_list["set"])
var/val = text2num(href_list["set"])
switch(href_list["chan"])
if("Equipment")
equipment = setsubsystem(val)
if("Lighting")
lighting = setsubsystem(val)
if("Environment")
environ = setsubsystem(val)
update_icon()
update()
@@ -1102,8 +1079,10 @@
else
locked = !locked
update_icon()
SSvueui.check_uis_for_change(src)
return FALSE
SSvueui.check_uis_for_change(src)
return TOPIC_REFRESH
/obj/machinery/power/apc/proc/toggle_breaker()
operating = !operating
@@ -1184,14 +1163,14 @@
// draw power from cell as before to power the area
cellused = min(cell.charge, CELLRATE * lastused_total) // clamp deduction to a max, amount left in cell
cell.use(cellused)
var/draw = 0
if(excess > lastused_total) // if power excess recharge the cell
// by the same amount just used
var/draw = draw_power(cellused/CELLRATE) // draw the power needed to charge this cell
draw = draw_power(cellused/CELLRATE) // draw the power needed to charge this cell
cell.give(draw * CELLRATE)
else // no excess, and not enough per-apc
if( (cell.charge/CELLRATE + excess) >= lastused_total) // can we draw enough from cell+grid to cover last usage?
var/draw = draw_power(excess)
draw = draw_power(excess)
cell.charge = min(cell.maxcharge, cell.charge + CELLRATE * draw) //recharge with what we can
charging = CHARGING_OFF
else // not enough power available to run the last tick!
@@ -1215,8 +1194,8 @@
ch = draw_power(ch/CELLRATE) // Removes the power we're taking from the grid
cell.give(ch*CELLRATE) // actually recharge the cell
lastused_charging = ch
lastused_total += ch // Sensors need this to stop reporting APC charging as "Other" load
lastused_charging = ch + draw
lastused_total += ch + draw // Sensors need this to stop reporting APC charging as "Other" load
else
charging = CHARGING_OFF // stop charging
chargecount = 0
@@ -1239,7 +1218,7 @@
charging = CHARGING_ON
else // chargemode off
charging = CHARGING_ON
charging = CHARGING_OFF
chargecount = 0
else // no cell, switch everything off
@@ -1423,12 +1402,12 @@
/obj/machinery/power/apc/proc/update_time()
var/delta_power = (lastused_charging) ? (-lastused_charging) : (lastused_total)
delta_power *= 0.0005
var/delta_power = (lastused_charging * 2) - lastused_total
delta_power *= CELLRATE
var/goal = (delta_power > 0) ? (cell.charge) : (cell.maxcharge - cell.charge)
var/time_secs = (delta_power) ? ((goal / abs(delta_power)) / (round(world.time - last_time) / 10)) : (0)
var/goal = (delta_power < 0) ? (cell.charge) : (cell.maxcharge - cell.charge)
time = world.time + (delta_power ? ((goal / abs(delta_power)) * (world.time - last_time)) : 0)
// If it is negative - we are discharging
if(delta_power < 0)
charge_mode = CHARGE_MODE_DISCHARGE
else if(delta_power > 0)
@@ -1436,7 +1415,6 @@
else
charge_mode = CHARGE_MODE_STABLE
last_time = world.time
time = ((time_secs / 3600) > 1) ? ("[round(time_secs / 3600)] hours, [round((time_secs % 3600) / 60)] minutes") : ("[round(time_secs / 60)] minutes, [round(time_secs % 60)] seconds")
#undef UPDATE_CELL_IN
#undef UPDATE_OPENED1
+35 -54
View File
@@ -201,8 +201,7 @@
delta_power *= SMESRATE
var/goal = (delta_power < 0) ? (charge) : (capacity - charge)
var/time_secs = (delta_power) ? ((goal / abs(delta_power)) * (round(world.time - last_time) / 10)) : (0)
time = world.time + (delta_power ? ((goal / abs(delta_power)) * (world.time - last_time)) : 0)
// If it is negative - we are discharging
if(delta_power < 0)
charge_mode = 0
@@ -211,7 +210,6 @@
else
charge_mode = 2
last_time = world.time
time = ((time_secs / 3600) > 1) ? ("[round(time_secs / 3600)] hours, [round((time_secs % 3600) / 60)] minutes") : ("[round(time_secs / 60)] minutes, [round(time_secs % 60)] seconds")
/obj/machinery/power/smes/machinery_process()
if(!can_function())
@@ -252,6 +250,8 @@
else
outputting = 0
SSvueui.check_uis_for_change(src)
// called after all power processes are finished
// restores charge level to smes if there was excess this ptick
/obj/machinery/power/smes/proc/restore(var/percent_load)
@@ -277,6 +277,7 @@
if(clev != chargedisplay() ) //if needed updates the icons overlay
update_icon()
SSvueui.check_uis_for_change(src)
return
//Will return 1 on failure
@@ -393,7 +394,32 @@
return 0
return 1
/obj/machinery/power/smes/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
/obj/machinery/power/smes/vueui_data_change(list/data, mob/user, datum/vueui/ui)
// this is the data that will be sent to the ui
data = list()
var/list/monitordata = ..()
if(monitordata)
data = monitordata
data["nameTag"] = name_tag
data["chargeTaken"] = round(input_taken)
data["charging"] = inputting
data["chargeAttempt"] = input_attempt
data["chargeLevel"] = input_level
data["chargeMax"] = input_level_max
data["outputLoad"] = round(output_used)
data["outputting"] = outputting
data["outputOnline"] = output_attempt
data["outputLevel"] = output_level
data["outputMax"] = output_level_max
data["time"] = time
data["chargeMode"] = charge_mode
data["storedCapacity"] = 0
if(capacity)
data["storedCapacity"] = round(100.0*charge/capacity, 0.1)
data["failTime"] = failure_timer * 2
return data
/obj/machinery/power/smes/ui_interact(mob/user)
if(!can_function())
if(!terminal)
to_chat(user, SPAN_WARNING("\The [src] is lacking a terminal!"))
@@ -401,41 +427,13 @@
if(is_badly_damaged())
to_chat(user, SPAN_WARNING("\The [src] is too damaged to function!"))
return
// this is the data which will be sent to the ui
var/data[0]
data["nameTag"] = name_tag
if(capacity)
data["storedCapacity"] = round(100.0*charge/capacity, 0.1)
else
data["storedCapacity"] = 0
data["charging"] = inputting
data["chargeMode"] = input_attempt
data["chargeLevel"] = input_level
data["chargeMax"] = input_level_max
data["charge_taken"] = round(input_taken)
data["outputOnline"] = output_attempt
data["outputLevel"] = output_level
data["outputMax"] = output_level_max
data["outputLoad"] = round(output_used)
data["failTime"] = failure_timer * 2
data["outputting"] = outputting
data["time"] = time
data["charge_mode"] = charge_mode
// update the ui if it exists, returns null if no ui is passed/found
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
var/datum/vueui/ui = SSvueui.get_open_ui(user, src)
if (!ui)
// the ui does not exist, so we'll create a new() one
// for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm
ui = new(user, src, ui_key, "smes.tmpl", "SMES Unit", 540, 420)
// when the ui is first opened this is the data it will use
ui.set_initial_data(data)
ui = new(user, src, "machinery-power-smes", 540, 420, "SMES Unit")
// open the new ui window
ui.open()
// auto update every Master Controller tick
ui.set_auto_update(1)
/obj/machinery/power/smes/proc/Percentage()
return round(100.0*charge/capacity, 0.1)
@@ -447,7 +445,6 @@
if( href_list["cmode"] )
inputting(!input_attempt)
update_icon()
else if( href_list["online"] )
outputting(!output_attempt)
update_icon()
@@ -455,27 +452,11 @@
failure_timer = 0
update_icon()
else if( href_list["input"] )
switch( href_list["input"] )
if("min")
input_level = 0
if("max")
input_level = input_level_max
if("set")
input_level = input(usr, "Enter new input level (0-[input_level_max])", "SMES Input Power Control", input_level) as num
input_level = max(0, min(input_level_max, input_level)) // clamp to range
input_level = clamp(href_list["input"], 0, input_level_max) // clamp to range
else if( href_list["output"] )
switch( href_list["output"] )
if("min")
output_level = 0
if("max")
output_level = output_level_max
if("set")
output_level = input(usr, "Enter new output level (0-[output_level_max])", "SMES Output Power Control", output_level) as num
output_level = max(0, min(output_level_max, output_level)) // clamp to range
output_level = clamp(href_list["output"], 0, output_level_max) // clamp to range
investigate_log("input/output; <font color='[input_level>output_level?"green":"red"][input_level]/[output_level]</font> | Output-mode: [output_attempt?"<font color='green'>on</font>":"<span class='warning'>off</span>"] | Input-mode: [input_attempt?"<font color='green'>auto</font>":"<span class='warning'>off</span>"] by [usr.key]","singulo")
SSvueui.check_uis_for_change(src)
return 1
/obj/machinery/power/smes/proc/energy_fail(var/duration)