Refactor NanoUI API

Also update NanoUI-using code to the new API.
This commit is contained in:
Bjorn Neergaard
2015-11-26 00:02:20 -05:00
parent 2156d594eb
commit 1a44e3d851
21 changed files with 413 additions and 523 deletions
@@ -93,16 +93,20 @@ Passive gate is similar to the regular pump except:
return 1
/obj/machinery/atmospherics/components/binary/passive_gate/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null)
if(stat & (BROKEN|NOPOWER))
return
/obj/machinery/atmospherics/components/binary/passive_gate/interact(mob/user)
if(stat & (BROKEN|NOPOWER)) return
ui_interact(user)
ui = SSnano.push_open_or_new_ui(user, src, ui_key, ui, "atmos_gas_pump.tmpl", name, 400, 120, 0)
/obj/machinery/atmospherics/components/binary/passive_gate/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null, force_open = 1)
SSnano.try_update_ui(user, src, ui_key, ui, force_open = force_open)
if (!ui)
ui = new(user, src, ui_key, "atmos_gas_pump.tmpl", name, 400, 120)
ui.open()
/obj/machinery/atmospherics/components/binary/passive_gate/get_ui_data()
var/data = list()
data["on"] = on
data["pressure_set"] = round(target_pressure*100) //Nano UI can't handle rounded non-integers, apparently.
data["set_pressure"] = round(target_pressure*100)
data["max_pressure"] = MAX_OUTPUT_PRESSURE
return data
@@ -142,18 +146,16 @@ Passive gate is similar to the regular pump except:
/obj/machinery/atmospherics/components/binary/passive_gate/attack_hand(mob/user)
if(..())
return
src.add_fingerprint(usr)
if(!src.allowed(user))
user << "<span class='danger'>Access denied.</span>"
return
usr.set_machine(src)
ui_interact(user)
return
if(..() || !user) return
add_fingerprint(usr)
interact(user)
/obj/machinery/atmospherics/components/binary/passive_gate/Topic(href,href_list)
/obj/machinery/atmospherics/components/binary/passive_gate/Topic(href, href_list)
if(..()) return
if(!src.allowed(usr))
usr << "<span class='danger'>Access denied.</span>"
return
if(href_list["power"])
on = !on
investigate_log("was turned [on ? "on" : "off"] by [key_name(usr)]", "atmos")
@@ -164,17 +166,13 @@ Passive gate is similar to the regular pump except:
if ("set")
target_pressure = max(0, min(MAX_OUTPUT_PRESSURE, safe_input("Pressure control", "Enter new output pressure (0-[MAX_OUTPUT_PRESSURE] kPa)", target_pressure)))
investigate_log("was set to [target_pressure] kPa by [key_name(usr)]", "atmos")
usr.set_machine(src)
src.update_icon()
src.updateUsrDialog()
return
update_icon()
/obj/machinery/atmospherics/components/binary/passive_gate/power_change()
..()
update_icon()
/obj/machinery/atmospherics/components/binary/passive_gate/attackby(obj/item/weapon/W, mob/user, params)
if (!istype(W, /obj/item/weapon/wrench))
return ..()
@@ -98,16 +98,23 @@ Thus, the two variables affect pump operation are set in New():
return 1
/obj/machinery/atmospherics/components/binary/pump/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null)
if(stat & (BROKEN|NOPOWER))
/obj/machinery/atmospherics/components/binary/pump/interact(mob/user)
if(stat & (BROKEN|NOPOWER)) return
if(!src.allowed(usr))
usr << "<span class='danger'>Access denied.</span>"
return
ui_interact(user)
ui = SSnano.push_open_or_new_ui(user, src, ui_key, ui, "atmos_gas_pump.tmpl", name, 400, 120, 0)
/obj/machinery/atmospherics/components/binary/pump/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null, force_open = 1)
SSnano.try_update_ui(user, src, ui_key, ui, force_open = force_open)
if (!ui)
ui = new(user, src, ui_key, "atmos_gas_pump.tmpl", name, 400, 120)
ui.open()
/obj/machinery/atmospherics/components/binary/pump/get_ui_data()
var/data = list()
data["on"] = on
data["pressure_set"] = round(target_pressure*100) //Nano UI can't handle rounded non-integers, apparently.
data["set_pressure"] = round(target_pressure*100)
data["max_pressure"] = MAX_OUTPUT_PRESSURE
return data
@@ -146,18 +153,12 @@ Thus, the two variables affect pump operation are set in New():
/obj/machinery/atmospherics/components/binary/pump/attack_hand(mob/user)
if(..())
return
src.add_fingerprint(usr)
if(!src.allowed(user))
user << "<span class='danger'>Access denied.</span>"
return
usr.set_machine(src)
ui_interact(user)
return
if(..() | !user) return
interact(user)
/obj/machinery/atmospherics/components/binary/pump/Topic(href,href_list)
if(..()) return
if(href_list["power"])
on = !on
investigate_log("was turned [on ? "on" : "off"] by [key_name(usr)]", "atmos")
@@ -168,10 +169,9 @@ Thus, the two variables affect pump operation are set in New():
if ("set")
target_pressure = max(0, min(MAX_OUTPUT_PRESSURE, safe_input("Pressure control", "Enter new output pressure (0-[MAX_OUTPUT_PRESSURE] kPa)", target_pressure)))
investigate_log("was set to [target_pressure] kPa by [key_name(usr)]", "atmos")
usr.set_machine(src)
src.update_icon()
src.updateUsrDialog()
return
add_fingerprint(usr)
update_icon()
/obj/machinery/atmospherics/components/binary/pump/power_change()
..()
@@ -94,16 +94,23 @@ Thus, the two variables affect pump operation are set in New():
return 1
/obj/machinery/atmospherics/components/binary/volume_pump/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null)
if(stat & (BROKEN|NOPOWER))
/obj/machinery/atmospherics/components/binary/volume_pump/interact(mob/user)
if(stat & (BROKEN|NOPOWER)) return
if(!src.allowed(usr))
usr << "<span class='danger'>Access denied.</span>"
return
ui_interact(user)
ui = SSnano.push_open_or_new_ui(user, src, ui_key, ui, "atmos_gas_pump.tmpl", name, 400, 120, 0)
/obj/machinery/atmospherics/components/binary/volume_pump/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null, force_open = 1)
SSnano.try_update_ui(user, src, ui_key, ui, force_open = force_open)
if (!ui)
ui = new(user, src, ui_key, "atmos_gas_pump.tmpl", name, 400, 120)
ui.open()
/obj/machinery/atmospherics/components/binary/volume_pump/get_ui_data()
var/data = list()
data["on"] = on
data["transfer_rate"] = round(transfer_rate*100) //Nano UI can't handle rounded non-integers, apparently.
data["transfer_rate"] = round(transfer_rate*100)
data["max_rate"] = MAX_TRANSFER_RATE
return data
@@ -142,18 +149,15 @@ Thus, the two variables affect pump operation are set in New():
/obj/machinery/atmospherics/components/binary/volume_pump/attack_hand(mob/user)
if(..())
return
src.add_fingerprint(usr)
if(!src.allowed(user))
user << "<span class='danger'>Access denied.</span>"
return
usr.set_machine(src)
ui_interact(user)
return
if(..() | !user) return
interact(user)
/obj/machinery/atmospherics/components/binary/volume_pump/Topic(href,href_list)
if(..()) return
if(!src.allowed(usr))
usr << "<span class='danger'>Access denied.</span>"
return
if(href_list["power"])
on = !on
investigate_log("was turned [on ? "on" : "off"] by [key_name(usr)]", "atmos")
@@ -164,17 +168,14 @@ Thus, the two variables affect pump operation are set in New():
if ("set")
transfer_rate = max(0, min(MAX_TRANSFER_RATE, safe_input("Pressure control", "Enter new transfer rate (0-[MAX_TRANSFER_RATE] L/s)", transfer_rate)))
investigate_log("was set to [transfer_rate] L/s by [key_name(usr)]", "atmos")
usr.set_machine(src)
src.update_icon()
src.updateUsrDialog()
return
add_fingerprint(usr)
update_icon()
/obj/machinery/atmospherics/components/binary/volume_pump/power_change()
..()
update_icon()
/obj/machinery/atmospherics/components/binary/volume_pump/attackby(obj/item/weapon/W, mob/user, params)
if (!istype(W, /obj/item/weapon/wrench))
return ..()
@@ -157,34 +157,36 @@ Filter types:
return ..()
/obj/machinery/atmospherics/components/trinary/filter/attack_hand(mob/user)
if(..())
return
if(..() | !user) return
interact(user)
if(!src.allowed(user))
user << "<span class='danger'>Access denied.</span>"
/obj/machinery/atmospherics/components/trinary/filter/interact(mob/user)
if(stat & (BROKEN|NOPOWER)) return
if(!src.allowed(usr))
usr << "<span class='danger'>Access denied.</span>"
return
ui_interact(user)
/obj/machinery/atmospherics/components/trinary/filter/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null)
if(stat & (BROKEN|NOPOWER))
return
ui = SSnano.push_open_or_new_ui(user, src, ui_key, ui, "atmos_filter.tmpl", name, 400, 320, 0)
/obj/machinery/atmospherics/components/trinary/filter/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null, force_open = 1)
SSnano.try_update_ui(user, src, ui_key, ui, force_open = force_open)
if (!ui)
ui = new(user, src, ui_key, "atmos_gas_pump.tmpl", name, 400, 320)
ui.open()
/obj/machinery/atmospherics/components/trinary/filter/get_ui_data()
var/data = list()
data["on"] = on
data["pressure_set"] = round(target_pressure*100) //Nano UI can't handle rounded non-integers, apparently.
data["set_pressure"] = round(target_pressure*100)
data["max_pressure"] = MAX_OUTPUT_PRESSURE
data["filter_type"] = filter_type
return data
/obj/machinery/atmospherics/components/trinary/filter/Topic(href, href_list)
if(..())
if(..()) return
if(!src.allowed(usr))
usr << "<span class='danger'>Access denied.</span>"
return
usr.set_machine(src)
src.add_fingerprint(usr)
if(href_list["filterset"])
src.filter_type = text2num(href_list["filterset"])
var/filtering_name = "nothing"
@@ -212,11 +214,6 @@ Filter types:
if(href_list["power"])
on=!on
investigate_log("was turned [on ? "on" : "off"] by [key_name(usr)]", "atmos")
src.update_icon()
src.updateUsrDialog()
/*
for(var/mob/M in viewers(1, src))
if ((M.client && M.machine == src))
src.attack_hand(M)
*/
return
add_fingerprint(usr)
update_icon()
@@ -120,25 +120,26 @@
return 1
/obj/machinery/atmospherics/components/trinary/mixer/attack_hand(mob/user)
if(..())
return
if(..() | !user) return
interact(user)
if(!src.allowed(user))
user << "<span class='danger'>Access denied.</span>"
/obj/machinery/atmospherics/components/trinary/mixer/interact(mob/user)
if(stat & (BROKEN|NOPOWER)) return
if(!src.allowed(usr))
usr << "<span class='danger'>Access denied.</span>"
return
ui_interact(user)
/obj/machinery/atmospherics/components/trinary/mixer/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null)
if(stat & (BROKEN|NOPOWER))
return
ui = SSnano.push_open_or_new_ui(user, src, ui_key, ui, "atmos_mixer.tmpl", name, 400, 320, 0)
/obj/machinery/atmospherics/components/trinary/mixer/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null, force_open = 1)
SSnano.try_update_ui(user, src, ui_key, ui, force_open = force_open)
if (!ui)
ui = new(user, src, ui_key, "atmos_gas_pump.tmpl", name, 400, 320)
ui.open()
/obj/machinery/atmospherics/components/trinary/mixer/get_ui_data()
var/data = list()
data["on"] = on
data["pressure_set"] = round(target_pressure*100) //Nano UI can't handle rounded non-integers, apparently.
data["set_pressure"] = round(target_pressure*100)
data["max_pressure"] = MAX_OUTPUT_PRESSURE
data["node1_concentration"] = round(node1_concentration*100)
data["node2_concentration"] = round(node2_concentration*100)
@@ -166,6 +167,6 @@
src.node2_concentration = max(0, min(1, src.node2_concentration + value))
src.node1_concentration = max(0, min(1, src.node1_concentration - value))
investigate_log("was set to [node2_concentration] % on node 2 by [key_name(usr)]", "atmos")
src.update_icon()
src.updateUsrDialog()
return
add_fingerprint(usr)
update_icon()
@@ -120,28 +120,18 @@
user << "Seems empty."
/obj/machinery/atmospherics/components/unary/cryo_cell/attack_hand(mob/user)
if(..())
return
if(..() | !user) return
interact(user)
/obj/machinery/atmospherics/components/unary/cryo_cell/interact(mob/user)
if(user == occupant || user.stat || panel_open) return
ui_interact(user)
/**
* The ui_interact proc is used to open and update Nano UIs
* If ui_interact is not used then the UI will not update correctly
* ui_interact is currently defined for /atom/movable
*
* @param user /mob The mob who is interacting with this ui
* @param ui_key string A string key to use for this ui. Allows for multiple unique uis on one obj/mob (defaut value "main")
*
* @return nothing
*/
/obj/machinery/atmospherics/components/unary/cryo_cell/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null)
if(user == occupant || user.stat || panel_open)
return
ui = SSnano.push_open_or_new_ui(user, src, ui_key, ui, "cryo.tmpl", "Cryo Cell Control System", 520, 410, 1)
//user.set_machine(src)
/obj/machinery/atmospherics/components/unary/cryo_cell/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null, force_open = 1)
SSnano.try_update_ui(user, src, ui_key, ui, force_open = force_open)
if (!ui)
ui = new(user, src, ui_key, "cryo.tmpl", name, 520, 410)
ui.open()
/obj/machinery/atmospherics/components/unary/cryo_cell/get_ui_data()
// this is the data which will be sent to the ui
@@ -193,11 +183,8 @@
return data
/obj/machinery/atmospherics/components/unary/cryo_cell/Topic(href, href_list)
if(usr == occupant || panel_open)
return 0 // don't update UIs attached to this object
if(..())
return 0 // don't update UIs attached to this object
if(..()) return 0
if(usr == occupant || panel_open) return 0
if(href_list["switchOn"])
if(!state_open)
@@ -215,9 +202,8 @@
B.loc = get_step(loc, SOUTH)
beaker = null
update_icon()
add_fingerprint(usr)
return 1 // update UIs attached to this object
update_icon()
/obj/machinery/atmospherics/components/unary/cryo_cell/attackby(obj/item/I, mob/user, params)
if(istype(I, /obj/item/weapon/reagent_containers/glass))