NanoUI updates.

* Simplified the code used in ui_interact procs and updated all current uses.
* Removed ununused jsviews JavaScript code (replaced it with vanilla jsrender).
* Added a message to the UI which shows if JavaScript is disabled (people with JavaScript disabled previously got blank UIs).
This commit is contained in:
Mark Aherne (Faerdan)
2014-01-06 02:49:25 +00:00
parent 909c873b2e
commit f25052fd4c
12 changed files with 1620 additions and 4763 deletions

View File

@@ -14,6 +14,29 @@
/datum/nanomanager/New()
return
/**
* Get an open /nanoui ui for the current user, src_object and ui_key and try to update it with data
*
* @param user /mob The mob who opened/owns the ui
* @param src_object /obj|/mob The obj or mob which the ui belongs to
* @param ui_key string A string key used for the ui
* @param ui /datum/nanoui An existing instance of the ui (can be null)
* @param data list The data to be passed to the ui, if it exists
*
* @return /nanoui Returns the found ui, for null if none exists
*/
/datum/nanomanager/proc/try_update_ui(var/mob/user, src_object, ui_key, var/datum/nanoui/ui, data)
if (!ui) // no ui has been passed, so we'll search for one
{
ui = get_open_ui(user, src, ui_key)
}
if (ui)
// The UI is already open so push the data to it
ui.push_data(data)
return ui
return null
/**
* Get an open /nanoui ui for the current user, src_object and ui_key
*
@@ -21,7 +44,7 @@
* @param src_object /obj|/mob The obj or mob which the ui belongs to
* @param ui_key string A string key used for the ui
*
* @return /nanoui Returns the found ui, for null if none exists
* @return /nanoui Returns the found ui, or null if none exists
*/
/datum/nanomanager/proc/get_open_ui(var/mob/user, src_object, ui_key)
var/src_object_key = "\ref[src_object]"

View File

@@ -308,6 +308,7 @@ nanoui is used to open and update nano browser uis
<div id='uiWrapper'>
[title ? "<div id='uiTitleWrapper'><div id='uiStatusIcon' class='icon24 uiStatusGood'></div><div id='uiTitle'>[title]</div><div id='uiTitleFluff'></div></div>" : ""]
<div id='uiContent'>
<noscript><div id='uiNoJavaScript'>Your browser does not have JavaScript enabled. Please enable JavaScript restart SS13.</div></noscript>
"}
/**

View File

@@ -10,7 +10,7 @@
icon_state = "dispenser"
use_power = 0
idle_power_usage = 40
var/ui_name = "Chem Dispenser 5000"
var/ui_title = "Chem Dispenser 5000"
var/energy = 100
var/max_energy = 100
var/amount = 30
@@ -104,7 +104,7 @@
*
* @return nothing
*/
/obj/machinery/chem_dispenser/ui_interact(mob/user, ui_key = "main")
/obj/machinery/chem_dispenser/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null)
if(stat & (BROKEN|NOPOWER)) return
if(user.stat || user.restrained()) return
@@ -140,18 +140,17 @@
if(temp)
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
var/datum/nanoui/ui = nanomanager.get_open_ui(user, src, ui_key)
// update the ui if it exists, returns null if no ui is passed/found
ui = nanomanager.try_update_ui(user, src, ui_key, ui, data)
if (!ui)
// the ui does not exist, so we'll create a new one
ui = new(user, src, ui_key, "chem_dispenser.tmpl", ui_name, 370, 605)
// When the UI is first opened this is the data it will use
ui.set_initial_data(data)
// 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, "chem_dispenser.tmpl", ui_title, 370, 605)
// when the ui is first opened this is the data it will use
ui.set_initial_data(data)
// open the new ui window
ui.open()
else
// The UI is already open so push the new data to it
ui.push_data(data)
return
/obj/machinery/chem_dispenser/Topic(href, href_list)
if(stat & (NOPOWER|BROKEN))
@@ -225,7 +224,7 @@
icon_state = "soda_dispenser"
name = "soda fountain"
desc = "A drink fabricating machine, capable of producing many sugary drinks with just one touch."
ui_name = "Soda Dispens-o-matic"
ui_title = "Soda Dispens-o-matic"
energy = 100
accept_glass = 1
max_energy = 100
@@ -248,7 +247,7 @@
/obj/machinery/chem_dispenser/beer
icon_state = "booze_dispenser"
name = "booze dispenser"
ui_name = "Booze Portal 9001"
ui_title = "Booze Portal 9001"
energy = 100
accept_glass = 1
max_energy = 100

View File

@@ -114,7 +114,7 @@
if(total_purity && fresh_coolant)
coolant_purity = total_purity / fresh_coolant
/obj/machinery/radiocarbon_spectrometer/ui_interact(mob/user, ui_key = "radio_spectro")
/obj/machinery/radiocarbon_spectrometer/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null)
if(user.stat)
return
@@ -144,20 +144,19 @@
data["radiation"] = round(radiation)
data["t_left_radspike"] = round(t_left_radspike)
data["rad_shield_on"] = rad_shield
var/datum/nanoui/ui = nanomanager.get_open_ui(user, src, ui_key)
// update the ui if it exists, returns null if no ui is passed/found
ui = nanomanager.try_update_ui(user, src, ui_key, ui, data)
if (!ui)
// the ui does not exist, so we'll create a new one
// 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, "geoscanner.tmpl", "High Res Radiocarbon Spectrometer", 900, 825)
// When the UI is first opened this is the data it will use
ui.set_initial_data(data)
// when the ui is first opened this is the data it will use
ui.set_initial_data(data)
// open the new ui window
ui.open()
// Auto update every Master Controller tick
// auto update every Master Controller tick
ui.set_auto_update(1)
else
// The UI is already open so push the new data to it
ui.push_data(data)
return
/obj/machinery/radiocarbon_spectrometer/process()
if(scanning)