From a7bcd6f4061b6e2e15f9e5996c0117b49d426e31 Mon Sep 17 00:00:00 2001 From: GinjaNinja32 Date: Tue, 16 Dec 2014 12:30:25 +0000 Subject: [PATCH] NanoUI camera console --- code/game/machinery/computer/camera.dm | 94 +++++++++++++++------- nano/templates/sec_camera.tmpl | 23 ++++++ nano/templates/sec_camera_map_content.tmpl | 20 +++++ nano/templates/sec_camera_map_header.tmpl | 23 ++++++ 4 files changed, 131 insertions(+), 29 deletions(-) create mode 100644 nano/templates/sec_camera.tmpl create mode 100644 nano/templates/sec_camera_map_content.tmpl create mode 100644 nano/templates/sec_camera_map_header.tmpl diff --git a/code/game/machinery/computer/camera.dm b/code/game/machinery/computer/camera.dm index 14c7847c6a..627cd25647 100644 --- a/code/game/machinery/computer/camera.dm +++ b/code/game/machinery/computer/camera.dm @@ -23,6 +23,69 @@ user.reset_view(current) return 1 + ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null, force_open = 1) + if(src.z > 6) return + if(stat & (NOPOWER|BROKEN)) return + if(user.stat) return + + var/data[0] + + data["current"] = null + + var/list/L = list() + for (var/obj/machinery/camera/C in cameranet.cameras) + if(can_access_camera(C)) + L.Add(C) + + camera_sort(L) + + var/cameras[0] + for(var/obj/machinery/camera/C in L) + var/cam[0] + cam["name"] = C.c_tag + cam["deact"] = !C.can_use() + cam["camera"] = "\ref[C]" + cam["x"] = C.x + cam["y"] = C.y + cam["z"] = C.z + + cameras[++cameras.len] = cam + + if(C == current) + data["current"] = cam + + data["cameras"] = cameras + + ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) + if (!ui) + ui = new(user, src, ui_key, "sec_camera.tmpl", "Camera Console", 900, 800) + + // adding a template with the key "mapContent" enables the map ui functionality + ui.add_template("mapContent", "sec_camera_map_content.tmpl") + // adding a template with the key "mapHeader" replaces the map header content + ui.add_template("mapHeader", "sec_camera_map_header.tmpl") + + ui.set_initial_data(data) + ui.open() + ui.set_auto_update(1) + + Topic(href, href_list) + if(href_list["switchTo"]) + if(src.z>6 || stat&(NOPOWER|BROKEN)) return + if(usr.stat || ((get_dist(usr, src) > 1 || !( usr.canmove ) || usr.blinded) && !istype(usr, /mob/living/silicon))) return + var/obj/machinery/camera/C = locate(href_list["switchTo"]) in cameranet.cameras + if(!C) return + + switch_to_camera(usr, C) + return 1 + else if(href_list["reset"]) + if(src.z>6 || stat&(NOPOWER|BROKEN)) return + if(usr.stat || ((get_dist(usr, src) > 1 || !( usr.canmove ) || usr.blinded) && !istype(usr, /mob/living/silicon))) return + current = null + usr.check_eye(current) + return 1 + else + . = ..() attack_hand(var/mob/user as mob) if (src.z > 6) @@ -32,35 +95,7 @@ if(!isAI(user)) user.set_machine(src) - - var/list/L = list() - for (var/obj/machinery/camera/C in cameranet.cameras) - L.Add(C) - - camera_sort(L) - - var/list/D = list() - D["Cancel"] = "Cancel" - for(var/obj/machinery/camera/C in L) - if(can_access_camera(C)) - D[text("[][]", C.c_tag, (C.can_use() ? null : " (Deactivated)"))] = C - - var/t = input(user, "Which camera should you change to?") as null|anything in D - if(!t) - user.unset_machine() - return 0 - - var/obj/machinery/camera/C = D[t] - - if(t == "Cancel") - user.unset_machine() - return 0 - - if(C) - switch_to_camera(user, C) - spawn(5) - attack_hand(user) - return + ui_interact(user) proc/can_access_camera(var/obj/machinery/camera/C) var/list/shared_networks = src.network & C.network @@ -79,6 +114,7 @@ if (!C.can_use() || user.stat || (get_dist(user, src) > 1 || user.machine != src || user.blinded || !( user.canmove ) && !istype(user, /mob/living/silicon))) return 0 src.current = C + check_eye(user) use_power(50) return 1 diff --git a/nano/templates/sec_camera.tmpl b/nano/templates/sec_camera.tmpl new file mode 100644 index 0000000000..ea18fb2047 --- /dev/null +++ b/nano/templates/sec_camera.tmpl @@ -0,0 +1,23 @@ + +{{:helper.link('Show Map', 'pin-s', {'showMap' : 1})}} +{{:helper.link('Reset', 'refresh', {'reset' : 1})}} +
+
Current Camera:
+ {{if data.current}} +
{{:data.current.name}}
+ {{else}} +
None
+ {{/if}} +
+{{for data.cameras}} + {{if data.current && value.name == data.current.name}} + {{:helper.link(value.name, '', {'switchTo' : value.camera}, 'selected')}} + {{else value.deact}} + {{:helper.link(value.name + " (deactivated)", '', {}, 'inactive')}} + {{else}} + {{:helper.link(value.name, '', {'switchTo' : value.camera})}} + {{/if}} +{{/for}} \ No newline at end of file diff --git a/nano/templates/sec_camera_map_content.tmpl b/nano/templates/sec_camera_map_content.tmpl new file mode 100644 index 0000000000..52dc8aeadd --- /dev/null +++ b/nano/templates/sec_camera_map_content.tmpl @@ -0,0 +1,20 @@ + +{{for data.cameras}} + {{if value.z == 1}} +
+ {{if data.current && value.name == data.current.name}} + {{:helper.link("#", '', {'switchTo' : value.camera}, 'selected')}} + {{else value.deact}} + {{:helper.link('#', '', {}, 'inactive')}} + {{else}} + {{:helper.link("#", '', {'switchTo' : value.camera})}} + {{/if}} + +
+ {{/if}} +{{/for}} \ No newline at end of file diff --git a/nano/templates/sec_camera_map_header.tmpl b/nano/templates/sec_camera_map_header.tmpl new file mode 100644 index 0000000000..175e61062e --- /dev/null +++ b/nano/templates/sec_camera_map_header.tmpl @@ -0,0 +1,23 @@ + +{{:helper.link('Show Camera List', 'script', {'showMap' : 0})}} +{{:helper.link('Reset', 'refresh', {'reset' : 1})}} +
+
+
Current Camera: 
+ {{if data.current}} +
{{:data.current.name}}
+ {{else}} +
None
+ {{/if}} +
+
+
+ Zoom Level:  + + + + +
\ No newline at end of file