From a7848ee5be811fac192d3a702ad932afa85c6b92 Mon Sep 17 00:00:00 2001 From: Ryan <80364400+Sirryan2002@users.noreply.github.com> Date: Wed, 22 Feb 2023 19:26:02 -0500 Subject: [PATCH] EFTPOS Tweaks + TGUI makeover (#20095) * eftpos changes * Apply suggestions from code review Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com> * request changes * tgui rebuild * Update code/modules/economy/economy_machinery/eftpos.dm Co-authored-by: Vi3trice <80771500+Vi3trice@users.noreply.github.com> --------- Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com> Co-authored-by: Vi3trice <80771500+Vi3trice@users.noreply.github.com> --- .../economy/economy_machinery/eftpos.dm | 55 +++--- tgui/packages/tgui/interfaces/EFTPOS.js | 169 +++++++++--------- tgui/packages/tgui/public/tgui.bundle.js | 4 +- 3 files changed, 121 insertions(+), 107 deletions(-) diff --git a/code/modules/economy/economy_machinery/eftpos.dm b/code/modules/economy/economy_machinery/eftpos.dm index c810a6a5f72..22681fa67c6 100644 --- a/code/modules/economy/economy_machinery/eftpos.dm +++ b/code/modules/economy/economy_machinery/eftpos.dm @@ -6,30 +6,33 @@ icon = 'icons/obj/device.dmi' icon_state = "eftpos" w_class = WEIGHT_CLASS_SMALL + /// Unique identifying name of this EFTPOS for transaction tracking in money accounts var/machine_name = "" - var/transaction_locked = 0 - var/transaction_paid = 0 + /// Whether or not the EFTPOS is locked into a transaction + var/transaction_locked = FALSE + /// Did the transaction go through? Will reset back to FALSE after 5 seconds, used as a cooldown and indicator to consumer + var/transaction_paid = FALSE + /// Amount in space credits to charge card swiper var/transaction_amount = 0 var/transaction_purpose = "Default charge" + /// The pin number needed to changed settings on the EFTPOS var/access_code var/transaction_sound = 'sound/machines/chime.ogg' ///linked money account database to this EFTPOS - var/datum/money_account_database/account_database + var/datum/money_account_database/main_station/account_database ///Current money account the EFTPOS is depositing to var/datum/money_account/linked_account /obj/item/eftpos/Initialize(mapload) - machine_name = "[station_name()] EFTPOS #[rand(101,999)]" + machine_name = "EFTPOS #[rand(101, 999)]" access_code = rand(1000, 9999) reconnect_database() + //linked account starts as service account by default + linked_account = account_database.get_account_by_department(DEPARTMENT_SERVICE) print_reference() - - //by default, connect to the station vendor account - linked_account = GLOB.station_money_database.vendor_account return ..() - /obj/item/eftpos/proc/reconnect_database() account_database = GLOB.station_money_database @@ -55,7 +58,7 @@ /obj/item/eftpos/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.inventory_state) ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open) if(!ui) - ui = new(user, src, ui_key, "EFTPOS", name, 800, 300, master_ui, state) + ui = new(user, src, ui_key, "EFTPOS", name, 500, 250, master_ui, state) ui.open() /obj/item/eftpos/ui_data(mob/user) @@ -65,7 +68,16 @@ data["transaction_paid"] = transaction_paid data["transaction_purpose"] = transaction_purpose data["transaction_amount"] = transaction_amount - data["linked_account"] = linked_account ? linked_account.account_name : null + data["linked_account"] = list("name" = linked_account?.account_name, "UID" = linked_account?.UID()) + data["available_accounts"] = list() + for(var/datum/money_account/department as anything in (account_database.get_all_department_accounts() + account_database.user_accounts)) + var/list/account_data = list( + "name" = department.account_name, + "UID" = department.UID() + ) + data["available_accounts"] += list(account_data) + + return data /obj/item/eftpos/ui_act(action, list/params, datum/tgui/ui) @@ -95,7 +107,7 @@ if(account_database) 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 - if(!check_user_position(user)) + if(!check_user_position(user) || !account_database) return var/datum/money_account/target_account = GLOB.station_money_database.find_user_account(attempt_account_num, include_departments = TRUE) if(!target_account) @@ -109,6 +121,14 @@ to_chat(user, "[bicon(src)]Unable to connect to inputed account.") else to_chat(user, "[bicon(src)]Unable to connect to accounts database.") + return + var/datum/money_account/target_account = locateUID(params["account"]) + if(!istype(target_account)) + to_chat(user, "[bicon(src)]Unable to connect to inputted account.") + return + // in this case we don't care about authenticating login because we're sending money into the account + linked_account = target_account + to_chat(user, "[bicon(src)]Linked account successfully set to [target_account.account_name]") if("trans_purpose") var/purpose = clean_input("Enter reason for EFTPOS transaction", "Transaction purpose", transaction_purpose) if(!check_user_position(user)) @@ -138,16 +158,6 @@ transaction_locked = TRUE else to_chat(user, "[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(!account_database) - reconnect_database() - if(account_database && linked_account) - var/obj/item/I = user.get_active_hand() - if(istype(I, /obj/item/card)) - scan_card(I, user) - else - to_chat(user, "[bicon(src)]Unable to link accounts.") if("reset") //reset the access code - requires HoP/captain access var/obj/item/I = user.get_active_hand() @@ -182,7 +192,7 @@ if(!D || !GLOB.station_money_database.try_authenticate_login(D, attempt_pin, restricted_bypass = FALSE)) to_chat(user, "[bicon(src)]Unable to access account, insufficient access.") return - if(alert("Are you sure you want to pay $[transaction_amount] to Account: [linked_account.account_name] ", "Confirm transaction", "Yes", "No") != "Yes") + if(alert("Are you sure you want to pay $[transaction_amount] to: [linked_account.account_name] ", "Confirm transaction", "Yes", "No") != "Yes") return if(!Adjacent(user)) return @@ -194,6 +204,7 @@ playsound(src, transaction_sound, 50, TRUE) visible_message("[src] chimes!") transaction_paid = TRUE + addtimer(VARSET_CALLBACK(src, transaction_paid, FALSE), 5 SECONDS) ///creates and builds paper with info about the EFTPOS /obj/item/eftpos/proc/print_reference() diff --git a/tgui/packages/tgui/interfaces/EFTPOS.js b/tgui/packages/tgui/interfaces/EFTPOS.js index c245d7c9f2e..f80f984368d 100644 --- a/tgui/packages/tgui/interfaces/EFTPOS.js +++ b/tgui/packages/tgui/interfaces/EFTPOS.js @@ -1,5 +1,6 @@ -import { useBackend } from '../backend'; -import { Box, Button, LabeledList, NoticeBox, Section } from '../components'; +import { createSearch } from 'common/string'; +import { useBackend, useLocalState } from "../backend"; +import { Box, Button, LabeledList, Section, Input, Dropdown } from '../components'; import { Window } from '../layouts'; export const EFTPOS = (props, context) => { @@ -8,11 +9,25 @@ export const EFTPOS = (props, context) => { return ( - - This terminal is {machine_name}. Report this code when contacting - Nanotrasen IT Support. - - {transaction_locked ? : } +
+
+
); @@ -21,94 +36,82 @@ export const EFTPOS = (props, context) => { const LockedView = (props, context) => { const { act, data } = useBackend(context); const { - transaction_purpose, transaction_amount, - linked_account, transaction_paid, } = data; return ( -
- - - {transaction_purpose} - - - {/* Ternary required otherwise the 0 is offset weirdly */} - {transaction_amount ? transaction_amount : '0'} - - - {linked_account ? linked_account : 'None'} - - -
+ + ); }; const UnlockedView = (props, context) => { const { act, data } = useBackend(context); - const { transaction_purpose, transaction_amount, linked_account } = data; + const [searchText, setSearchText] = useLocalState(context, 'searchText', ''); + const { + transaction_purpose, + transaction_amount, + linked_account, + available_accounts + } = data; + + let accountMap = [] + available_accounts.map(account => ( + accountMap[account.name] = account.UID + )) return ( -
- - -
+ + +