Skip to content

Commit

Permalink
Changes to notice:
Browse files Browse the repository at this point in the history
- When crest is lowered, it will notify player that crest is lowered.
- balloon alerts now include "delay" so you don't need to create shit ton of code to prevent text spam.
  • Loading branch information
Venuska1117 committed Dec 2, 2024
1 parent cfd309f commit b212241
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions code/datums/balloon_alerts/balloon_alerts.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@
/// The amount of characters needed before this increase takes into effect
#define BALLOON_TEXT_CHAR_LIFETIME_INCREASE_MIN 10

/// Creates text that will float from the atom upwards to the viewer.
/atom/proc/balloon_alert(mob/viewer, text, text_color)
var/list/last_balloon_alert = list()

/proc/can_display_balloon_alert(atom/source, delay)
var/last_time = last_balloon_alert[source]
if (last_time && (world.time - last_time < delay))
return FALSE
return TRUE

/atom/proc/balloon_alert(mob/viewer, text, text_color, delay = 0)
SHOULD_NOT_SLEEP(TRUE)

if (delay > 0 && !can_display_balloon_alert(src, delay))
return

last_balloon_alert[src] = world.time
INVOKE_ASYNC(src, PROC_REF(balloon_alert_perform), viewer, text, text_color)

/// 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, max_distance = DEFAULT_MESSAGE_RANGE, list/ignored_mobs, text_color)
/atom/proc/balloon_alert_to_viewers(message, self_message, max_distance = DEFAULT_MESSAGE_RANGE, list/ignored_mobs, text_color, delay = 0)
SHOULD_NOT_SLEEP(TRUE)

var/list/hearers = get_mobs_in_view(max_distance, src)
Expand All @@ -25,8 +36,7 @@
for(var/mob/hearer in hearers)
if(is_blind(hearer))
continue

balloon_alert(hearer, (hearer == src && self_message) || message, text_color)
balloon_alert(hearer, (hearer == src && self_message) || message, text_color, delay)

// Do not use.
// MeasureText blocks. I have no idea for how long.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
return

if(xeno.crest_defense)
to_chat(src, SPAN_XENOWARNING("We cannot use tail swipe with our crest lowered."))
xeno.balloon_alert(xeno, "our crest is lowered!", text_color = "#7d32bb", delay = 1 SECONDS)
return

xeno.visible_message(SPAN_XENOWARNING("[xeno] sweeps its tail in a wide circle!"), \
Expand Down Expand Up @@ -155,7 +155,7 @@
return

if(xeno.crest_defense)
to_chat(src, SPAN_XENOWARNING("We cannot use fortify with our crest lowered."))
xeno.balloon_alert(xeno, "our crest is lowered!", text_color = "#7d32bb", delay = 1 SECONDS)
return

if(!xeno.check_state())
Expand Down

0 comments on commit b212241

Please sign in to comment.