From 7e231f9ed577a9dd60a10f6b217ae6e6495c70e2 Mon Sep 17 00:00:00 2001 From: Tigercat2000 Date: Mon, 5 Oct 2015 16:36:32 -0700 Subject: [PATCH] NanoUI Intellicards This add NanoUI to IntelliCard's. --- code/game/objects/items/devices/aicard.dm | 134 ++++++++++------------ nano/templates/aicard.tmpl | 98 ++++++++++++++++ 2 files changed, 157 insertions(+), 75 deletions(-) create mode 100644 nano/templates/aicard.tmpl diff --git a/code/game/objects/items/devices/aicard.dm b/code/game/objects/items/devices/aicard.dm index e061b993e72..159365f0b79 100644 --- a/code/game/objects/items/devices/aicard.dm +++ b/code/game/objects/items/devices/aicard.dm @@ -20,7 +20,7 @@ add_logs(AI,user, "carded", object="[name]") else //No AI on the card, therefore the user wants to download one. target.transfer_ai(AI_TRANS_TO_CARD, user, null, src) - update_state() //Whatever happened, update the card's state (icon, name) to match. + update_state() //Whatever happened, update the card's state (icon, name) to match. /obj/item/device/aicard/proc/update_state() var/mob/living/silicon/ai/AI = locate(/mob/living/silicon/ai) in src //AI is inside. @@ -34,90 +34,74 @@ else icon_state = "aicard" name = "intelliCard" - overlays.Cut() - + overlays.Cut() + /obj/item/device/aicard/attack_self(mob/user) - if (!in_range(src, user)) - return - user.set_machine(src) - var/dat = "Intelicard
" - var/laws - for(var/mob/living/silicon/ai/A in src) - dat += "Stored AI: [A.name]
System integrity: [(A.health+100)/2]%
" + ui_interact(user) - for (var/datum/ai_law/law in A.laws.all_laws()) - laws += "[law.get_index()]: [law.law]
" - dat += "Laws:
[laws]
" +/obj/item/device/aicard/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/topic_state/state = inventory_state) + var/data[0] - if (A.stat == 2) - dat += "AI nonfunctional" - else - if (!src.flush) - dat += {"Wipe AI"} - else - dat += "Wipe in progress" - dat += "
" - dat += {"[A.control_disabled ? "Enable" : "Disable"] Wireless Activity"} - dat += "
" - dat += "Subspace Transceiver is: [A.aiRadio.disabledAi ? "Disabled" : "Enabled"]" - dat += "
" - dat += {"[A.aiRadio.disabledAi ? "Enable" : "Disable"] Subspace Transceiver"} - dat += "
" - dat += {" Close"} - user << browse(dat, "window=aicard") - onclose(user, "aicard") - return + var/mob/living/silicon/ai/AI = locate() in src + if(istype(AI)) + data["has_ai"] = 1 + data["name"] = AI.name + data["hardware_integrity"] = ((AI.health + 100) / 2) + data["radio"] = !AI.aiRadio.disabledAi + data["wireless"] = !AI.control_disabled + data["operational"] = AI.stat != DEAD + data["flushing"] = flush -/obj/item/device/aicard/Topic(href, href_list) - var/mob/U = usr - if (!in_range(src, U)||U.machine!=src)//If they are not in range of 1 or less or their machine is not the card (ie, clicked on something else). - U << browse(null, "window=aicard") - U.unset_machine() - return + var/laws[0] + for(var/datum/ai_law/AL in AI.laws.all_laws()) + laws[++laws.len] = list("index" = AL.get_index(), "law" = sanitize(AL.law)) + data["laws"] = laws + data["has_laws"] = laws.len - add_fingerprint(U) - U.set_machine(src) + ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) + if (!ui) + ui = new(user, src, ui_key, "aicard.tmpl", "[name]", 600, 400, state = state) + ui.set_initial_data(data) + ui.open() + ui.set_auto_update(1) - switch(href_list["choice"])//Now we switch based on choice. - if ("Close") - U << browse(null, "window=aicard") - U.unset_machine() - return - if ("Wipe") - var/confirm = alert("Are you sure you want to wipe this card's memory? This cannot be undone once started.", "Confirm Wipe", "Yes", "No") - if(confirm == "Yes") - if(isnull(src)||!in_range(src, U)||U.machine!=src) - U << browse(null, "window=aicard") - U.unset_machine() - return - else - flush = 1 - for(var/mob/living/silicon/ai/A in src) - A.suiciding = 1 - A << "Your core files are being wiped!" - while (A.stat != 2) - A.adjustOxyLoss(2) - A.updatehealth() - sleep(10) - flush = 0 +/obj/item/device/aicard/Topic(href, href_list, nowindow, state) + if(..()) + return 1 - if ("Radio") - for(var/mob/living/silicon/ai/A in src) - A.aiRadio.disabledAi = !A.aiRadio.disabledAi - A << "Your Subspace Transceiver has been: [A.aiRadio.disabledAi ? "disabled" : "enabled"]" - U << "You [A.aiRadio.disabledAi ? "Disable" : "Enable"] the AI's Subspace Transceiver" + var/mob/living/silicon/ai/AI = locate() in src + if(!istype(AI)) + return 1 - if ("Wireless") - for(var/mob/living/silicon/ai/A in src) - A.control_disabled = !A.control_disabled - A << "The intelicard's wireless port has been [A.control_disabled ? "disabled" : "enabled"]!" - if (A.control_disabled) - overlays -= image('icons/obj/aicards.dmi', "aicard-on") - else - overlays += image('icons/obj/aicards.dmi', "aicard-on") - attack_self(U) + var/user = usr + + if (href_list["wipe"]) + var/confirm = alert("Are you sure you want to wipe this card's memory? This cannot be undone once started.", "Confirm Wipe", "Yes", "No") + if(confirm == "Yes" && (CanUseTopic(user, state) == STATUS_INTERACTIVE)) + msg_admin_attack("[key_name_admin(user)] wiped [key_name_admin(AI)] with \the [src].") + flush = 1 + AI.suiciding = 1 + AI << "Your core files are being wiped!" + while (AI && AI.stat != DEAD) + AI.adjustOxyLoss(2) + AI.updatehealth() + sleep(10) + flush = 0 + + if (href_list["radio"]) + AI.aiRadio.disabledAi = text2num(href_list["radio"]) + AI << "Your Subspace Transceiver has been [AI.aiRadio.disabledAi ? "disabled" : "enabled"]!" + user << "You [AI.aiRadio.disabledAi ? "disable" : "enable"] the AI's Subspace Transceiver." + + if (href_list["wireless"]) + AI.control_disabled = text2num(href_list["wireless"]) + AI << "Your wireless interface has been [AI.control_disabled ? "disabled" : "enabled"]!" + user << "You [AI.control_disabled ? "disable" : "enable"] the AI's wireless interface." + update_icon() + + return 1 /obj/item/device/aicard/ex_act(severity) switch(severity) diff --git a/nano/templates/aicard.tmpl b/nano/templates/aicard.tmpl new file mode 100644 index 00000000000..0cf123de8ad --- /dev/null +++ b/nano/templates/aicard.tmpl @@ -0,0 +1,98 @@ + + + + + +{{if data.has_ai}} +
+
+ Hardware Integrity: +
+
+ {{:data.hardware_integrity}}% +
+
+ + {{if data.has_laws}} + + + +
+ Laws: +
+ {{for data.laws}} + + {{/for}} +
IndexLaw
{{:value.index}}.{{:value.law}}
+ {{else}} + No laws found. + {{/if}} + + {{if data.operational}} + + + + + + + + + + + {{if data.flushing}} + + {{else}} + + + + + {{/if}} +
Radio Subspace Transceiver{{:helper.link("Enabled", null, {'radio' : 0}, data.radio ? 'selected' : null)}}{{:helper.link("Disabled", null, {'radio' : 1}, data.radio ? null : 'redButton' )}}
Wireless Interface{{:helper.link("Enabled", null, {'wireless' : 0}, data.wireless ? 'selected' : null)}}{{:helper.link("Disabled", null, {'wireless' : 1}, data.wireless ? null : 'redButton' )}}
AI wipe in progress...
Wipe AI{{:helper.link("Wipe", 'radiation', {'wipe' : 1}, null, 'redButton')}}
+ {{/if}} +{{else}} + Stored AI: No AI detected. +{{/if}}