show what points to a dialog

This commit is contained in:
Sokomine 2021-07-18 01:24:55 +02:00
parent d48195cd6a
commit 45335caeda
2 changed files with 91 additions and 0 deletions

View File

@ -339,3 +339,76 @@ yl_speak_up.get_fs_edit_dialog_modification = function(dialog, d_id, alternate_d
"button[6.0,12.3;1,0.7;save_dialog_modification;Save]"..
"button[9.0,12.3;6,0.7;turn_alternate_text_into_new_dialog;Turn this into a new dialog]"
end
-- show which dialogs point/lead to this_dialog
yl_speak_up.show_what_points_to_this_dialog = function(player, pname, dialog, this_dialog)
if(not(dialog)
or not(dialog.n_dialogs)
or not(this_dialog)
or not(dialog.n_dialogs[ this_dialog ])) then
return ""
end
local found = {}
-- iterate over all dialogs
for d_id, d in pairs(dialog.n_dialogs) do
-- we are looking for dialogs that point here - not the dialog itself
if(d_id ~= this_dialog and d.d_options) then
-- iterate over all options
for o_id, o in pairs(d.d_options) do
-- preconditions are not relevant;
-- effects are (dialog and on_failure)
if(o.o_results) then
for r_id, r in pairs(o.o_results) do
if(r and r.r_type and r.r_type == "dialog"
and r.r_value == this_dialog) then
table.insert(found, {d_id, o_id, r_id,
"option was selected"})
elseif(r and r.r_type and r.r_type == "on_failure"
and r.r_value == this_dialog) then
table.insert(found, {d_id, o_id, r_id,
"the previous effect failed"})
end
end
end
-- actions may be relevant
if(o.actions) then
for a_id, a in pairs(o.actions) do
if(a and a.a_on_failure
and a.a_on_failure == this_dialog) then
table.insert(found, {d_id, o_id, a_id,
"action failed"})
end
end
end
end
end
end
local formspec = {
"formspec_version[3]",
"size[20,8]",
-- back to the list with that one precondition or effect
"button[0.2,0.2;19.4,0.6;back;Back to dialog "..minetest.formspec_escape(this_dialog).."]",
"button[0.2,7.2;19.4,0.6;back;Back to dialog "..minetest.formspec_escape(this_dialog).."]",
"label[0.2,1.1;Dialog \""..minetest.formspec_escape(this_dialog).."\" "..
"is referenced here:]",
"tablecolumns[color,span=1;text;color,span=1;text]",
"table[1.2,1.4;17.6,5.5;table_of_dialog_uses;"
}
for i, v in ipairs(found) do
local a_or_e = ""
if(v[4] ~= "action failed") then
a_or_e = "effect"
else
a_or_e = "action"
end
table.insert(formspec, "#FFFFFF,"..
minetest.formspec_escape(
"Dialog \""..tostring(v[1]).."\", option \""..tostring(v[2])..
"\", "..tostring(a_or_e).." \""..tostring(v[3]).."\":")..
",#FFFFFF,"..minetest.formspec_escape(v[4])..",")
end
return table.concat(formspec, "").."]"
end

View File

@ -1123,6 +1123,14 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text)
"need to delete all options and its text first.]")
end
-- chat option: "Show what points to this dialog."
h = h + 1
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;show_what_points_to_this_dialog;]")
table.insert(formspec, "tooltip[show_what_points_to_this_dialog;"..
"Show which other dialog options or failed actions\n"..
"or effects lead the player to this dialog here.]")
table.insert(formspec, "label[0.7,"..(h+0.45)..";Show what points to this dialog.]")
-- chat option: "Make this dialog the first one shown when starting to talk."
h = h + 1
if(active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) ~= 0) then
@ -2203,6 +2211,16 @@ yl_speak_up.input_talk = function(player, formname, fields)
local result = yl_speak_up.edit_mode_apply_changes(pname, fields)
end
-- show which dialogs point to this one
if(fields.show_what_points_to_this_dialog) then
local dialog = yl_speak_up.speak_to[pname].dialog
local d_id = yl_speak_up.speak_to[pname].d_id
-- TODO: use show_fs here
minetest.show_formspec(pname, "yl_speak_up:show_points_to_dialog",
yl_speak_up.show_what_points_to_this_dialog(player, pname, dialog, d_id))
return
end
-- the player wants to change name and description; show the formspec
if(edit_mode and fields.button_edit_name_and_description) then
-- this is not the initial config - but the same formspec can be used