moved edit options for main text into extra function in fs_talkdialog.lua

This commit is contained in:
Sokomine 2022-07-18 21:39:42 +02:00
parent c92db604d2
commit 4953f23737

View File

@ -314,6 +314,81 @@ yl_speak_up.get_start_dialog_id = function(dialog)
end
-- helper function for yl_speak_up.get_fs_talkdialog:
-- shows the text the NPC "speaks" and adds edit and navigation buttons
-- (all only in *edit_mode*)
yl_speak_up.get_fs_talkdialog_main_text_in_edit_mode = function(
formspec, h, dialog, dialog_list, edit_mode, c_d_id, active_dialog)
local d_id_to_dropdown_index = {}
if(not(edit_mode)) then
return {h = h, formspec = formspec, d_id_to_dropdown_index = {}, dialog_list = dialog_list}
end
-- allow to change skin, wielded items etc.
table.insert(formspec, "button[15.75,3.5;3.5,0.9;edit_skin;Edit Skin]")
if(not(dialog) or not(dialog.n_dialogs)) then
return {h = h, formspec = formspec, d_id_to_dropdown_index = {}, dialog_list = dialog_list}
end
-- display the window with the text the NPC is saying
-- sort all dialogs by d_sort
local sorted_list = yl_speak_up.get_sorted_options(dialog.n_dialogs, "d_sort")
-- add buttons for previous/next dialog
for i, d in ipairs(sorted_list) do
-- build the list of available dialogs for the dropdown list(s)
dialog_list = dialog_list..","..minetest.formspec_escape(d)
if(d == c_d_id) then
local prev_dialog = tostring(minetest.formspec_escape(sorted_list[i-1]))
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"button", "8.5,4.0;2,0.9", "prev_dialog_"..prev_dialog,
"<",
"Go to previous dialog "..prev_dialog..".",
(sorted_list[ i-1 ]))
local next_dialog = tostring(minetest.formspec_escape(sorted_list[i+1]))
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"button", "11,4.0;2,0.9", "next_dialog_"..next_dialog,
">",
"Go to next dialog "..next_dialog..".",
(sorted_list[ i+1 ]))
end
d_id_to_dropdown_index[d] = i + 1
end
dialog_list = dialog_list..",d_end"
d_id_to_dropdown_index["d_end"] = #sorted_list + 2
table.insert(formspec, "label[0.2,4.6;Dialog:]") -- "..minetest.formspec_escape(c_d_id)..":]")
table.insert(formspec, "dropdown[3.0,4.0;5,1;d_id;"..dialog_list..";"..
d_id_to_dropdown_index[c_d_id]..",]")
table.insert(formspec, "tooltip[3.0,4.0;5,1;"..
"Select the dialog you want to edit. Currently, dialog "..c_d_id..
" is beeing displayed.;#FFFFFF;#000000]")
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"button", "13.9,4.0;1,0.9", "show_new_dialog",
"+",
"Create a new dialog.",
true)
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"button", "13.4,0.3;2,0.9", "button_edit_name_and_description",
"Edit",
"Edit name and description of your NPC.",
true)
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"button", "15.7,0.3;2,0.9", "button_save_dialog",
"Save",
"Save this dialog.",
true)
table.insert(formspec, "textarea[0.2,5;19.6,17.8;d_text;;"..
minetest.formspec_escape(active_dialog.d_text)..
"]")
return {h = h, formspec = formspec, d_id_to_dropdown_index = d_id_to_dropdown_index,
dialog_list = dialog_list}
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(
@ -457,7 +532,7 @@ end
-- either add a button for entering edit mode
-- or add the buttons needed to edit the dialog when in *edit mode*
yl_speak_up.get_fs_talkdialog_add_edit_buttons = function(
formspec, h, pname_for_old_fs, oid, sb_v,
formspec, h, pname_for_old_fs, is_a_start_dialog,
active_dialog, luaentity, edit_mode, may_edit_npc, anz_options)
if(not(may_edit_npc)) then
return {h = h, formspec = formspec}
@ -696,71 +771,16 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
-- this is used to build a list of all available dialogs for a dropdown menu in edit mode
-- (only relevant in edit mode)
local dialog_list = yl_speak_up.text_new_dialog_id
-- find the right index for the dialog_list dropdown above
local d_id_to_dropdown_index = {}
-- allow to change skin, wielded items etc.
if(edit_mode) then
table.insert(formspec, "button[15.75,3.5;3.5,0.9;edit_skin;Edit Skin]")
end
-- display the window with the text the NPC is saying
if(edit_mode and dialog and dialog.n_dialogs) then
-- sort all dialogs by d_sort
local sorted_list = yl_speak_up.get_sorted_options(dialog.n_dialogs, "d_sort")
-- add buttons for previous/next dialog
for i, d in ipairs(sorted_list) do
-- build the list of available dialogs for the dropdown list(s)
dialog_list = dialog_list..","..minetest.formspec_escape(d)
if(d == c_d_id) then
local prev_dialog = tostring(minetest.formspec_escape(sorted_list[i-1]))
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"button", "8.5,4.0;2,0.9", "prev_dialog_"..prev_dialog,
"<",
"Go to previous dialog "..prev_dialog..".",
(sorted_list[ i-1 ]))
local next_dialog = tostring(minetest.formspec_escape(sorted_list[i+1]))
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"button", "11,4.0;2,0.9", "next_dialog_"..next_dialog,
">",
"Go to next dialog "..next_dialog..".",
(sorted_list[ i+1 ]))
end
d_id_to_dropdown_index[d] = i + 1
end
dialog_list = dialog_list..",d_end"
d_id_to_dropdown_index["d_end"] = #sorted_list + 2
table.insert(formspec, "label[0.2,4.6;Dialog:]") -- "..minetest.formspec_escape(c_d_id)..":]")
table.insert(formspec, "dropdown[3.0,4.0;5,1;d_id;"..dialog_list..";"..
d_id_to_dropdown_index[c_d_id]..",]")
table.insert(formspec, "tooltip[3.0,4.0;5,1;"..
"Select the dialog you want to edit. Currently, dialog "..c_d_id..
" is beeing displayed.;#FFFFFF;#000000]")
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"button", "13.9,4.0;1,0.9", "show_new_dialog",
"+",
"Create a new dialog.",
true)
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"button", "13.4,0.3;2,0.9", "button_edit_name_and_description",
"Edit",
"Edit name and description of your NPC.",
true)
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"button", "15.7,0.3;2,0.9", "button_save_dialog",
"Save",
"Save this dialog.",
true)
table.insert(formspec, "textarea[0.2,5;19.6,17.8;d_text;;"..
minetest.formspec_escape(active_dialog.d_text)..
"]")
end
-- display the window with the text the NPC is saying in *edit_mode*
local res_edit_top = yl_speak_up.get_fs_talkdialog_main_text_in_edit_mode(
formspec, h, dialog, dialog_list, edit_mode, c_d_id, active_dialog)
-- we are finished with adding buttons and text etc. to the left side of the formspec
local left_window_fs = table.concat(formspec, "\n")
local left_window_fs = table.concat(res_edit_top.formspec, "\n")
dialog_list = res_edit_top.dialog_list
-- find the right index for the dialog_list dropdown above
local d_id_to_dropdown_index = res_edit_top.d_id_to_dropdown_index
-- empty formspec for the bottom part
formspec = {}
@ -831,7 +851,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
-- If in edit mode, add new menu entries: "add new options", "end edit mode" and what else is needed.
-- Else allow to enter edit mode
local res = yl_speak_up.get_fs_talkdialog_add_edit_buttons(
formspec, h, pname_for_old_fs, oid, sb_v,
formspec, h, pname_for_old_fs, is_a_start_dialog,
active_dialog, luaentity, edit_mode, may_edit_npc, anz_options)
formspec = res.formspec
h = res.h
@ -863,6 +883,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
true, nil, nil, pname_for_old_fs)
end
-- mobs_redo based NPC can follow, stand or wander around
if(luaentity and luaentity.order and may_edit_npc) then
if(luaentity.order ~= "follow") then
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,