deal with formspec_version lower than 3 and display formspec where possible

This commit is contained in:
Sokomine 2022-01-16 21:49:52 +01:00
parent 68f5ac0d7c
commit 5204c5c8ee
11 changed files with 44 additions and 36 deletions

View File

@ -400,8 +400,7 @@ yl_speak_up.get_fs_edit_dialog_modification = function(dialog, d_id, alternate_d
if(forbid_turn_into_new_dialog) then
nd = ""
end
return "formspec_version[3]"..
"size[20,13.5]"..
return "size[20,13.5]"..
"label[6.0,0.5;Edit alternate text]"..
"label[0.2,1.0;The alternate text which you can edit here will be shown instead of "..
"the normal text of the dialog \""..tostring(d_id).."\" - but *only*\n"..

View File

@ -1292,8 +1292,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
yl_speak_up.speak_to[pname][ tmp_data_cache ] = nil
-- display the selected element
if(x_id ~= "new") then
return "formspec_version[3]"..
"size[20,3]"..
return "size[20,3]"..
"bgcolor[#00000000;false]"..
"label[0.2,0.5;Selected "..element_desc..":]"..
"tablecolumns[text;color,span=1;text;text]"..
@ -1378,7 +1377,6 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
local save_button = "button[5.0,12.2;1,0.7;save_element;Save]"
local formspec =
"formspec_version[3]"..
"size[20,13]"..
"label[5,0.5;Edit "..element_desc.." \""..minetest.formspec_escape(x_id)..
"\" of option \""..minetest.formspec_escape(tostring(o_id))..

View File

@ -602,7 +602,6 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
-- build up the formspec
local formspec = ""..
"formspec_version[3]"..
"size[22,21]"..
"bgcolor[#00000000;false]"..
-- button back to the current dialog (of which this is an option)

View File

@ -186,7 +186,6 @@ yl_speak_up.get_fs_fashion = function(pname)
button_cancel = "Back"
end
local formspec = {
"formspec_version[3]",
"size[13.4,15]",
"dropdown[0.3,0.2;4,0.75;set_skin;",
mainlist,

View File

@ -104,8 +104,7 @@ yl_speak_up.get_fs_save_or_discard_changes = function(player, param)
text = minetest.formspec_escape(t).."\n"..text
end
-- build a formspec showing the changes to this dialog and ask for save
return "formspec_version[3]"..
"size[14,6.2]"..
return "size[14,6.2]"..
"bgcolor[#00000000;false]"..
-- TODO: make this more flexible
"label[0.2,0.2;You are about to leave dialog "..minetest.formspec_escape(d_id)..

View File

@ -489,8 +489,11 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
else
fs_version = 1
end
-- store which formspec version the player has
if(not(yl_speak_up.fs_version[pname])) then
yl_speak_up.fs_version[pname] = fs_version
end
formspec = {
"formspec_version["..tostring(fs_version).."]",
"size[57,33]",
"position[0,0.45]",
"anchor[0,0.45]",

View File

@ -68,7 +68,6 @@ end
yl_speak_up.get_error_message = function()
local formspec = {
"formspec_version[3]",
"size[13.4,8.5]",
"bgcolor[#FF0000]",
"label[0.2,0.35;Please save a NPC file first]",

View File

@ -15,6 +15,13 @@ yl_speak_up.status = yl_speak_up.modstorage:get_int("status") or 0
yl_speak_up.number_of_npcs = yl_speak_up.modstorage:get_int("amount") or 0
yl_speak_up.speak_to = {}
-- allow to request the highest possible version number for formspec_version
-- for each individual player; formspec_version...
-- ver 1 looks very bad because button height can't be set)
-- ver 2 works pretty well because the code has workarounds for the scroll elements
-- ver 3 is what this was developed with and looks best
yl_speak_up.fs_version = {}
dofile(modpath .. "config.lua")
dofile(modpath .. "privs.lua")
-- react to right-click etc.

View File

@ -109,7 +109,6 @@ yl_speak_up.print_as_table_prepare_formspec = function(res, table_name, back_but
concat_with = ",#FFFFFF,,#FFFFFF,,#FFFFFF,,#FFFFFF,,"
end
local formspec = {
"formspec_version[3]",
"size[57,33]",
-- back to the list with that one precondition or effect
"button[0.2,0.2;56.6,1.2;"..back_button_name..";"..

View File

@ -83,6 +83,14 @@ minetest.register_on_player_receive_fields( function(player, formname, fields)
end)
-- show formspec with highest possible version information for the player
yl_speak_up.show_fs_ver = function(pname, formname, formspec)
minetest.show_formspec(pname, formname,
"formspec_version["..tostring(yl_speak_up.fs_version[pname] or "2").."]"..
formspec)
end
-- call show_formspec with the right input_* function for the right formspec
-- (handles all show_formspec-calls)
yl_speak_up.show_fs = function(player, fs_name, param)
@ -97,7 +105,7 @@ yl_speak_up.show_fs = function(player, fs_name, param)
local last_fs = yl_speak_up.speak_to[pname].last_fs
-- show the save or discard changes dialog
if(fs_name and fs_name == "save_or_discard_changes") then
minetest.show_formspec(pname, "yl_speak_up:save_or_discard_changes",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:save_or_discard_changes",
yl_speak_up.get_fs_save_or_discard_changes(player, param))
return
@ -184,7 +192,7 @@ yl_speak_up.show_fs = function(player, fs_name, param)
if(not(param)) then
param = {}
end
minetest.show_formspec(pname, param.input_to, param.formspec)
yl_speak_up.show_fs_ver(pname, param.input_to, param.formspec)
elseif(fs_name == "quit") then
@ -195,14 +203,14 @@ yl_speak_up.show_fs = function(player, fs_name, param)
if(not(param)) then
param = {}
end
minetest.show_formspec(pname, "yl_speak_up:optiondialog",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:optiondialog",
yl_speak_up.get_fs_optiondialog(player, param.n_id, param.d_id, param.o_id, param.p_id, param.r_id))
elseif(fs_name == "setdialog") then
if(not(param)) then
param = {}
end
minetest.show_formspec(pname, "yl_speak_up:setdialog",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:setdialog",
yl_speak_up.get_fs_setdialog(player, param.n_id, param.d_id))
elseif(fs_name == "edit_option_dialog") then
@ -211,7 +219,7 @@ yl_speak_up.show_fs = function(player, fs_name, param)
param = {}
end
yl_speak_up.speak_to[pname].o_id = param.o_id
minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:edit_option_dialog",
yl_speak_up.get_fs_edit_option_dialog(player, param.n_id, param.d_id, param.o_id,
param.caller))
@ -219,24 +227,24 @@ yl_speak_up.show_fs = function(player, fs_name, param)
if(not(param)) then
param = {}
end
minetest.show_formspec(pname, "yl_speak_up:talk",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:talk",
-- recursion depth from autoanswer: 0 (the player selected manually)
yl_speak_up.get_fs_talkdialog(player, param.n_id, param.d_id, param.alternate_text,0))
elseif(fs_name == "fashion") then
minetest.show_formspec(pname, "yl_speak_up:fashion",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:fashion",
yl_speak_up.get_fs_fashion(pname))
elseif(fs_name == "inventory") then
minetest.show_formspec(pname, "yl_speak_up:inventory",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:inventory",
yl_speak_up.get_fs_inventory(player))
elseif(fs_name == "trade_list") then
minetest.show_formspec(pname, "yl_speak_up:trade_list",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:trade_list",
yl_speak_up.get_fs_trade_list(player, param))
elseif(fs_name == "player_offers_item") then
minetest.show_formspec(pname, "yl_speak_up:player_offers_item",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:player_offers_item",
yl_speak_up.get_fs_player_offers_item(player, param))
elseif(fs_name == "trade_simple") then
@ -244,7 +252,7 @@ yl_speak_up.show_fs = function(player, fs_name, param)
if(not(param) and yl_speak_up.speak_to[pname]) then
param = yl_speak_up.speak_to[pname].trade_id
end
minetest.show_formspec(pname, "yl_speak_up:do_trade_simple",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:do_trade_simple",
yl_speak_up.get_fs_trade_simple(player, param))
elseif(fs_name == "add_trade_simple") then
@ -252,52 +260,52 @@ yl_speak_up.show_fs = function(player, fs_name, param)
if(not(param) and yl_speak_up.speak_to[pname]) then
param = yl_speak_up.speak_to[pname].trade_id
end
minetest.show_formspec(pname, "yl_speak_up:add_trade_simple",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:add_trade_simple",
yl_speak_up.get_fs_add_trade_simple(player, param))
elseif(fs_name == "initial_config") then
if(not(param)) then
param = {}
end
minetest.show_formspec(pname, "yl_speak_up:initial_config",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:initial_config",
yl_speak_up.get_fs_initial_config(player, param.n_id, param.d_id,
param.is_initial_config))
elseif(fs_name == "edit_preconditions") then
minetest.show_formspec(pname, "yl_speak_up:edit_preconditions",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:edit_preconditions",
yl_speak_up.get_fs_edit_preconditions(player, param))
elseif(fs_name == "edit_actions") then
minetest.show_formspec(pname, "yl_speak_up:edit_actions",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:edit_actions",
yl_speak_up.get_fs_edit_actions(player, param))
elseif(fs_name == "edit_effects") then
minetest.show_formspec(pname, "yl_speak_up:edit_effects",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:edit_effects",
yl_speak_up.get_fs_edit_effects(player, param))
-- action related
elseif(fs_name == "action_npc_gives") then
minetest.show_formspec(pname, "yl_speak_up:action_npc_gives",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:action_npc_gives",
yl_speak_up.get_fs_action_npc_gives(player, param))
elseif(fs_name == "action_npc_wants") then
minetest.show_formspec(pname, "yl_speak_up:action_npc_wants",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:action_npc_wants",
yl_speak_up.get_fs_action_npc_wants(player, param))
elseif(fs_name == "action_text_input") then
minetest.show_formspec(pname, "yl_speak_up:action_text_input",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:action_text_input",
yl_speak_up.get_fs_action_text_input(player, param))
elseif(fs_name == "action_custom") then
minetest.show_formspec(pname, "yl_speak_up:action_custom",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:action_custom",
yl_speak_up.get_fs_action_custom(player, param))
elseif(fs_name == "manage_variables") then
minetest.show_formspec(pname, "yl_speak_up:manage_variables",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:manage_variables",
yl_speak_up.get_fs_manage_variables(player, param))
elseif(fs_name == "show_what_points_to_this_dialog") then
minetest.show_formspec(pname, "yl_speak_up:show_what_points_to_this_dialog",
yl_speak_up.show_fs_ver(pname, "yl_speak_up:show_what_points_to_this_dialog",
yl_speak_up.show_what_points_to_this_dialog(player, param))
-- fallback in case of wrong call

View File

@ -189,7 +189,6 @@ yl_speak_up.get_fs_setdialog = function(clicker, n_id, d_id)
end
local formspec = {
"formspec_version[3]",
"size[13.4,8.5]",
"label[0.2,0.35;",
dialog.n_id,
@ -386,7 +385,6 @@ yl_speak_up.get_fs_optiondialog = function(player, n_id, d_id, o_id, p_id, r_id)
end
local formspec = {
"formspec_version[3]",
"size[13.4,8.5]",
-- npc
"field[-10,-10;4,0.5;n_id;;",