From ab171de57462560b731e621c8af9a00c4dca8ab6 Mon Sep 17 00:00:00 2001 From: CHOMPStation2StaffMirrorBot <94713762+CHOMPStation2StaffMirrorBot@users.noreply.github.com> Date: Thu, 6 Mar 2025 18:06:09 -0700 Subject: [PATCH] [MIRROR] tgui say update (#10323) Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com> --- code/__defines/text.dm | 2 ++ code/modules/tgui/tgui.dm | 24 +++++++++++++ code/modules/tgui_input/say_modal/modal.dm | 32 ++++++++++++++--- code/modules/tgui_input/text.dm | 2 +- .../tgui-panel/styles/components/Ping.scss | 1 + tgui/packages/tgui-say/TguiSay.tsx | 18 +++++++--- tgui/packages/tgui-say/styles/styles.scss | 2 +- tgui/packages/tgui/constants.ts | 35 +++++++++++-------- .../tgui/interfaces/common/RankIcon.tsx | 16 ++++----- tgui/public/tgui.html | 18 ++++++++++ tools/build/build.js | 1 + 11 files changed, 118 insertions(+), 33 deletions(-) diff --git a/code/__defines/text.dm b/code/__defines/text.dm index b48754dd32..6885d859cb 100644 --- a/code/__defines/text.dm +++ b/code/__defines/text.dm @@ -11,3 +11,5 @@ /// Simply removes the < and > characters, and limits the length of the message. #define STRIP_HTML_SIMPLE(text, limit) (GLOB.angular_brackets.Replace(copytext(text, 1, limit), "")) + +#define MAX_MESSAGE_CHUNKS 130 diff --git a/code/modules/tgui/tgui.dm b/code/modules/tgui/tgui.dm index f337b41cdc..105db02945 100644 --- a/code/modules/tgui/tgui.dm +++ b/code/modules/tgui/tgui.dm @@ -45,6 +45,8 @@ var/datum/tgui/parent_ui /// Children of this UI var/list/children = list() + /// Any partial packets that we have received from TGUI, waiting to be sent + var/partial_packets /** * public @@ -349,6 +351,28 @@ // Pass act type messages to tgui_act if(type && copytext(type, 1, 5) == "act/") var/act_type = copytext(type, 5) + var/id = href_list["packetId"] + if(!isnull(id)) + id = text2num(id) + + var/total = text2num(href_list["totalPackets"]) + if(id == 1) + if(total > MAX_MESSAGE_CHUNKS) + return + + partial_packets = new /list(total) + + partial_packets[id] = href_list["packet"] + + if(id != total) + return + + var/assembled_payload = "" + for(var/packet in partial_packets) + assembled_payload += packet + + payload = json_decode(assembled_payload) + partial_packets = null #ifdef TGUI_DEBUGGING log_tgui(user, "Action: [act_type] [href_list["payload"]], Window: [window.id], Source: [src_object]") #endif diff --git a/code/modules/tgui_input/say_modal/modal.dm b/code/modules/tgui_input/say_modal/modal.dm index 17f229da49..ce48695ef3 100644 --- a/code/modules/tgui_input/say_modal/modal.dm +++ b/code/modules/tgui_input/say_modal/modal.dm @@ -31,6 +31,8 @@ var/datum/tgui_window/window /// Boolean for whether the tgui_say was opened by the user. var/window_open + /// Any partial packets that we have received from TGUI, waiting to be sent + var/partial_packets /** Creates the new input window to exist in the background. */ /datum/tgui_say/New(client/client, id) @@ -64,14 +66,14 @@ /datum/tgui_say/proc/load() window_open = FALSE - var/minimum_height = client?.prefs?.read_preference(/datum/preference/numeric/tgui_say_height) || 1 - var/minimu_width = client?.prefs?.read_preference(/datum/preference/numeric/tgui_say_width) || 1 + var/minimum_width = client?.prefs?.read_preference(/datum/preference/numeric/tgui_say_width) || 1 + var/minimum_height = (client?.prefs?.read_preference(/datum/preference/numeric/tgui_say_height) || 1) * 20 + 10 winset(client, "tgui_say", "pos=410,400;size=360,30;is-visible=0;") window.send_message("props", list( lightMode = client?.prefs?.read_preference(/datum/preference/toggle/tgui_say_light), + minimumWidth = minimum_width, minimumHeight = minimum_height, - minimumWidth = minimu_width, maxLength = max_length, )) @@ -106,7 +108,7 @@ * The equivalent of ui_act, this waits on messages from the window * and delegates actions. */ -/datum/tgui_say/proc/on_message(type, payload) +/datum/tgui_say/proc/on_message(type, payload, href_list) if(type == "ready") load() return TRUE @@ -128,6 +130,28 @@ start_typing(payload["channel"]) return TRUE if(type == "entry" || type == "force") + var/id = href_list["packetId"] + if(!isnull(id)) + id = text2num(id) + + var/total = text2num(href_list["totalPackets"]) + if(id == 1) + if(total > MAX_MESSAGE_CHUNKS) + return + + partial_packets = new /list(total) + + partial_packets[id] = href_list["packet"] + + if(id != total) + return + + var/assembled_payload = "" + for(var/packet in partial_packets) + assembled_payload += packet + + payload = json_decode(assembled_payload) + partial_packets = null handle_entry(type, payload) return TRUE if(type == "lenwarn") diff --git a/code/modules/tgui_input/text.dm b/code/modules/tgui_input/text.dm index a4a7f080a5..b1b02e2052 100644 --- a/code/modules/tgui_input/text.dm +++ b/code/modules/tgui_input/text.dm @@ -15,7 +15,7 @@ * * encode - Toggling this determines if input is filtered via html_encode. Setting this to FALSE gives raw input. * * timeout - The timeout of the textbox, after which the modal will close and qdel itself. Set to zero for no timeout. */ -/proc/tgui_input_text(mob/user, message = "", title = "Text Input", default, max_length = INFINITY, multiline = FALSE, encode = FALSE, timeout = 0, prevent_enter = FALSE) +/proc/tgui_input_text(mob/user, message = "", title = "Text Input", default, max_length = 130000, multiline = FALSE, encode = FALSE, timeout = 0, prevent_enter = FALSE) // 130k limit due to chunking limit... if we need longer that needs fixing if (!user) user = usr if (!istype(user)) diff --git a/tgui/packages/tgui-panel/styles/components/Ping.scss b/tgui/packages/tgui-panel/styles/components/Ping.scss index 251b0fd953..b3796c343d 100644 --- a/tgui/packages/tgui-panel/styles/components/Ping.scss +++ b/tgui/packages/tgui-panel/styles/components/Ping.scss @@ -14,6 +14,7 @@ $border-color: rgba(140, 140, 140, 0.5) !default; border-radius: 0.25em; width: 3.75em; text-align: right; + user-select: 'none'; } .Ping__indicator { diff --git a/tgui/packages/tgui-say/TguiSay.tsx b/tgui/packages/tgui-say/TguiSay.tsx index 2d93c4b835..ffa9c74355 100644 --- a/tgui/packages/tgui-say/TguiSay.tsx +++ b/tgui/packages/tgui-say/TguiSay.tsx @@ -20,6 +20,8 @@ import { byondMessages } from './timers'; type ByondOpen = { channel: Channel; + minimumWidth: number; + minimumHeight: number; }; type ByondProps = { @@ -287,8 +289,8 @@ export function TguiSay() { function handleOpen(data: ByondOpen): void { setTimeout(() => { innerRef.current?.focus(); - windowSet(WindowSize.Width, WindowSize.Small); - setSize(WindowSize.Width); + setSize(minimumHeight); + windowSet(minimumWidth, minimumHeight); }, 1); const { channel } = data; @@ -339,7 +341,7 @@ export function TguiSay() { } else { newSize = WindowSize.Small; } - newSize = clamp(newSize, minimumHeight * 20 + 10, WindowSize.Max); + newSize = clamp(newSize, minimumHeight, WindowSize.Max); if (size !== newSize) { setSize(newSize); @@ -370,16 +372,24 @@ export function TguiSay() { {buttonContent}