forked from Sokomine/yl_speak_up
		
	added helper function +yl_speak_up.add_edit_button_fs_talkdialog
This commit is contained in:
		
							parent
							
								
									fc10be7d0e
								
							
						
					
					
						commit
						07be18bcf6
					
				| @ -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,143 +719,130 @@ 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 | 			"If you want to give something (items) to this NPC\n".. | ||||||
| 			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".. |  | ||||||
| 				"- 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 | ||||||
|             -- chat option: "Add a new answer/option to this dialog." | 		h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, | ||||||
|             h = h + 1 | 			"add_option", | ||||||
| 	    if(anz_options < yl_speak_up.max_number_of_options_per_dialog) then | 			-- chat option: "Add a new answer/option to this dialog." | ||||||
|                 table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;add_option;]") | 			"Adds a new option to this dialog. You can delete options via the option edit menu.", | ||||||
|                 table.insert(formspec, "tooltip[add_option;Adds a new option to this dialog. You can ".. | 			"Add a new option/answer to this dialog. You can delete options via the option ".. | ||||||
| 			"delete options via the option edit menu.]") | 				"edit menu.", | ||||||
|                 table.insert(formspec, "label[0.7,"..(h+0.45)..";Add a new option/answer to this dialog. ".. | 			-- the amount of allowed options/answers has been reached | ||||||
| 			"You can delete options via the option edit menu.]") | 			(anz_options < yl_speak_up.max_number_of_options_per_dialog), | ||||||
|             -- the amount of allowed options/answers has been reached | 			"Maximum number of allowed answers/options reached. No further options/answers ".. | ||||||
|             else | 				"can be added.") | ||||||
|                 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 |  | ||||||
| 
 | 
 | ||||||
| 	    -- chat option: "Delete this dialog." | 		h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, | ||||||
| 	    h = h + 1 | 			"delete_this_empty_dialog", | ||||||
| 	    if(active_dialog | 			-- chat option: "Delete this dialog." | ||||||
| 		    and active_dialog.d_text == "" | 			"Dialogs can only be deleted when they are empty and have no more ".. | ||||||
| 		    and anz_options == 0) then | 				"options/answers. This is the case here, so the dialog can be deleted.", | ||||||
|                 table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;delete_this_empty_dialog;]") | 			"Delete this empty dialog.", | ||||||
|                 table.insert(formspec, "tooltip[delete_this_empty_dialog;Dialogs can only be deleted ".. | 			(active_dialog and active_dialog.d_text == "" and anz_options == 0), | ||||||
| 			"when they are empty and have no more options/answers. This is the case here, ".. | 			-- (but only show this option if the dialog is empty) | ||||||
| 			"so the dialog can be deleted.]") | 			"If you want to delete this dialog, you need to delete all options and its ".. | ||||||
|                 table.insert(formspec, "label[0.7,"..(h+0.45)..";Delete this empty dialog.]") | 				"text first.") | ||||||
| 	    -- (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 |  | ||||||
| 
 | 
 | ||||||
| 	    -- chat option: "Show what points to this dialog." | 		h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, | ||||||
| 	    h = h + 1 | 			"show_what_points_to_this_dialog", | ||||||
|             table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;show_what_points_to_this_dialog;]") | 			-- chat option: "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) | ||||||
| 
 | 
 | ||||||
| 	    -- chat option: "Make this dialog the first one shown when starting to talk." | 		h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, | ||||||
|             h = h + 1 | 			"make_first_option", | ||||||
| 	    if(active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) ~= 0) then | 			-- chat option: "Make this dialog the first one shown when starting to talk." | ||||||
|                 table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;make_first_option;]") | 			"The NPC has to start with one dialog when he is right-clicked. ".. | ||||||
|                 table.insert(formspec, "tooltip[make_first_option;The NPC has to start with one dialog ".. | 				"Make this dialog the one shown.", | ||||||
| 			"when he is right-clicked. Make this dialog the one shown.]") | 			"Make this dialog the first one shown when starting a conversation.", | ||||||
|                 table.insert(formspec, "label[0.7,"..(h+0.45)..";Make this dialog the first one shown ".. | 			(active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) ~= 0), | ||||||
| 			"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) | 			"This dialog will be shown whenever a conversation is started.") | ||||||
|             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 |  | ||||||
| 
 | 
 | ||||||
| 	    -- access the inventory of the NPC | 		h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, | ||||||
| 	    h = h + 1 | 			"show_inventory", | ||||||
|             table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;show_inventory;]") | 			"Access and manage the inventory of the NPC. This is used for adding trade ".. | ||||||
|             table.insert(formspec, "tooltip[show_inventory;Access and manage the inventory of the NPC. ".. | 				"items, getting collected payments and managing quest items.", | ||||||
| 			"This is used for adding trade items, getting collected payments and managing ".. | 			"Show your inventory (only accessible to owner)!", | ||||||
| 			"quest items.]") | 			true, nil) | ||||||
|             table.insert(formspec, "label[0.7,"..(h+0.45)..";".. |  | ||||||
| 			"Show your inventory (only accessible to owner)!]") |  | ||||||
| 
 | 
 | ||||||
| 	    -- 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!" | 		-- chat option: Mute/Unmute NPC | ||||||
|             h = h + 1 | 		local obj = yl_speak_up.speak_to[pname].obj | ||||||
|             table.insert(formspec, "button_exit[0.5," .. h .. ";53.8,0.9;button_end_edit_mode;]") | 		-- some precautions - someone else might have eliminated the NPC in the meantime | ||||||
|             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.]") | 		local luaentity = nil | ||||||
|             table.insert(formspec, "label[0.7,"..(h+0.45)..";That was all. I'm finished with giving you new orders. Remember them!]") | 		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. | 	-- 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 | ||||||
|             -- chat option: "I am your owner. I have new orders for you. | 		h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, | ||||||
|             h = h + 1 | 			"button_start_edit_mode", | ||||||
|             table.insert(formspec, "button_exit[0.5," .. h .. ";53.8,0.9;button_start_edit_mode;]") | 			"Enters edit mode. In this mode, you can edit the texts the NPC says and the ".. | ||||||
|             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.]") | 				"answers that can be given.", | ||||||
|             table.insert(formspec, "label[0.7,"..(h+0.45)..";I am your owner. I have new orders for you.]") | 			-- chat option: "I am your owner. I have new orders for you. | ||||||
|         end | 			"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 | 	-- 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 | 	if(active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) == 0 | ||||||
| 	  and dialog.trades) then | 	  and dialog.trades) then | ||||||
| 	    local has_trades = nil | 		local has_trades = nil | ||||||
| 	    for k, v in pairs(dialog.trades) do | 		for k, v in pairs(dialog.trades) do | ||||||
| 	        -- has the NPC any *public* trades that are not effects/results? | 			-- has the NPC any *public* trades that are not effects/results? | ||||||
| 	        if(not(v.hide) and not(v.d_id)) then | 			if(not(v.hide) and not(v.d_id)) then | ||||||
| 	            has_trades = true | 				has_trades = true | ||||||
| 		    break | 				break | ||||||
|  | 			end | ||||||
| 		end | 		end | ||||||
| 	    end | 		h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, | ||||||
| 	    if(has_trades) then | 			"show_trade_list", | ||||||
| 	        h = h + 1 | 			"Show a list of trades the NPC has to offer.", | ||||||
|                 table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;show_trade_list;]") | 			"Let's trade!", | ||||||
|                 table.insert(formspec, "tooltip[show_trade_list;Show a list of trades the NPC has to offer.]") | 			(has_trades), nil) | ||||||
|                 table.insert(formspec, "label[0.7,"..(h+0.45)..";Let's trade!]") |  | ||||||
| 	    end |  | ||||||
| 	end | 	end | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user