diff --git a/baystation12.dme b/baystation12.dme index 06ddf79d437..8f2c766a274 100644 --- a/baystation12.dme +++ b/baystation12.dme @@ -1136,6 +1136,7 @@ #include "code\modules\mob\living\silicon\ai\life.dm" #include "code\modules\mob\living\silicon\ai\login.dm" #include "code\modules\mob\living\silicon\ai\logout.dm" +#include "code\modules\mob\living\silicon\ai\nano.dm" #include "code\modules\mob\living\silicon\ai\say.dm" #include "code\modules\mob\living\silicon\ai\freelook\cameranet.dm" #include "code\modules\mob\living\silicon\ai\freelook\chunk.dm" @@ -1225,7 +1226,9 @@ #include "code\modules\nano\nanoexternal.dm" #include "code\modules\nano\nanomanager.dm" #include "code\modules\nano\nanomapgen.dm" +#include "code\modules\nano\nanoprocs.dm" #include "code\modules\nano\nanoui.dm" +#include "code\modules\nano\modules\rcon.dm" #include "code\modules\organs\blood.dm" #include "code\modules\organs\organ.dm" #include "code\modules\organs\organ_alien.dm" diff --git a/code/game/machinery/computer/RCON_Console.dm b/code/game/machinery/computer/RCON_Console.dm index 93b18cf9896..f80f0b93c4d 100644 --- a/code/game/machinery/computer/RCON_Console.dm +++ b/code/game/machinery/computer/RCON_Console.dm @@ -12,12 +12,11 @@ circuit = /obj/item/weapon/circuitboard/rcon_console req_one_access = list(access_engine) var/current_tag = null - var/list/known_SMESs = null - var/list/known_breakers = null - // Allows you to hide specific parts of the UI - var/hide_SMES = 0 - var/hide_SMES_details = 0 - var/hide_breakers = 0 + var/obj/nano_module/rcon/rcon + +/obj/machinery/computer/rcon/New() + ..() + rcon = new(src) // Proc: attack_hand() // Parameters: 1 (user - Person which clicked this computer) @@ -29,106 +28,5 @@ // Proc: ui_interact() // Parameters: 4 (standard NanoUI parameters) // Description: Uses dark magic (NanoUI) to render this machine's UI -/obj/machinery/computer/rcon/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1) - FindDevices() // Update our devices list - var/data[0] - - // SMES DATA (simplified view) - var/list/smeslist[0] - for(var/obj/machinery/power/smes/buildable/SMES in known_SMESs) - smeslist.Add(list(list( - "charge" = round(SMES.Percentage()), - "input_set" = SMES.input_attempt, - "input_val" = round(SMES.input_level), - "output_set" = SMES.output_attempt, - "output_val" = round(SMES.output_level), - "output_load" = round(SMES.output_used), - "RCON_tag" = SMES.RCon_tag - ))) - - data["smes_info"] = sortByKey(smeslist, "RCON_tag") - - // BREAKER DATA (simplified view) - var/list/breakerlist[0] - for(var/obj/machinery/power/breakerbox/BR in known_breakers) - breakerlist.Add(list(list( - "RCON_tag" = BR.RCon_tag, - "enabled" = BR.on - ))) - data["breaker_info"] = breakerlist - data["hide_smes"] = hide_SMES - data["hide_smes_details"] = hide_SMES_details - data["hide_breakers"] = hide_breakers - - ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) - if (!ui) - ui = new(user, src, ui_key, "rcon.tmpl", "RCON Console", 600, 400) - ui.set_initial_data(data) - ui.open() - ui.set_auto_update(1) - -// Proc: Topic() -// Parameters: 2 (href, href_list - allows us to process UI clicks) -// Description: Allows us to process UI clicks, which are relayed in form of hrefs. -/obj/machinery/computer/rcon/Topic(href, href_list) - if(href_list["smes_in_toggle"]) - var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_in_toggle"]) - if(SMES) - SMES.toggle_input() - if(href_list["smes_out_toggle"]) - var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_out_toggle"]) - if(SMES) - SMES.toggle_output() - if(href_list["smes_in_set"]) - var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_in_set"]) - if(SMES) - var/inputset = input(usr, "Enter new input level (0-[SMES.input_level_max])", "SMES Input Power Control") as num - SMES.set_input(inputset) - if(href_list["smes_out_set"]) - var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_out_set"]) - if(SMES) - var/outputset = input(usr, "Enter new output level (0-[SMES.output_level_max])", "SMES Input Power Control") as num - SMES.set_output(outputset) - - if(href_list["toggle_breaker"]) - var/obj/machinery/power/breakerbox/toggle = null - for(var/obj/machinery/power/breakerbox/breaker in known_breakers) - if(breaker.RCon_tag == href_list["toggle_breaker"]) - toggle = breaker - if(toggle) - if(toggle.update_locked) - usr << "The breaker box was recently toggled. Please wait before toggling it again." - else - toggle.auto_toggle() - if(href_list["hide_smes"]) - hide_SMES = !hide_SMES - if(href_list["hide_smes_details"]) - hide_SMES_details = !hide_SMES_details - if(href_list["hide_breakers"]) - hide_breakers = !hide_breakers - - -// Proc: GetSMESByTag() -// Parameters: 1 (tag - RCON tag of SMES we want to look up) -// Description: Looks up and returns SMES which has matching RCON tag -/obj/machinery/computer/rcon/proc/GetSMESByTag(var/tag) - if(!tag) - return - - for(var/obj/machinery/power/smes/buildable/S in known_SMESs) - if(S.RCon_tag == tag) - return S - -// Proc: FindDevices() -// Parameters: None -// Description: Refreshes local list of known devices. -/obj/machinery/computer/rcon/proc/FindDevices() - known_SMESs = new /list() - for(var/obj/machinery/power/smes/buildable/SMES in machines) - if(SMES.RCon_tag && (SMES.RCon_tag != "NO_TAG") && SMES.RCon) - known_SMESs.Add(SMES) - - known_breakers = new /list() - for(var/obj/machinery/power/breakerbox/breaker in machines) - if(breaker.RCon_tag != "NO_TAG") - known_breakers.Add(breaker) \ No newline at end of file +/obj/machinery/computer/rcon/ui_interact(mob/user, ui_key = "rcon", var/datum/nanoui/ui = null, var/force_open = 1) + rcon.ui_interact(user, ui_key, ui, force_open) diff --git a/code/game/objects/objs.dm b/code/game/objects/objs.dm index bbcad347b59..8f54b76717b 100644 --- a/code/game/objects/objs.dm +++ b/code/game/objects/objs.dm @@ -20,7 +20,8 @@ // Calling Topic without a corresponding window open causes runtime errors if(!nowindow && ..()) return 1 - if(usr.can_interact_with_interface(src, checkrange) != STATUS_INTERACTIVE) + + if(usr.can_interact_with_interface(nano_host(), checkrange) != STATUS_INTERACTIVE) return 1 add_fingerprint(usr) return 0 diff --git a/code/modules/mob/living/silicon/ai/ai.dm b/code/modules/mob/living/silicon/ai/ai.dm index 2bc59be1961..c0601f9c595 100644 --- a/code/modules/mob/living/silicon/ai/ai.dm +++ b/code/modules/mob/living/silicon/ai/ai.dm @@ -23,7 +23,8 @@ var/list/ai_verbs_default = list( /mob/living/silicon/ai/proc/sensor_mode, /mob/living/silicon/ai/proc/show_laws_verb, /mob/living/silicon/ai/proc/toggle_acceleration, - /mob/living/silicon/ai/proc/toggle_camera_light + /mob/living/silicon/ai/proc/toggle_camera_light, + /mob/living/silicon/ai/proc/nano_rcon ) //Not sure why this is necessary... @@ -163,6 +164,8 @@ var/list/ai_verbs_default = list( hud_list[IMPTRACK_HUD] = image('icons/mob/hud.dmi', src, "hudblank") hud_list[SPECIALROLE_HUD] = image('icons/mob/hud.dmi', src, "hudblank") + init_subsystems() + ai_list += src ..() return diff --git a/code/modules/mob/living/silicon/ai/nano.dm b/code/modules/mob/living/silicon/ai/nano.dm new file mode 100644 index 00000000000..fe572a0a2f5 --- /dev/null +++ b/code/modules/mob/living/silicon/ai/nano.dm @@ -0,0 +1,10 @@ +var/obj/nano_module/rcon/rcon + +/mob/living/silicon/ai/proc/init_subsystems() + rcon = new(src) + +/mob/living/silicon/ai/proc/nano_rcon() + set category = "AI Subystems" + set name = "RCON" + + rcon.ui_interact(usr) diff --git a/code/modules/nano/modules/rcon.dm b/code/modules/nano/modules/rcon.dm new file mode 100644 index 00000000000..6224c56de8f --- /dev/null +++ b/code/modules/nano/modules/rcon.dm @@ -0,0 +1,116 @@ +/obj/nano_module/rcon + name = "RCON interface" + + var/list/known_SMESs = null + var/list/known_breakers = null + // Allows you to hide specific parts of the UI + var/hide_SMES = 0 + var/hide_SMES_details = 0 + var/hide_breakers = 0 + +/obj/nano_module/rcon/ui_interact(mob/user, ui_key = "rcon", datum/nanoui/ui=null, force_open=1) + FindDevices() // Update our devices list + var/data[0] + + // SMES DATA (simplified view) + var/list/smeslist[0] + for(var/obj/machinery/power/smes/buildable/SMES in known_SMESs) + smeslist.Add(list(list( + "charge" = round(SMES.Percentage()), + "input_set" = SMES.input_attempt, + "input_val" = round(SMES.input_level), + "output_set" = SMES.output_attempt, + "output_val" = round(SMES.output_level), + "output_load" = round(SMES.output_used), + "RCON_tag" = SMES.RCon_tag + ))) + + data["smes_info"] = sortByKey(smeslist, "RCON_tag") + + // BREAKER DATA (simplified view) + var/list/breakerlist[0] + for(var/obj/machinery/power/breakerbox/BR in known_breakers) + breakerlist.Add(list(list( + "RCON_tag" = BR.RCon_tag, + "enabled" = BR.on + ))) + data["breaker_info"] = breakerlist + data["hide_smes"] = hide_SMES + data["hide_smes_details"] = hide_SMES_details + data["hide_breakers"] = hide_breakers + + ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) + if (!ui) + ui = new(user, src, ui_key, "rcon.tmpl", "RCON Console", 600, 400) + ui.set_initial_data(data) + ui.open() + ui.set_auto_update(1) + +// Proc: Topic() +// Parameters: 2 (href, href_list - allows us to process UI clicks) +// Description: Allows us to process UI clicks, which are relayed in form of hrefs. +/obj/nano_module/rcon/Topic(href, href_list) + if(..()) + return + + if(href_list["smes_in_toggle"]) + var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_in_toggle"]) + if(SMES) + SMES.toggle_input() + if(href_list["smes_out_toggle"]) + var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_out_toggle"]) + if(SMES) + SMES.toggle_output() + if(href_list["smes_in_set"]) + var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_in_set"]) + if(SMES) + var/inputset = input(usr, "Enter new input level (0-[SMES.input_level_max])", "SMES Input Power Control") as num + SMES.set_input(inputset) + if(href_list["smes_out_set"]) + var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_out_set"]) + if(SMES) + var/outputset = input(usr, "Enter new output level (0-[SMES.output_level_max])", "SMES Input Power Control") as num + SMES.set_output(outputset) + + if(href_list["toggle_breaker"]) + var/obj/machinery/power/breakerbox/toggle = null + for(var/obj/machinery/power/breakerbox/breaker in known_breakers) + if(breaker.RCon_tag == href_list["toggle_breaker"]) + toggle = breaker + if(toggle) + if(toggle.update_locked) + usr << "The breaker box was recently toggled. Please wait before toggling it again." + else + toggle.auto_toggle() + if(href_list["hide_smes"]) + hide_SMES = !hide_SMES + if(href_list["hide_smes_details"]) + hide_SMES_details = !hide_SMES_details + if(href_list["hide_breakers"]) + hide_breakers = !hide_breakers + + +// Proc: GetSMESByTag() +// Parameters: 1 (tag - RCON tag of SMES we want to look up) +// Description: Looks up and returns SMES which has matching RCON tag +/obj/nano_module/rcon/proc/GetSMESByTag(var/tag) + if(!tag) + return + + for(var/obj/machinery/power/smes/buildable/S in known_SMESs) + if(S.RCon_tag == tag) + return S + +// Proc: FindDevices() +// Parameters: None +// Description: Refreshes local list of known devices. +/obj/nano_module/rcon/proc/FindDevices() + known_SMESs = new /list() + for(var/obj/machinery/power/smes/buildable/SMES in machines) + if(SMES.RCon_tag && (SMES.RCon_tag != "NO_TAG") && SMES.RCon) + known_SMESs.Add(SMES) + + known_breakers = new /list() + for(var/obj/machinery/power/breakerbox/breaker in machines) + if(breaker.RCon_tag != "NO_TAG") + known_breakers.Add(breaker) diff --git a/code/modules/nano/nanomanager.dm b/code/modules/nano/nanomanager.dm index da546ac66da..ddc3fcac9f4 100644 --- a/code/modules/nano/nanomanager.dm +++ b/code/modules/nano/nanomanager.dm @@ -1,249 +1,249 @@ -// This is the window/UI manager for Nano UI -// There should only ever be one (global) instance of nanomanger -/datum/nanomanager - // a list of current open /nanoui UIs, grouped by src_object and ui_key - var/open_uis[0] - // a list of current open /nanoui UIs, not grouped, for use in processing - var/list/processing_uis = list() - // a list of asset filenames which are to be sent to the client on user logon - var/list/asset_files = list() - - /** - * Create a new nanomanager instance. - * This proc generates a list of assets which are to be sent to each client on connect - * - * @return /nanomanager new nanomanager object - */ -/datum/nanomanager/New() - var/list/nano_asset_dirs = list(\ - "nano/css/",\ - "nano/images/",\ - "nano/js/",\ - "nano/templates/"\ - ) - - var/list/filenames = null - for (var/path in nano_asset_dirs) - filenames = flist(path) - for(var/filename in filenames) - if(copytext(filename, length(filename)) != "/") // filenames which end in "/" are actually directories, which we want to ignore - if(fexists(path + filename)) - asset_files.Add(fcopy_rsc(path + filename)) // add this file to asset_files for sending to clients when they connect - - 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 - * @param force_open boolean The ui is being forced to (re)open, so close ui if it exists (instead of updating) - * - * @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, var/force_open = 0) - if (isnull(ui)) // no ui has been passed, so we'll search for one - { - ui = get_open_ui(user, src_object, ui_key) - } - if (!isnull(ui)) - // The UI is already open - if (!force_open) - ui.push_data(data) - return ui - else - //testing("nanomanager/try_update_ui mob [user.name] [src_object:name] [ui_key] [force_open] - forcing opening of ui") - ui.close() - return null - - /** - * Get an open /nanoui ui for the current user, src_object and ui_key - * - * @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 - * - * @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]" - if (isnull(open_uis[src_object_key]) || !istype(open_uis[src_object_key], /list)) - //testing("nanomanager/get_open_ui mob [user.name] [src_object:name] [ui_key] - there are no uis open") - return null - else if (isnull(open_uis[src_object_key][ui_key]) || !istype(open_uis[src_object_key][ui_key], /list)) - //testing("nanomanager/get_open_ui mob [user.name] [src_object:name] [ui_key] - there are no uis open for this object") - return null - - for (var/datum/nanoui/ui in open_uis[src_object_key][ui_key]) - if (ui.user == user) - return ui - - //testing("nanomanager/get_open_ui mob [user.name] [src_object:name] [ui_key] - ui not found") - return null - - /** - * Update all /nanoui uis attached to src_object - * - * @param src_object /obj|/mob The obj or mob which the uis are attached to - * - * @return int The number of uis updated - */ -/datum/nanomanager/proc/update_uis(src_object) - var/src_object_key = "\ref[src_object]" - if (isnull(open_uis[src_object_key]) || !istype(open_uis[src_object_key], /list)) - return 0 - - var/update_count = 0 - for (var/ui_key in open_uis[src_object_key]) - for (var/datum/nanoui/ui in open_uis[src_object_key][ui_key]) - if(ui && ui.src_object && ui.user) - ui.process(1) - update_count++ - return update_count - - /** - * Update /nanoui uis belonging to user - * - * @param user /mob The mob who owns the uis - * @param src_object /obj|/mob If src_object is provided, only update uis which are attached to src_object (optional) - * @param ui_key string If ui_key is provided, only update uis with a matching ui_key (optional) - * - * @return int The number of uis updated - */ -/datum/nanomanager/proc/update_user_uis(var/mob/user, src_object = null, ui_key = null) - if (isnull(user.open_uis) || !istype(user.open_uis, /list) || open_uis.len == 0) - return 0 // has no open uis - - var/update_count = 0 - for (var/datum/nanoui/ui in user.open_uis) - if ((isnull(src_object) || !isnull(src_object) && ui.src_object == src_object) && (isnull(ui_key) || !isnull(ui_key) && ui.ui_key == ui_key)) - ui.process(1) - update_count++ - - return update_count - - /** - * Close /nanoui uis belonging to user - * - * @param user /mob The mob who owns the uis - * @param src_object /obj|/mob If src_object is provided, only close uis which are attached to src_object (optional) - * @param ui_key string If ui_key is provided, only close uis with a matching ui_key (optional) - * - * @return int The number of uis closed - */ -/datum/nanomanager/proc/close_user_uis(var/mob/user, src_object = null, ui_key = null) - if (isnull(user.open_uis) || !istype(user.open_uis, /list) || open_uis.len == 0) - //testing("nanomanager/close_user_uis mob [user.name] has no open uis") - return 0 // has no open uis - - var/close_count = 0 - for (var/datum/nanoui/ui in user.open_uis) - if ((isnull(src_object) || !isnull(src_object) && ui.src_object == src_object) && (isnull(ui_key) || !isnull(ui_key) && ui.ui_key == ui_key)) - ui.close() - close_count++ - - //testing("nanomanager/close_user_uis mob [user.name] closed [open_uis.len] of [close_count] uis") - - return close_count - - /** - * Add a /nanoui ui to the list of open uis - * This is called by the /nanoui open() proc - * - * @param ui /nanoui The ui to add - * - * @return nothing - */ -/datum/nanomanager/proc/ui_opened(var/datum/nanoui/ui) - var/src_object_key = "\ref[ui.src_object]" - if (isnull(open_uis[src_object_key]) || !istype(open_uis[src_object_key], /list)) - open_uis[src_object_key] = list(ui.ui_key = list()) - else if (isnull(open_uis[src_object_key][ui.ui_key]) || !istype(open_uis[src_object_key][ui.ui_key], /list)) - open_uis[src_object_key][ui.ui_key] = list(); - - ui.user.open_uis.Add(ui) - var/list/uis = open_uis[src_object_key][ui.ui_key] - uis.Add(ui) - processing_uis.Add(ui) - //testing("nanomanager/ui_opened mob [ui.user.name] [ui.src_object:name] [ui.ui_key] - user.open_uis [ui.user.open_uis.len] | uis [uis.len] | processing_uis [processing_uis.len]") - - /** - * Remove a /nanoui ui from the list of open uis - * This is called by the /nanoui close() proc - * - * @param ui /nanoui The ui to remove - * - * @return int 0 if no ui was removed, 1 if removed successfully - */ -/datum/nanomanager/proc/ui_closed(var/datum/nanoui/ui) - var/src_object_key = "\ref[ui.src_object]" - if (isnull(open_uis[src_object_key]) || !istype(open_uis[src_object_key], /list)) - return 0 // wasn't open - else if (isnull(open_uis[src_object_key][ui.ui_key]) || !istype(open_uis[src_object_key][ui.ui_key], /list)) - return 0 // wasn't open - - processing_uis.Remove(ui) - ui.user.open_uis.Remove(ui) - var/list/uis = open_uis[src_object_key][ui.ui_key] - uis.Remove(ui) - - //testing("nanomanager/ui_closed mob [ui.user.name] [ui.src_object:name] [ui.ui_key] - user.open_uis [ui.user.open_uis.len] | uis [uis.len] | processing_uis [processing_uis.len]") - - return 1 - - /** - * This is called on user logout - * Closes/clears all uis attached to the user's /mob - * - * @param user /mob The user's mob - * - * @return nothing - */ - -// -/datum/nanomanager/proc/user_logout(var/mob/user) - //testing("nanomanager/user_logout user [user.name]") - return close_user_uis(user) - - /** - * This is called when a player transfers from one mob to another - * Transfers all open UIs to the new mob - * - * @param oldMob /mob The user's old mob - * @param newMob /mob The user's new mob - * - * @return nothing - */ -/datum/nanomanager/proc/user_transferred(var/mob/oldMob, var/mob/newMob) - //testing("nanomanager/user_transferred from mob [oldMob.name] to mob [newMob.name]") - if (isnull(oldMob.open_uis) || !istype(oldMob.open_uis, /list) || open_uis.len == 0) - //testing("nanomanager/user_transferred mob [oldMob.name] has no open uis") - return 0 // has no open uis - - if (isnull(newMob.open_uis) || !istype(newMob.open_uis, /list)) - newMob.open_uis = list() - - for (var/datum/nanoui/ui in oldMob.open_uis) - ui.user = newMob - newMob.open_uis.Add(ui) - - oldMob.open_uis.Cut() - - return 1 // success - - /** - * Sends all nano assets to the client - * This is called on user login - * - * @param client /client The user's client - * - * @return nothing - */ - -/datum/nanomanager/proc/send_resources(client) - for(var/file in asset_files) - client << browse_rsc(file) // send the file to the client - +// This is the window/UI manager for Nano UI +// There should only ever be one (global) instance of nanomanger +/datum/nanomanager + // a list of current open /nanoui UIs, grouped by src_object and ui_key + var/open_uis[0] + // a list of current open /nanoui UIs, not grouped, for use in processing + var/list/processing_uis = list() + // a list of asset filenames which are to be sent to the client on user logon + var/list/asset_files = list() + + /** + * Create a new nanomanager instance. + * This proc generates a list of assets which are to be sent to each client on connect + * + * @return /nanomanager new nanomanager object + */ +/datum/nanomanager/New() + var/list/nano_asset_dirs = list(\ + "nano/css/",\ + "nano/images/",\ + "nano/js/",\ + "nano/templates/"\ + ) + + var/list/filenames = null + for (var/path in nano_asset_dirs) + filenames = flist(path) + for(var/filename in filenames) + if(copytext(filename, length(filename)) != "/") // filenames which end in "/" are actually directories, which we want to ignore + if(fexists(path + filename)) + asset_files.Add(fcopy_rsc(path + filename)) // add this file to asset_files for sending to clients when they connect + + 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 + * @param force_open boolean The ui is being forced to (re)open, so close ui if it exists (instead of updating) + * + * @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, var/force_open = 0) + if (isnull(ui)) // no ui has been passed, so we'll search for one + { + ui = get_open_ui(user, src_object, ui_key) + } + if (!isnull(ui)) + // The UI is already open + if (!force_open) + ui.push_data(data) + return ui + else + //testing("nanomanager/try_update_ui mob [user.name] [src_object:name] [ui_key] [force_open] - forcing opening of ui") + ui.close() + return null + + /** + * Get an open /nanoui ui for the current user, src_object and ui_key + * + * @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 + * + * @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]" + if (isnull(open_uis[src_object_key]) || !istype(open_uis[src_object_key], /list)) + //testing("nanomanager/get_open_ui mob [user.name] [src_object:name] [ui_key] - there are no uis open") + return null + else if (isnull(open_uis[src_object_key][ui_key]) || !istype(open_uis[src_object_key][ui_key], /list)) + //testing("nanomanager/get_open_ui mob [user.name] [src_object:name] [ui_key] - there are no uis open for this object") + return null + + for (var/datum/nanoui/ui in open_uis[src_object_key][ui_key]) + if (ui.user == user) + return ui + + //testing("nanomanager/get_open_ui mob [user.name] [src_object:name] [ui_key] - ui not found") + return null + + /** + * Update all /nanoui uis attached to src_object + * + * @param src_object /obj|/mob The obj or mob which the uis are attached to + * + * @return int The number of uis updated + */ +/datum/nanomanager/proc/update_uis(src_object) + var/src_object_key = "\ref[src_object]" + if (isnull(open_uis[src_object_key]) || !istype(open_uis[src_object_key], /list)) + return 0 + + var/update_count = 0 + for (var/ui_key in open_uis[src_object_key]) + for (var/datum/nanoui/ui in open_uis[src_object_key][ui_key]) + if(ui && ui.src_object && ui.user && ui.src_object.nano_host()) + ui.process(1) + update_count++ + return update_count + + /** + * Update /nanoui uis belonging to user + * + * @param user /mob The mob who owns the uis + * @param src_object /obj|/mob If src_object is provided, only update uis which are attached to src_object (optional) + * @param ui_key string If ui_key is provided, only update uis with a matching ui_key (optional) + * + * @return int The number of uis updated + */ +/datum/nanomanager/proc/update_user_uis(var/mob/user, src_object = null, ui_key = null) + if (isnull(user.open_uis) || !istype(user.open_uis, /list) || open_uis.len == 0) + return 0 // has no open uis + + var/update_count = 0 + for (var/datum/nanoui/ui in user.open_uis) + if ((isnull(src_object) || !isnull(src_object) && ui.src_object == src_object) && (isnull(ui_key) || !isnull(ui_key) && ui.ui_key == ui_key)) + ui.process(1) + update_count++ + + return update_count + + /** + * Close /nanoui uis belonging to user + * + * @param user /mob The mob who owns the uis + * @param src_object /obj|/mob If src_object is provided, only close uis which are attached to src_object (optional) + * @param ui_key string If ui_key is provided, only close uis with a matching ui_key (optional) + * + * @return int The number of uis closed + */ +/datum/nanomanager/proc/close_user_uis(var/mob/user, src_object = null, ui_key = null) + if (isnull(user.open_uis) || !istype(user.open_uis, /list) || open_uis.len == 0) + //testing("nanomanager/close_user_uis mob [user.name] has no open uis") + return 0 // has no open uis + + var/close_count = 0 + for (var/datum/nanoui/ui in user.open_uis) + if ((isnull(src_object) || !isnull(src_object) && ui.src_object == src_object) && (isnull(ui_key) || !isnull(ui_key) && ui.ui_key == ui_key)) + ui.close() + close_count++ + + //testing("nanomanager/close_user_uis mob [user.name] closed [open_uis.len] of [close_count] uis") + + return close_count + + /** + * Add a /nanoui ui to the list of open uis + * This is called by the /nanoui open() proc + * + * @param ui /nanoui The ui to add + * + * @return nothing + */ +/datum/nanomanager/proc/ui_opened(var/datum/nanoui/ui) + var/src_object_key = "\ref[ui.src_object]" + if (isnull(open_uis[src_object_key]) || !istype(open_uis[src_object_key], /list)) + open_uis[src_object_key] = list(ui.ui_key = list()) + else if (isnull(open_uis[src_object_key][ui.ui_key]) || !istype(open_uis[src_object_key][ui.ui_key], /list)) + open_uis[src_object_key][ui.ui_key] = list(); + + ui.user.open_uis.Add(ui) + var/list/uis = open_uis[src_object_key][ui.ui_key] + uis.Add(ui) + processing_uis.Add(ui) + //testing("nanomanager/ui_opened mob [ui.user.name] [ui.src_object:name] [ui.ui_key] - user.open_uis [ui.user.open_uis.len] | uis [uis.len] | processing_uis [processing_uis.len]") + + /** + * Remove a /nanoui ui from the list of open uis + * This is called by the /nanoui close() proc + * + * @param ui /nanoui The ui to remove + * + * @return int 0 if no ui was removed, 1 if removed successfully + */ +/datum/nanomanager/proc/ui_closed(var/datum/nanoui/ui) + var/src_object_key = "\ref[ui.src_object]" + if (isnull(open_uis[src_object_key]) || !istype(open_uis[src_object_key], /list)) + return 0 // wasn't open + else if (isnull(open_uis[src_object_key][ui.ui_key]) || !istype(open_uis[src_object_key][ui.ui_key], /list)) + return 0 // wasn't open + + processing_uis.Remove(ui) + ui.user.open_uis.Remove(ui) + var/list/uis = open_uis[src_object_key][ui.ui_key] + uis.Remove(ui) + + //testing("nanomanager/ui_closed mob [ui.user.name] [ui.src_object:name] [ui.ui_key] - user.open_uis [ui.user.open_uis.len] | uis [uis.len] | processing_uis [processing_uis.len]") + + return 1 + + /** + * This is called on user logout + * Closes/clears all uis attached to the user's /mob + * + * @param user /mob The user's mob + * + * @return nothing + */ + +// +/datum/nanomanager/proc/user_logout(var/mob/user) + //testing("nanomanager/user_logout user [user.name]") + return close_user_uis(user) + + /** + * This is called when a player transfers from one mob to another + * Transfers all open UIs to the new mob + * + * @param oldMob /mob The user's old mob + * @param newMob /mob The user's new mob + * + * @return nothing + */ +/datum/nanomanager/proc/user_transferred(var/mob/oldMob, var/mob/newMob) + //testing("nanomanager/user_transferred from mob [oldMob.name] to mob [newMob.name]") + if (isnull(oldMob.open_uis) || !istype(oldMob.open_uis, /list) || open_uis.len == 0) + //testing("nanomanager/user_transferred mob [oldMob.name] has no open uis") + return 0 // has no open uis + + if (isnull(newMob.open_uis) || !istype(newMob.open_uis, /list)) + newMob.open_uis = list() + + for (var/datum/nanoui/ui in oldMob.open_uis) + ui.user = newMob + newMob.open_uis.Add(ui) + + oldMob.open_uis.Cut() + + return 1 // success + + /** + * Sends all nano assets to the client + * This is called on user login + * + * @param client /client The user's client + * + * @return nothing + */ + +/datum/nanomanager/proc/send_resources(client) + for(var/file in asset_files) + client << browse_rsc(file) // send the file to the client + diff --git a/code/modules/nano/nanoprocs.dm b/code/modules/nano/nanoprocs.dm new file mode 100644 index 00000000000..65432a8f24b --- /dev/null +++ b/code/modules/nano/nanoprocs.dm @@ -0,0 +1,11 @@ +/atom/movable/proc/nano_host() + return src + +/obj/nano_module/nano_host() + return loc + +/atom/movable/proc/nano_can_update() + return 1 + +/obj/machinery/nano_can_update() + return !(stat & (NOPOWER|BROKEN)) diff --git a/code/modules/nano/nanoui.dm b/code/modules/nano/nanoui.dm index fbd809cd03c..04ef3cc95b9 100644 --- a/code/modules/nano/nanoui.dm +++ b/code/modules/nano/nanoui.dm @@ -132,7 +132,12 @@ nanoui is used to open and update nano browser uis * @return nothing */ /datum/nanoui/proc/update_status(var/push_update = 0) - var/status = user.can_interact_with_interface(src_object) + var/atom/movable/host = src_object.nano_host() + if(!host.nano_can_update()) + close() + return + + var/status = user.can_interact_with_interface(host.nano_host()) if(status == STATUS_CLOSE) close() else @@ -181,7 +186,7 @@ nanoui is used to open and update nano browser uis return STATUS_UPDATE /mob/living/silicon/ai/can_interact_with_interface(var/src_object) - if(stat || !client) + if(!client || check_unable(1)) return STATUS_CLOSE // Prevents the AI from using Topic on admin levels (by for example viewing through the court/thunderdome cameras) // unless it's on the same level as the object it's interacting with.