mirror of
				https://gitea.your-land.de/Sokomine/yl_speak_up.git
				synced 2025-11-04 06:13:08 +01:00 
			
		
		
		
	split show_fs.lua into editor/ and normal function
This commit is contained in:
		
							parent
							
								
									dfc88b4895
								
							
						
					
					
						commit
						7c72e4215b
					
				@ -82,6 +82,8 @@ yl_speak_up.add_to_command_help_text = yl_speak_up.add_to_command_help_text..
 | 
			
		||||
--	dofile(modpath .. "add_generic_dialogs.lua")
 | 
			
		||||
--	-- handle on_player_receive_fields and showing of formspecs
 | 
			
		||||
--	dofile(modpath .. "show_fs.lua")
 | 
			
		||||
	-- handle page changes and asking for saving when in edit mode:
 | 
			
		||||
	dofile(modpath .. "show_fs_in_edit_mode.lua")
 | 
			
		||||
--	-- general decoration part for main formspec, trade window etc.
 | 
			
		||||
--	dofile(modpath .. "api/api_decorated.lua")
 | 
			
		||||
--	-- the formspec and input handling for the main dialog
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										98
									
								
								editor/show_fs_in_edit_mode.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								editor/show_fs_in_edit_mode.lua
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,98 @@
 | 
			
		||||
 | 
			
		||||
-- when in edit mode: ask for saving dialogs when needed
 | 
			
		||||
local old_show_fs = yl_speak_up.show_fs
 | 
			
		||||
yl_speak_up.show_fs = function(player, fs_name, param)
 | 
			
		||||
	if(not(player)) then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	local pname = player:get_player_name()
 | 
			
		||||
	if(not(yl_speak_up.speak_to[pname])) then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local last_fs = yl_speak_up.speak_to[pname].last_fs
 | 
			
		||||
	-- show the save or discard changes dialog
 | 
			
		||||
	if(fs_name and fs_name == "save_or_discard_changes") then
 | 
			
		||||
		yl_speak_up.show_fs_ver(pname, "yl_speak_up:save_or_discard_changes",
 | 
			
		||||
			yl_speak_up.get_fs_save_or_discard_changes(player, param))
 | 
			
		||||
		return
 | 
			
		||||
 | 
			
		||||
	-- the player either saved or discarded; we may proceed now
 | 
			
		||||
	elseif(fs_name and fs_name == "proceed_after_save") then
 | 
			
		||||
		fs_name = yl_speak_up.speak_to[pname].next_fs
 | 
			
		||||
		param = yl_speak_up.speak_to[pname].next_fs_param
 | 
			
		||||
		yl_speak_up.speak_to[pname].next_fs = nil
 | 
			
		||||
		yl_speak_up.speak_to[pname].next_fs_param = nil
 | 
			
		||||
		yl_speak_up.speak_to[pname].last_fs = fs_name
 | 
			
		||||
		yl_speak_up.speak_to[pname].last_fs_param = param
 | 
			
		||||
		if(not(fs_name) or fs_name == "quit") then
 | 
			
		||||
			yl_speak_up.reset_vars_for_player(pname, false)
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
	-- the player clicked on "back" in the above dialog
 | 
			
		||||
	elseif(fs_name and fs_name == "show_last_fs") then
 | 
			
		||||
		-- call the last formspec again - and with the same parameters
 | 
			
		||||
		fs_name = yl_speak_up.speak_to[pname].last_fs
 | 
			
		||||
		param = yl_speak_up.speak_to[pname].last_fs_param
 | 
			
		||||
 | 
			
		||||
	-- do we need to check if there is something that needs saving?
 | 
			
		||||
	elseif(fs_name
 | 
			
		||||
	  -- msg is just a loop for displaying (mostly error) messages
 | 
			
		||||
	  and fs_name ~= "msg"
 | 
			
		||||
	  and fs_name ~= "player_offers_item"
 | 
			
		||||
	  -- is the player editing the NPC? that is: might there be any changes?
 | 
			
		||||
	  and (yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id)) then
 | 
			
		||||
		local last_fs = yl_speak_up.speak_to[pname].last_fs
 | 
			
		||||
		local d_id = yl_speak_up.speak_to[pname].d_id
 | 
			
		||||
		local o_id = yl_speak_up.speak_to[pname].o_id
 | 
			
		||||
		-- only these two formspecs need to ask specificly if the data ought to be saved
 | 
			
		||||
		if(last_fs == "talk" or last_fs == "edit_option_dialog" or fs_name == "quit") then
 | 
			
		||||
			local last_param = yl_speak_up.speak_to[pname].last_fs_param
 | 
			
		||||
			local show_save_fs = false
 | 
			
		||||
			if(not(param)) then
 | 
			
		||||
				param = {}
 | 
			
		||||
			end
 | 
			
		||||
			-- set the target dialog
 | 
			
		||||
			yl_speak_up.speak_to[pname].target_dialog = param.d_id
 | 
			
		||||
			-- if we are switching from one dialog to another: is it the same?
 | 
			
		||||
			if(last_fs == "talk" and fs_name == last_fs
 | 
			
		||||
			  and param and param.d_id and param.d_id ~= d_id) then
 | 
			
		||||
				-- diffrent parameters: save (if needed)
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			elseif(fs_name == "talk" and param and param.do_save) then
 | 
			
		||||
				-- player clicked on save button
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			-- leaving a dialog: save!
 | 
			
		||||
			elseif(last_fs == "talk" and fs_name ~= last_fs) then
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			-- clicking on "save" in an edit option dialog: save!
 | 
			
		||||
			elseif(last_fs == "edit_option_dialog" and fs_name == last_fs
 | 
			
		||||
			  and param and param.caller and param.caller == "save_option") then
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			-- leaving editing an option: save!
 | 
			
		||||
			elseif(last_fs == "edit_option_dialog" and fs_name ~= last_fs) then
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			-- quitting: save!
 | 
			
		||||
			elseif(fs_name == "quit") then
 | 
			
		||||
				yl_speak_up.speak_to[pname].target_dialog = nil
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			end
 | 
			
		||||
			-- show the save or discard dialog
 | 
			
		||||
			if(show_save_fs) then
 | 
			
		||||
				yl_speak_up.speak_to[pname].next_fs = fs_name
 | 
			
		||||
				yl_speak_up.speak_to[pname].next_fs_param = param
 | 
			
		||||
				-- check first if it's necessary to ask for save or discard
 | 
			
		||||
				yl_speak_up.input_save_or_discard_changes(player, "", {})
 | 
			
		||||
				return
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
		-- store the new formspec
 | 
			
		||||
		yl_speak_up.speak_to[pname].last_fs = fs_name
 | 
			
		||||
		-- and its parameter
 | 
			
		||||
		yl_speak_up.speak_to[pname].last_fs_param = param
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	-- Note: fs_name and param *may* have been changed in edit_mode by the code above
 | 
			
		||||
	old_show_fs(player, fs_name, param)
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										83
									
								
								show_fs.lua
									
									
									
									
									
								
							
							
						
						
									
										83
									
								
								show_fs.lua
									
									
									
									
									
								
							@ -61,86 +61,6 @@ yl_speak_up.show_fs = function(player, fs_name, param)
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local last_fs = yl_speak_up.speak_to[pname].last_fs
 | 
			
		||||
 | 
			
		||||
	if(false) then
 | 
			
		||||
	-- the player either saved or discarded; we may proceed now
 | 
			
		||||
	elseif(fs_name and fs_name == "proceed_after_save") then
 | 
			
		||||
		fs_name = yl_speak_up.speak_to[pname].next_fs
 | 
			
		||||
		param = yl_speak_up.speak_to[pname].next_fs_param
 | 
			
		||||
		yl_speak_up.speak_to[pname].next_fs = nil
 | 
			
		||||
		yl_speak_up.speak_to[pname].next_fs_param = nil
 | 
			
		||||
		yl_speak_up.speak_to[pname].last_fs = fs_name
 | 
			
		||||
		yl_speak_up.speak_to[pname].last_fs_param = param
 | 
			
		||||
		if(not(fs_name) or fs_name == "quit") then
 | 
			
		||||
			yl_speak_up.reset_vars_for_player(pname, false)
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
	-- the player clicked on "back" in the above dialog
 | 
			
		||||
	elseif(fs_name and fs_name == "show_last_fs") then
 | 
			
		||||
		-- call the last formspec again - and with the same parameters
 | 
			
		||||
		fs_name = yl_speak_up.speak_to[pname].last_fs
 | 
			
		||||
		param = yl_speak_up.speak_to[pname].last_fs_param
 | 
			
		||||
 | 
			
		||||
	-- do we need to check if there is something that needs saving?
 | 
			
		||||
	elseif(fs_name
 | 
			
		||||
	  -- msg is just a loop for displaying (mostly error) messages
 | 
			
		||||
	  and fs_name ~= "msg"
 | 
			
		||||
	  and fs_name ~= "player_offers_item"
 | 
			
		||||
	  -- is the player editing the NPC? that is: might there be any changes?
 | 
			
		||||
	  and yl_speak_up.edit_mode
 | 
			
		||||
	  and (yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id)) then
 | 
			
		||||
		local last_fs = yl_speak_up.speak_to[pname].last_fs
 | 
			
		||||
		local d_id = yl_speak_up.speak_to[pname].d_id
 | 
			
		||||
		local o_id = yl_speak_up.speak_to[pname].o_id
 | 
			
		||||
		-- only these two formspecs need to ask specificly if the data ought to be saved
 | 
			
		||||
		if(last_fs == "talk" or last_fs == "edit_option_dialog" or fs_name == "quit") then
 | 
			
		||||
			local last_param = yl_speak_up.speak_to[pname].last_fs_param
 | 
			
		||||
			local show_save_fs = false
 | 
			
		||||
			if(not(param)) then
 | 
			
		||||
				param = {}
 | 
			
		||||
			end
 | 
			
		||||
			-- set the target dialog
 | 
			
		||||
			yl_speak_up.speak_to[pname].target_dialog = param.d_id
 | 
			
		||||
			-- if we are switching from one dialog to another: is it the same?
 | 
			
		||||
			if(last_fs == "talk" and fs_name == last_fs
 | 
			
		||||
			  and param and param.d_id and param.d_id ~= d_id) then
 | 
			
		||||
				-- diffrent parameters: save (if needed)
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			elseif(fs_name == "talk" and param and param.do_save) then
 | 
			
		||||
				-- player clicked on save button
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			-- leaving a dialog: save!
 | 
			
		||||
			elseif(last_fs == "talk" and fs_name ~= last_fs) then
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			-- clicking on "save" in an edit option dialog: save!
 | 
			
		||||
			elseif(last_fs == "edit_option_dialog" and fs_name == last_fs
 | 
			
		||||
			  and param and param.caller and param.caller == "save_option") then
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			-- leaving editing an option: save!
 | 
			
		||||
			elseif(last_fs == "edit_option_dialog" and fs_name ~= last_fs) then
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			-- quitting: save!
 | 
			
		||||
			elseif(fs_name == "quit") then
 | 
			
		||||
				yl_speak_up.speak_to[pname].target_dialog = nil
 | 
			
		||||
				show_save_fs = true
 | 
			
		||||
			end
 | 
			
		||||
			-- show the save or discard dialog
 | 
			
		||||
			if(show_save_fs) then
 | 
			
		||||
				yl_speak_up.speak_to[pname].next_fs = fs_name
 | 
			
		||||
				yl_speak_up.speak_to[pname].next_fs_param = param
 | 
			
		||||
				-- check first if it's necessary to ask for save or discard
 | 
			
		||||
				yl_speak_up.input_save_or_discard_changes(player, "", {})
 | 
			
		||||
				return
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
		-- store the new formspec
 | 
			
		||||
		yl_speak_up.speak_to[pname].last_fs = fs_name
 | 
			
		||||
		-- and its parameter
 | 
			
		||||
		yl_speak_up.speak_to[pname].last_fs_param = param
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	-- abort talk if we hit d_end
 | 
			
		||||
	if(fs_name == "talk" and param and param.d_id and param.d_id == "d_end") then
 | 
			
		||||
		yl_speak_up.stop_talking(pname)
 | 
			
		||||
@ -153,11 +73,10 @@ yl_speak_up.show_fs = function(player, fs_name, param)
 | 
			
		||||
			fun(player, param),
 | 
			
		||||
			yl_speak_up.registered_forms_force_fs_ver[fs_name])
 | 
			
		||||
		return true
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	-- this is here mostly to fascilitate debugging - so that really all calls to
 | 
			
		||||
	-- minetest.show_formspec are routed through here
 | 
			
		||||
	if(fs_name == "msg") then
 | 
			
		||||
	elseif(fs_name == "msg") then
 | 
			
		||||
		if(not(param)) then
 | 
			
		||||
			param = {}
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user