From 8a6094685a6430e83d9b0e76a2930291f0132096 Mon Sep 17 00:00:00 2001 From: "Mark Aherne (Faerdan)" Date: Wed, 11 Sep 2013 21:27:54 +0100 Subject: [PATCH 1/3] Minor fixes. Added Templates Guide (wip). --- code/game/machinery/cryo.dm | 2 +- code/modules/nano/nanoui.dm | 18 ++---------------- code/modules/reagents/Chemistry-Machinery.dm | 2 +- nano/templates/TemplatesGuide.txt | 13 +++++++++++++ 4 files changed, 17 insertions(+), 18 deletions(-) create mode 100644 nano/templates/TemplatesGuide.txt diff --git a/code/game/machinery/cryo.dm b/code/game/machinery/cryo.dm index 98d93cafd8b..69dffee4425 100644 --- a/code/game/machinery/cryo.dm +++ b/code/game/machinery/cryo.dm @@ -1,5 +1,5 @@ /obj/machinery/atmospherics/unary/cryo_cell - name = "Cryo Cell" + name = "cryo cell" icon = 'icons/obj/cryogenics.dmi' icon_state = "cell-off" density = 1 diff --git a/code/modules/nano/nanoui.dm b/code/modules/nano/nanoui.dm index 4261a617c11..ca8e7f115bc 100644 --- a/code/modules/nano/nanoui.dm +++ b/code/modules/nano/nanoui.dm @@ -11,7 +11,7 @@ nanoui is used to open and update nano browser uis #define STATUS_UPDATE 1 // ORANGE Visability #define STATUS_DISABLED 0 // RED Visability -/datum/nanoui +/datum/nanoui // the user who opened this ui var/mob/user // the object this ui "belongs" to @@ -180,8 +180,7 @@ nanoui is used to open and update nano browser uis data["ui"] = list( "status" = status, "user" = list("name" = user.name) - ) - //user << list2json(data) + ) return data /** @@ -272,8 +271,6 @@ nanoui is used to open and update nano browser uis if (initial_data.len > 0) initial_data_json = list2json(initial_data) - //user << initial_data_json - var/url_parameters_json = list2json(list("src" = "\ref[src]")) return {" @@ -374,7 +371,6 @@ nanoui is used to open and update nano browser uis */ /datum/nanoui/proc/on_close_winset() if(!user.client) - world << "ERROR: No user.client!?" return var/params = "\ref[src]" @@ -390,28 +386,21 @@ nanoui is used to open and update nano browser uis set hidden = 1 // hide this verb from the user's panel set name = "nanoclose" // no autocomplete on cmd line - //world << "world [src] looking for [uiref]" - var/datum/nanoui/ui = locate(uiref) if (ui) - //world << "[src] UI found [ui.window_id]" ui.close() if (ui.on_close_logic) if(ui.ref) var/href = "close=1" - //world << "[src] Topic [href] [ui.ref]" src.Topic(href, params2list(href), ui.ref) // this will direct to the atom's // Topic() proc via client.Topic() else // no atomref specified (or not found) // so just reset the user mob's machine var if(src && src.mob) - //world << "[src] was [src.mob.machine], setting to null" src.mob.unset_machine() - else - world << "[src] UI not found" /** * Push data to an already open UI window @@ -424,9 +413,7 @@ nanoui is used to open and update nano browser uis return // Cannot update UI, no visibility data = add_default_data(data) - //user << list2json(data) user << output(list2params(list(list2json(data))),"[window_id].browser:receiveUpdateData") - //on_close_winset() /** * This Topic() proc is called whenever a user clicks on a link within a Nano UI @@ -438,7 +425,6 @@ nanoui is used to open and update nano browser uis /datum/nanoui/Topic(href, href_list) update_status(0) // update the status if (status != STATUS_INTERACTIVE || user != usr) // If UI is not interactive or usr calling Topic is not the UI user - //usr << "Not interaction or wrong usr" return if (src_object.Topic(href, href_list)) diff --git a/code/modules/reagents/Chemistry-Machinery.dm b/code/modules/reagents/Chemistry-Machinery.dm index 729004f6e19..acd98f362f9 100644 --- a/code/modules/reagents/Chemistry-Machinery.dm +++ b/code/modules/reagents/Chemistry-Machinery.dm @@ -3,7 +3,7 @@ #define GAS 3 /obj/machinery/chem_dispenser - name = "Chem Dispenser" + name = "chem dispenser" density = 1 anchored = 1 icon = 'icons/obj/chemical.dmi' diff --git a/nano/templates/TemplatesGuide.txt b/nano/templates/TemplatesGuide.txt new file mode 100644 index 00000000000..3cef9b91287 --- /dev/null +++ b/nano/templates/TemplatesGuide.txt @@ -0,0 +1,13 @@ +-------------------------------- +Nano UI Template Guide +-------------------------------- + +Nano UI uses templates, which are comprised of HTML and a markup syntax. The markup allows you +to easily add conditionals (if statements), loops (for loops) and custom formatting (using helpers). + +Templates are stored in the /nano/templates folder and the file extension is .tmpl. + +This guide is a work in progress. However the templating system is "JSRender", and documentation for it's +markup syntax can be found here: http://www.jsviews.com/#jsrtags + + From 762baa490ffc417765b7d5d48506ceead918014c Mon Sep 17 00:00:00 2001 From: "Mark Aherne (Faerdan)" Date: Wed, 11 Sep 2013 21:46:59 +0100 Subject: [PATCH 2/3] Better documentation for the ui_interact proc. --- code/game/machinery/cryo.dm | 19 +++++++++++++----- code/modules/reagents/Chemistry-Machinery.dm | 21 +++++++++++++------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/code/game/machinery/cryo.dm b/code/game/machinery/cryo.dm index 69dffee4425..baf362883b3 100644 --- a/code/game/machinery/cryo.dm +++ b/code/game/machinery/cryo.dm @@ -62,14 +62,24 @@ /obj/machinery/atmospherics/unary/cryo_cell/attack_hand(mob/user) 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 /obj and /mob + * + * @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/unary/cryo_cell/ui_interact(mob/user, ui_key = "main") if(user == occupant || user.stat) return - var/data[0] + // this is the data which will be sent to the ui + var/data[0] data["isOperating"] = on - data["hasOccupant"] = occupant ? 1 : 0 var/occupantData[0] @@ -111,10 +121,9 @@ beakerContents.Add(list(list("name" = R.name, "volume" = R.volume))) // list in a list because Byond merges the first list... data["beakerContents"] = beakerContents - //user << list2json(data) - var/datum/nanoui/ui = nanomanager.get_open_ui(user, src, ui_key) - if (!ui) + if (!ui) + // the ui does not exist, so we'll create a new one ui = new(user, src, ui_key, "cryo.tmpl", "Cryo Cell Control System", 520, 410) // When the UI is first opened this is the data it will use ui.set_initial_data(data) diff --git a/code/modules/reagents/Chemistry-Machinery.dm b/code/modules/reagents/Chemistry-Machinery.dm index acd98f362f9..fd2b9397118 100644 --- a/code/modules/reagents/Chemistry-Machinery.dm +++ b/code/modules/reagents/Chemistry-Machinery.dm @@ -67,19 +67,27 @@ del(src) return -/obj/machinery/chem_dispenser/ui_interact(mob/user, ui_key = "main") + /** + * 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 /obj and /mob + * + * @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/chem_dispenser/ui_interact(mob/user, ui_key = "main") if(stat & (BROKEN|NOPOWER)) return if(user.stat || user.restrained()) return + // this is the data which will be sent to the ui var/data[0] - data["amount"] = amount data["energy"] = energy data["maxEnergy"] = max_energy - data["isBeakerLoaded"] = beaker ? 1 : 0 - var beakerContents[0] var beakerCurrentVolume = 0 if(beaker && beaker:reagents && beaker:reagents.reagent_list.len) @@ -102,10 +110,9 @@ chemicals.Add(list(list("title" = temp.name, "id" = temp.id, "commands" = list("dispense" = temp.id)))) // list in a list because Byond merges the first list... data["chemicals"] = chemicals - //user << list2json(data) - var/datum/nanoui/ui = nanomanager.get_open_ui(user, src, ui_key) - if (!ui) + if (!ui) + // the ui does not exist, so we'll create a new one ui = new(user, src, ui_key, "chem_dispenser.tmpl", "Chem Dispenser 5000", 370, 605) // When the UI is first opened this is the data it will use ui.set_initial_data(data) From 2e957c8b51749ff11e2a13fea79d3d0b7ff0fbcc Mon Sep 17 00:00:00 2001 From: "Mark Aherne (Faerdan)" Date: Wed, 11 Sep 2013 22:24:21 +0100 Subject: [PATCH 3/3] Updated the documentation for the ui_interact proc. Moved the client nanoclose verb into nanoexternal.dm. Removed debug comments. --- code/game/machinery/cryo.dm | 2 +- code/modules/nano/nanoexternal.dm | 38 +++++++++++++++++++- code/modules/nano/nanoui.dm | 30 ++-------------- code/modules/reagents/Chemistry-Machinery.dm | 2 +- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/code/game/machinery/cryo.dm b/code/game/machinery/cryo.dm index baf362883b3..b8523312804 100644 --- a/code/game/machinery/cryo.dm +++ b/code/game/machinery/cryo.dm @@ -65,7 +65,7 @@ /** * 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 /obj and /mob + * 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") diff --git a/code/modules/nano/nanoexternal.dm b/code/modules/nano/nanoexternal.dm index 7efe4dd4771..609bb604dcb 100644 --- a/code/modules/nano/nanoexternal.dm +++ b/code/modules/nano/nanoexternal.dm @@ -1,4 +1,40 @@ -// All movable things can have a Nano UI, always use ui_interact to open/interact with a Nano UI + // This file contains all Nano procs/definitions for external classes/objects + + /** + * Called when a Nano UI window is closed + * This is how Nano handles closed windows + * It must be a verb so that it can be called using winset + * + * @return nothing + */ +/client/verb/nanoclose(var/uiref as text) + set hidden = 1 // hide this verb from the user's panel + set name = "nanoclose" + + var/datum/nanoui/ui = locate(uiref) + + if (ui) + ui.close() + + if(ui.ref) + var/href = "close=1" + src.Topic(href, params2list(href), ui.ref) // this will direct to the atom's Topic() proc via client.Topic() + else if (ui.on_close_logic) + // no atomref specified (or not found) + // so just reset the user mob's machine var + if(src && src.mob) + src.mob.unset_machine() + + /** + * 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 + */ /atom/movable/proc/ui_interact(mob/user, ui_key = "main") return diff --git a/code/modules/nano/nanoui.dm b/code/modules/nano/nanoui.dm index ca8e7f115bc..e1ac8556f2b 100644 --- a/code/modules/nano/nanoui.dm +++ b/code/modules/nano/nanoui.dm @@ -28,7 +28,7 @@ nanoui is used to open and update nano browser uis var/height = 0 // whether to use extra logic when window closes var/on_close_logic = 1 - // the ref to use when the window is closed (if on_close_logic is 1), usually null + // an extra ref to use when the window is closed, usually null var/atom/ref = null // options for modifying window behaviour var/window_options = "focus=0;can_close=1;can_minimize=1;can_maximize=0;can_resize=1;titlebar=1;" // window option is set using window_id @@ -240,7 +240,7 @@ nanoui is used to open and update nano browser uis content = ncontent /** - * Set whether or not to use the "old" on close logic (custom refs and unset_machine()) + * Set whether or not to use the "old" on close logic (mainly unset_machine()) * * @param state int (bool) Set on_close_logic to 1 or 0 (true/false) * @@ -376,32 +376,6 @@ nanoui is used to open and update nano browser uis winset(user, window_id, "on-close=\"nanoclose [params]\"") - /** - * Called when a Nano UI window is closed - * This is how Nano handles closed windows - * - * @return nothing - */ -/client/verb/nanoclose(var/uiref as text) - set hidden = 1 // hide this verb from the user's panel - set name = "nanoclose" // no autocomplete on cmd line - - var/datum/nanoui/ui = locate(uiref) - - if (ui) - ui.close() - - if (ui.on_close_logic) - if(ui.ref) - var/href = "close=1" - src.Topic(href, params2list(href), ui.ref) // this will direct to the atom's - // Topic() proc via client.Topic() - else - // no atomref specified (or not found) - // so just reset the user mob's machine var - if(src && src.mob) - src.mob.unset_machine() - /** * Push data to an already open UI window * diff --git a/code/modules/reagents/Chemistry-Machinery.dm b/code/modules/reagents/Chemistry-Machinery.dm index fd2b9397118..3b94b005e23 100644 --- a/code/modules/reagents/Chemistry-Machinery.dm +++ b/code/modules/reagents/Chemistry-Machinery.dm @@ -70,7 +70,7 @@ /** * 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 /obj and /mob + * 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")