made delete option work
This commit is contained in:
		
							parent
							
								
									2107b7833a
								
							
						
					
					
						commit
						f88ef64f7f
					
				@ -2101,6 +2101,28 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
 | 
			
		||||
		result["show_next_option"] = future_o_id
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if(fields[ "del_option"] and fields.o_id and dialog.n_dialogs[d_id].d_options[fields.o_id]) then
 | 
			
		||||
		local o_id = fields.o_id
 | 
			
		||||
		-- which dialog to show instead of the deleted one?
 | 
			
		||||
		local next_o_id = o_id
 | 
			
		||||
		local sorted_list = yl_speak_up.get_sorted_options(dialog.n_dialogs[d_id].d_options)
 | 
			
		||||
		for i, o in ipairs(sorted_list) do
 | 
			
		||||
			if(o == o_id and sorted_list[ i+1 ]) then
 | 
			
		||||
				next_o_id = sorted_list[ i+1 ]
 | 
			
		||||
			elseif(o == o_id and sorted_list[ i-1 ]) then
 | 
			
		||||
				next_o_id = sorted_list[ i-1 ]
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
		table.insert(yl_speak_up.npc_was_changed[ n_id ],
 | 
			
		||||
			"Dialog "..d_id..": Option "..tostring(o_id).." deleted.")
 | 
			
		||||
		-- actually delete the dialog
 | 
			
		||||
		dialog.n_dialogs[d_id].d_options[o_id] = nil
 | 
			
		||||
		-- the current dialog is deleted; we need to show another one
 | 
			
		||||
		result["show_next_option"] = next_o_id
 | 
			
		||||
		-- after deleting the entry, all previous/further changes to it are kind of unintresting
 | 
			
		||||
		return result
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	-- changes to options are not possible if there are none
 | 
			
		||||
	if(dialog.n_dialogs[ d_id ].d_options) then
 | 
			
		||||
@ -2285,13 +2307,14 @@ minetest.register_on_player_receive_fields(
 | 
			
		||||
	-- handles changes to o_text_when_prerequisites_met, target dialog, adding of a new dialog
 | 
			
		||||
	local result = yl_speak_up.edit_mode_apply_changes(pname, fields)
 | 
			
		||||
	-- if a new option was added or the target dialog of this one changed, display the right new option
 | 
			
		||||
	if(result and result["show_next_option"]) then
 | 
			
		||||
	if(result and result["show_next_option"] and n_dialog.d_options[result["show_next_option"]]) then
 | 
			
		||||
		minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog", get_fs_edit_option_dialog(player, n_id, d_id, result["show_next_option"]))
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	-- back to the main dialog window?
 | 
			
		||||
	if(fields.show_current_dialog or fields.quit or fields.button_exit or not(d_option)) then
 | 
			
		||||
	-- (this also happens when the last option was deleted)
 | 
			
		||||
	if(fields.show_current_dialog or fields.quit or fields.button_exit or not(d_option) or fields.del_option) then
 | 
			
		||||
		minetest.show_formspec(pname, "yl_speak_up:talk", get_fs_talkdialog(player, n_id, d_id))
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user