mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-06-26 09:08:03 +02:00
buttons/lines with options/answers are now handled by extra function in fs_talkdialog.lua
This commit is contained in:
parent
1d06c2a825
commit
8a921180cd
@ -314,6 +314,144 @@ yl_speak_up.get_start_dialog_id = function(dialog)
|
||||
end
|
||||
|
||||
|
||||
-- helper function for yl_speak_up.get_fs_talkdialog:
|
||||
-- prints one entry (option/answer) in normal mode - not in edit_mode
|
||||
yl_speak_up.get_fs_talkdialog_line_in_normal_mode = function(
|
||||
formspec, h, pname_for_old_fs, oid, sb_v,
|
||||
dialog, allowed, pname)
|
||||
local t = "- no text given -"
|
||||
local t_alt = nil
|
||||
-- the preconditions are fulfilled; showe the option
|
||||
if(allowed[sb_v.o_id] == true) then
|
||||
-- replace $NPC_NAME$ etc.
|
||||
t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
sb_v.o_text_when_prerequisites_met, dialog, pname))
|
||||
-- precondition not fulfilled? the option shall be hidden
|
||||
elseif(sb_v.o_hide_when_prerequisites_not_met == "true") then
|
||||
-- show nothing; t_alt remains nil
|
||||
t = nil
|
||||
-- precondition not fulfilled? the option shall be greyed out
|
||||
-- default to greyed out (this option cannot be selected)
|
||||
elseif(sb_v.o_grey_when_prerequisites_not_met == "true") then
|
||||
local text = sb_v.o_text_when_prerequisites_not_met
|
||||
if(not(text) or text == "") then
|
||||
text = t or yl_speak_up.message_button_option_prerequisites_not_met_default
|
||||
end
|
||||
t = nil
|
||||
-- replace $NPC_NAME$ etc.
|
||||
t_alt = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
text, dialog, pname))
|
||||
elseif(sb_v.o_grey_when_prerequisites_not_met == "false"
|
||||
and sb_v.o_text_when_prerequisites_not_met ~= "") then
|
||||
-- show in normal coor
|
||||
t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
sb_v.o_text_when_prerequisites_not_met, dialog, pname))
|
||||
end
|
||||
if(t or t_alt) then
|
||||
-- actually show the button
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"button_" .. oid,
|
||||
t,
|
||||
t,
|
||||
(t and not(t_alt)),
|
||||
t_alt,
|
||||
nil, pname_for_old_fs)
|
||||
end
|
||||
return {h = h, formspec = formspec}
|
||||
end
|
||||
|
||||
|
||||
-- helper function for yl_speak_up.get_fs_talkdialog:
|
||||
-- prints one entry (option/answer) in *edit_mode*
|
||||
yl_speak_up.get_fs_talkdialog_line_in_edit_mode = function(
|
||||
formspec, h, pname_for_old_fs, oid, sb_v,
|
||||
dialog, active_dialog, dialog_list, d_id_to_dropdown_index)
|
||||
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
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"button", tostring(2.3+offset).."," .. h .. ";2,0.9", "edit_option_" .. oid,
|
||||
oid,
|
||||
"Edit target dialog, pre(C)onditions and (Ef)fects for option "..oid..".",
|
||||
true)
|
||||
-- find the right target dialog for this option (if it exists):
|
||||
local target_dialog = nil
|
||||
local results = active_dialog.d_options[sb_v.o_id].o_results
|
||||
-- has this option more results/effects than just switching to another dialog?
|
||||
local has_other_results = false
|
||||
if(results ~= nil) then
|
||||
for k, v in pairs(results) do
|
||||
if v.r_type == "dialog"
|
||||
and (dialog.n_dialogs[v.r_value] ~= nil
|
||||
or v.r_value == "d_end"
|
||||
or v.r_value == "d_got_item") then
|
||||
-- there may be more than one in the data structure
|
||||
target_dialog = v.r_value
|
||||
elseif v.r_type ~= "dialog" then
|
||||
has_other_results = true
|
||||
end
|
||||
end
|
||||
end
|
||||
-- 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!
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"button", tostring(9.0+offset)..","..h..";1,0.9", "button_" .. oid,
|
||||
"->",
|
||||
"Go to target dialog "..minetest.formspec_escape(target_dialog or "")..
|
||||
" that will be shown when this option ("..oid..") is selected.",
|
||||
(target_dialog))
|
||||
|
||||
-- allow to set a new target dialog
|
||||
table.insert(formspec, "dropdown["..tostring(4.4+offset)..","..h..";4.7,1;d_id_"..
|
||||
oid..";"..
|
||||
dialog_list..";"..
|
||||
(d_id_to_dropdown_index[(target_dialog or "?")] or "0")..",]")
|
||||
-- add a tooltip "Change target dialog"
|
||||
table.insert(formspec, "tooltip[4.4,"..h..";4.7,1;"..
|
||||
"Change target dialog for option "..oid..".;#FFFFFF;#000000]")
|
||||
|
||||
-- are there any prerequirements?
|
||||
local prereq = active_dialog.d_options[sb_v.o_id].o_prerequisites
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"button", tostring(0.5+offset)..","..h..";0.5,0.9", "conditions_"..oid,
|
||||
"C",
|
||||
"There are pre(C)onditions required for showing this option. Display them.",
|
||||
(prereq and next(prereq)))
|
||||
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"button", tostring(1.6+offset)..","..h..";0.6,0.9", "effects_"..oid,
|
||||
"Ef",
|
||||
"There are further (Ef)fects (apart from switching\n"..
|
||||
"to a new dialog) set for this option. Display them.",
|
||||
(has_other_results))
|
||||
|
||||
-- are there any actions defined?
|
||||
local actions = active_dialog.d_options[sb_v.o_id].actions
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"button", tostring(1.1+offset)..","..h..";0.5,0.9", "actions_"..oid,
|
||||
"A",
|
||||
"There is an (A)ction (i.e. a trade) that will happen\n"..
|
||||
"when switching to a new dialog. Display actions and\n"..
|
||||
"trade of this option.",
|
||||
(actions and next(actions)))
|
||||
|
||||
-- show the actual text for the option
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"field", tostring(9.9+offset)..","..h..";"..
|
||||
tostring(field_length)..",0.9",
|
||||
"text_option_" .. oid,
|
||||
";"..minetest.formspec_escape(sb_v.o_text_when_prerequisites_met),
|
||||
"Edit the text that is displayed on button "..oid..".",
|
||||
true)
|
||||
return {h = h, formspec = formspec}
|
||||
end
|
||||
|
||||
|
||||
-- recursion_depth is increased each time autoanswer is automaticly selected
|
||||
yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, recursion_depth)
|
||||
local pname = player:get_player_name()
|
||||
@ -527,132 +665,20 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
||||
for _, s_o_id in ipairs(sorted_o_list) do
|
||||
local sb_v = active_dialog.d_options[s_o_id]
|
||||
local oid = minetest.formspec_escape(sb_v.o_id)
|
||||
local res = {}
|
||||
-- in edit_mode: show all options
|
||||
if(edit_mode and yl_speak_up.old_fs_version_show_line(pname_for_old_fs)) then
|
||||
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
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"button", tostring(2.3+offset).."," .. h .. ";2,0.9", "edit_option_" .. oid,
|
||||
oid,
|
||||
"Edit target dialog, pre(C)onditions and (Ef)fects for option "..oid..".",
|
||||
true)
|
||||
-- find the right target dialog for this option (if it exists):
|
||||
local target_dialog = nil
|
||||
local results = active_dialog.d_options[sb_v.o_id].o_results
|
||||
-- has this option more results/effects than just switching to another dialog?
|
||||
local has_other_results = false
|
||||
if(results ~= nil) then
|
||||
for k, v in pairs(results) do
|
||||
if v.r_type == "dialog"
|
||||
and (dialog.n_dialogs[v.r_value] ~= nil
|
||||
or v.r_value == "d_end"
|
||||
or v.r_value == "d_got_item") then
|
||||
-- there may be more than one in the data structure
|
||||
target_dialog = v.r_value
|
||||
elseif v.r_type ~= "dialog" then
|
||||
has_other_results = true
|
||||
end
|
||||
end
|
||||
end
|
||||
-- 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!
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"button", tostring(9.0+offset)..","..h..";1,0.9", "button_" .. oid,
|
||||
"->",
|
||||
"Go to target dialog "..minetest.formspec_escape(target_dialog or "")..
|
||||
" that will be shown when this option ("..oid..") is selected.",
|
||||
(target_dialog))
|
||||
|
||||
-- allow to set a new target dialog
|
||||
table.insert(formspec, "dropdown["..tostring(4.4+offset)..","..h..";4.7,1;d_id_"..
|
||||
oid..";"..
|
||||
dialog_list..";"..
|
||||
(d_id_to_dropdown_index[(target_dialog or "?")] or "0")..",]")
|
||||
-- add a tooltip "Change target dialog"
|
||||
table.insert(formspec, "tooltip[4.4,"..h..";4.7,1;"..
|
||||
"Change target dialog for option "..oid..".;#FFFFFF;#000000]")
|
||||
|
||||
-- are there any prerequirements?
|
||||
local prereq = active_dialog.d_options[sb_v.o_id].o_prerequisites
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"button", tostring(0.5+offset)..","..h..";0.5,0.9", "conditions_"..oid,
|
||||
"C",
|
||||
"There are pre(C)onditions required for showing this option. Display them.",
|
||||
(prereq and next(prereq)))
|
||||
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"button", tostring(1.6+offset)..","..h..";0.6,0.9", "effects_"..oid,
|
||||
"Ef",
|
||||
"There are further (Ef)fects (apart from switching\n"..
|
||||
"to a new dialog) set for this option. Display them.",
|
||||
(has_other_results))
|
||||
|
||||
-- are there any actions defined?
|
||||
local actions = active_dialog.d_options[sb_v.o_id].actions
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"button", tostring(1.1+offset)..","..h..";0.5,0.9", "actions_"..oid,
|
||||
"A",
|
||||
"There is an (A)ction (i.e. a trade) that will happen\n"..
|
||||
"when switching to a new dialog. Display actions and\n"..
|
||||
"trade of this option.",
|
||||
(actions and next(actions)))
|
||||
|
||||
-- show the actual text for the option
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"field", tostring(9.9+offset)..","..h..";"..
|
||||
tostring(field_length)..",0.9",
|
||||
"text_option_" .. oid,
|
||||
";"..minetest.formspec_escape(sb_v.o_text_when_prerequisites_met),
|
||||
"Edit the text that is displayed on button "..oid..".",
|
||||
true)
|
||||
|
||||
res = yl_speak_up.get_fs_talkdialog_line_in_edit_mode(
|
||||
formspec, h, pname_for_old_fs, oid, sb_v,
|
||||
dialog, active_dialog, dialog_list, d_id_to_dropdown_index)
|
||||
-- normal mode: show an option if the prerequirements (if any are defined) are met
|
||||
elseif(not(edit_mode)) then
|
||||
local t = "- no text given -"
|
||||
local t_alt = nil
|
||||
-- the preconditions are fulfilled; showe the option
|
||||
if(allowed[sb_v.o_id] == true) then
|
||||
-- replace $NPC_NAME$ etc.
|
||||
t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
sb_v.o_text_when_prerequisites_met, dialog, pname))
|
||||
-- precondition not fulfilled? the option shall be hidden
|
||||
elseif(sb_v.o_hide_when_prerequisites_not_met == "true") then
|
||||
-- show nothing; t_alt remains nil
|
||||
t = nil
|
||||
-- precondition not fulfilled? the option shall be greyed out
|
||||
-- default to greyed out (this option cannot be selected)
|
||||
elseif(sb_v.o_grey_when_prerequisites_not_met == "true") then
|
||||
local text = sb_v.o_text_when_prerequisites_not_met
|
||||
if(not(text) or text == "") then
|
||||
text = t or yl_speak_up.message_button_option_prerequisites_not_met_default
|
||||
end
|
||||
t = nil
|
||||
-- replace $NPC_NAME$ etc.
|
||||
t_alt = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
text, dialog, pname))
|
||||
elseif(sb_v.o_grey_when_prerequisites_not_met == "false"
|
||||
and sb_v.o_text_when_prerequisites_not_met ~= "") then
|
||||
-- show in normal coor
|
||||
t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
sb_v.o_text_when_prerequisites_not_met, dialog, pname))
|
||||
end
|
||||
if(t or t_alt) then
|
||||
-- actually show the button
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"button_" .. oid,
|
||||
t,
|
||||
t,
|
||||
(t and not(t_alt)),
|
||||
t_alt,
|
||||
nil, pname_for_old_fs)
|
||||
end
|
||||
res = yl_speak_up.get_fs_talkdialog_line_in_normal_mode(
|
||||
formspec, h, pname_for_old_fs, oid, sb_v,
|
||||
dialog, allowed, pname)
|
||||
end
|
||||
formspec = res.formspec
|
||||
h = res.h
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user