diff --git a/edit_mode.lua b/edit_mode.lua
index c674253..cf84807 100644
--- a/edit_mode.lua
+++ b/edit_mode.lua
@@ -39,3 +39,154 @@ yl_speak_up.apply_autoanswer_and_random_and_d_got_item = function(player, pname,
return old_apply_autoanswer_etc(player, pname, d_id, dialog, allowed, active_dialog, recursion_depth)
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*)
+local old_talkdialog_main_text = yl_speak_up.get_fs_talkdialog_main_text
+yl_speak_up.get_fs_talkdialog_main_text = function(pname, formspec, h, dialog, dialog_list, c_d_id, active_dialog)
+ if(not(yl_speak_up.in_edit_mode(pname))) then
+ return old_talkdialog_main_text(pname, formspec, h, dialog, dialog_list, c_d_id, active_dialog)
+ end
+ local d_id_to_dropdown_index = {}
+ -- 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] or "1")..",]")
+ 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", "11.0,0.3;2,1.0", "button_edit_notes",
+ "Notes",
+ "Keep notes of what this NPC is for, how his character is etc.",
+ true)
+ yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
+ "button", "13.2,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.4,0.3;2,0.9", "button_save_dialog",
+ "Save",
+ "Save this dialog.",
+ true)
+ yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
+ "button", "17.5,0.3;2.4,0.9", "button_export_dialog",
+ "Export",
+ "Export: Show the dialog in .json format which you can copy and store on your computer.",
+ true)
+
+
+ -- static help text instead of text input field for d_got_item
+ if(c_d_id == "d_got_item") then
+ table.insert(formspec, "hypertext[0.2,5;19.6,17.8;d_text;"..
+ "Note:\nThis is a special dialog."..
+ "It will be called when the player clicks on "..
+ "I want to give you something."..
+ "\nMost of the things listed below will be added automaticly when you add a "..
+ "new option to this dialog. In most cases you may just have to edit the "..
+ "precondition so that the right item is accepted, and then "..
+ "set the target dialog according to your needs. Please also "..
+ "edit the alternate text so that it fits your item!"..
+ "\nThis is how it works in detail:"..
+ "\nEach option you add here ought to deal with one item(stack) that "..
+ "the NPC expects from the player, i.e. farming:bread 2. "..
+ "Each option needs to be selected automaticly and ought to contain:"..
+ "\n* a precondition regarding "..
+ "an item the player offered/gave to the NPC "..
+ "(shown as player_offered_item in overview) "..
+ "where you define which item(stack) is relevant for this option"..
+ "\n* an effect regarding an item the player offered to the NPC "..
+ "(shown as deal_with_offered_item in overview) "..
+ "where you define what shall happen to the offered item. Usually "..
+ "the NPC will accept the item and put it into its inventory."..
+ "\n* Don't forget to set a suitable target dialog for the effect! "..
+ "Your NPC ought to comment on what he got, i.e. "..
+ "Thank you for those two breads! You saved me from starving."..
+ "You can also work with an alternate text here (as is done in the "..
+ "default setup when adding a new option here)."..
+ "\n]")
+ -- static help text instead of text input field for d_trade
+ elseif(c_d_id == "d_trade") then
+ table.insert(formspec, "hypertext[0.2,5;19.6,17.8;d_text;"..
+ "Note:\nThis is a special dialog."..
+ "It will be called when the player clicks on "..
+ "Let's trade!."..
+ "\nSome of the things listed below will be added automaticly when you add a "..
+ "new option to this dialog. In most cases you may just have to edit the "..
+ "precondition so that the right item(stack) is beeing "..
+ "searched for, and you need to add suitable effects. The ones added "..
+ "automaticly are just an example."..
+ "\nNote that once the NPC found a matching precondition, it will execute the "..
+ "relevant effects and present the player the trade list. Any further options "..
+ "that might also fit will not be executed this time. Only one option "..
+ "(or none) will be selected each time."..
+ "\nThis is how it works in detail:"..
+ "\nEach option you add here ought to deal with one item(stack) that "..
+ "the NPC might or might not have in its inventory, "..
+ "i.e. default:stick 4. "..
+ "Each option needs to be selected automaticly and ought to contain:"..
+ "\n* at least one precondition regarding "..
+ "the inventory of the NPC "..
+ "where you define which item(stack) is relevant for this option "..
+ "(you can add multiple such preconditions for each option)"..
+ "\n* at least one effect regarding what the NPC shall do if the "..
+ "precondition matches. In most cases, NPC crafts something, "..
+ "put item from the NPC's inventory into a chest etc. or "..
+ "take item from a chest etc. and put it into the NPC's inventory "..
+ "will be what you are looking for. More than one effect is possible."..
+ "\n* In this particular case, no target dialog needs to be selected. After "..
+ "executing the effect(s), the trade list view will be shown to the "..
+ "player."..
+ "\n]")
+ elseif(active_dialog and active_dialog.d_text) then
+ table.insert(formspec, "textarea[0.2,5;19.6,17.8;d_text;;"..
+ minetest.formspec_escape(active_dialog.d_text or "?")..
+ "]")
+ else
+ table.insert(formspec, "textarea[0.2,5;19.6,17.8;d_text;;"..
+ minetest.formspec_escape("[no text]")..
+ "]")
+ end
+ return {h = h, formspec = formspec, d_id_to_dropdown_index = d_id_to_dropdown_index,
+ dialog_list = dialog_list}
+end
diff --git a/fs/fs_talkdialog.lua b/fs/fs_talkdialog.lua
index ddaf106..782bd44 100644
--- a/fs/fs_talkdialog.lua
+++ b/fs/fs_talkdialog.lua
@@ -320,154 +320,10 @@ 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] or "1")..",]")
- 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", "11.0,0.3;2,1.0", "button_edit_notes",
- "Notes",
- "Keep notes of what this NPC is for, how his character is etc.",
- true)
- yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
- "button", "13.2,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.4,0.3;2,0.9", "button_save_dialog",
- "Save",
- "Save this dialog.",
- true)
- yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
- "button", "17.5,0.3;2.4,0.9", "button_export_dialog",
- "Export",
- "Export: Show the dialog in .json format which you can copy and store on your computer.",
- true)
-
-
- -- static help text instead of text input field for d_got_item
- if(c_d_id == "d_got_item") then
- table.insert(formspec, "hypertext[0.2,5;19.6,17.8;d_text;"..
- "Note:\nThis is a special dialog."..
- "It will be called when the player clicks on "..
- "I want to give you something."..
- "\nMost of the things listed below will be added automaticly when you add a "..
- "new option to this dialog. In most cases you may just have to edit the "..
- "precondition so that the right item is accepted, and then "..
- "set the target dialog according to your needs. Please also "..
- "edit the alternate text so that it fits your item!"..
- "\nThis is how it works in detail:"..
- "\nEach option you add here ought to deal with one item(stack) that "..
- "the NPC expects from the player, i.e. farming:bread 2. "..
- "Each option needs to be selected automaticly and ought to contain:"..
- "\n* a precondition regarding "..
- "an item the player offered/gave to the NPC "..
- "(shown as player_offered_item in overview) "..
- "where you define which item(stack) is relevant for this option"..
- "\n* an effect regarding an item the player offered to the NPC "..
- "(shown as deal_with_offered_item in overview) "..
- "where you define what shall happen to the offered item. Usually "..
- "the NPC will accept the item and put it into its inventory."..
- "\n* Don't forget to set a suitable target dialog for the effect! "..
- "Your NPC ought to comment on what he got, i.e. "..
- "Thank you for those two breads! You saved me from starving."..
- "You can also work with an alternate text here (as is done in the "..
- "default setup when adding a new option here)."..
- "\n]")
- -- static help text instead of text input field for d_trade
- elseif(c_d_id == "d_trade") then
- table.insert(formspec, "hypertext[0.2,5;19.6,17.8;d_text;"..
- "Note:\nThis is a special dialog."..
- "It will be called when the player clicks on "..
- "Let's trade!."..
- "\nSome of the things listed below will be added automaticly when you add a "..
- "new option to this dialog. In most cases you may just have to edit the "..
- "precondition so that the right item(stack) is beeing "..
- "searched for, and you need to add suitable effects. The ones added "..
- "automaticly are just an example."..
- "\nNote that once the NPC found a matching precondition, it will execute the "..
- "relevant effects and present the player the trade list. Any further options "..
- "that might also fit will not be executed this time. Only one option "..
- "(or none) will be selected each time."..
- "\nThis is how it works in detail:"..
- "\nEach option you add here ought to deal with one item(stack) that "..
- "the NPC might or might not have in its inventory, "..
- "i.e. default:stick 4. "..
- "Each option needs to be selected automaticly and ought to contain:"..
- "\n* at least one precondition regarding "..
- "the inventory of the NPC "..
- "where you define which item(stack) is relevant for this option "..
- "(you can add multiple such preconditions for each option)"..
- "\n* at least one effect regarding what the NPC shall do if the "..
- "precondition matches. In most cases, NPC crafts something, "..
- "put item from the NPC's inventory into a chest etc. or "..
- "take item from a chest etc. and put it into the NPC's inventory "..
- "will be what you are looking for. More than one effect is possible."..
- "\n* In this particular case, no target dialog needs to be selected. After "..
- "executing the effect(s), the trade list view will be shown to the "..
- "player."..
- "\n]")
- elseif(active_dialog and active_dialog.d_text) then
- table.insert(formspec, "textarea[0.2,5;19.6,17.8;d_text;;"..
- minetest.formspec_escape(active_dialog.d_text or "?")..
- "]")
- else
- table.insert(formspec, "textarea[0.2,5;19.6,17.8;d_text;;"..
- minetest.formspec_escape("[no text]")..
- "]")
- end
- return {h = h, formspec = formspec, d_id_to_dropdown_index = d_id_to_dropdown_index,
- dialog_list = dialog_list}
+-- shows the text the NPC "speaks"
+-- (this is pretty boring; the more intresting stuff happens in edit_mode)
+yl_speak_up.get_fs_talkdialog_main_text = function(pname, formspec, h, dialog, dialog_list, c_d_id, active_dialog)
+ return {h = h, formspec = formspec, d_id_to_dropdown_index = {}, dialog_list = dialog_list}
end
@@ -948,9 +804,9 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
-- (only relevant in edit mode)
local dialog_list = yl_speak_up.text_new_dialog_id
-- allow to change skin, wielded items etc.
- -- 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)
+ -- display the window with the text the NPC is saying (diffrent in *edit_mode*)
+ local res_edit_top = yl_speak_up.get_fs_talkdialog_main_text(
+ pname, formspec, h, dialog, dialog_list, 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(res_edit_top.formspec, "\n")
dialog_list = res_edit_top.dialog_list