diff --git a/quest_api.lua b/quest_api.lua index a41d0b7..4f49293 100644 --- a/quest_api.lua +++ b/quest_api.lua @@ -386,6 +386,30 @@ yl_speak_up.get_npc_users_of_variable = function(var_name) end +-- helper function +yl_speak_up.wrap_long_lines_for_table = function(text, prefix, line_length, max_lines) + -- show newlines as <\n> in order to save space + local text = minetest.formspec_escape(text or "?") + text = string.gsub(text, "\n", minetest.formspec_escape("
")) + -- break the text up into lines of length x + local parts = minetest.wrap_text(text, line_length, true) + if(not(parts) or #parts < 2) then + return text + end + local show_parts = {} + -- only show the first two lines (we don't have infinite room) + for i, p in ipairs(parts) do + if(i <= max_lines) then + table.insert(show_parts, minetest.formspec_escape(p)) + end + end + if(#parts > max_lines) then + return table.concat(show_parts, prefix)..minetest.formspec_escape(" [...]") + end + return table.concat(show_parts, prefix) +end + + -- find out where this variable is used in NPCs yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_preconditions, back_button_name, back_button_text) @@ -440,41 +464,26 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec -- if preconditions or effects apply: show the action as well if(o and o.actions and (p_text ~= "" or r_text ~= "")) then for a_id, a in pairs(o.actions) do + -- these lines can get pretty long when a description for a quest + -- item is set + local a_text = yl_speak_up.wrap_long_lines_for_table( + yl_speak_up.show_action(a, pname), + ",#FFFFFF,,#FFFFFF,,#FFFFFF,,#FF9900,", + 80, 4) -- no need to introduce an a_text; this will follow -- directly after p_text, and p_text is finished p_text = p_text..",FF9900,".. minetest.formspec_escape(tostring(a_id)).. ",#FF9900,(A)ction,#FF9900,".. minetest.formspec_escape(a.a_type)..",#FF9900,".. - minetest.formspec_escape( - yl_speak_up.show_action(a, pname)) + a_text end end if(p_text ~= "" or r_text ~= "") then - -- show newlines as <\n> in order to save space - local d_text = string.gsub( - dialog.n_dialogs[ d_id ].d_text or "?", - "\n", minetest.formspec_escape("
")) - -- break the text up into lines of length x - local parts = minetest.wrap_text(d_text, 80, true) - -- only show the first two lines (we don't have infinite room) - local prefix = ",#FFFFFF,,#FFFFFF,,#FFFFFF,,#BBBBFF," - if(#parts < 2) then - d_text = minetest.formspec_escape(parts[1]) - elseif(#parts == 2) then - d_text = minetest.formspec_escape(parts[1]).. - prefix..minetest.formspec_escape(parts[2]) - elseif(#parts == 3) then - d_text = minetest.formspec_escape(parts[1]).. - prefix..minetest.formspec_escape(parts[2]).. - prefix..minetest.formspec_escape(parts[3]) - else - -- indicate that there is more - d_text = minetest.formspec_escape(parts[1]).. - prefix..minetest.formspec_escape(parts[2]).. - prefix..minetest.formspec_escape(parts[3]).. - minetest.formspec_escape(" [...]") - end + local d_text = yl_speak_up.wrap_long_lines_for_table( + dialog.n_dialogs[ d_id ].d_text or "?", + ",#FFFFFF,,#FFFFFF,,#FFFFFF,,#BBBBFF,", + 80, 3) res[ tostring(n_id).." "..tostring(d_id).." "..tostring(o_id) ] = { text = "#6666FF,".. @@ -510,7 +519,8 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec "button[0.2,31.6;56.6,1.2;"..back_button_name..";".. minetest.formspec_escape(back_button_text).."]", "label[20.0,1.8;".. - minetest.formspec_escape("Variable \""..tostring(var_name or "- ? -").. + minetest.formspec_escape("Variable \"".. + minetest.colorize("#FFFF00", tostring(var_name or "- ? -")).. "\" is used here:").."]".. -- type x_id color type text "tablecolumns[color,span=1;text;color,span=1;text;color,span=1;text;color,span=1;text]", @@ -521,9 +531,11 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec if(#sorted_res > 0 and (count_read > 0 or count_changed > 0)) then table.insert(formspec, - "label[16.0,31.0;The variable is accessed in "..tostring(count_read).. - " pre(C)onditions and changed in "..tostring(count_changed).. - " (Ef)ffects.]") + "label[16.0,31.0;The variable is accessed in ".. + minetest.colorize("#FFFF00", tostring(count_read).." pre(C)onditions").. + " and changed in ".. + minetest.colorize("#55FF55", tostring(count_changed).." (Ef)fects").. + ".]") else -- TODO: make delete_unused_variable work table.insert(formspec,