diff --git a/functions.lua b/functions.lua index db52824..7ce73c0 100644 --- a/functions.lua +++ b/functions.lua @@ -1439,6 +1439,21 @@ local function get_fs_talkdialog(player, n_id, d_id) table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;add_option;]") table.insert(formspec, "tooltip[add_option;Adds a new option to this dialog. You can delete options via the option edit menu.]") table.insert(formspec, "label[0.7,"..(h+0.45)..";Add a new option/answer to this dialog. You can delete options via the option edit menu.]") + -- 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 + table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;make_first_option;]") + table.insert(formspec, "tooltip[make_first_option;The NPC has to start with one dialog ".. + "when he is right-clicked. Make this dialog the one shown.]") + table.insert(formspec, "label[0.7,"..(h+0.45)..";Make this dialog the first one shown ".. + "when starting a conversation.]") + -- (but only show this option if it's not already the first one) + else + table.insert(formspec, "box[0.5,"..h..";53.8,0.9;#BBBBBB]") + table.insert(formspec, "label[0.7,"..(h+0.45)..";This dialog will be shown whenever ".. + "a conversation is started.]") + end + -- chat option: "That was all. I'm finished with giving you new orders. Remember them!" h = h + 1 table.insert(formspec, "button_exit[0.5," .. h .. ";53.8,0.9;button_end_edit_mode;]") @@ -2081,6 +2096,27 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields) -- new options etc. may be added; store these IDs so that we can switch to the right target local result = {} + -- make this the first dialog shown when starting a conversation + if(fields.make_first_option) then + -- check which dialog(s) previously had the highest priority and change thsoe + for k, v in pairs(dialog.n_dialogs) do + if(v and v.d_sort and (v.d_sort=="0" or v.d_sort==0)) then + -- try to derive a sensible future sort priority from the key: + -- here we make use of the d_ pattern; but even if that fails to yield + -- a number, the sort function will later be able to deal with it anyway + local new_priority = string.sub(k, 3) + dialog.n_dialogs[ k ].d_sort = new_priority + end + end + -- actually make this the chat with the highest priority + dialog.n_dialogs[ d_id ].d_sort = "0" + -- this is not immediately saved, even though the changes to the previous dialog with + -- the highest priority cannot be automaticly undone (but as long as it is not saved, + -- it really does not matter; and when saving, the player has to take some care) + table.insert(yl_speak_up.npc_was_changed[ n_id ], + "Dialog "..d_id..": Turned into new start dialog.") + end + -- detect changes to d_text: text of the dialog (what the npc is saying) -- (only happens in dialog edit menu) if(fields.d_text and dialog.n_dialogs[ d_id ].d_text ~= fields.d_text) then