diff --git a/fs_talkdialog.lua b/fs_talkdialog.lua index 9ee0cbe..d671b08 100644 --- a/fs_talkdialog.lua +++ b/fs_talkdialog.lua @@ -271,6 +271,26 @@ yl_speak_up.input_talk = function(player, formname, fields) end +-- show an edit option in the main menu of the NPC; +-- helper function for yl_speak_up.fs_talkdialog(..) +yl_speak_up.add_edit_button_fs_talkdialog = function(formspec, h, button_name, tooltip, label, + show_main_not_alternate, alternate_label) + -- do not show this button at all if there is no alternate text and the condition is false + if(not(alternate_label) and not(show_main_not_alternate)) then + return h + end + h = h + 1 + if(show_main_not_alternate) then + table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;"..tostring(button_name)..";]") + table.insert(formspec, "tooltip["..tostring(button_name)..";"..tostring(tooltip).."]") + table.insert(formspec, "label[0.7,"..(h+0.45)..";"..tostring(label).."]") + else + table.insert(formspec, "box[0.5,"..h..";53.8,0.9;#BBBBBB]") + table.insert(formspec, "label[0.7,"..(h+0.45)..";"..tostring(alternate_label).."]") + end + return h +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() @@ -699,143 +719,130 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec if(edit_mode) then offer_item_add_text = minetest.formspec_escape("[dialog d_got_item] -> ") end - -- show this in edit mode and when the NPC actually accepts items - if(edit_mode or dialog.n_dialogs["d_got_item"]) then - h = h + 1 - table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;player_offers_item;]") - table.insert(formspec, "tooltip[player_offers_item;".. - "If you want to give something (items) to this NPC\n".. + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "player_offers_item", + "If you want to give something (items) to this NPC\n".. "- either because he requested it or as a present -\n".. - "click here. The NPC will return items he doesn't want.]") - table.insert(formspec, "label[0.7,"..(h+0.45)..";"..offer_item_add_text.. - "I want to give you something.]") - end + "click here. The NPC will return items he doesn't want.", + offer_item_add_text.."I want to give you something.", + -- show this in edit mode and when the NPC actually accepts items + (edit_mode or dialog.n_dialogs["d_got_item"]), nil) end - -- If in edit mode, add two new menu entries: "add new options" and "end edit mode". + + -- If in edit mode, add new menu entries: "add new options", "end edit mode" and what else is needed. if(edit_mode) then - -- chat option: "Add a new answer/option to this dialog." - h = h + 1 - if(anz_options < yl_speak_up.max_number_of_options_per_dialog) then - 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.]") - -- the amount of allowed options/answers has been reached - else - table.insert(formspec, "box[0.5,"..h..";53.8,0.9;#BBBBBB]") - table.insert(formspec, "label[0.7,"..(h+0.45)..";Maximum number of allowed answers/options ".. - "reached. No further options/answers can be added.]") - end + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "add_option", + -- chat option: "Add a new answer/option to this dialog." + "Adds a new option to this dialog. You can delete options via the option edit menu.", + "Add a new option/answer to this dialog. You can delete options via the option ".. + "edit menu.", + -- the amount of allowed options/answers has been reached + (anz_options < yl_speak_up.max_number_of_options_per_dialog), + "Maximum number of allowed answers/options reached. No further options/answers ".. + "can be added.") - -- chat option: "Delete this dialog." - h = h + 1 - if(active_dialog - and active_dialog.d_text == "" - and anz_options == 0) then - table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;delete_this_empty_dialog;]") - table.insert(formspec, "tooltip[delete_this_empty_dialog;Dialogs can only be deleted ".. - "when they are empty and have no more options/answers. This is the case here, ".. - "so the dialog can be deleted.]") - table.insert(formspec, "label[0.7,"..(h+0.45)..";Delete this empty dialog.]") - -- (but only show this option if the dialog is empty) - else - table.insert(formspec, "box[0.5,"..h..";53.8,0.9;#BBBBBB]") - table.insert(formspec, "label[0.7,"..(h+0.45)..";If you want to delete this dialog, you ".. - "need to delete all options and its text first.]") - end + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "delete_this_empty_dialog", + -- chat option: "Delete this dialog." + "Dialogs can only be deleted when they are empty and have no more ".. + "options/answers. This is the case here, so the dialog can be deleted.", + "Delete this empty dialog.", + (active_dialog and active_dialog.d_text == "" and anz_options == 0), + -- (but only show this option if the dialog is empty) + "If you want to delete this dialog, you need to delete all options and its ".. + "text first.") - -- 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;".. + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "show_what_points_to_this_dialog", + -- chat option: "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.]") + "or effects lead the player to this dialog here.", + "Show what points to this dialog.", + -- there is no alternate text to show + true, nil) - -- 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 + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "make_first_option", + -- chat option: "Make this dialog the first one shown when starting to talk." + "The NPC has to start with one dialog when he is right-clicked. ".. + "Make this dialog the one shown.", + "Make this dialog the first one shown when starting a conversation.", + (active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) ~= 0), + -- (but only show this option if it's not already the first one) + "This dialog will be shown whenever a conversation is started.") - -- access the inventory of the NPC - h = h + 1 - table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;show_inventory;]") - table.insert(formspec, "tooltip[show_inventory;Access and manage the inventory of the NPC. ".. - "This is used for adding trade items, getting collected payments and managing ".. - "quest items.]") - table.insert(formspec, "label[0.7,"..(h+0.45)..";".. - "Show your inventory (only accessible to owner)!]") + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "show_inventory", + "Access and manage the inventory of the NPC. This is used for adding trade ".. + "items, getting collected payments and managing quest items.", + "Show your inventory (only accessible to owner)!", + true, nil) - -- chat option: Mute/Unmute NPC - h = h + 1 - local obj = yl_speak_up.speak_to[pname].obj - -- some precautions - someone else might have eliminated the NPC in the meantime - local luaentity = nil - if(obj) then - luaentity = obj:get_luaentity() - end - if(luaentity and luaentity.yl_speak_up.talk) then - table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;mute_npc;]") - table.insert(formspec, "tooltip[mute_npc;The NPC will no longer show his dialogs ".. - "when he is right-clicked. This is useful while you edit the NPC and don't ".. - "want players to see unfinished entries and/or quests.]") - table.insert(formspec, "label[0.7,"..(h+0.45)..";State: Not muted. Stop talking to other ".. - "players while I give you new orders.]") - elseif(luaentity) then - -- unmute the NPC - table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;un_mute_npc;]") - table.insert(formspec, "tooltip[un_mute_npc;The NPC will show his dialogs to other ".. - "players when he is right-clicked. This is the normal mode of operation. Choose ".. - "this when you are finished editing.]") - table.insert(formspec, "label[0.7,"..(h+0.45)..";State: You are currently muted. Talk to ".. - "anyone again who wants to talk to you.]") - 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;]") - table.insert(formspec, "tooltip[button_end_edit_mode;Ends edit mode. From now on, your NPC will talk to you like he talks to other players. You can always give him new orders by entering edit mode again.]") - table.insert(formspec, "label[0.7,"..(h+0.45)..";That was all. I'm finished with giving you new orders. Remember them!]") + -- chat option: Mute/Unmute NPC + local obj = yl_speak_up.speak_to[pname].obj + -- some precautions - someone else might have eliminated the NPC in the meantime + local luaentity = nil + if(obj) then + luaentity = obj:get_luaentity() + end + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "mute_npc", + -- chat option: mute the NPC + "The NPC will no longer show his dialogs when he is right-clicked. This is ".. + "useful while you edit the NPC and don't want players to see ".. + "unfinished entries and/or quests.", + "State: Not muted. Stop talking to other players while I give you new orders.", + (luaentity and luaentity.yl_speak_up.talk), nil) + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "un_mute_npc", + -- unmute the NPC + "The NPC will show his dialogs to other players when he is right-clicked. ".. + "This is the normal mode of operation. Choose this when you are ".. + "finished editing.", + "State: You are currently muted. Talk to anyone again who wants to talk to you.", + -- the NPC has to be there + (luaentity and not(luaentity.yl_speak_up.talk)), nil) - -- Offer to enter edit mode if the player has the npc_talk_owner priv AND owns the npc. + + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "button_end_edit_mode", + "Ends edit mode. From now on, your NPC will talk to you like he talks to other ".. + "players. You can always give him new orders by entering edit mode again.", + -- chat option:"That was all. I'm finished with giving you new orders. Remember them!" + "That was all. I'm finished with giving you new orders. Remember them!", + true, nil) + + -- Offer to enter edit mode if the player has the npc_talk_owner priv AND owns the npc. -- The npc_master priv allows to edit all NPC. elseif(yl_speak_up.may_edit_npc(player, n_id)) then - -- chat option: "I am your owner. I have new orders for you. - h = h + 1 - table.insert(formspec, "button_exit[0.5," .. h .. ";53.8,0.9;button_start_edit_mode;]") - table.insert(formspec, "tooltip[button_start_edit_mode;Enters edit mode. In this mode, you can edit the texts the NPC says and the answers that can be given.]") - table.insert(formspec, "label[0.7,"..(h+0.45)..";I am your owner. I have new orders for you.]") - end + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "button_start_edit_mode", + "Enters edit mode. In this mode, you can edit the texts the NPC says and the ".. + "answers that can be given.", + -- chat option: "I am your owner. I have new orders for you. + "I am your owner. I have new orders for you.", + true, nil) + end -- add a Let's trade button to the first dialog if the NPC has trades if(active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) == 0 and dialog.trades) then - local has_trades = nil - for k, v in pairs(dialog.trades) do - -- has the NPC any *public* trades that are not effects/results? - if(not(v.hide) and not(v.d_id)) then - has_trades = true - break + local has_trades = nil + for k, v in pairs(dialog.trades) do + -- has the NPC any *public* trades that are not effects/results? + if(not(v.hide) and not(v.d_id)) then + has_trades = true + break + end end - end - if(has_trades) then - h = h + 1 - table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;show_trade_list;]") - table.insert(formspec, "tooltip[show_trade_list;Show a list of trades the NPC has to offer.]") - table.insert(formspec, "label[0.7,"..(h+0.45)..";Let's trade!]") - end + h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, + "show_trade_list", + "Show a list of trades the NPC has to offer.", + "Let's trade!", + (has_trades), nil) end