From ec8b5778f8908f1383dff2132099647a5d92310a Mon Sep 17 00:00:00 2001 From: Morrow Date: Sun, 5 Nov 2023 13:19:24 -0500 Subject: [PATCH] Delayed Narration --- code/datums/components/atom_narrate.dm | 60 ++++++++++++++++++++++++++ code/modules/admin/verbs/mob_verbs.dm | 25 +++-------- colonialmarines.dme | 1 + 3 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 code/datums/components/atom_narrate.dm diff --git a/code/datums/components/atom_narrate.dm b/code/datums/components/atom_narrate.dm new file mode 100644 index 0000000000..a5180720bd --- /dev/null +++ b/code/datums/components/atom_narrate.dm @@ -0,0 +1,60 @@ +#define NARRATION_METHOD_SAY "Say" +#define NARRATION_METHOD_ME "Me" +#define NARRATION_METHOD_DIRECT "Direct" + +/datum/component/atom_narrate + var/message + var/narration_type + var/narrator + +/datum/component/atom_narrate/Initialize(message, narration_type, delayed, narrator) + . = ..() + + src.message = message + src.narration_type = narration_type + src.narrator = narrator + + if(!delayed) + send_narration() + return + + var/turf/parent_turf = get_turf(parent) + + if(!parent_turf) + return COMPONENT_INCOMPATIBLE + + var/list/message_turfs = block(locate(max(parent_turf.x - 4, 1), max(parent_turf.y - 4, 1), parent_turf.z), locate(parent_turf.x + 4, parent_turf.y + 4, parent_turf.z)) + + for(var/turf/cycled_turf as anything in message_turfs) + RegisterSignal(cycled_turf, COMSIG_TURF_ENTERED, PROC_REF(send_message_on_movement)) + +/datum/component/atom_narrate/proc/send_message_on_movement(turf/source, atom/movable/entered) + SIGNAL_HANDLER + + if(!istype(entered, /mob/living/carbon/human)) + return + + send_narration() + qdel(src) + +/datum/component/atom_narrate/proc/send_narration() + var/atom/atom_parent = parent + + if(!atom_parent) + qdel(src) + return + + var/list/heard = get_mobs_in_view(world_view_size, atom_parent) + + switch(narration_type) + if(NARRATION_METHOD_SAY) + atom_parent.langchat_speech(message, heard, GLOB.all_languages, skip_language_check = TRUE) + atom_parent.visible_message("[atom_parent] says, \"[message]\"") + if(NARRATION_METHOD_ME) + atom_parent.langchat_speech(message, heard, GLOB.all_languages, skip_language_check = TRUE, animation_style = 2, additional_styles = list("langchat_small", "emote")) + atom_parent.visible_message("[atom_parent] [message]") + if(NARRATION_METHOD_DIRECT) + atom_parent.visible_message("[message]") + + log_admin("[narrator] sent an Atom Narrate with message \"[message]\" from [atom_parent].") + message_admins("[narrator] sent an Atom Narrate with message \"[message]\" from [atom_parent].") diff --git a/code/modules/admin/verbs/mob_verbs.dm b/code/modules/admin/verbs/mob_verbs.dm index abea58ae8c..7d4c123510 100644 --- a/code/modules/admin/verbs/mob_verbs.dm +++ b/code/modules/admin/verbs/mob_verbs.dm @@ -1,7 +1,3 @@ -#define NARRATION_METHOD_SAY "Say" -#define NARRATION_METHOD_ME "Me" -#define NARRATION_METHOD_DIRECT "Direct" - // Converted this into a proc. Verb will be separate /client/proc/change_ckey(mob/M in GLOB.mob_list, a_ckey = null) var/new_ckey = a_ckey @@ -210,9 +206,11 @@ if(!check_rights(R_MOD)) return - var/type = tgui_input_list(mob,"What type of narration?", "Narration", list(NARRATION_METHOD_SAY, NARRATION_METHOD_ME, NARRATION_METHOD_DIRECT)) + var/delayed = tgui_alert(mob, "Do you want this narration to occur when someone walks nearby?", "Confirmation", list("Yes", "No")) == "Yes" + + var/narration_type = tgui_input_list(mob,"What type of narration?", "Narration", list(NARRATION_METHOD_SAY, NARRATION_METHOD_ME, NARRATION_METHOD_DIRECT)) - if(!type) + if(!narration_type) return var/message = tgui_input_text(mob, "What should it say?", "Narrating as [selected]") @@ -220,20 +218,7 @@ if(!message) return - var/list/heard = get_mobs_in_view(world_view_size, selected) - - switch(type) - if(NARRATION_METHOD_SAY) - selected.langchat_speech(message, heard, GLOB.all_languages, skip_language_check = TRUE) - selected.visible_message("[selected] says, \"[message]\"") - if(NARRATION_METHOD_ME) - selected.langchat_speech(message, heard, GLOB.all_languages, skip_language_check = TRUE, animation_style = LANGCHAT_FAST_POP, additional_styles = list("langchat_small", "emote")) - selected.visible_message("[selected] [message]") - if(NARRATION_METHOD_DIRECT) - selected.visible_message("[message]") - - log_admin("[key_name(src)] sent an Atom Narrate with message [message].") - message_admins("[key_name(src)] sent an Atom Narrate with message [message].") + selected.AddComponent(/datum/component/atom_narrate, message, narration_type, delayed, key_name(src)) /client/proc/cmd_admin_direct_narrate(mob/M) set name = "Narrate" diff --git a/colonialmarines.dme b/colonialmarines.dme index 903d50130b..6b46ddacf1 100644 --- a/colonialmarines.dme +++ b/colonialmarines.dme @@ -379,6 +379,7 @@ #include "code\datums\balloon_alerts\balloon_alerts.dm" #include "code\datums\components\_component.dm" #include "code\datums\components\armor_link.dm" +#include "code\datums\components\atom_narrate.dm" #include "code\datums\components\bad_leg.dm" #include "code\datums\components\bonus_damage_stack.dm" #include "code\datums\components\cluster_stack.dm"