removed deprecated handling of older formspec versions (now handled in another part of the code)

This commit is contained in:
Sokomine 2022-01-09 02:10:32 +01:00
parent 5b49bfbccd
commit 1967eeef15

View File

@ -531,7 +531,7 @@ 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 > 2) then
table.insert(formspec, "style_type[button;bgcolor=#a37e45]")
@ -632,6 +632,10 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
table.insert(formspec, "scroll_container[0,24;56,7;scr0;vertical;1]")
else
if(fs_version < 2) then
-- if the player has an older formspec version
minetest.log( "info",
"[MOD] yl_speak_up: User " .. pname .. " talked to NPC ID n_" .. n_id ..
" with an old formspec version!")
table.insert(formspec,
"box[0.3,20;19,2.6;red]"..
"label[0.7,20.3;"..yl_speak_up.text_version_warning.."]")
@ -940,148 +944,6 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
table.insert(formspec, "container_end[]")
end
table.insert(formspec, "container_end[]")
-- if the player has an older formspec version
-- TODO: the version for older formspec versions lacks quite a lot - in particular regarding editing
else
minetest.log(
"info",
"[MOD] yl_speak_up: User " .. pname .. " talked to NPC ID n_" .. n_id .. " with an old formspec version!"
)
local upgrade_warning = ""
local max_number_of_buttons = yl_speak_up.max_number_of_buttons
local start_index = yl_speak_up.speak_to[pname].option_index
if formspec_v < 3 or protocol_v < 39 then
local warn = {
"box[0.3,3;15,2;red]",
"label[0.7,3.2;",
yl_speak_up.text_version_warning,
"]"
}
upgrade_warning = table.concat(warn, "")
end
if(alternate_text) then
alternate_text = string.gsub(alternate_text, "%$TEXT%$", active_dialog.d_text)
end
-- 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))
table.insert(formspec, upgrade_warning)
table.insert(formspec, "textarea[0.5,5;19.6,13.5;;;"..t .. "\n".."]")
table.insert(formspec, "container[0,24]")
h = -1
if active_dialog ~= nil and active_dialog.d_options ~= nil then
-- Let's sort the options by o_sort.
local sorted_buttons = {}
for _, ad_v in pairs(active_dialog.d_options) do
sorted_buttons[tonumber(ad_v.o_sort)] = ad_v
end
if #sorted_buttons > max_number_of_buttons then
-- Generate arrows
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]")
end
local counter = 1
for _, sb_v in pairs(sorted_buttons) do
local end_index = start_index + max_number_of_buttons
if counter >= start_index and counter < end_index then
local oid = minetest.formspec_escape(sb_v.o_id)
if allowed[sb_v.o_id] == true then
h = h + 1
table.insert(
formspec,
"button[1," ..
h .. ";44,0.9;button_" .. oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_met) .. "]"
)
table.insert(
formspec,
"tooltip[button_" .. oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_met) .. "]"
)
else
if sb_v.o_hide_when_prerequisites_not_met == "true" then
-- hide! Nothing to do
else
if
sb_v.o_grey_when_prerequisites_not_met == "true" and
sb_v.o_text_when_prerequisites_not_met == ""
then
h = h + 1
local l = h - 0.2
table.insert(formspec, "box[1," .. l .. ";43,1;#BBBBBB]")
table.insert(
formspec,
"label[3," ..
h ..
";" ..
yl_speak_up.message_button_option_prerequisites_not_met_default .. "]"
)
end
if
sb_v.o_grey_when_prerequisites_not_met == "true" and
sb_v.o_text_when_prerequisites_not_met ~= ""
then
h = h + 1
local l = h - 0.2
table.insert(formspec, "box[1," .. l .. ";43,1;#BBBBBB]")
table.insert(
formspec,
"label[3," ..
h ..
";" ..
yl_speak_up.message_button_option_prerequisites_not_met_default ..
" : " .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_not_met) .. "]"
)
end
if
sb_v.o_grey_when_prerequisites_not_met == "false" and
sb_v.o_text_when_prerequisites_not_met == ""
then
-- no hide, no grey, no text
end
if
sb_v.o_grey_when_prerequisites_not_met == "false" and
sb_v.o_text_when_prerequisites_not_met ~= ""
then
h = h + 1
table.insert(
formspec,
"button[1," ..
h ..
";44,0.9;button_" ..
oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_not_met) .. "]"
)
table.insert(
formspec,
"tooltip[button_" ..
oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_not_met) .. "]"
)
end
end
end
end
counter = counter + 1
end
end
h = h + 1
table.insert(
formspec,
"button_exit[1," .. h .. ";44,0.9;button_exit;" .. yl_speak_up.message_button_option_exit .. "]"
)
table.insert(formspec, "tooltip[button_exit;" .. yl_speak_up.message_button_option_exit .. "]")
table.insert(formspec, "container_end[]")
table.insert(formspec, "container_end[]")
end
return table.concat(formspec, "")
return table.concat(formspec, "")
end