From 61328bdd7662b78bbf2bf69eafb89099a5d470f2 Mon Sep 17 00:00:00 2001
From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Date: Mon, 26 Oct 2020 19:25:26 +0000
Subject: [PATCH] [TGUI] Request Consoles (#14734)
* TGUI Request Consoles
* Mochi tewaks
* Else ill do this
---
code/game/machinery/requests_console.dm | 317 +++++++-------
code/modules/research/message_server.dm | 39 +-
nano/templates/request_console.tmpl | 152 -------
.../tgui/interfaces/RequestConsole.js | 401 ++++++++++++++++++
tgui/packages/tgui/public/tgui.bundle.js | 6 +-
5 files changed, 579 insertions(+), 336 deletions(-)
delete mode 100644 nano/templates/request_console.tmpl
create mode 100644 tgui/packages/tgui/interfaces/RequestConsole.js
diff --git a/code/game/machinery/requests_console.dm b/code/game/machinery/requests_console.dm
index 85799279ff4..981fb9fa2e1 100644
--- a/code/game/machinery/requests_console.dm
+++ b/code/game/machinery/requests_console.dm
@@ -27,6 +27,10 @@
#define COM_ROLES list("Blueshield","NT Representative","Head of Personnel's Desk","Captain's Desk","Bridge")
#define SCI_ROLES list("Robotics","Science","Research Director's Desk")
+#define RQ_NONEW_MESSAGES 0
+#define RQ_NORMALPRIORITY 1
+#define RQ_HIGHPRIORITY 2
+
GLOBAL_LIST_EMPTY(req_console_assistance)
GLOBAL_LIST_EMPTY(req_console_supplies)
GLOBAL_LIST_EMPTY(req_console_information)
@@ -35,7 +39,7 @@ GLOBAL_LIST_EMPTY(allRequestConsoles)
/obj/machinery/requests_console
name = "Requests Console"
desc = "A console intended to send requests to different departments on the station."
- anchored = 1
+ anchored = TRUE
icon = 'icons/obj/terminals.dmi'
icon_state = "req_comp0"
max_integrity = 300
@@ -43,19 +47,15 @@ GLOBAL_LIST_EMPTY(allRequestConsoles)
var/department = "Unknown" //The list of all departments on the station (Determined from this variable on each unit) Set this to the same thing if you want several consoles in one department
var/list/message_log = list() //List of all messages
var/departmentType = 0 //Bitflag. Zero is reply-only. Map currently uses raw numbers instead of defines.
- var/newmessagepriority = 0
- // 0 = no new message
- // 1 = normal priority
- // 2 = high priority
+ var/newmessagepriority = RQ_NONEW_MESSAGES
+ // RQ_NONEWMESSAGES = no new message
+ // RQ_NORMALPRIORITY = normal priority
+ // RQ_HIGHPRIORITY = high priority
var/screen = RCS_MAINMENU
- var/silent = 0 // set to 1 for it not to beep all the time
-// var/hackState = 0
- // 0 = not hacked
- // 1 = hacked
- var/announcementConsole = 0
- // 0 = This console cannot be used to send department announcements
- // 1 = This console can send department announcementsf
- var/open = 0 // 1 if open
+ var/silent = FALSE // set to TRUE for it not to beep all the time
+ var/announcementConsole = FALSE
+ // FALSE = This console cannot be used to send department announcements
+ // TRUE = This console can send department announcementsf
var/announceAuth = 0 //Will be set to 1 when you authenticate yourself for announcements
var/msgVerified = "" //Will contain the name of the person who varified it
var/msgStamped = "" //If a message is stamped, this will contain the stamp name
@@ -82,15 +82,15 @@ GLOBAL_LIST_EMPTY(allRequestConsoles)
else
icon_state = "req_comp[newmessagepriority]"
-/obj/machinery/requests_console/New()
+/obj/machinery/requests_console/Initialize(mapload)
Radio = new /obj/item/radio(src)
- Radio.listening = 1
- Radio.config(list("Engineering","Medical","Supply","Command","Science","Service","Security", "AI Private" = 0))
+ Radio.listening = TRUE
+ Radio.config(list("Engineering", "Medical", "Supply", "Command", "Science", "Service", "Security", "AI Private" = FALSE))
Radio.follow_target = src
- ..()
+ . = ..()
announcement.title = "[department] announcement"
- announcement.newscast = 0
+ announcement.newscast = FALSE
name = "[department] Requests Console"
GLOB.allRequestConsoles += src
@@ -101,14 +101,15 @@ GLOBAL_LIST_EMPTY(allRequestConsoles)
if(departmentType & RC_INFO)
GLOB.req_console_information |= department
+ // NOT BOOLEAN. DO NOT CONVERT.
set_light(1)
/obj/machinery/requests_console/Destroy()
GLOB.allRequestConsoles -= src
- var/lastDeptRC = 1
+ var/lastDeptRC = TRUE
for(var/obj/machinery/requests_console/Console in GLOB.allRequestConsoles)
if(Console.department == department)
- lastDeptRC = 0
+ lastDeptRC = FALSE
break
if(lastDeptRC)
if(departmentType & RC_ASSIST)
@@ -124,22 +125,22 @@ GLOBAL_LIST_EMPTY(allRequestConsoles)
if(stat & NOPOWER)
return
- ui_interact(user)
+ tgui_interact(user)
/obj/machinery/requests_console/attack_hand(user as mob)
if(..(user))
return
- ui_interact(user)
-/obj/machinery/requests_console/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)
+ tgui_interact(user)
+
+/obj/machinery/requests_console/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_default_state)
+ ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
- ui = new(user, src, ui_key, "request_console.tmpl", "[department] Request Console", 520, 410)
+ ui = new(user, src, ui_key, "RequestConsole", "[department] Request Console", 520, 410, master_ui, state)
ui.open()
- ui.set_auto_update(1)
-/obj/machinery/requests_console/ui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.default_state)
- var/data[0]
+/obj/machinery/requests_console/tgui_data(mob/user)
+ var/list/data = list()
data["department"] = department
data["screen"] = screen
@@ -164,142 +165,130 @@ GLOBAL_LIST_EMPTY(allRequestConsoles)
return data
-/obj/machinery/requests_console/Topic(href, href_list)
+/obj/machinery/requests_console/tgui_act(action, list/params)
if(..())
- return 1
- usr.set_machine(src)
+ return
+
add_fingerprint(usr)
- if(reject_bad_text(href_list["write"]))
- recipient = href_list["write"] //write contains the string of the receiving department's name
+ . = TRUE
- var/new_message = sanitize(input("Write your message:", "Awaiting Input", ""))
- if(new_message)
- message = new_message
- screen = RCS_MESSAUTH
- switch(href_list["priority"])
- if("1") priority = 1
- if("2") priority = 2
- else priority = 0
- else
- reset_message(1)
+ switch(action)
+ if("writeInput")
+ if(reject_bad_text(params["write"]))
+ recipient = params["write"] //write contains the string of the receiving department's name
- if(href_list["writeAnnouncement"])
- var/new_message = sanitize(input("Write your message:", "Awaiting Input", ""))
- if(new_message)
- message = new_message
- else
- reset_message(1)
+ var/new_message = sanitize(input("Write your message:", "Awaiting Input", ""))
+ if(new_message)
+ message = new_message
+ screen = RCS_MESSAUTH
+ switch(params["priority"])
+ if("1")
+ priority = RQ_NORMALPRIORITY
+ if("2")
+ priority = RQ_HIGHPRIORITY
+ else
+ priority = RQ_NONEW_MESSAGES
+ else
+ reset_message(TRUE)
- if(href_list["sendAnnouncement"])
- if(!announcementConsole) return
- announcement.Announce(message, msg_sanitized = 1)
- reset_message(1)
+ if("writeAnnouncement")
+ var/new_message = sanitize(input("Write your message:", "Awaiting Input", ""))
+ if(new_message)
+ message = new_message
+ else
+ reset_message(TRUE)
- if( href_list["department"] && message )
- var/log_msg = message
- var/pass = 0
- screen = RCS_SENTFAIL
- for(var/obj/machinery/message_server/MS in GLOB.machines)
- if(!MS.active) continue
- MS.send_rc_message(ckey(href_list["department"]),department,log_msg,msgStamped,msgVerified,priority)
- pass = 1
- if(pass)
- screen = RCS_SENTPASS
- if(recipient in ENGI_ROLES)
- radiochannel = "Engineering"
- if(recipient in SEC_ROLES)
- radiochannel = "Security"
- if(recipient in MISC_ROLES)
- radiochannel = "Service"
- if(recipient in MED_ROLES)
- radiochannel = "Medical"
- if(recipient in COM_ROLES)
- radiochannel = "Command"
- if(recipient in SCI_ROLES)
- radiochannel = "Science"
- if(recipient == "AI")
- radiochannel = "AI Private"
- if(recipient == "Cargo Bay")
- radiochannel = "Supply"
- message_log += "Message sent to [recipient] at [station_time_timestamp()]
[message]"
- Radio.autosay("Alert; a new requests console message received for [recipient] from [department]", null, "[radiochannel]")
- else
- atom_say("No server detected!")
+ if("sendAnnouncement")
+ if(!announcementConsole)
+ return
+ announcement.Announce(message, msg_sanitized = TRUE)
+ reset_message(TRUE)
- //Handle screen switching
- if(href_list["setScreen"])
- var/tempScreen = text2num(href_list["setScreen"])
- if(tempScreen == RCS_ANNOUNCE && !announcementConsole)
- return
- if(tempScreen == RCS_VIEWMSGS)
- for(var/obj/machinery/requests_console/Console in GLOB.allRequestConsoles)
- if(Console.department == department)
- Console.newmessagepriority = 0
- Console.icon_state = "req_comp0"
- Console.set_light(1)
- if(tempScreen == RCS_MAINMENU)
- reset_message()
- screen = tempScreen
+ if("department")
+ if(!message)
+ return
+ var/log_msg = message
+ var/pass = FALSE
+ screen = RCS_SENTFAIL
+ for(var/M in GLOB.message_servers)
+ var/obj/machinery/message_server/MS = M
+ if(!MS.active)
+ continue
+ MS.send_rc_message(ckey(params["department"]), department, log_msg, msgStamped, msgVerified, priority)
+ pass = TRUE
+ if(pass)
+ screen = RCS_SENTPASS
+ if(recipient in ENGI_ROLES)
+ radiochannel = "Engineering"
+ else if(recipient in SEC_ROLES)
+ radiochannel = "Security"
+ else if(recipient in MISC_ROLES)
+ radiochannel = "Service"
+ else if(recipient in MED_ROLES)
+ radiochannel = "Medical"
+ else if(recipient in COM_ROLES)
+ radiochannel = "Command"
+ else if(recipient in SCI_ROLES)
+ radiochannel = "Science"
+ else if(recipient == "AI")
+ radiochannel = "AI Private"
+ else if(recipient == "Cargo Bay")
+ radiochannel = "Supply"
+ message_log += "Message sent to [recipient] at [station_time_timestamp()] - [message]"
+ Radio.autosay("Alert; a new requests console message received for [recipient] from [department]", null, "[radiochannel]")
+ else
+ atom_say("No server detected!")
- if(href_list["shipSelect"])
- ship_tag_name = href_list["shipSelect"]
- ship_tag_index = GLOB.TAGGERLOCATIONS.Find(ship_tag_name)
+ //Handle screen switching
+ if("setScreen")
+ // Ensures screen cant be set higher or lower than it should be
+ var/tempScreen = round(clamp(text2num(params["setScreen"]), 0, 10), 1)
+ if(tempScreen == RCS_ANNOUNCE && !announcementConsole)
+ return
+ if(tempScreen == RCS_VIEWMSGS)
+ for(var/obj/machinery/requests_console/Console in GLOB.allRequestConsoles)
+ if(Console.department == department)
+ Console.newmessagepriority = RQ_NONEW_MESSAGES
+ Console.icon_state = "req_comp0"
+ Console.set_light(1)
+ if(tempScreen == RCS_MAINMENU)
+ reset_message()
+ screen = tempScreen
- //Handle Shipping Label Printing
- if(href_list["printLabel"])
- var/error_message = ""
- if(!ship_tag_index)
- error_message = "Please select a destination."
- else if(!msgVerified)
- error_message = "Please verify shipper ID."
- else if(world.time < print_cooldown)
- error_message = "Please allow the printer time to prepare the next shipping label."
- if(error_message)
- atom_say("[error_message]")
- return
- print_label(ship_tag_name, ship_tag_index)
- shipping_log += "Shipping Label printed for [ship_tag_name]
[msgVerified]"
- reset_message(1)
+ if("shipSelect")
+ ship_tag_name = params["shipSelect"]
+ ship_tag_index = GLOB.TAGGERLOCATIONS.Find(ship_tag_name)
- //Handle silencing the console
- if(href_list["toggleSilent"])
- silent = !silent
+ //Handle Shipping Label Printing
+ if("printLabel")
+ var/error_message
+ if(!ship_tag_index)
+ error_message = "Please select a destination."
+ else if(!msgVerified)
+ error_message = "Please verify shipper ID."
+ else if(world.time < print_cooldown)
+ error_message = "Please allow the printer time to prepare the next shipping label."
+ if(error_message)
+ atom_say("[error_message]")
+ return
+ print_label(ship_tag_name, ship_tag_index)
+ shipping_log += "Shipping Label printed for [ship_tag_name] - [msgVerified]"
+ reset_message(TRUE)
+
+ //Handle silencing the console
+ if("toggleSilent")
+ silent = !silent
- SSnanoui.update_uis(src)
- return
- //err... hacking code, which has no reason for existing... but anyway... it was once supposed to unlock priority 3 messanging on that console (EXTREME priority...), but the code for that was removed.
/obj/machinery/requests_console/attackby(obj/item/I, mob/user)
- /*
- if(istype(O, /obj/item/crowbar))
- if(open)
- open = 0
- icon_state="req_comp0"
- else
- open = 1
- if(hackState == 0)
- icon_state="req_comp_open"
- else if(hackState == 1)
- icon_state="req_comp_rewired"
- if(istype(O, /obj/item/screwdriver))
- if(open)
- if(hackState == 0)
- hackState = 1
- icon_state="req_comp_rewired"
- else if(hackState == 1)
- hackState = 0
- icon_state="req_comp_open"
- else
- to_chat(user, "You can't do much with that.")*/
-
if(istype(I, /obj/item/card/id))
if(inoperable(MAINT))
return
if(screen == RCS_MESSAUTH)
var/obj/item/card/id/T = I
- msgVerified = text("Verified by [T.registered_name] ([T.assignment])")
- updateUsrDialog()
+ msgVerified = "Verified by [T.registered_name] ([T.assignment])"
+ SStgui.update_uis(src)
if(screen == RCS_ANNOUNCE)
var/obj/item/card/id/ID = I
if(ACCESS_RC_ANNOUNCE in ID.GetAccess())
@@ -308,31 +297,31 @@ GLOBAL_LIST_EMPTY(allRequestConsoles)
else
reset_message()
to_chat(user, "You are not authorized to send announcements.")
- updateUsrDialog()
+ SStgui.update_uis(src)
if(screen == RCS_SHIPPING)
var/obj/item/card/id/T = I
- msgVerified = text("Sender verified as [T.registered_name] ([T.assignment])")
- updateUsrDialog()
+ msgVerified = "Sender verified as [T.registered_name] ([T.assignment])"
+ SStgui.update_uis(src)
if(istype(I, /obj/item/stamp))
if(inoperable(MAINT))
return
if(screen == RCS_MESSAUTH)
var/obj/item/stamp/T = I
- msgStamped = text("Stamped with the [T.name]")
- updateUsrDialog()
+ msgStamped = "Stamped with the [T.name]"
+ SStgui.update_uis(src)
else
return ..()
-/obj/machinery/requests_console/proc/reset_message(var/mainmenu = 0)
+/obj/machinery/requests_console/proc/reset_message(mainmenu = FALSE)
message = ""
recipient = ""
- priority = 0
+ priority = RQ_NONEW_MESSAGES
msgVerified = ""
msgStamped = ""
- announceAuth = 0
+ announceAuth = FALSE
announcement.announcer = ""
ship_tag_name = ""
- ship_tag_index = 0
+ ship_tag_index = FALSE
if(mainmenu)
screen = RCS_MAINMENU
@@ -340,23 +329,23 @@ GLOBAL_LIST_EMPTY(allRequestConsoles)
var/linkedSender
if(istype(source, /obj/machinery/requests_console))
var/obj/machinery/requests_console/sender = source
- linkedSender = ""
+ linkedSender = sender.department
else
capitalize(source)
linkedSender = source
capitalize(title)
- if(src.newmessagepriority < priority)
- src.newmessagepriority = priority
+ if(newmessagepriority < priority)
+ newmessagepriority = priority
update_icon()
- if(!src.silent)
- playsound(src.loc, 'sound/machines/twobeep.ogg', 50, 1)
+ if(!silent)
+ playsound(loc, 'sound/machines/twobeep.ogg', 50, TRUE)
atom_say(title)
switch(priority)
- if(2) // High
- src.message_log += "High Priority
From: [linkedSender]
[message]"
+ if(RQ_HIGHPRIORITY) // High
+ message_log += "High Priority - From: [linkedSender] - [message]"
else // Normal
- src.message_log += "From: [linkedSender]
[message]"
+ message_log += "From: [linkedSender] - [message]"
set_light(2)
/obj/machinery/requests_console/proc/print_label(tag_name, tag_index)
@@ -364,3 +353,7 @@ GLOBAL_LIST_EMPTY(allRequestConsoles)
sp.sortTag = tag_index
sp.update_desc()
print_cooldown = world.time + 600 //1 minute cooldown before you can print another label, but you can still configure the next one during this time
+
+#undef RQ_NONEW_MESSAGES
+#undef RQ_NORMALPRIORITY
+#undef RQ_HIGHPRIORITY
diff --git a/code/modules/research/message_server.dm b/code/modules/research/message_server.dm
index 009e4810d3e..7828d1b81a3 100644
--- a/code/modules/research/message_server.dm
+++ b/code/modules/research/message_server.dm
@@ -86,31 +86,32 @@ GLOBAL_LIST_EMPTY(message_servers)
/obj/machinery/message_server/proc/send_rc_message(var/recipient = "",var/sender = "",var/message = "",var/stamp = "", var/id_auth = "", var/priority = 1)
rc_msgs += new/datum/data_rc_msg(recipient,sender,message,stamp,id_auth)
- var/authmsg = "[message]
"
+ var/authmsg = "[message]"
if(id_auth)
- authmsg += "[id_auth]
"
+ authmsg += " - [id_auth]"
if(stamp)
- authmsg += "[stamp]
"
- for(var/obj/machinery/requests_console/Console in GLOB.allRequestConsoles)
- if(ckey(Console.department) == ckey(recipient))
- if(Console.inoperable())
- Console.message_log += "Message lost due to console failure.
Please contact [station_name()] system adminsitrator or AI for technical assistance.
"
+ authmsg += " - [stamp]"
+ for(var/C in GLOB.allRequestConsoles)
+ var/obj/machinery/requests_console/RC = C
+ if(ckey(RC.department) == ckey(recipient))
+ if(RC.inoperable())
+ RC.message_log += "Message lost due to console failure. Please contact [station_name()]'s system administrator or AI for technical assistance."
continue
- if(Console.newmessagepriority < priority)
- Console.newmessagepriority = priority
- Console.icon_state = "req_comp[priority]"
+ if(RC.newmessagepriority < priority)
+ RC.newmessagepriority = priority
+ RC.icon_state = "req_comp[priority]"
switch(priority)
if(2)
- if(!Console.silent)
- playsound(Console.loc, 'sound/machines/twobeep.ogg', 50, 1)
- Console.atom_say("PRIORITY Alert in [sender]")
- Console.message_log += "High Priority message from [sender]
[authmsg]"
+ if(!RC.silent)
+ playsound(RC.loc, 'sound/machines/twobeep.ogg', 50, 1)
+ RC.atom_say("PRIORITY Alert in [sender]")
+ RC.message_log += "High Priority message from [sender]: [authmsg]"
else
- if(!Console.silent)
- playsound(Console.loc, 'sound/machines/twobeep.ogg', 50, 1)
- Console.atom_say("Message from [sender]")
- Console.message_log += "Message from [sender]
[authmsg]"
- Console.set_light(2)
+ if(!RC.silent)
+ playsound(RC.loc, 'sound/machines/twobeep.ogg', 50, 1)
+ RC.atom_say("Message from [sender]")
+ RC.message_log += "Message [sender]: [authmsg]"
+ RC.set_light(2)
/obj/machinery/message_server/attack_hand(user as mob)
// to_chat(user, "There seem to be some parts missing from this server. They should arrive on the station in a few days, give or take a few CentComm delays.")
diff --git a/nano/templates/request_console.tmpl b/nano/templates/request_console.tmpl
deleted file mode 100644
index aaa8726f50a..00000000000
--- a/nano/templates/request_console.tmpl
+++ /dev/null
@@ -1,152 +0,0 @@
-
-
-{{if data.screen == 1}}
- Request assistance from another department.
{{:value}} - |
- {{:helper.link('Message', null, { 'write' : value , 'priority' : 1 })}} |
- {{:helper.link('High Priority', null, { 'write' : value , 'priority' : 2 })}} |
-
There are no available departments to request assistance from. |
{{:value}} - |
- {{:helper.link('Message', null, { 'write' : value , 'priority' : 1 })}} |
- {{:helper.link('High Priority', null, { 'write' : value , 'priority' : 2 })}} |
-
There are no available departments to request supplies from. |
{{:value}} - |
- {{:helper.link('Message', null, { 'write' : value , 'priority' : 1 })}} |
- {{:helper.link('High Priority', null, { 'write' : value , 'priority' : 2 })}} |
-
There are no available departments to relay information to. |
{{:value}} - |
- {{:helper.link('Select', null, { 'shipSelect' : value })}} |
-
There are no available shipping destinations. |