From 2cbdae2f0aaa76557a77d8c98158aa502bd085d3 Mon Sep 17 00:00:00 2001 From: Ghommie <42542238+Ghommie@users.noreply.github.com> Date: Thu, 5 Mar 2020 18:46:33 +0100 Subject: [PATCH] Made flavor texts into an element datum. --- code/__DEFINES/components.dm | 3 + code/__HELPERS/_cit_helpers.dm | 32 ----- code/datums/dna.dm | 6 +- code/datums/elements/flavor_text.dm | 113 ++++++++++++++++++ code/modules/client/preferences.dm | 2 + code/modules/mob/living/carbon/carbon.dm | 5 + .../mob/living/carbon/human/examine.dm | 27 +---- code/modules/mob/living/carbon/human/human.dm | 6 +- code/modules/mob/mob.dm | 8 -- .../code/modules/client/preferences.dm | 1 - tgstation.dme | 1 + 11 files changed, 138 insertions(+), 66 deletions(-) create mode 100644 code/datums/elements/flavor_text.dm diff --git a/code/__DEFINES/components.dm b/code/__DEFINES/components.dm index 5a4e7c0380..fb44916ee1 100644 --- a/code/__DEFINES/components.dm +++ b/code/__DEFINES/components.dm @@ -210,6 +210,7 @@ // /mob/living/carbon signals #define COMSIG_CARBON_SOUNDBANG "carbon_soundbang" //from base of mob/living/carbon/soundbang_act(): (list(intensity)) +#define COMSIG_CARBON_IDENTITY_TRANSFERRED_TO "carbon_id_transferred_to" //from datum/dna/transfer_identity(): (datum/dna, transfer_SE) // /mob/living/simple_animal/hostile signals #define COMSIG_HOSTILE_ATTACKINGTARGET "hostile_attackingtarget" @@ -274,6 +275,8 @@ #define COMSIG_HUMAN_MELEE_UNARMED_ATTACK "human_melee_unarmed_attack" //from mob/living/carbon/human/UnarmedAttack(): (atom/target) #define COMSIG_HUMAN_MELEE_UNARMED_ATTACKBY "human_melee_unarmed_attackby" //from mob/living/carbon/human/UnarmedAttack(): (mob/living/carbon/human/attacker) #define COMSIG_HUMAN_DISARM_HIT "human_disarm_hit" //Hit by successful disarm attack (mob/living/carbon/human/attacker,zone_targeted) +#define COMSIG_HUMAN_PREFS_COPIED_TO "human_prefs_copied_to" //from datum/preferences/copy_to(): (datum/preferences, icon_updates, roundstart_checks) +#define COMSIG_HUMAN_HARDSET_DNA "human_hardset_dna" //from mob/living/carbon/human/hardset_dna(): (ui, se, newreal_name, newblood_type, datum/species, newfeatures) // /datum/species signals #define COMSIG_SPECIES_GAIN "species_gain" //from datum/species/on_species_gain(): (datum/species/new_species, datum/species/old_species) diff --git a/code/__HELPERS/_cit_helpers.dm b/code/__HELPERS/_cit_helpers.dm index 4ae30838e4..ffc1bcc6b7 100644 --- a/code/__HELPERS/_cit_helpers.dm +++ b/code/__HELPERS/_cit_helpers.dm @@ -107,38 +107,6 @@ GLOBAL_VAR_INIT(miscreants_allowed, FALSE) if(!src.holder) return message_admins("[key_name_admin(usr)] manually reloaded mentors") -//Flavor Text -/mob/proc/set_flavor() - set name = "Set Flavor Text" - set desc = "Sets an extended description of your character's features." - set category = "IC" - - var/new_flavor = stripped_multiline_input(usr, "Set the flavor text in your 'examine' verb. This can also be used for OOC notes and preferences!", "Flavor Text", flavor_text, MAX_FAVOR_LEN, TRUE) - if(!isnull(new_flavor)) - flavor_text = html_decode(new_flavor) - to_chat(src, "Your flavor text has been updated.") - -//Flavor Text -/mob/proc/set_flavor_2() - set name = "Set Temporary Flavor Text" - set desc = "Sets a description of your character's current appearance. Use this for emotions, poses etc." - set category = "IC" - - var/new_flavor = stripped_multiline_input(usr, "Set the temporary flavor text in your 'examine' verb. This should be used only for things pertaining to the current round!", "Short-Term Flavor Text", flavor_text_2, MAX_FAVOR_LEN, TRUE) - if(!isnull(new_flavor)) - flavor_text_2 = html_decode(new_flavor) - to_chat(src, "Your temporary flavor text has been updated.") - -/mob/proc/print_flavor_text(flavor,temp = FALSE) - if(!flavor) - return - // We are decoding and then encoding to not only get correct amount of characters, but also to prevent partial escaping characters being shown. - var/msg = html_decode(replacetext(flavor, "\n", " ")) - if(length_char(msg) <= 40) - return "[html_encode(msg)]" - else - return "[html_encode(copytext_char(msg, 1, 37))]... More..." - //LOOC toggles /client/verb/listen_looc() set name = "Show/Hide LOOC" diff --git a/code/datums/dna.dm b/code/datums/dna.dm index 68c6839482..3994dcc8bc 100644 --- a/code/datums/dna.dm +++ b/code/datums/dna.dm @@ -51,10 +51,11 @@ if(ishuman(destination)) var/mob/living/carbon/human/H = destination H.give_genitals(TRUE)//This gives the body the genitals of this DNA. Used for any transformations based on DNA - destination.flavor_text = destination.dna.features["flavor_text"] //Update the flavor_text to use new dna text if(transfer_SE) destination.dna.struc_enzymes = struc_enzymes + SEND_SIGNAL(destination, COMSIG_CARBON_IDENTITY_TRANSFERRED_TO, src, transfer_SE) + /datum/dna/proc/copy_dna(datum/dna/new_dna) new_dna.unique_enzymes = unique_enzymes new_dna.struc_enzymes = struc_enzymes @@ -284,7 +285,6 @@ if(newfeatures) dna.features = newfeatures - flavor_text = dna.features["flavor_text"] //Update the flavor_text to use new dna text if(mrace) var/datum/species/newrace = new mrace.type @@ -306,6 +306,8 @@ dna.struc_enzymes = se domutcheck() + SEND_SIGNAL(src, COMSIG_HUMAN_HARDSET_DNA, ui, se, newreal_name, newblood_type, mrace, newfeatures) + if(mrace || newfeatures || ui) update_body() update_hair() diff --git a/code/datums/elements/flavor_text.dm b/code/datums/elements/flavor_text.dm new file mode 100644 index 0000000000..f823f4aa79 --- /dev/null +++ b/code/datums/elements/flavor_text.dm @@ -0,0 +1,113 @@ +/datum/element/flavor_text + element_flags = ELEMENT_BESPOKE|ELEMENT_DETACH + id_arg_index = 3 + var/flavor_name = "Flavor Text" + var/procpath/verb_instance + var/invoke_proc + var/list/texts_by_mob = list() + var/addendum = "This can also be used for OOC notes and preferences!" + var/always_show = FALSE + var/max_len = MAX_FAVOR_LEN + +/datum/element/flavor_text/Attach(datum/target, text, _proc, _name = "Flavor Text", _desc = "Sets an extended description of your character's features.", _addendum, _max_len = MAX_FAVOR_LEN, _always_show = FALSE, can_edit = TRUE) + . = ..() + + if(. == ELEMENT_INCOMPATIBLE || !isatom(target)) //no reason why this shouldn't work on atoms too. + return ELEMENT_INCOMPATIBLE + + texts_by_mob[target] = text + if(_name) + flavor_name = _name + if(_proc) + invoke_proc = _proc + if(_max_len) + max_len = _max_len + if(!isnull(addendum)) + addendum = _addendum + always_show = _always_show + + RegisterSignal(target, COMSIG_PARENT_EXAMINE, .proc/show_flavor) + + if(can_edit && ismob(target)) //but only mobs receive the proc/verb for the time being + var/mob/M = target + if(!verb_instance) + verb_instance = new /datum/element/flavor_text/proc/set_flavor (src, "Set [_name]", _desc) + M.verbs += verb_instance + +/datum/element/flavor_text/Detach(atom/A) + . = ..() + UnregisterSignal(A, COMSIG_PARENT_EXAMINE) + texts_by_mob -= A + A.verbs -= verb_instance + +/datum/element/flavor_text/proc/show_flavor(atom/target, mob/user, list/examine_list) + if(!always_show && isliving(target)) + var/mob/living/L = target + var/unknown = L.get_visible_name() == "Unknown" + if(!unknown && iscarbon(target)) + var/mob/living/carbon/C = L + unknown = (C.wear_mask && (C.wear_mask.flags_inv & HIDEFACE)) || (C.head && (C.head.flags_inv & HIDEFACE)) + if(unknown) + if(!("...?" in examine_list)) //can't think of anything better in case of multiple flavor texts. + examine_list += "...?" + return + var/text = texts_by_mob[target] + if(!text) + return + var/msg = replacetext(text, "\n", " ") + if(length_char(msg) <= 40) + return "[html_encode(msg)]" + else + return "[html_encode(copytext_char(msg, 1, 37))]... More..." + +/datum/element/flavor_text/Topic(href, href_list) + . = ..() + if(.) + return + if(href_list["show_flavor"]) + var/atom/target = href_list["show_flavor"] + var/text = texts_by_mob[target] + if(text) + usr << browse("