Files
Kyle Spier-Swenson c54a263a8c Command bar typing indicators (client side html version) (#83081)
This uses a browser skin element to spy on the command bar and report
back to the server what verb is currently in it and how many characters
it has. it skips reporting if the text hasn't changed since the last
report.

im intentionally not providing the full text in the command bar to the
server, while designing the system so new verbs can be given typing
indicators by editing DM code, not html code.

The report rate is once a second but this could be lowered or tweaked.

Both the tgui say window being open and this system being active because
the command bar starts with `say "` is undefined behavior, mostly the
first one to end the indicator will just freeze indicators for the other
one until it too ends its current indicator session.

The system waits until something besides the `"` is in the argument to
say.

It is enabled for verbs `say`, `me`, and `whisper`.

I don't actually know if this is the case for tgui say. this is a one
line tweak anyways so let me know if this should be changed.

[(This pr closes a
bounty)](https://tgstation13.org/phpBB/viewtopic.php?p=726634#p726634)

🆑 MrStonedOne & Lilah Novi
add: Say commands typed in the command bar now trigger typing indicators
/🆑

---------

Co-authored-by: san7890 <the@ san7890.com>
2024-05-08 21:37:55 -04:00

99 lines
3.0 KiB
Plaintext

/** Creates a thinking indicator over the mob. */
/mob/proc/create_thinking_indicator()
return
/** Removes the thinking indicator over the mob. */
/mob/proc/remove_thinking_indicator()
return
/** Creates a typing indicator over the mob. */
/mob/proc/create_typing_indicator()
return
/** Removes the typing indicator over the mob. */
/mob/proc/remove_typing_indicator()
return
/** Removes any indicators and marks the mob as not speaking IC. */
/mob/proc/remove_all_indicators()
return
/mob/set_stat(new_stat)
. = ..()
if(.)
remove_all_indicators()
/mob/Logout()
remove_all_indicators()
return ..()
/// Whether or not to show a typing indicator when speaking. Defaults to on.
/datum/preference/toggle/typing_indicator
category = PREFERENCE_CATEGORY_GAME_PREFERENCES
savefile_key = "typingIndicator"
savefile_identifier = PREFERENCE_PLAYER
/datum/preference/toggle/typing_indicator/apply_to_client(client/client, value)
client?.typing_indicators = value
/** Sets the mob as "thinking" - with indicator and the TRAIT_THINKING_IN_CHARACTER trait */
/datum/tgui_say/proc/start_thinking()
if(!window_open)
return FALSE
return client.start_thinking()
/** Removes typing/thinking indicators and flags the mob as not thinking */
/datum/tgui_say/proc/stop_thinking()
return client.stop_thinking()
/**
* 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()
if(!window_open)
return FALSE
return client.start_typing()
/**
* Remove the typing indicator after a brief period of inactivity or during say events.
* If the user was typing IC, the thinking indicator is shown.
*/
/datum/tgui_say/proc/stop_typing()
if(!window_open)
return FALSE
client.stop_typing()
/// Overrides for overlay creation
/mob/living/create_thinking_indicator()
if(active_thinking_indicator || active_typing_indicator || stat != CONSCIOUS || !HAS_TRAIT(src, TRAIT_THINKING_IN_CHARACTER))
return FALSE
active_thinking_indicator = mutable_appearance('icons/mob/effects/talk.dmi', "[bubble_icon]3", TYPING_LAYER)
add_overlay(active_thinking_indicator)
play_fov_effect(src, 6, "talk", ignore_self = TRUE)
/mob/living/remove_thinking_indicator()
if(!active_thinking_indicator)
return FALSE
cut_overlay(active_thinking_indicator)
active_thinking_indicator = null
/mob/living/create_typing_indicator()
if(active_typing_indicator || active_thinking_indicator || stat != CONSCIOUS || !HAS_TRAIT(src, TRAIT_THINKING_IN_CHARACTER))
return FALSE
active_typing_indicator = mutable_appearance('icons/mob/effects/talk.dmi', "[bubble_icon]0", TYPING_LAYER)
add_overlay(active_typing_indicator)
play_fov_effect(src, 6, "talk", ignore_self = TRUE)
/mob/living/remove_typing_indicator()
if(!active_typing_indicator)
return FALSE
cut_overlay(active_typing_indicator)
active_typing_indicator = null
/mob/living/remove_all_indicators()
REMOVE_TRAIT(src, TRAIT_THINKING_IN_CHARACTER, CURRENTLY_TYPING_TRAIT)
remove_thinking_indicator()
remove_typing_indicator()