From 22ce6fb6233fb8be98af4e0ea40e0cc4cb5c989b Mon Sep 17 00:00:00 2001 From: Sokomine Date: Fri, 2 Jun 2023 21:44:02 +0200 Subject: [PATCH] make tooltip for npc talking more readable when lines are longer --- fs_decorated.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs_decorated.lua b/fs_decorated.lua index a77d21f..c7cd289 100644 --- a/fs_decorated.lua +++ b/fs_decorated.lua @@ -136,6 +136,14 @@ yl_speak_up.add_formspec_element_with_tooltip_if = function(formspec, element_ty return end table.insert(formspec, element_type.."["..position..";"..element_name..";"..element_text.."]") + + -- make sure the lines in the mouseover text don't get too long + -- each paragraph has to be split seperately so that the old newlines are kept + local paragraphs = string.split(tooltip, "\n", true, -1, false) + for i, p in ipairs(paragraphs) do + paragraphs[i] = minetest.wrap_text(paragraphs[i], 100, false) + end + tooltip = table.concat(paragraphs, "\n") table.insert(formspec, "tooltip["..tostring(element_name)..";"..tostring(tooltip).."]") end