forked from Sokomine/yl_speak_up
made edit dialog work in formspec versions < 3 as far as possible
This commit is contained in:
parent
e950cdc1f0
commit
5b49bfbccd
@ -276,6 +276,24 @@ yl_speak_up.input_talk = function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- older formspecs (before v3) do not offer a scroll container and have to scroll manually;
|
||||||
|
-- we maintain a player-name-based counter in order to see if this line ought to be shown
|
||||||
|
yl_speak_up.old_fs_version_show_line = function(pname)
|
||||||
|
-- the player is using a new enough version for scroll_container to work
|
||||||
|
if(not(pname)) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
local max_number_of_buttons = yl_speak_up.max_number_of_buttons
|
||||||
|
local start_index = yl_speak_up.speak_to[pname].option_index
|
||||||
|
local counter = yl_speak_up.speak_to[pname].counter
|
||||||
|
yl_speak_up.speak_to[pname].counter = counter + 1
|
||||||
|
if counter < start_index or counter >= start_index + max_number_of_buttons then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- show an edit option in the main menu of the NPC;
|
-- show an edit option in the main menu of the NPC;
|
||||||
-- helper function for yl_speak_up.fs_talkdialog(..)
|
-- helper function for yl_speak_up.fs_talkdialog(..)
|
||||||
yl_speak_up.add_edit_button_fs_talkdialog = function(formspec, h, button_name, tooltip, label,
|
yl_speak_up.add_edit_button_fs_talkdialog = function(formspec, h, button_name, tooltip, label,
|
||||||
@ -289,11 +307,7 @@ yl_speak_up.add_edit_button_fs_talkdialog = function(formspec, h, button_name, t
|
|||||||
local label_start_pos = "0.7"
|
local label_start_pos = "0.7"
|
||||||
-- older formspecs (before v4) do not offer a scroll container and have to scroll manually
|
-- older formspecs (before v4) do not offer a scroll container and have to scroll manually
|
||||||
if(pname) then
|
if(pname) then
|
||||||
local max_number_of_buttons = yl_speak_up.max_number_of_buttons
|
if(not(yl_speak_up.old_fs_version_show_line(pname))) then
|
||||||
local start_index = yl_speak_up.speak_to[pname].option_index
|
|
||||||
local counter = yl_speak_up.speak_to[pname].counter
|
|
||||||
yl_speak_up.speak_to[pname].counter = counter + 1
|
|
||||||
if counter < start_index or counter >= start_index + max_number_of_buttons then
|
|
||||||
return h
|
return h
|
||||||
end
|
end
|
||||||
-- there has to be more room for the up and down arrows
|
-- there has to be more room for the up and down arrows
|
||||||
@ -657,11 +671,17 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
for _, sb_v in pairs(sorted_buttons) do
|
for _, sb_v in pairs(sorted_buttons) do
|
||||||
local oid = minetest.formspec_escape(sb_v.o_id)
|
local oid = minetest.formspec_escape(sb_v.o_id)
|
||||||
-- in edit_mode: show all options
|
-- in edit_mode: show all options
|
||||||
if edit_mode then
|
if(edit_mode and yl_speak_up.old_fs_version_show_line(pname_for_old_fs)) then
|
||||||
h = h + 1
|
local offset = 0.0
|
||||||
|
local field_length = 44.4
|
||||||
|
if(pname_for_old_fs) then
|
||||||
|
offset = 0.7
|
||||||
|
field_length = 42.4
|
||||||
|
end
|
||||||
|
h = h + 1
|
||||||
-- add a button "o_<nr>:" that leads to an edit formspec for this option
|
-- add a button "o_<nr>:" that leads to an edit formspec for this option
|
||||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||||
"button", "2.3," .. h .. ";2,0.9", "edit_option_" .. oid,
|
"button", tostring(2.3+offset).."," .. h .. ";2,0.9", "edit_option_" .. oid,
|
||||||
oid,
|
oid,
|
||||||
"Edit target dialog, pre(C)onditions and (Ef)fects for option "..oid..".",
|
"Edit target dialog, pre(C)onditions and (Ef)fects for option "..oid..".",
|
||||||
true)
|
true)
|
||||||
@ -683,16 +703,17 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
-- add a button "-> d_<nr>" that leads to the target dialog (if one is set)
|
-- add a button "-> d_<nr>" that leads to the target dialog (if one is set)
|
||||||
-- selecting an option this way MUST NOT execute the pre(C)onditions or (Ef)fects!
|
-- selecting an option this way MUST NOT execute the pre(C)onditions or (Ef)fects!
|
||||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||||
"button", "9.0," .. h .. ";1,0.9", "button_" .. oid,
|
"button", tostring(9.0+offset).."," .. h .. ";1,0.9", "button_" .. oid,
|
||||||
"->",
|
"->",
|
||||||
"Go to target dialog "..minetest.formspec_escape(target_dialog)..
|
"Go to target dialog "..minetest.formspec_escape(target_dialog or "")..
|
||||||
" that will be shown when this option ("..oid..") is selected.",
|
" that will be shown when this option ("..oid..") is selected.",
|
||||||
(target_dialog))
|
(target_dialog))
|
||||||
|
|
||||||
-- allow to set a new target dialog
|
-- allow to set a new target dialog
|
||||||
table.insert(formspec, "dropdown[4.4,"..h..";4.7,1;d_id_"..oid..";"..
|
table.insert(formspec, "dropdown["..tostring(4.4+offset)..","..h..";4.7,1;d_id_"..
|
||||||
|
oid..";"..
|
||||||
dialog_list..";"..
|
dialog_list..";"..
|
||||||
minetest.formspec_escape(d_id_to_dropdown_index[target_dialog] or "0")..",]")
|
minetest.formspec_escape(d_id_to_dropdown_index[(target_dialog or "?")] or "0")..",]")
|
||||||
-- add a tooltip "Change target dialog"
|
-- add a tooltip "Change target dialog"
|
||||||
table.insert(formspec, "tooltip[4.4,"..h..";4.7,1;"..
|
table.insert(formspec, "tooltip[4.4,"..h..";4.7,1;"..
|
||||||
"Change target dialog for option "..oid..".;#FFFFFF;#000000]")
|
"Change target dialog for option "..oid..".;#FFFFFF;#000000]")
|
||||||
@ -700,13 +721,13 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
-- are there any prerequirements?
|
-- are there any prerequirements?
|
||||||
local prereq = active_dialog.d_options[sb_v.o_id].o_prerequisites
|
local prereq = active_dialog.d_options[sb_v.o_id].o_prerequisites
|
||||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||||
"button", "0.5," .. h .. ";0.5,0.9", "conditions_"..oid,
|
"button", tostring(0.5+offset).."," .. h .. ";0.5,0.9", "conditions_"..oid,
|
||||||
"C",
|
"C",
|
||||||
"There are pre(C)onditions required for showing this option. Display them.",
|
"There are pre(C)onditions required for showing this option. Display them.",
|
||||||
(prereq and next(prereq)))
|
(prereq and next(prereq)))
|
||||||
|
|
||||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||||
"button", "1.6," .. h .. ";0.6,0.9", "effects_"..oid,
|
"button", tostring(1.6+offset).."," .. h .. ";0.6,0.9", "effects_"..oid,
|
||||||
"Ef",
|
"Ef",
|
||||||
"There are further (Ef)fects (apart from switching\n"..
|
"There are further (Ef)fects (apart from switching\n"..
|
||||||
"to a new dialog) set for this option. Display them.",
|
"to a new dialog) set for this option. Display them.",
|
||||||
@ -715,7 +736,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
-- are there any actions defined?
|
-- are there any actions defined?
|
||||||
local actions = active_dialog.d_options[sb_v.o_id].actions
|
local actions = active_dialog.d_options[sb_v.o_id].actions
|
||||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||||
"button", "1.1," .. h .. ";0.5,0.9", "actions_"..oid,
|
"button", tostring(1.1+offset).."," .. h .. ";0.5,0.9", "actions_"..oid,
|
||||||
"A",
|
"A",
|
||||||
"There is an (A)ction (i.e. a trade) that will happen\n"..
|
"There is an (A)ction (i.e. a trade) that will happen\n"..
|
||||||
"when switching to a new dialog. Display actions and\n"..
|
"when switching to a new dialog. Display actions and\n"..
|
||||||
@ -724,13 +745,15 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
|
|
||||||
-- show the actual text for the option
|
-- show the actual text for the option
|
||||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||||
"field", "9.9," .. h .. ";44.4,0.9", "text_option_" .. oid,
|
"field", tostring(9.9+offset).."," .. h .. ";"..
|
||||||
|
tostring(field_length)..",0.9",
|
||||||
|
"text_option_" .. oid,
|
||||||
";"..minetest.formspec_escape(sb_v.o_text_when_prerequisites_met),
|
";"..minetest.formspec_escape(sb_v.o_text_when_prerequisites_met),
|
||||||
"Edit the text that is displayed on button "..oid..".",
|
"Edit the text that is displayed on button "..oid..".",
|
||||||
true)
|
true)
|
||||||
|
|
||||||
-- normal mode: show an option if the prerequirements (if any are defined) are met
|
-- normal mode: show an option if the prerequirements (if any are defined) are met
|
||||||
else
|
elseif(not(edit_mode)) then
|
||||||
local t = "- no text given -"
|
local t = "- no text given -"
|
||||||
local t_alt = nil
|
local t_alt = nil
|
||||||
-- the preconditions are fulfilled; showe the option
|
-- the preconditions are fulfilled; showe the option
|
||||||
|
Loading…
Reference in New Issue
Block a user