From e950cdc1f02c8b3d86fdd340e5540a1c92c58c49 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 9 Jan 2022 00:05:50 +0100 Subject: [PATCH] diffrent handling for formspec versions 2 and 1 (2 is pretty ok; 1 is ugly and barely usable) --- fs_talkdialog.lua | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/fs_talkdialog.lua b/fs_talkdialog.lua index 8e16733..e2fe706 100644 --- a/fs_talkdialog.lua +++ b/fs_talkdialog.lua @@ -297,7 +297,7 @@ yl_speak_up.add_edit_button_fs_talkdialog = function(formspec, h, button_name, t return h end -- there has to be more room for the up and down arrows - button_dimensions = "1.2,"..(h+1)..";52.8,0.9;" + button_dimensions = "1.2,"..(h+1)..";52.3,0.9;" label_start_pos = "1.4" end h = h + 1 @@ -464,12 +464,16 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec owner_info = "\n\n(owned by "..minetest.formspec_escape(yl_speak_up.npc_owner[ n_id ])..")" end - local fs_version = "1" + local fs_version = 1 if formspec_v >= 4 then - fs_version = "3" + fs_version = 3 + elseif formspec_v >= 2 then + fs_version = 2 + else + fs_version = 1 end formspec = { - "formspec_version["..fs_version.."]", + "formspec_version["..tostring(fs_version).."]", "size[57,33]", "position[0,0.45]", "anchor[0,0.45]", @@ -513,10 +517,9 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec portrait, "]", } - if formspec_v >= 4 or true then -- add those things that only exist in formspec_v >= 4 - if(fs_version ~= "1") then + if(fs_version > 2) then table.insert(formspec, "style_type[button;bgcolor=#a37e45]") table.insert(formspec, "style_type[button_exit;bgcolor=#a37e45]") -- Dialog -- table.insert(formspec, "background[-1,-1;22,25;yl_speak_up_bg_dialog2.png;false]") @@ -593,7 +596,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec -- replace $NPC_NAME$ etc. local t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text( (alternate_text or active_dialog.d_text), dialog, pname)) - if(fs_version ~= "1") then + if(fs_version > 2) then yl_speak_up.add_formspec_element_with_tooltip_if(formspec, "hypertext", "0.2,5;19.6,17.8", "d_text", ""..t.."\n", @@ -609,17 +612,35 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec end local pname_for_old_fs = nil - if(fs_version ~= "1") then + if(fs_version > 2) then table.insert(formspec, "scrollbaroptions[min=0;max=14;smallstep=1;largestep=2;arrows=show]") table.insert(formspec, "scrollbar[0.2,24.2;0.2,7;vertical;scr0;0]") table.insert(formspec, "scroll_container[0,24;56,7;scr0;vertical;1]") else + if(fs_version < 2) then + table.insert(formspec, + "box[0.3,20;19,2.6;red]".. + "label[0.7,20.3;"..yl_speak_up.text_version_warning.."]") + -- The up and down buttons are microscopic. Offer some (still small) + -- additional text buttons so that players have a chance to hit them. + table.insert(formspec, "button[49,22.8;6,0.9;button_down;^ Scroll Up ^]") + table.insert(formspec, "button[49,31.8;6,0.9;button_up;v Scroll Down v]") + end -- old formspec versions need to remember somewhere extern how far the player scrolled pname_for_old_fs = pname yl_speak_up.speak_to[pname_for_old_fs].counter = 1 table.insert(formspec, "container[0,24]") - table.insert(formspec, "button[0.1,0;1,3;button_down;^\nU\np]") - table.insert(formspec, "button[0.1,3.2;1,4.5;button_up;D\no\nw\nn\nv]") + if(fs_version < 2) then + -- very small, ugly, and difficult to hit + table.insert(formspec, "button[0.1,0;1,0.9;button_down;^]") + table.insert(formspec, "button[0.1,7.0;1,0.9;button_up;v]") + else + -- somewhat larger and quite usable (v2 is pretty ok) + table.insert(formspec, "button[0.1,0;1,3;button_down;^\nU\np]") + table.insert(formspec, "button[0.1,3.2;1,4.5;button_up;D\no\nw\nn\nv]") + table.insert(formspec, "button[53.5,0;1,3;button_down;^\nU\np]") + table.insert(formspec, "button[53.5,3.2;1,4.5;button_up;D\no\nw\nn\nv]") + end end h = -0.8 @@ -890,7 +911,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec yl_speak_up.message_button_option_exit, true, nil, true, pname_for_old_fs) -- button_exit - if(fs_version ~= "1") then + if(fs_version > 2) then table.insert(formspec, "scroll_container_end[]") else table.insert(formspec, "container_end[]")