From 845ad465ccdc6858cc67b7564741a1087606d243 Mon Sep 17 00:00:00 2001 From: CHOMPStation2StaffMirrorBot <94713762+CHOMPStation2StaffMirrorBot@users.noreply.github.com> Date: Tue, 31 Dec 2024 12:27:45 -0700 Subject: [PATCH] [MIRROR] fix speechbubble and runechat position (#9747) Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com> --- code/datums/chat_message.dm | 4 ++-- code/game/atoms.dm | 26 +++++++++++++++++++++ code/modules/tgui_input/say_modal/typing.dm | 4 ++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/code/datums/chat_message.dm b/code/datums/chat_message.dm index f216ae01cf..b5c41302ba 100644 --- a/code/datums/chat_message.dm +++ b/code/datums/chat_message.dm @@ -368,10 +368,10 @@ var/list/runechat_image_cache = list() return world.icon_size * 0.95 /atom/movable/runechat_x_offset(width, height) - return (width - bound_width) * -0.5 + return (width - bound_width) * -0.5 + get_oversized_icon_offsets()["x"] /atom/movable/runechat_y_offset(width, height) - return bound_height * 0.95 + return bound_height * 0.95 + get_oversized_icon_offsets()["y"] /* Nothing special /mob/runechat_x_offset(width, height) diff --git a/code/game/atoms.dm b/code/game/atoms.dm index e7cbc1e17d..60d47315ea 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -793,3 +793,29 @@ var/mouseparams = list2params(paramslist) usr_client.Click(src, loc, null, mouseparams) return TRUE + +GLOBAL_LIST_EMPTY(icon_dimensions) + +/atom/proc/get_oversized_icon_offsets() + if (pixel_x == 0 && pixel_y == 0) + return list("x" = 0, "y" = 0) + var/list/icon_dimensions = get_icon_dimensions(icon) + var/icon_width = icon_dimensions["width"] + var/icon_height = icon_dimensions["height"] + return list( + "x" = icon_width > world.icon_size && pixel_x != 0 ? (icon_width - world.icon_size) * 0.5 : 0, + "y" = icon_height > world.icon_size /*&& pixel_y != 0*/ ? (icon_height - world.icon_size) * 0.5 : 0, // we don't have pixel_y in use + ) + +/// Returns a list containing the width and height of an icon file +/proc/get_icon_dimensions(icon_path) + // Icons can be a real file(), a rsc backed file(), a dynamic rsc (dyn.rsc) reference (known as a cache reference in byond docs), or an /icon which is pointing to one of those. + // Runtime generated dynamic icons are an unbounded concept cache identity wise, the same icon can exist millions of ways and holding them in a list as a key can lead to unbounded memory usage if called often by consumers. + // Check distinctly that this is something that has this unspecified concept, and thus that we should not cache. + if (!isfile(icon_path) || !length("[icon_path]")) + var/icon/my_icon = icon(icon_path) + return list("width" = my_icon.Width(), "height" = my_icon.Height()) + if (isnull(GLOB.icon_dimensions[icon_path])) + var/icon/my_icon = icon(icon_path) + GLOB.icon_dimensions[icon_path] = list("width" = my_icon.Width(), "height" = my_icon.Height()) + return GLOB.icon_dimensions[icon_path] diff --git a/code/modules/tgui_input/say_modal/typing.dm b/code/modules/tgui_input/say_modal/typing.dm index f4f3a63b87..333632e3ce 100644 --- a/code/modules/tgui_input/say_modal/typing.dm +++ b/code/modules/tgui_input/say_modal/typing.dm @@ -13,6 +13,8 @@ cur_bubble_appearance = speech_bubble_appearance() active_thinking_indicator = mutable_appearance('icons/mob/talk_vr.dmi', "[cur_bubble_appearance]_thinking", FLOAT_LAYER) active_thinking_indicator.appearance_flags |= (RESET_COLOR|PIXEL_SCALE) + active_thinking_indicator.pixel_x = get_oversized_icon_offsets()["x"] + active_thinking_indicator.pixel_y = get_oversized_icon_offsets()["y"] add_overlay(active_thinking_indicator) /** Removes the thinking indicator over the mob. */ @@ -31,6 +33,8 @@ cur_bubble_appearance = speech_bubble_appearance() active_typing_indicator = mutable_appearance('icons/mob/talk_vr.dmi', "[cur_bubble_appearance]_typing", ABOVE_MOB_LAYER) active_typing_indicator.appearance_flags |= (RESET_COLOR|PIXEL_SCALE) + active_typing_indicator.pixel_x = get_oversized_icon_offsets()["x"] + active_typing_indicator.pixel_y = get_oversized_icon_offsets()["y"] add_overlay(active_typing_indicator) /** Removes the typing indicator over the mob. */