Skip to content

Commit

Permalink
feat(faxmachine): converts fax UI to TGUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Filatelele authored Jan 25, 2024
1 parent 9f551c9 commit 5792605
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 131 deletions.
228 changes: 98 additions & 130 deletions code/modules/paperwork/faxmachine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ GLOBAL_LIST_EMPTY(alldepartments)

GLOBAL_LIST_EMPTY(adminfaxes) //cache for faxes that have been sent to admins

#define FAX_PRINT_COOLDOWN 30 SECONDS
#define FAX_SEND_COOLDOWN 60 SECONDS

/obj/machinery/photocopier/faxmachine
name = "fax machine"
icon = 'icons/obj/library.dmi'
Expand All @@ -14,7 +17,7 @@ GLOBAL_LIST_EMPTY(adminfaxes) //cache for faxes that have been sent to admins
active_power_usage = 200 WATTS
layer = BELOW_OBJ_LAYER

var/obj/item/card/id/scan = null // identification
var/obj/item/card/id/inserted_id
var/authenticated = 0
var/sendcooldown = 0 // to avoid spamming fax messages
var/print_cooldown = 0 //to avoid spamming printing complaints
Expand All @@ -35,184 +38,153 @@ GLOBAL_LIST_EMPTY(adminfaxes) //cache for faxes that have been sent to admins
GLOB.alldepartments |= department

/obj/machinery/photocopier/faxmachine/Destroy()
QDEL_NULL(scan)
QDEL_NULL(inserted_id)
GLOB.allfaxes -= src
return ..()

/obj/machinery/photocopier/faxmachine/attack_hand(mob/user as mob)
user.set_machine(src)
/obj/machinery/photocopier/faxmachine/attack_hand(mob/user)
if(inoperable(MAINT))
return

var/dat = "<meta charset=\"utf-8\">Fax Machine<BR>"
if(user.lying || user.is_ic_dead())
return

var/scan_name
if(scan)
scan_name = scan.name
else
scan_name = "--------"
tgui_interact(user)

dat += "Confirm Identity: <a href='byond://?src=\ref[src];scan=1'>[scan_name]</a><br>"
/obj/machinery/photocopier/faxmachine/tgui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Fax")
ui.set_autoupdate(TRUE)
ui.open()

if(authenticated)
dat += "<a href='byond://?src=\ref[src];logout=1'>{Log Out}</a>"
else
dat += "<a href='byond://?src=\ref[src];auth=1'>{Log In}</a>"
/obj/machinery/photocopier/faxmachine/tgui_data(mob/user)
var/list/data = list(
"user" = user?.name,
"idCard" = inserted_id?.registered_name,
"authenticated" = check_access(inserted_id),
"paper" = copyitem?.name,
"printCooldown" = print_cooldown,
"canSend" = (world.time > sendcooldown ? TRUE : FALSE)
)

dat += "<hr>"
var/list/possible_destinations = GLOB.alldepartments + admin_departments

if(authenticated)
dat += "<b>Logged in to:</b> [GLOB.using_map.boss_name] Quantum Entanglement Network<br><br>"
for(var/fax in possible_destinations)
var/list/faxlist = list(
"fax_name" = fax
)
data["faxes"] += list(faxlist)

if(copyitem)
dat += "<a href='byond://?src=\ref[src];remove=1'>Remove Item</a><br><br>"
return data

if(sendcooldown)
dat += "<b>Transmitter arrays realigning. Please stand by.</b><br>"
/obj/machinery/photocopier/faxmachine/tgui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()

if(.)
return TRUE

switch(action)
if("idInteract")
if(inserted_id)
if(ishuman(usr))
usr.pick_or_drop(inserted_id, loc)
inserted_id = null
else
inserted_id.forceMove(loc)
inserted_id = null
else

dat += "<a href='byond://?src=\ref[src];send=1'>Send</a><br>"
dat += "<b>Currently sending:</b> [copyitem.name]<br>"
dat += "<b>Sending to:</b> <a href='byond://?src=\ref[src];dept=1'>[destination]</a><br>"

else
if(sendcooldown)
dat += "Please insert paper to send via secure connection.<br><br>"
dat += "<b>Transmitter arrays realigning. Please stand by.</b><br>"
var/obj/item/I = usr.get_active_hand()
if(istype(I, /obj/item/card/id) && usr.drop(I, src))
inserted_id = I
return TRUE
if("paperInteract")
if(copyitem)
usr.pick_or_drop(copyitem, loc)
to_chat(usr, SPAN_NOTICE("You take \the [copyitem] out of \the [src]."))
copyitem = null
else
dat += "Please insert paper to send via secure connection.<br><br>"
if (print_cooldown)
dat += "<b> Complaint printer is recharging. Please stand by. </b><br>"
else
dat += "<a href ='byond://?src=\ref[src];print_complaint=1'>Print complaint kit</a><br>"
else
dat += "Proper authentication is required to use this device.<br><br>"

if(copyitem)
dat += "<a href ='byond://?src=\ref[src];remove=1'>Remove Item</a><br>"
var/obj/item/I = usr.get_active_hand()
if(!istype(I, /obj/item/paper) && !istype(I, /obj/item/photo) && !istype(I, /obj/item/paper_bundle) && !istype(copyitem, /obj/item/complaint_folder))
return

if(!usr.drop(I, src))
return

show_browser(user, dat, "window=copier")
onclose(user, "copier")
return

/obj/machinery/photocopier/faxmachine/proc/print_cooldown_check()
if (print_cooldown)
return
print_cooldown = 30 SECONDS
addtimer(CALLBACK(src, nameof(.proc/go_off_print_cooldown)), print_cooldown)
return TRUE

/obj/machinery/photocopier/faxmachine/proc/go_off_print_cooldown()
print_cooldown = 0
copyitem = I
to_chat(usr, SPAN_NOTICE("You insert \the [I] into \the [src]."))
flick(insert_anim, src)
return TRUE
if("print_kit")
if(world.time < print_cooldown)
return

/obj/machinery/photocopier/faxmachine/Topic(href, href_list)
. = ..()
if (. != TOPIC_NOACTION)
return
if(href_list["print_complaint"])
if (print_cooldown_check())
playsound(src.loc, 'sound/signals/processing20.ogg', 25)
var/id = IAAJ_generate_fake_id()
ASSERT(id)
new /obj/item/complaint_folder(src.loc, id)
. = TOPIC_HANDLED
if(href_list["send"])
if(copyitem)
if (destination in admin_departments)
print_cooldown = world.time + FAX_PRINT_COOLDOWN
return TRUE
if("send")
if(world.time < sendcooldown)
return

if(params["destination"] in admin_departments)
playsound(src.loc, 'sound/signals/processing19.ogg', 25)
send_admin_fax(usr, destination)
else
INVOKE_ASYNC(src, send_admin_fax(.proc/sendfax), usr, params["destination"])
else if(params["destination"] in GLOB.alldepartments)
playsound(src.loc, 'sound/signals/processing19.ogg', 25)
sendfax(destination)

if (sendcooldown)
spawn(sendcooldown) // cooldown time
sendcooldown = 0

else if(href_list["remove"])
if(copyitem)
usr.pick_or_drop(copyitem, loc)
to_chat(usr, "<span class='notice'>You take \the [copyitem] out of \the [src].</span>")
copyitem = null
updateUsrDialog()

if(href_list["scan"])
if(scan)
if(ishuman(usr))
usr.pick_or_drop(scan, loc)
scan = null
else
scan.forceMove(loc)
scan = null
else
var/obj/item/I = usr.get_active_hand()
if (istype(I, /obj/item/card/id) && usr.drop(I, src))
scan = I
authenticated = 0

if(href_list["dept"])
var/lastdestination = destination
destination = input(usr, "Which department?", "Choose a department", "") as null|anything in (GLOB.alldepartments + admin_departments)
if(!destination) destination = lastdestination

if(href_list["auth"])
if ( (!( authenticated ) && (scan)) )
if (check_access(scan))
authenticated = 1

if(href_list["logout"])
authenticated = 0

updateUsrDialog()
INVOKE_ASYNC(src, nameof(.proc/sendfax), params["destination"])
return TRUE

/obj/machinery/photocopier/faxmachine/proc/sendfax(destination)
if(stat & (BROKEN|NOPOWER))
return

use_power_oneoff(200)
sendcooldown = world.time + FAX_SEND_COOLDOWN

var/success = 0
for(var/obj/machinery/photocopier/faxmachine/F in GLOB.allfaxes)
if( F.department == destination )
success = F.recievefax(copyitem)
if(F.department != destination)
continue

if (success)
visible_message("[src] beeps, \"Message transmitted successfully.\"")
//sendcooldown = 600
else
visible_message("[src] beeps, \"Error transmitting message.\"")
if(F.recievefax(copyitem))
show_splash_text(usr, "Message transmitted successfully.")

show_splash_text(usr, "Error transmitting message.")

/obj/machinery/photocopier/faxmachine/proc/recievefax(obj/item/incoming)
if(stat & (BROKEN|NOPOWER))
return 0
return FALSE

if(department == "Unknown")
return 0 //You can't send faxes to "Unknown"
return FALSE

flick("faxreceive", src)
playsound(loc, 'sound/machines/dotprinter.ogg', 50, 1)

// give the sprite some time to flick
sleep(20)

if (istype(incoming, /obj/item/paper))
if(istype(incoming, /obj/item/paper))
copy(incoming)
else if (istype(incoming, /obj/item/photo))
else if(istype(incoming, /obj/item/photo))
photocopy(incoming)
else if (istype(incoming, /obj/item/paper_bundle))
else if(istype(incoming, /obj/item/paper_bundle))
bundlecopy(incoming)
else
return 0
return FALSE

use_power_oneoff(active_power_usage)
return 1
return TRUE

/obj/machinery/photocopier/faxmachine/proc/send_admin_fax(mob/sender, destination)
if(stat & (BROKEN|NOPOWER))
return

use_power_oneoff(200)

sendcooldown = world.time + FAX_SEND_COOLDOWN

//recieved copies should not use toner since it's being used by admins only.
var/obj/item/rcvdcopy
if (istype(copyitem, /obj/item/paper))
Expand All @@ -225,20 +197,18 @@ GLOBAL_LIST_EMPTY(adminfaxes) //cache for faxes that have been sent to admins
var/obj/item/complaint_folder/CF = copyitem
var/fail_reason = CF.prevalidate()
if (fail_reason)
visible_message("[src] beeps, \"Error transmitting message: [fail_reason].\"")
sendcooldown = 100 //here to prevent spam
show_splash_text(usr, "Error transmitting message.")
return
rcvdcopy = complaintcopy(copyitem, 0)
else
visible_message("[src] beeps, \"Error transmitting message.\"")
show_splash_text(usr, "Error transmitting message.")
return

rcvdcopy.forceMove(null) //hopefully this shouldn't cause trouble
GLOB.adminfaxes += rcvdcopy

var/mob/intercepted = check_for_interception()


//message badmins that a fax has arrived
var/msg_color = null
if (destination == GLOB.using_map.boss_name)
Expand All @@ -264,10 +234,8 @@ GLOBAL_LIST_EMPTY(adminfaxes) //cache for faxes that have been sent to admins
if (fail_reason)
message_admins("Complaint postvalidation failed: [fail_reason]. Check received fax to manually correct it.")

sendcooldown = 1800
sleep(50)
visible_message("[src] beeps, \"Message transmitted successfully.\"")

show_splash_text(usr, "Message transmitted successfully.")

/obj/machinery/photocopier/faxmachine/proc/fax_message_admins(mob/sender, faxname, obj/item/sent, reply_type, font_colour="#006100")
var/msg = "<span class='notice'><b><font color='[font_colour]'>[faxname]: </font>[get_options_bar(sender, 2,1,1)]"
Expand Down
Loading

0 comments on commit 5792605

Please sign in to comment.