* TGUI Say

* Add icon_ref_map.json to make tgui-dev-server stop screaming

* Update tgui.bundle.js

* bundle recompile

---------

Co-authored-by: Heroman3003 <31296024+Heroman3003@users.noreply.github.com>
Co-authored-by: Heroman <alesha3000@list.ru>
This commit is contained in:
ShadowLarkens
2024-08-11 12:48:06 -07:00
committed by GitHub
parent bd1d79aebf
commit 7a7920f29e
53 changed files with 2502 additions and 339 deletions
+129
View File
@@ -0,0 +1,129 @@
/** Assigned say modal of the client */
/client/var/datum/tgui_say/tgui_say
/**
* Creates a JSON encoded message to open TGUI say modals properly.
*
* Arguments:
* channel - The channel to open the modal in.
* Returns:
* string - A JSON encoded message to open the modal.
*/
/client/proc/tgui_say_create_open_command(channel)
var/message = TGUI_CREATE_MESSAGE("open", list(
channel = channel,
))
return "\".output tgui_say.browser:update [message]\""
/**
* The tgui say modal. This initializes an input window which hides until
* the user presses one of the speech hotkeys. Once something is entered, it will
* delegate the speech to the proper channel.
*/
/datum/tgui_say
/// The user who opened the window
var/client/client
/// Injury phrases to blurt out
var/list/hurt_phrases = list("GACK!", "GLORF!", "OOF!", "AUGH!", "OW!", "URGH!", "HRNK!")
/// Max message length
var/max_length = MAX_MESSAGE_LEN
/// The modal window
var/datum/tgui_window/window
/// Boolean for whether the tgui_say was opened by the user.
var/window_open
/** Creates the new input window to exist in the background. */
/datum/tgui_say/New(client/client, id)
src.client = client
window = new(client, id)
winset(client, "tgui_say", "size=1,1;is-visible=0;")
window.subscribe(src, PROC_REF(on_message))
window.is_browser = TRUE
/**
* After a brief period, injects the scripts into
* the window to listen for open commands.
*/
/datum/tgui_say/proc/initialize()
set waitfor = FALSE
// Sleep to defer initialization to after client constructor
sleep(3 SECONDS)
window.initialize(
strict_mode = TRUE,
fancy = TRUE,
inline_css = file("tgui/public/tgui-say.bundle.css"),
inline_js = file("tgui/public/tgui-say.bundle.js"),
);
/**
* Ensures nothing funny is going on window load.
* Minimizes the window, sets max length, closes all
* typing and thinking indicators. This is triggered
* as soon as the window sends the "ready" message.
*/
/datum/tgui_say/proc/load()
window_open = FALSE
winset(client, "tgui_say", "pos=410,400;size=360,30;is-visible=0;")
window.send_message("props", list(
lightMode = client.is_preference_enabled(/datum/client_preference/tgui_say_light),
maxLength = max_length,
))
stop_thinking()
return TRUE
/**
* Sets the window as "opened" server side, though it is already
* visible to the user. We do this to set local vars &
* start typing (if enabled and in an IC channel). Logs the event.
*
* Arguments:
* payload - A list containing the channel the window was opened in.
*/
/datum/tgui_say/proc/open(payload)
if(!payload?["channel"])
CRASH("No channel provided to an open TGUI-Say")
window_open = TRUE
if(payload["channel"] != OOC_CHANNEL && payload["channel"] != ADMIN_CHANNEL)
start_thinking()
return TRUE
/**
* Closes the window serverside. Closes any open chat bubbles
* regardless of preference. Logs the event.
*/
/datum/tgui_say/proc/close()
window_open = FALSE
stop_thinking()
/**
* The equivalent of ui_act, this waits on messages from the window
* and delegates actions.
*/
/datum/tgui_say/proc/on_message(type, payload)
if(type == "ready")
load()
return TRUE
if(type == "open")
open(payload)
return TRUE
if(type == "close")
close()
return TRUE
if(type == "thinking")
if(payload["visible"] == TRUE)
start_thinking(payload["channel"])
return TRUE
if(payload["visible"] == FALSE)
stop_thinking(payload["channel"])
return TRUE
return FALSE
if(type == "typing")
start_typing(payload["channel"])
return TRUE
if(type == "entry" || type == "force")
handle_entry(type, payload)
return TRUE
return FALSE
+106
View File
@@ -0,0 +1,106 @@
/**
* Alters text when players are injured.
* Adds text, trims left and right side
*
* Arguments:
* payload - a string list containing entry & channel
* Returns:
* string - the altered entry
*/
/datum/tgui_say/proc/alter_entry(payload)
var/entry = payload["entry"]
/// No OOC leaks
if(!entry || payload["channel"] == OOC_CHANNEL || payload["channel"] == ME_CHANNEL || payload["channel"] == LOOC_CHANNEL)
return pick(hurt_phrases)
/// Random trimming for larger sentences
if(length(entry) > 50)
entry = trim(entry, rand(40, 50))
else
/// Otherwise limit trim to just last letter
if(length(entry) > 1)
entry = trim(entry, length(entry))
return entry + "-" + pick(hurt_phrases)
/**
* Delegates the speech to the proper channel.
*
* Arguments:
* entry - the text to broadcast
* channel - the channel to broadcast in
* Returns:
* boolean - on success or failure
*/
/datum/tgui_say/proc/delegate_speech(entry, channel)
switch(channel)
if(SAY_CHANNEL)
client.mob.say_verb(entry)
return TRUE
if(RADIO_CHANNEL)
client.mob.say_verb(";" + entry)
return TRUE
if(ME_CHANNEL)
client.mob.me_verb(entry)
return TRUE
if(WHIS_CHANNEL)
client.mob.whisper(entry)
return TRUE
if(SUBTLE_CHANNEL)
client.mob.me_verb_subtle(entry)
return TRUE
if(OOC_CHANNEL)
client.ooc(entry)
return TRUE
if(LOOC_CHANNEL)
client.looc(entry)
return TRUE
if(ADMIN_CHANNEL)
if(check_rights(R_ADMIN, show_msg = FALSE))
client.cmd_admin_say(entry)
return TRUE
return FALSE
/**
* Force say handler.
* Sends a message to the say modal to send its current value.
*/
// /datum/tgui_say/proc/force_say()
// window.send_message("force")
// stop_typing()
/**
* Makes the player force say what's in their current input box.
*/
// /mob/living/carbon/human/proc/force_say()
// if(stat != CONSCIOUS || !client?.tgui_say?.window_open)
// return FALSE
// client.tgui_say.force_say()
// if(client.typing_indicators)
// log_speech_indicators("[key_name(client)] FORCED to stop typing, indicators enabled.")
// else
// log_speech_indicators("[key_name(client)] FORCED to stop typing, indicators DISABLED.")
// SEND_SIGNAL(src, COMSIG_HUMAN_FORCESAY)
/**
* Handles text entry and forced speech.
*
* Arguments:
* type - a string "entry" or "force" based on how this function is called
* payload - a string list containing entry & channel
* Returns:
* boolean - success or failure
*/
/datum/tgui_say/proc/handle_entry(type, payload)
if(!payload?["channel"] || !payload["entry"])
CRASH("[usr] entered in a null payload to the chat window.")
if(length(payload["entry"]) > max_length)
CRASH("[usr] has entered more characters than allowed into a TGUI-Say")
if(type == "entry")
delegate_speech(payload["entry"], payload["channel"])
return TRUE
if(type == "force")
var/target_channel = payload["channel"]
if(target_channel == ME_CHANNEL || target_channel == OOC_CHANNEL || target_channel == LOOC_CHANNEL)
target_channel = SAY_CHANNEL // No ooc leaks - this is fine because alter_entry will override this completely
delegate_speech(alter_entry(payload), target_channel)
return TRUE
return FALSE
@@ -0,0 +1,75 @@
/mob
///the icon currently used for the typing indicator's bubble
var/mutable_appearance/active_typing_indicator
///the icon currently used for the thinking indicator's bubble
var/mutable_appearance/active_thinking_indicator
/** Creates a thinking indicator over the mob. Note: Prefs are checked in /client/proc/start_thinking() */
/mob/proc/create_thinking_indicator()
if(active_thinking_indicator || active_typing_indicator || stat != CONSCIOUS || !HAS_TRAIT(src, TRAIT_THINKING_IN_CHARACTER))
return FALSE
var/cur_bubble_appearance = custom_speech_bubble
if(!cur_bubble_appearance || cur_bubble_appearance == "default")
cur_bubble_appearance = speech_bubble_appearance()
active_thinking_indicator = mutable_appearance('icons/mob/talk_vr.dmi', "[cur_bubble_appearance]_thinking", FLOAT_LAYER)
active_thinking_indicator.appearance_flags |= (RESET_COLOR|PIXEL_SCALE)
add_overlay(active_thinking_indicator)
/** Removes the thinking indicator over the mob. */
/mob/proc/remove_thinking_indicator()
if(!active_thinking_indicator)
return FALSE
cut_overlay(active_thinking_indicator)
active_thinking_indicator = null
/** Creates a typing indicator over the mob. Note: Prefs are checked in /client/proc/start_typing() */
/mob/proc/create_typing_indicator()
if(active_typing_indicator || active_thinking_indicator || stat != CONSCIOUS || !HAS_TRAIT(src, TRAIT_THINKING_IN_CHARACTER))
return FALSE
var/cur_bubble_appearance = custom_speech_bubble
if(!cur_bubble_appearance || cur_bubble_appearance == "default")
cur_bubble_appearance = speech_bubble_appearance()
active_typing_indicator = mutable_appearance('icons/mob/talk_vr.dmi', "[cur_bubble_appearance]_typing", ABOVE_MOB_LAYER)
active_typing_indicator.appearance_flags |= (RESET_COLOR|PIXEL_SCALE)
add_overlay(active_typing_indicator)
/** Removes the typing indicator over the mob. */
/mob/proc/remove_typing_indicator()
if(!active_typing_indicator)
return FALSE
cut_overlay(active_typing_indicator)
active_typing_indicator = null
/** Removes any indicators and marks the mob as not speaking IC. */
/mob/proc/remove_all_indicators()
REMOVE_TRAIT(src, TRAIT_THINKING_IN_CHARACTER, CURRENTLY_TYPING_TRAIT)
remove_thinking_indicator()
remove_typing_indicator()
/mob/set_stat(new_stat)
. = ..()
if(.)
remove_all_indicators()
/mob/Logout()
remove_all_indicators()
return ..()
/** Sets the mob as "thinking" - with indicator and the TRAIT_THINKING_IN_CHARACTER trait */
/datum/tgui_say/proc/start_thinking(channel)
if(!window_open)
return FALSE
return client.start_thinking(channel)
/** Removes typing/thinking indicators and flags the mob as not thinking */
/datum/tgui_say/proc/stop_thinking(channel)
return client.stop_thinking(channel)
/**
* Handles the user typing. After a brief period of inactivity,
* signals the client mob to revert to the "thinking" icon.
*/
/datum/tgui_say/proc/start_typing(channel)
if(!window_open)
return FALSE
return client.start_typing(channel)