From 2c999ccef144f49a2252b6f939090e9d85204c14 Mon Sep 17 00:00:00 2001
From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Date: Wed, 21 Oct 2020 14:36:53 +0100
Subject: [PATCH] TGUI EFTPOS (#14683)
---
code/modules/economy/EFTPOS.dm | 144 +++++++++++------------
nano/templates/eftpos.tmpl | 53 ---------
tgui/packages/tgui/interfaces/EFTPOS.js | 130 ++++++++++++++++++++
tgui/packages/tgui/public/tgui.bundle.js | 4 +-
4 files changed, 203 insertions(+), 128 deletions(-)
delete mode 100644 nano/templates/eftpos.tmpl
create mode 100644 tgui/packages/tgui/interfaces/EFTPOS.js
diff --git a/code/modules/economy/EFTPOS.dm b/code/modules/economy/EFTPOS.dm
index f84b40ebb10..bfa3954af63 100644
--- a/code/modules/economy/EFTPOS.dm
+++ b/code/modules/economy/EFTPOS.dm
@@ -12,17 +12,16 @@
var/obj/machinery/computer/account_database/linked_db
var/datum/money_account/linked_account
-/obj/item/eftpos/New()
- ..()
+/obj/item/eftpos/Initialize(mapload)
machine_name = "[station_name()] EFTPOS #[GLOB.num_financial_terminals++]"
access_code = rand(1111,111111)
reconnect_database()
- spawn(0)
- print_reference()
+ print_reference()
//by default, connect to the station account
//the user of the EFTPOS device can change the target account though, and no-one will be the wiser (except whoever's being charged)
linked_account = GLOB.station_account
+ return ..()
/obj/item/eftpos/proc/print_reference()
playsound(loc, 'sound/goonstation/machines/printer_thermal.ogg', 50, 1)
@@ -55,7 +54,7 @@
break
/obj/item/eftpos/attack_self(mob/user)
- ui_interact(user)
+ tgui_interact(user)
/obj/item/eftpos/attackby(obj/O, mob/user, params)
if(istype(O, /obj/item/card))
@@ -65,7 +64,7 @@
if(linked_db)
if(linked_account)
scan_card(O, user)
- SSnanoui.update_uis(src)
+ SStgui.update_uis(src)
else
to_chat(user, "[bicon(src)]Unable to connect to linked account.")
else
@@ -73,14 +72,14 @@
else
return ..()
-/obj/item/eftpos/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
- ui = SSnanoui.try_update_ui(user, src, ui_key, ui, force_open)
+/obj/item/eftpos/tgui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/tgui_state/state = GLOB.tgui_inventory_state)
+ ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
- ui = new(user, src, ui_key, "eftpos.tmpl", name, 790, 310)
+ ui = new(user, src, ui_key, "EFTPOS", name, 800, 300, master_ui, state)
ui.open()
-/obj/item/eftpos/ui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.default_state)
- var/data[0]
+/obj/item/eftpos/tgui_data(mob/user)
+ var/list/data = list()
data["machine_name"] = machine_name
data["transaction_locked"] = transaction_locked
data["transaction_paid"] = transaction_paid
@@ -89,76 +88,75 @@
data["linked_account"] = linked_account ? linked_account.owner_name : null
return data
-/obj/item/eftpos/Topic(href, list/href_list)
+/obj/item/eftpos/tgui_act(action, list/params)
if(..())
- return 1
+ return
- if(href_list["choice"])
- switch(href_list["choice"])
- if("change_code")
- var/attempt_code = input("Re-enter the current EFTPOS access code", "Confirm old EFTPOS code") as num
+ . = TRUE
+
+ switch(action)
+ if("change_code")
+ var/attempt_code = input("Re-enter the current EFTPOS access code", "Confirm old EFTPOS code") as num
+ if(attempt_code == access_code)
+ var/trycode = input("Enter a new access code for this device (4-6 digits, numbers only)", "Enter new EFTPOS code") as num
+ if(trycode >= 1000 && trycode <= 999999)
+ access_code = trycode
+ else
+ alert("That is not a valid code!")
+ print_reference()
+ else
+ to_chat(usr, "[bicon(src)]Incorrect code entered.")
+ if("link_account")
+ if(!linked_db)
+ reconnect_database()
+ if(linked_db)
+ var/attempt_account_num = input("Enter account number to pay EFTPOS charges into", "New account number") as num
+ var/attempt_pin = input("Enter pin code", "Account pin") as num
+ linked_account = attempt_account_access(attempt_account_num, attempt_pin, 1)
+ else
+ to_chat(usr, "[bicon(src)]Unable to connect to accounts database.")
+ if("trans_purpose")
+ var/purpose = clean_input("Enter reason for EFTPOS transaction", "Transaction purpose", transaction_purpose)
+ if(purpose)
+ transaction_purpose = purpose
+ if("trans_value")
+ 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
+ transaction_amount = try_num
+ if("toggle_lock")
+ if(transaction_locked)
+ var/attempt_code = input("Enter EFTPOS access code", "Reset Transaction") as num
if(attempt_code == access_code)
- var/trycode = input("Enter a new access code for this device (4-6 digits, numbers only)", "Enter new EFTPOS code") as num
- if(trycode >= 1000 && trycode <= 999999)
- access_code = trycode
- else
- alert("That is not a valid code!")
- print_reference()
- else
- to_chat(usr, "[bicon(src)]Incorrect code entered.")
- if("link_account")
- if(!linked_db)
- reconnect_database()
- if(linked_db)
- var/attempt_account_num = input("Enter account number to pay EFTPOS charges into", "New account number") as num
- var/attempt_pin = input("Enter pin code", "Account pin") as num
- linked_account = attempt_account_access(attempt_account_num, attempt_pin, 1)
- else
- to_chat(usr, "[bicon(src)]Unable to connect to accounts database.")
- if("trans_purpose")
- var/purpose = clean_input("Enter reason for EFTPOS transaction", "Transaction purpose", transaction_purpose)
- if(purpose)
- transaction_purpose = purpose
- if("trans_value")
- 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
- transaction_amount = try_num
- if("toggle_lock")
- if(transaction_locked)
- var/attempt_code = input("Enter EFTPOS access code", "Reset Transaction") as num
- if(attempt_code == access_code)
- transaction_locked = 0
- transaction_paid = 0
- else if(linked_account)
- transaction_locked = 1
- else
- to_chat(usr, "[bicon(src)]No account connected to send transactions to.")
- if("scan_card")
- //attempt to connect to a new db, and if that doesn't work then fail
- if(!linked_db)
- reconnect_database()
- if(linked_db && linked_account)
- var/obj/item/I = usr.get_active_hand()
- if(istype(I, /obj/item/card))
- scan_card(I, usr)
- else
- to_chat(usr, "[bicon(src)]Unable to link accounts.")
- if("reset")
- //reset the access code - requires HoP/captain access
+ transaction_locked = 0
+ transaction_paid = 0
+ else if(linked_account)
+ transaction_locked = 1
+ else
+ to_chat(usr, "[bicon(src)]No account connected to send transactions to.")
+ if("scan_card")
+ //attempt to connect to a new db, and if that doesn't work then fail
+ if(!linked_db)
+ reconnect_database()
+ if(linked_db && linked_account)
var/obj/item/I = usr.get_active_hand()
if(istype(I, /obj/item/card))
- var/obj/item/card/id/C = I
- if((ACCESS_CENT_COMMANDER in C.access) || (ACCESS_HOP in C.access) || (ACCESS_CAPTAIN in C.access))
- access_code = 0
- to_chat(usr, "[bicon(src)]Access code reset to 0.")
- else if(istype(I, /obj/item/card/emag))
+ scan_card(I, usr)
+ else
+ to_chat(usr, "[bicon(src)]Unable to link accounts.")
+ if("reset")
+ //reset the access code - requires HoP/captain access
+ var/obj/item/I = usr.get_active_hand()
+ if(istype(I, /obj/item/card))
+ var/obj/item/card/id/C = I
+ if((ACCESS_CENT_COMMANDER in C.access) || (ACCESS_HOP in C.access) || (ACCESS_CAPTAIN in C.access))
access_code = 0
to_chat(usr, "[bicon(src)]Access code reset to 0.")
+ else if(istype(I, /obj/item/card/emag))
+ access_code = 0
+ to_chat(usr, "[bicon(src)]Access code reset to 0.")
- SSnanoui.update_uis(src)
- return 1
/obj/item/eftpos/proc/scan_card(obj/item/card/I, mob/user)
if(istype(I, /obj/item/card/id))
diff --git a/nano/templates/eftpos.tmpl b/nano/templates/eftpos.tmpl
deleted file mode 100644
index 15f6aae465e..00000000000
--- a/nano/templates/eftpos.tmpl
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
-This terminal is {{:data.machine_name}}. Report this code when contacting Nanotrasen IT Support
-{{if data.transaction_locked == 1}}
-