Merge pull request #6482 from davipatury/eftpos-ui

EFTPOS Nano-UI-ification
This commit is contained in:
Crazy Lemon
2017-02-24 18:53:19 -08:00
committed by GitHub
2 changed files with 100 additions and 63 deletions
+45 -63
View File
@@ -27,7 +27,7 @@
/obj/item/device/eftpos/proc/print_reference()
playsound(loc, 'sound/goonstation/machines/printer_thermal.ogg', 50, 1)
var/obj/item/weapon/paper/R = new(src.loc)
var/obj/item/weapon/paper/R = new(loc)
R.name = "Reference: [eftpos_name]"
// AUTOFIXED BY fix_string_idiocy.py
@@ -45,7 +45,7 @@
R.overlays += stampoverlay
R.stamps += "<HR><i>This paper has been stamped by the EFTPOS device.</i>"
var/obj/item/smallDelivery/D = new(R.loc)
R.loc = D
R.forceMove(D)
D.wrapped = R
D.name = "small parcel - 'EFTPOS access code'"
@@ -54,70 +54,51 @@
if(!location)
return
for(var/obj/machinery/computer/account_database/DB in world) //Hotfix until someone finds out why it isn't in 'machines'
for(var/obj/machinery/computer/account_database/DB in machines)
if(DB.z == location.z)
linked_db = DB
break
/obj/item/device/eftpos/attack_self(mob/user as mob)
if(get_dist(src,user) <= 1)
/obj/item/device/eftpos/attack_self(mob/user)
ui_interact(user)
// AUTOFIXED BY fix_string_idiocy.py
// C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\EFTPOS.dm:59: var/dat = "<b>[eftpos_name]</b><br>"
var/dat = {"<b>[eftpos_name]</b><br>
<i>This terminal is</i> [machine_id]. <i>Report this code when contacting Nanotrasen IT Support</i><br>"}
// END AUTOFIX
if(transaction_locked)
// AUTOFIXED BY fix_string_idiocy.py
// C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\EFTPOS.dm:59: dat += "<a href='?src=[UID()];choice=toggle_lock'>Reset[transaction_paid ? "" : " (authentication required)"]</a><br><br>"
dat += {"<a href='?src=[UID()];choice=toggle_lock'>Reset[transaction_paid ? "" : " (authentication required)"]</a><br><br>
Transaction purpose: <b>[transaction_purpose]</b><br>
Value: <b>$[transaction_amount]</b><br>
Linked account: <b>[linked_account ? linked_account.owner_name : "None"]</b><hr>"}
// END AUTOFIX
if(transaction_paid)
dat += "<i>This transaction has been processed successfully.</i><hr>"
else
// AUTOFIXED BY fix_string_idiocy.py
// C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\EFTPOS.dm:67: dat += "<i>Swipe your card below the line to finish this transaction.</i><hr>"
dat += {"<i>Swipe your card below the line to finish this transaction.</i><hr>
<a href='?src=[UID()];choice=scan_card'>\[------\]</a>"}
// END AUTOFIX
else
// AUTOFIXED BY fix_string_idiocy.py
// C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\EFTPOS.dm:70: dat += "<a href='?src=[UID()];choice=toggle_lock'>Lock in new transaction</a><br><br>"
dat += {"<a href='?src=[UID()];choice=toggle_lock'>Lock in new transaction</a><br><br>
Transaction purpose: <a href='?src=[UID()];choice=trans_purpose'>[transaction_purpose]</a><br>
Value: <a href='?src=[UID()];choice=trans_value'>$[transaction_amount]</a><br>
Linked account: <a href='?src=[UID()];choice=link_account'>[linked_account ? linked_account.owner_name : "None"]</a><hr>
<a href='?src=[UID()];choice=change_code'>Change access code</a><br>
<a href='?src=[UID()];choice=change_id'>Change EFTPOS ID</a><br>
Scan card to reset access code <a href='?src=[UID()];choice=reset'>\[------\]</a>"}
// END AUTOFIX
user << browse(dat,"window=eftpos")
else
user << browse(null,"window=eftpos")
/obj/item/device/eftpos/attackby(O as obj, user as mob, params)
/obj/item/device/eftpos/attackby(obj/O, mob/user, params)
if(istype(O, /obj/item/weapon/card))
//attempt to connect to a new db, and if that doesn't work then fail
if(!linked_db)
reconnect_database()
if(linked_db)
if(linked_account)
var/obj/item/weapon/card/I = O
scan_card(I)
scan_card(O, user)
nanomanager.update_uis(src)
else
to_chat(usr, "[bicon(src)]<span class='warning'>Unable to connect to linked account.</span>")
to_chat(user, "[bicon(src)]<span class='warning'>Unable to connect to linked account.</span>")
else
to_chat(usr, "[bicon(src)]<span class='warning'>Unable to connect to accounts database.</span>")
to_chat(user, "[bicon(src)]<span class='warning'>Unable to connect to accounts database.</span>")
else
..()
/obj/item/device/eftpos/Topic(var/href, var/href_list)
/obj/item/device/eftpos/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
ui = nanomanager.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "eftpos.tmpl", name, 790, 310)
ui.open()
/obj/item/device/eftpos/ui_data(mob/user, ui_key = "main", datum/topic_state/state = default_state)
var/data[0]
data["eftpos_name"] = eftpos_name
data["machine_id"] = machine_id
data["transaction_locked"] = transaction_locked
data["transaction_paid"] = transaction_paid
data["transaction_purpose"] = transaction_purpose
data["transaction_amount"] = transaction_amount
data["linked_account"] = linked_account ? linked_account.owner_name : null
return data
/obj/item/device/eftpos/Topic(href, list/href_list)
if(..())
return 1
if(href_list["choice"])
switch(href_list["choice"])
if("change_code")
@@ -134,9 +115,9 @@
if("change_id")
var/attempt_code = text2num(input("Re-enter the current EFTPOS access code", "Confirm EFTPOS code"))
if(attempt_code == access_code)
var name = input("Enter a new terminal ID for this device", "Enter new EFTPOS ID") as text|null
var/name = input("Enter a new terminal ID for this device", "Enter new EFTPOS ID") as text|null
if(name)
eftpos_name = name + " EFTPOS scanner"
eftpos_name = "[name] EFTPOS scanner"
print_reference()
else
to_chat(usr, "[bicon(src)]<span class='warning'>Incorrect code entered.</span>")
@@ -150,11 +131,11 @@
else
to_chat(usr, "[bicon(src)]<span class='warning'>Unable to connect to accounts database.</span>")
if("trans_purpose")
var/purpose = input("Enter reason for EFTPOS transaction", "Transaction purpose") as text|null
var/purpose = input("Enter reason for EFTPOS transaction", "Transaction purpose", transaction_purpose) as text|null
if(purpose)
transaction_purpose = purpose
if("trans_value")
var/try_num = input("Enter amount for EFTPOS transaction", "Transaction amount") as num
var/try_num = input("Enter amount for EFTPOS transaction", "Transaction amount", transaction_amount) as num
if(try_num < 0)
alert("That is not a valid amount!")
else
@@ -168,7 +149,7 @@
else if(linked_account)
transaction_locked = 1
else
to_chat(usr, "[bicon(src)] <span class='warning'>No account connected to send transactions to.</span>")
to_chat(usr, "[bicon(src)]<span class='warning'>No account connected to send transactions to.</span>")
if("scan_card")
//attempt to connect to a new db, and if that doesn't work then fail
if(!linked_db)
@@ -176,7 +157,7 @@
if(linked_db && linked_account)
var/obj/item/I = usr.get_active_hand()
if(istype(I, /obj/item/weapon/card))
scan_card(I)
scan_card(I, usr)
else
to_chat(usr, "[bicon(src)]<span class='warning'>Unable to link accounts.</span>")
if("reset")
@@ -191,12 +172,13 @@
access_code = 0
to_chat(usr, "[bicon(src)]<span class='info'>Access code reset to 0.</span>")
src.attack_self(usr)
nanomanager.update_uis(src)
return 1
/obj/item/device/eftpos/proc/scan_card(var/obj/item/weapon/card/I)
/obj/item/device/eftpos/proc/scan_card(obj/item/weapon/card/I, mob/user)
if(istype(I, /obj/item/weapon/card/id))
var/obj/item/weapon/card/id/C = I
visible_message("<span class='info'>[usr] swipes a card through [src].</span>")
visible_message("<span class='info'>[user] swipes a card through [src].</span>")
if(transaction_locked && !transaction_paid)
if(linked_account)
var/attempt_pin = input("Enter pin code", "EFTPOS transaction") as num
@@ -204,7 +186,7 @@
if(D)
if(transaction_amount <= D.money)
playsound(src, 'sound/machines/chime.ogg', 50, 1)
src.visible_message("[bicon(src)] The [src] chimes.")
visible_message("[bicon(src)] The [src] chimes.")
transaction_paid = 1
//transfer the money
@@ -233,11 +215,11 @@
T.time = worldtime2text()
linked_account.transaction_log.Add(T)
else
to_chat(usr, "[bicon(src)]<span class='warning'>You don't have that much money!</span>")
to_chat(user, "[bicon(src)]<span class='warning'>You don't have that much money!</span>")
else
to_chat(usr, "[bicon(src)]<span class='warning'>Unable to access account. Check security settings and try again.</span>")
to_chat(user, "[bicon(src)]<span class='warning'>Unable to access account. Check security settings and try again.</span>")
else
to_chat(usr, "[bicon(src)]<span class='warning'>EFTPOS is not connected to an account.</span>")
to_chat(user, "[bicon(src)]<span class='warning'>EFTPOS is not connected to an account.</span>")
else
..()