Skip to content

Commit

Permalink
refactor: rewrite text blurb from the ground to subtype of `/obj/scre…
Browse files Browse the repository at this point in the history
…en/text`
  • Loading branch information
Gaxeer committed Dec 12, 2023
1 parent da576b8 commit c5f0e7f
Showing 1 changed file with 133 additions and 38 deletions.
171 changes: 133 additions & 38 deletions modular_ss220/loc_blurb/code/location_blurb.dm
Original file line number Diff line number Diff line change
@@ -1,43 +1,138 @@
/obj/screen/text/blurb
maptext_height = 64
maptext_width = 512
screen_loc = "LEFT+1,BOTTOM+2"
/// Font size in pixels
var/font_size = 11
/// Font family
var/font_family = "Fixedsys"
/// Where text is aligned
var/text_alignment = "left"
/// Color of text in RGB
var/text_color = COLOR_WHITE
/// Color of text outline
var/text_outline_color = COLOR_BLACK
/// Width of text outline in pixels
var/text_outline_width = 1
/// Text that will be shown in blurb
var/blurb_text = ""
/// Number of chars from the `text` that will be displayed per interval. Defaults to 1
var/chars_per_interval = 1
/// The interval between chars rendering
var/interval = 1 DECISECONDS
/// Amount of time the blurb will be present on the screen. 0 means that blurb will dissappear immediately
var/hold_for = 0
/// Amount of time the blurbs appering (alpha changing from 0 to 255). 0 means blurb is fully opaque from the start
var/appear_animation_duration = 0
/// Amount of time the blurb takes to fade (alpha changing from 255 to 0). 0 means blurb is instantly removed from the screen after finished
var/fade_animation_duration = 0

/proc/show_location_blurb(client/C, duration = 3 SECONDS)
set waitfor = FALSE

var/style = "font-family: 'Fixedsys'; -dm-text-outline: 1 black; font-size: 11px;"
var/area/A = get_area(C.mob)
var/text = "[GLOB.current_date_string], [station_time_timestamp()]\n[station_name()], [A.name]"
text = uppertext(text)

var/atom/movable/screen/T = new /atom/movable/screen{
maptext_height = 64;
maptext_width = 512;
layer = FLOAT_LAYER;
plane = HUD_PLANE;
appearance_flags = APPEARANCE_UI_IGNORE_ALPHA;
screen_loc = "LEFT+1,BOTTOM+2";
alpha = 0;
}

C.screen += T
animate(T, alpha = 255, time = 10)
for(var/i = 1 to length_char(text) + 1)
T.maptext = "<span style=\"[style]\">[copytext_char(text, 1, i)] </span>"
sleep(1)

addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(fade_location_blurb), C, T), duration)

/proc/fade_location_blurb(client/C, obj/T)
animate(T, alpha = 0, time = 5)
sleep(5)
if(C)
C.screen -= T
qdel(T)


/datum/controller/subsystem/jobs/EquipRank(mob/living/carbon/human/H, rank, joined_late = 0)

/obj/screen/text/blurb/proc/show_to(list/client/viewers)
if(!blurb_text || !viewers)
return

if(islist(viewers))
if(!length(viewers))
return

else
viewers = list(viewers)

for(var/client/viewer as anything in viewers)
viewer.screen += src

appear()
print_text()

if(hold_for)
addtimer(CALLBACK(src, TYPE_PROC_REF(/obj/screen/text/blurb, hide_from), viewers), hold_for)
else
hide_from(viewers)


/obj/screen/text/blurb/proc/get_text_style()
return {"\
font-family: [font_family], [initial(font_family)]; \
-dm-text-outline: [text_outline_width] [text_outline_color]; \
font-size: [font_size]px; \
text-align: [text_alignment]; \
color: [text_color];
"}

/obj/screen/text/blurb/proc/hide_from(list/client/viewers)
PRIVATE_PROC(TRUE)

fade()
addtimer(CALLBACK(src, TYPE_PROC_REF(/obj/screen/text/blurb, remove_from_viewers), viewers), fade_animation_duration)

/obj/screen/text/blurb/proc/appear()
PRIVATE_PROC(TRUE)

animate(src, alpha = 255, time = appear_animation_duration)


/obj/screen/text/blurb/proc/fade()
PRIVATE_PROC(TRUE)

animate(src, alpha = 0, time = fade_animation_duration)


/obj/screen/text/blurb/proc/print_text()
PRIVATE_PROC(TRUE)

var/text_style = get_text_style()
var/text_length = length_char(blurb_text)
for(var/segment_start = 1, segment_start <= text_length, segment_start += chars_per_interval)
var/segment_end = min(text_length + 1, segment_start + chars_per_interval)
maptext += get_formatted_text_segment(text_style, segment_start, segment_end)
sleep(interval)

/obj/screen/text/blurb/proc/get_formatted_text_segment(style, segment_start, segment_end)
return "<span style=\"[style]\">[copytext_char(blurb_text, segment_start, segment_end)]</span>"

/obj/screen/text/blurb/proc/remove_from_viewers(list/client/viewers)
PRIVATE_PROC(TRUE)

for(var/client/viewer as anything in viewers)
viewer.screen -= src

qdel(src)

/datum/controller/subsystem/jobs/proc/show_location_blurb(client/show_blurb_to)
PRIVATE_PROC(TRUE)

if(!show_blurb_to.mob)
return

var/obj/screen/text/blurb/location_blurb = new()
location_blurb.blurb_text = uppertext("[GLOB.current_date_string], [station_time_timestamp()]\n[station_name()], [get_area_name(show_blurb_to.mob, TRUE)]")
location_blurb.hold_for = 3 SECONDS
location_blurb.appear_animation_duration = 1 SECONDS
location_blurb.fade_animation_duration = 0.5 SECONDS

location_blurb.show_to(show_blurb_to)

/datum/controller/subsystem/jobs/EquipRank(mob/living/carbon/human/human_to_equip, rank, joined_late)
. = ..()
INVOKE_ASYNC(GLOBAL_PROC, GLOBAL_PROC_REF(show_location_blurb), H.client, 30)
INVOKE_ASYNC(src, TYPE_PROC_REF(/datum/controller/subsystem/jobs, show_location_blurb), human_to_equip.client)

/datum/controller/subsystem/ticker/reboot_helper(reason, end_string, delay)
for(var/mob/M as anything in GLOB.player_list)
show_blurb(M, 900, "Round is restarting...", null, "center", "center", COLOR_RED, null, null, 1)
if(delay)
INVOKE_ASYNC(src, TYPE_PROC_REF(/datum/controller/subsystem/ticker, show_server_restart_blurb), reason)

. = ..()


/datum/controller/subsystem/ticker/proc/show_server_restart_blurb(reason)
if(!length(GLOB.clients))
return

var/obj/screen/text/blurb/server_restart_blurp = new()
server_restart_blurp.text_color = COLOR_RED
server_restart_blurp.blurb_text = "Round is restarting...\n[reason]"
server_restart_blurp.hold_for = 90 SECONDS
server_restart_blurp.appear_animation_duration = 1 SECONDS
server_restart_blurp.fade_animation_duration = 0.5 SECONDS

server_restart_blurp.show_to(GLOB.clients)

0 comments on commit c5f0e7f

Please sign in to comment.