Skip to content

Commit

Permalink
tgui for airlock electronics.
Browse files Browse the repository at this point in the history
  • Loading branch information
NullSnapshot authored and NullSnapshot committed Jul 13, 2016
1 parent a026b68 commit 051ef3c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 71 deletions.
134 changes: 63 additions & 71 deletions code/game/machinery/doors/airlock_electronics.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,100 +11,92 @@
req_access = list(access_engine)

var/secure = 0 //if set, then wires will be randomized and bolts will drop if the door is broken
var/list/conf_access = null
var/list/conf_access = list()
var/one_access = 0 //if set to 1, door would receive req_one_access instead of req_access
var/last_configurator = null
var/locked = 1

attack_self(mob/user as mob)
if (!ishuman(user) && !istype(user,/mob/living/silicon/robot))
return ..(user)

var/t1 = text("<B>Access control</B><br>\n")

if (last_configurator)
t1 += "Operator: [last_configurator]<br>"
/obj/item/weapon/airlock_electronics/attack_self(mob/user as mob)
if (!ishuman(user) && !istype(user,/mob/living/silicon/robot))
return ..(user)

if (locked)
t1 += "<a href='?src=\ref[src];login=1'>Swipe ID</a><hr>"
else
t1 += "<a href='?src=\ref[src];logout=1'>Block</a><hr>"
tg_ui_interact(user)

t1 += "Access requirement is set to "
t1 += one_access ? "<a style='color: green' href='?src=\ref[src];one_access=1'>ONE</a><hr>" : "<a style='color: red' href='?src=\ref[src];one_access=1'>ALL</a><hr>"

t1 += conf_access == null ? "<font color=red>All</font><br>" : "<a href='?src=\ref[src];access=all'>All</a><br>"

t1 += "<br>"
//tgui interact code generously lifted from tgstation.
/obj/item/weapon/airlock_electronics/tg_ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = 0, \
datum/tgui/master_ui = null, datum/ui_state/state = hands_state)

var/list/accesses = get_all_station_access()
for (var/acc in accesses)
var/aname = get_access_desc(acc)
tgui_process.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "airlock_electronics", src.name, 1000, 500, master_ui, state)
ui.open()

if (!conf_access || !conf_access.len || !(acc in conf_access))
t1 += "<a href='?src=\ref[src];access=[acc]'>[aname]</a><br>"
else if(one_access)
t1 += "<a style='color: green' href='?src=\ref[src];access=[acc]'>[aname]</a><br>"
else
t1 += "<a style='color: red' href='?src=\ref[src];access=[acc]'>[aname]</a><br>"

t1 += text("<p><a href='?src=\ref[];close=1'>Close</a></p>\n", src)
/obj/item/weapon/airlock_electronics/ui_data(mob/user)
var/list/data = list()
var/list/regions = list()

user << browse(t1, "window=airlock_electronics")
onclose(user, "airlock")
for(var/i in ACCESS_REGION_SECURITY to ACCESS_REGION_SUPPLY) //code/game/jobs/_access_defs.dm
var/list/region = list()
var/list/accesses = list()
for(var/j in get_region_accesses(i))
var/list/access = list()
access["name"] = get_access_desc(j)
access["id"] = j
access["req"] = (j in src.conf_access)
accesses[++accesses.len] = access
region["name"] = get_region_accesses_name(i)
region["accesses"] = accesses
regions[++regions.len] = region
data["regions"] = regions
data["oneAccess"] = one_access
data["locked"] = locked

Topic(href, href_list)
..()
if (usr.stat || usr.restrained() || (!ishuman(usr) && !istype(usr,/mob/living/silicon)))
return
if (href_list["close"])
usr << browse(null, "window=airlock")
return
return data

if (href_list["login"])
/obj/item/weapon/airlock_electronics/ui_act(action, params)
if(..())
return TRUE
switch(action)
if("clear")
conf_access = list()
one_access = 0
return TRUE
if("one_access")
one_access = !one_access
return TRUE
if("set")
var/access = text2num(params["access"])
if (!(access in conf_access))
conf_access += access
else
conf_access -= access
return TRUE
if("unlock")
if(istype(usr,/mob/living/silicon))
src.locked = 0
src.last_configurator = usr.name
locked = 0
last_configurator = usr.name
return TRUE
else
var/obj/item/I = usr.get_active_hand()
if (istype(I, /obj/item/device/pda))
var/obj/item/device/pda/pda = I
I = pda.id
if(!istype(I, /obj/item/weapon/card/id))
usr << "<span class='warning'>[\src] flashes a yellow LED near the ID scanner. Did you remember to scan your ID or PDA?</span>"
return TRUE
if (I && src.check_access(I))
src.locked = 0
src.last_configurator = I:registered_name

if (locked)
return

if (href_list["logout"])
locked = 1

if (href_list["one_access"])
one_access = !one_access

if (href_list["access"])
toggle_access(href_list["access"])

attack_self(usr)

proc
toggle_access(var/acc)
if (acc == "all")
conf_access = null
else
var/req = text2num(acc)

if (conf_access == null)
conf_access = list()

if (!(req in conf_access))
conf_access += req
locked = 0
last_configurator = I:registered_name
else
conf_access -= req
if (!conf_access.len)
conf_access = null

usr << "<span class='warning'>[\src] flashes a red LED near the ID scanner, indicating your access has been denied.</span>"
return TRUE
if("lock")
locked = 1
. = TRUE

/obj/item/weapon/airlock_electronics/secure
name = "secure airlock electronics"
Expand Down
7 changes: 7 additions & 0 deletions tgui/src/interfaces/airlock_electronics.ract
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<ui-display>
{{#if data.locked}}
<ui-section label='Card locked!'>
Swipe ID to continue: <ui-button icon='unlock' action='unlock'>Unlock</ui-button>
</ui-section>
{{else}}
<ui-section>
<ui-button icon='{{data.oneAccess ? "unlock" : "lock"}}' action='one_access'>{{data.oneAccess ? "One" : "All"}} Required</ui-button>
<ui-button icon='refresh' action='clear'>Clear</ui-button>
<ui-button icon='lock' action='lock'>Lock</ui-button>
</ui-section>
<hr/>
<table>
Expand All @@ -20,6 +26,7 @@
{{/each}}</tr>
</tbody>
</table>
{{/if}}
</ui-display>

<style>
Expand Down

0 comments on commit 051ef3c

Please sign in to comment.