From 9b34f6b5b026b9f56af796f445dccce8941a2223 Mon Sep 17 00:00:00 2001 From: "Mark Aherne (Faerdan)" Date: Wed, 21 Aug 2013 01:50:50 +0200 Subject: [PATCH] I added nanomanager.update_uis(src) to the cryo.dm Topic(). This method updates all UIs attached to the (src) object.Fixed issue with Nano UI windows taking seconds to load. Removed user << browse_rsc() entries as they caused the delay. New assets (stylesheets, scripts, templates and images) have to be added to the client's send_resources proc or they will not exist on the client. --- code/game/machinery/cryo.dm | 2 +- code/modules/client/client procs.dm | 2 +- code/modules/nano/nanoui.dm | 114 ++++++++++++---------------- nano/css/{common.css => shared.css} | 0 4 files changed, 49 insertions(+), 69 deletions(-) rename nano/css/{common.css => shared.css} (100%) diff --git a/code/game/machinery/cryo.dm b/code/game/machinery/cryo.dm index 79962deaaf..163c5f6bae 100644 --- a/code/game/machinery/cryo.dm +++ b/code/game/machinery/cryo.dm @@ -110,7 +110,7 @@ var/datum/nanoui/ui = nanomanager.get_open_ui(user, src, ui_key) if (!ui) - ui = new(user, src, ui_key, 'nano/templates/cryo.tmpl', "Cryo Cell Control System", 520, 410) + 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) ui.open() diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index 0cfa286689..f372f27e54 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -246,7 +246,7 @@ 'nano/js/nano_update.js', 'nano/js/nano_config.js', 'nano/js/nano_base_helpers.js', - 'nano/css/common.css', + 'nano/css/shared.css', 'nano/css/icons.css', 'nano/templates/cryo.tmpl', 'nano/images/uiBackground.png', diff --git a/code/modules/nano/nanoui.dm b/code/modules/nano/nanoui.dm index 52b9c3d004..add6437c3b 100644 --- a/code/modules/nano/nanoui.dm +++ b/code/modules/nano/nanoui.dm @@ -9,8 +9,8 @@ var/atom/ref = null var/on_close_logic = 1 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 - var/stylesheets[0] - var/scripts[0] + var/list/stylesheets = list() + var/list/scripts = list() var/templates[0] var/title_image var/head_elements @@ -23,13 +23,13 @@ /datum/nanoui/New(nuser, nsrc_object, nui_key, ntemplate, ntitle = 0, nwidth = 0, nheight = 0, var/atom/nref = null) - user = nuser + user = nuser src_object = nsrc_object ui_key = nui_key window_id = "[ui_key]\ref[src_object]" - + add_template("main", ntemplate) - + if (ntitle) title = ntitle if (nwidth) @@ -37,27 +37,25 @@ if (nheight) height = nheight if (nref) - ref = nref - + ref = nref + add_common_assets() - + /datum/nanoui/proc/add_common_assets() - add_script("libraries", 'nano/js/libraries.min.js') // The jQuery library - //add_script("jquery", 'nano/js/jquery.js') // The jQuery library - //add_script("jsviews", 'nano/js/jsviews.js') // JSViews, for rendering templates - add_script("nanoupdate", 'nano/js/nano_update.js') // The NanoUpdate JS, this is used to receive updates and apply them. - add_script("nanoconfig", 'nano/js/nano_config.js') // The NanoUpdate JS, this is used to receive updates and apply them. - add_script("nanobasehelpers", 'nano/js/nano_base_helpers.js') // The NanoBaseHelpers JS, this is used to set up template helpers which are common to all templates - add_stylesheet("common", 'nano/css/common.css') // this CSS sheet is common to all UIs - add_stylesheet("icons", 'nano/css/icons.css') // this CSS sheet is common to all UIs + add_script("libraries.min.js") // The jQuery library + add_script("nano_update.js") // The NanoUpdate JS, this is used to receive updates and apply them. + add_script("nano_config.js") // The NanoUpdate JS, this is used to receive updates and apply them. + add_script("nano_base_helpers.js") // The NanoBaseHelpers JS, this is used to set up template helpers which are common to all templates + add_stylesheet("shared.css") // this CSS sheet is common to all UIs + add_stylesheet("icons.css") // this CSS sheet is common to all UIs /datum/nanoui/proc/set_status(state) if (state != status) status = state push_data(list(), 1) // Update the UI - else + else status = state - + /datum/nanoui/proc/set_auto_update(state = 1) is_auto_updating = state @@ -73,11 +71,11 @@ /datum/nanoui/proc/set_title_image(ntitle_image) //title_image = ntitle_image -/datum/nanoui/proc/add_stylesheet(name, file) - stylesheets[name] = file +/datum/nanoui/proc/add_stylesheet(file) + stylesheets.Add(file) -/datum/nanoui/proc/add_script(name, file) - scripts[name] = file +/datum/nanoui/proc/add_script(file) + scripts.Add(file) /datum/nanoui/proc/add_template(name, file) templates[name] = file @@ -87,35 +85,21 @@ /datum/nanoui/proc/add_content(ncontent) content += ncontent - + /datum/nanoui/proc/use_on_close_logic(nsetting) - on_close_logic = nsetting + on_close_logic = nsetting /datum/nanoui/proc/get_header() - var/key - var/filename - - for (key in stylesheets) - filename = "[ckey(key)].css" - user << browse_rsc(stylesheets[key], filename) + for (var/filename in stylesheets) head_content += "" - - user << browse_rsc('nano/images/uiBackground.png', "uiBackground.png") - user << browse_rsc('nano/images/uiIcons16.png', "uiIcons16.png") - user << browse_rsc('nano/images/uiIcons24.png', "uiIcons24.png") - user << browse_rsc('nano/images/uiLinkPendingIcon.gif', "uiLinkPendingIcon.gif") - user << browse_rsc('nano/images/uiNoticeBackground.jpg', "uiNoticeBackground.jpg") - user << browse_rsc('nano/images/uiTitleFluff.png', "uiTitleFluff.png") var/title_attributes = "id='uiTitle'" if (title_image) title_attributes = "id='uiTitle icon' style='background-image: url([title_image]);'" var/templatel_data[0] - for (key in templates) - filename = "[ckey(key)].tmpl" - user << browse_rsc(templates[key], filename) - templatel_data[key] = filename; + for (var/key in templates) + templatel_data[key] = templates[key]; var/template_data_json = "{}" // An empty JSON object if (templatel_data.len > 0) @@ -136,7 +120,7 @@ " - + return {" [scriptsContent] @@ -197,17 +177,17 @@ /datum/nanoui/proc/close() is_auto_updating = 0 - nanomanager.ui_closed(src) - user << browse(null, "window=[window_id]") - + nanomanager.ui_closed(src) + user << browse(null, "window=[window_id]") + /datum/nanoui/proc/on_close_winset() - if(!user.client) + if(!user.client) world << "ERROR: No user.client!?" return var/params = "\ref[src]" - + winset(user, window_id, "on-close=\"nanoclose [params]\"") - + /datum/nanoui/proc/process(update = 0) var/dist = get_dist(src_object, user) if (dist <= 1) @@ -219,11 +199,11 @@ return // don't auto update else close() - return - + return + if (update || is_auto_updating) src_object.ui_interact(user, ui_key) - + /datum/nanoui/proc/modify_data(data) data["ui"] = list( "status" = status, @@ -231,14 +211,14 @@ ) //user << list2json(data) return data - + /datum/nanoui/proc/push_data(data, force_push = 0) if (!status && !force_push) user << "Cannot update UI, user out of range (status [status])" return - + data = modify_data(data) - + user << output(list2params(list(list2json(data))),"[window_id].browser:receiveUpdateData") on_close_winset() @@ -247,13 +227,13 @@ set name = "nanoclose" // no autocomplete on cmd line //world << "world [src] looking for [uiref]" - - var/datum/nanoui/ui = locate(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" @@ -265,7 +245,7 @@ // 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() + src.mob.unset_machine() else world << "[src] UI not found" return \ No newline at end of file diff --git a/nano/css/common.css b/nano/css/shared.css similarity index 100% rename from nano/css/common.css rename to nano/css/shared.css