From dd7d5df5eb655de613f54e6da9cce343b2123d1e Mon Sep 17 00:00:00 2001 From: Mothblocks <35135081+Mothblocks@users.noreply.github.com> Date: Sun, 23 May 2021 03:55:30 -0700 Subject: [PATCH] Show balloon alert to viewers, no more async (#59256) Adds balloon_alert_to_viewers, which provides a visible_message-esque interface to show balloon alerts around you. Use sparingly, as I'd also like for Runechat emotes to take this place (such as sneezing not showing in chat, but having an emote). balloon_alert no longer yields, letting it be used in SHOULD_NOT_SLEEP(TRUE) procs, like signal handlers. Balloon alerts now use get_atom_on_turf(src), meaning if used on mobs they will move with them, rather than on their tile. --- code/modules/balloon_alert/balloon_alert.dm | 25 ++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/code/modules/balloon_alert/balloon_alert.dm b/code/modules/balloon_alert/balloon_alert.dm index c068d08d56c..495f5dba90d 100644 --- a/code/modules/balloon_alert/balloon_alert.dm +++ b/code/modules/balloon_alert/balloon_alert.dm @@ -6,6 +6,29 @@ /// Creates text that will float from the atom upwards to the viewer. /atom/proc/balloon_alert(mob/viewer, text) + SHOULD_NOT_SLEEP(TRUE) + + INVOKE_ASYNC(src, .proc/balloon_alert_perform, viewer, text) + +/// Create balloon alerts (text that floats up) to everything within range. +/// Will only display to people who can see. +/atom/proc/balloon_alert_to_viewers(message, self_message, vision_distance = DEFAULT_MESSAGE_RANGE, list/ignored_mobs) + SHOULD_NOT_SLEEP(TRUE) + + var/list/hearers = get_hearers_in_view(vision_distance, src) + hearers -= ignored_mobs + + for (var/mob/hearer in hearers) + if (hearer.is_blind()) + continue + + balloon_alert(hearer, (hearer == src && self_message) || message) + +// Do not use. +// MeasureText blocks. I have no idea for how long. +// I would've made the maptext_height update on its own, but I don't know +// if this would look bad on laggy clients. +/atom/proc/balloon_alert_perform(mob/viewer, text) var/client/viewer_client = viewer.client if (isnull(viewer_client)) return @@ -15,7 +38,7 @@ var/atom/movable/movable_source = src bound_width = movable_source.bound_width - var/image/balloon_alert = image(loc = loc, layer = ABOVE_MOB_LAYER) + var/image/balloon_alert = image(loc = get_atom_on_turf(src), layer = ABOVE_MOB_LAYER) balloon_alert.plane = BALLOON_CHAT_PLANE balloon_alert.alpha = 0 balloon_alert.maptext = MAPTEXT("[text]")