added helper function +yl_speak_up.add_edit_button_fs_talkdialog

This commit is contained in:
Sokomine 2022-01-07 23:24:49 +01:00
parent fc10be7d0e
commit 07be18bcf6

View File

@ -271,6 +271,26 @@ yl_speak_up.input_talk = function(player, formname, fields)
end 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 -- 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) yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, recursion_depth)
local pname = player:get_player_name() local pname = player:get_player_name()
@ -699,124 +719,112 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
if(edit_mode) then if(edit_mode) then
offer_item_add_text = minetest.formspec_escape("[dialog d_got_item] -> ") offer_item_add_text = minetest.formspec_escape("[dialog d_got_item] -> ")
end end
-- show this in edit mode and when the NPC actually accepts items h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
if(edit_mode or dialog.n_dialogs["d_got_item"]) then "player_offers_item",
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".. "If you want to give something (items) to this NPC\n"..
"- either because he requested it or as a present -\n".. "- either because he requested it or as a present -\n"..
"click here. The NPC will return items he doesn't want.]") "click here. The NPC will return items he doesn't want.",
table.insert(formspec, "label[0.7,"..(h+0.45)..";"..offer_item_add_text.. offer_item_add_text.."I want to give you something.",
"I want to give you something.]") -- show this in edit mode and when the NPC actually accepts items
end (edit_mode or dialog.n_dialogs["d_got_item"]), nil)
end 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 if(edit_mode) then
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
"add_option",
-- chat option: "Add a new answer/option to this dialog." -- chat option: "Add a new answer/option to this dialog."
h = h + 1 "Adds a new option to this dialog. You can delete options via the option edit menu.",
if(anz_options < yl_speak_up.max_number_of_options_per_dialog) then "Add a new option/answer to this dialog. You can delete options via the option "..
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;add_option;]") "edit menu.",
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 -- the amount of allowed options/answers has been reached
else (anz_options < yl_speak_up.max_number_of_options_per_dialog),
table.insert(formspec, "box[0.5,"..h..";53.8,0.9;#BBBBBB]") "Maximum number of allowed answers/options reached. No further options/answers "..
table.insert(formspec, "label[0.7,"..(h+0.45)..";Maximum number of allowed answers/options ".. "can be added.")
"reached. No further options/answers can be added.]")
end
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
"delete_this_empty_dialog",
-- chat option: "Delete this dialog." -- chat option: "Delete this dialog."
h = h + 1 "Dialogs can only be deleted when they are empty and have no more "..
if(active_dialog "options/answers. This is the case here, so the dialog can be deleted.",
and active_dialog.d_text == "" "Delete this empty dialog.",
and anz_options == 0) then (active_dialog and active_dialog.d_text == "" and anz_options == 0),
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) -- (but only show this option if the dialog is empty)
else "If you want to delete this dialog, you need to delete all options and its "..
table.insert(formspec, "box[0.5,"..h..";53.8,0.9;#BBBBBB]") "text first.")
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,
"show_what_points_to_this_dialog",
-- chat option: "Show what points to this dialog." -- 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".. "Show which other dialog options or failed actions\n"..
"or effects lead the player to this dialog here.]") "or effects lead the player to this dialog here.",
table.insert(formspec, "label[0.7,"..(h+0.45)..";Show what points to this dialog.]") "Show what points to this dialog.",
-- there is no alternate text to show
true, nil)
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." -- chat option: "Make this dialog the first one shown when starting to talk."
h = h + 1 "The NPC has to start with one dialog when he is right-clicked. "..
if(active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) ~= 0) then "Make this dialog the one shown.",
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;make_first_option;]") "Make this dialog the first one shown when starting a conversation.",
table.insert(formspec, "tooltip[make_first_option;The NPC has to start with one dialog ".. (active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) ~= 0),
"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) -- (but only show this option if it's not already the first one)
else "This dialog will be shown whenever a conversation is started.")
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 ".. h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
"a conversation is started.]") "show_inventory",
end "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)
-- 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)!]")
-- chat option: Mute/Unmute NPC -- chat option: Mute/Unmute NPC
h = h + 1
local obj = yl_speak_up.speak_to[pname].obj local obj = yl_speak_up.speak_to[pname].obj
-- some precautions - someone else might have eliminated the NPC in the meantime -- some precautions - someone else might have eliminated the NPC in the meantime
local luaentity = nil local luaentity = nil
if(obj) then if(obj) then
luaentity = obj:get_luaentity() luaentity = obj:get_luaentity()
end end
if(luaentity and luaentity.yl_speak_up.talk) then h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;mute_npc;]") "mute_npc",
table.insert(formspec, "tooltip[mute_npc;The NPC will no longer show his dialogs ".. -- chat option: mute the NPC
"when he is right-clicked. This is useful while you edit the NPC and don't ".. "The NPC will no longer show his dialogs when he is right-clicked. This is "..
"want players to see unfinished entries and/or quests.]") "useful while you edit the NPC and don't want players to see "..
table.insert(formspec, "label[0.7,"..(h+0.45)..";State: Not muted. Stop talking to other ".. "unfinished entries and/or quests.",
"players while I give you new orders.]") "State: Not muted. Stop talking to other players while I give you new orders.",
elseif(luaentity) then (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 -- unmute the NPC
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;un_mute_npc;]") "The NPC will show his dialogs to other players when he is right-clicked. "..
table.insert(formspec, "tooltip[un_mute_npc;The NPC will show his dialogs to other ".. "This is the normal mode of operation. Choose this when you are "..
"players when he is right-clicked. This is the normal mode of operation. Choose ".. "finished editing.",
"this when you are finished editing.]") "State: You are currently muted. Talk to anyone again who wants to talk to you.",
table.insert(formspec, "label[0.7,"..(h+0.45)..";State: You are currently muted. Talk to ".. -- the NPC has to be there
"anyone again who wants to talk to you.]") (luaentity and not(luaentity.yl_speak_up.talk)), nil)
end
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!" -- chat option:"That was all. I'm finished with giving you new orders. Remember them!"
h = h + 1 "That was all. I'm finished with giving you new orders. Remember them!",
table.insert(formspec, "button_exit[0.5," .. h .. ";53.8,0.9;button_end_edit_mode;]") true, nil)
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!]")
-- Offer to enter edit mode if the player has the npc_talk_owner priv AND owns the npc. -- 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. -- The npc_master priv allows to edit all NPC.
elseif(yl_speak_up.may_edit_npc(player, n_id)) then elseif(yl_speak_up.may_edit_npc(player, n_id)) then
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. -- chat option: "I am your owner. I have new orders for you.
h = h + 1 "I am your owner. I have new orders for you.",
table.insert(formspec, "button_exit[0.5," .. h .. ";53.8,0.9;button_start_edit_mode;]") true, nil)
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 end
-- add a Let's trade button to the first dialog if the NPC has trades -- add a Let's trade button to the first dialog if the NPC has trades
@ -830,12 +838,11 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
break break
end end
end end
if(has_trades) then h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
h = h + 1 "show_trade_list",
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;show_trade_list;]") "Show a list of trades the NPC has to offer.",
table.insert(formspec, "tooltip[show_trade_list;Show a list of trades the NPC has to offer.]") "Let's trade!",
table.insert(formspec, "label[0.7,"..(h+0.45)..";Let's trade!]") (has_trades), nil)
end
end end