added button in options edit menu for adding trades
This commit is contained in:
		
							parent
							
								
									2e2ede2ebf
								
							
						
					
					
						commit
						870751aaab
					
				@ -827,7 +827,7 @@ end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- edit options (not via staff but via the "I am your owner" dialog)
 | 
			
		||||
local function get_fs_edit_option_dialog(player, n_id, d_id, o_id)
 | 
			
		||||
yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id)
 | 
			
		||||
	-- n_id, d_id and o_id have already been checked when this function is called
 | 
			
		||||
	local pname = player:get_player_name()
 | 
			
		||||
	local dialog = yl_speak_up.speak_to[pname].dialog
 | 
			
		||||
@ -851,6 +851,7 @@ local function get_fs_edit_option_dialog(player, n_id, d_id, o_id)
 | 
			
		||||
	-- and build the list of effects
 | 
			
		||||
	local list_of_effects = ""
 | 
			
		||||
	local results = d_option.o_results
 | 
			
		||||
	local has_trade = false
 | 
			
		||||
	if(results) then
 | 
			
		||||
		for k, v in pairs(results) do
 | 
			
		||||
			if v.r_type == "dialog" and dialog.n_dialogs[v.r_value] ~= nil then
 | 
			
		||||
@ -861,9 +862,25 @@ local function get_fs_edit_option_dialog(player, n_id, d_id, o_id)
 | 
			
		||||
					minetest.formspec_escape(v.r_id)..",#FFFF00,"..
 | 
			
		||||
					minetest.formspec_escape(v.r_type)..","..
 | 
			
		||||
					minetest.formspec_escape(v.r_value)..","
 | 
			
		||||
				if(v.r_type == "trade") then
 | 
			
		||||
					has_trade = v
 | 
			
		||||
				end
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	-- trade is one of the very few effects players can set
 | 
			
		||||
	local button_add_edit_trade = ""
 | 
			
		||||
	if(has_trade) then
 | 
			
		||||
		button_add_edit_trade = ""..
 | 
			
		||||
				"button[14.8,10;2.0,0.9;effect_show_trade;Show trade]"..
 | 
			
		||||
				"tooltip[effect_edit_trade;Show and edit the trade that starts "..
 | 
			
		||||
				"when selectiong this option.]"
 | 
			
		||||
	else
 | 
			
		||||
		button_add_edit_trade = ""..
 | 
			
		||||
				"button[14.8,10;2.0,0.9;effect_add_trade;Add trade]"..
 | 
			
		||||
				"tooltip[effect_add_trade;Add a trade that will start "..
 | 
			
		||||
				"when selectiong this option.]"
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	-- if no target dialog has been selected: default is to go to the dialog with d_sort 0
 | 
			
		||||
	if(not(target_dialog) or target_dialog == "" or not(dialog.n_dialogs[target_dialog])) then
 | 
			
		||||
@ -970,6 +987,7 @@ local function get_fs_edit_option_dialog(player, n_id, d_id, o_id)
 | 
			
		||||
			"preconditions are NOT all fulfilled.]"..
 | 
			
		||||
		-- list of effects
 | 
			
		||||
		"label[0.2,10.6;When this answer has been selected, apply the following (Ef)fects:]"..
 | 
			
		||||
		button_add_edit_trade..
 | 
			
		||||
		-- TODO: perhaps add tooltip for the type of the conditions
 | 
			
		||||
		"tablecolumns[text;color,span=1;text;text]"..
 | 
			
		||||
		"table[1.2,11.0;19.6,2.0;table_of_effect;"..
 | 
			
		||||
@ -1730,6 +1748,9 @@ minetest.register_on_player_receive_fields( function(player, formname, fields)
 | 
			
		||||
	elseif formname == "yl_speak_up:inventory" then
 | 
			
		||||
		yl_speak_up.input_inventory(player, formname, fields)
 | 
			
		||||
		return true
 | 
			
		||||
	elseif formname == "yl_speak_up:add_trade_simple" then
 | 
			
		||||
		yl_speak_up.input_add_trade_simple(player, formname, fields)
 | 
			
		||||
		return true
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
@ -2577,7 +2598,8 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
 | 
			
		||||
	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"] 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"]))
 | 
			
		||||
		minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog",
 | 
			
		||||
			yl_speak_up.get_fs_edit_option_dialog(player, n_id, d_id, result["show_next_option"]))
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
@ -2599,7 +2621,8 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
		-- show that dialog; fallback: show the same (o_id) again
 | 
			
		||||
		minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog", get_fs_edit_option_dialog(player, n_id, d_id, o_found))
 | 
			
		||||
		minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog",
 | 
			
		||||
			yl_speak_up.get_fs_edit_option_dialog(player, n_id, d_id, o_found))
 | 
			
		||||
		return
 | 
			
		||||
 | 
			
		||||
	-- the player wants to see the next option/answer
 | 
			
		||||
@ -2613,8 +2636,48 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
		-- show that dialog; fallback: show the same (o_id) again
 | 
			
		||||
		minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog", get_fs_edit_option_dialog(player, n_id, d_id, o_found))
 | 
			
		||||
		minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog",
 | 
			
		||||
			yl_speak_up.get_fs_edit_option_dialog(player, n_id, d_id, o_found))
 | 
			
		||||
		return
 | 
			
		||||
 | 
			
		||||
	elseif(fields.effect_add_trade) then
 | 
			
		||||
		yl_speak_up.trade[pname] = {
 | 
			
		||||
			-- we start with the simple trade
 | 
			
		||||
			trade_type = "trade_simple",
 | 
			
		||||
			-- we will create a new trade
 | 
			
		||||
			player_gives = nil,
 | 
			
		||||
			npc_gives    = nil,
 | 
			
		||||
			-- can be determined from other variables, but it is easier to store it here
 | 
			
		||||
			n_id = n_id,
 | 
			
		||||
			npc_name = dialog.n_npc,
 | 
			
		||||
			-- for statistics and in order to determine which dialog to show next
 | 
			
		||||
			trade_done = 0,
 | 
			
		||||
			-- we need to know which option this is
 | 
			
		||||
			o_id = fields.o_id,
 | 
			
		||||
		}
 | 
			
		||||
		minetest.show_formspec(pname, "yl_speak_up:add_trade_simple",
 | 
			
		||||
			yl_speak_up.get_fs_trade_simple(player))
 | 
			
		||||
		return
 | 
			
		||||
 | 
			
		||||
	elseif(fields.effect_show_trade) then
 | 
			
		||||
		-- TODO: identify the right result and trade items
 | 
			
		||||
		-- TODO: this may not be a simple trade but instead a more complex one
 | 
			
		||||
		yl_speak_up.trade[pname] = {
 | 
			
		||||
			-- we start with the simple trade
 | 
			
		||||
			trade_type = "trade_simple",
 | 
			
		||||
			-- we will create a new trade
 | 
			
		||||
			player_gives = nil, -- TODO
 | 
			
		||||
			npc_gives    = nil, -- TODO
 | 
			
		||||
			-- can be determined from other variables, but it is easier to store it here
 | 
			
		||||
			n_id = n_id,
 | 
			
		||||
			npc_name = dialog.n_npc,
 | 
			
		||||
			-- for statistics and in order to determine which dialog to show next
 | 
			
		||||
			trade_done = 0,
 | 
			
		||||
			-- we need to know which option this is
 | 
			
		||||
			o_id = fields.o_id,
 | 
			
		||||
		}
 | 
			
		||||
		minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog",
 | 
			
		||||
			yl_speak_up.get_fs_trade_simple(player))
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -2882,7 +2945,9 @@ yl_speak_up.input_talk = function(player, formname, fields)
 | 
			
		||||
				if( fields["edit_option_"..o_id]
 | 
			
		||||
				 or fields["conditions_"..o_id]
 | 
			
		||||
				 or fields["effects_"..o_id]) then
 | 
			
		||||
					minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog", get_fs_edit_option_dialog(player, yl_speak_up.speak_to[pname].n_id, d_id, o_id))
 | 
			
		||||
					minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog",
 | 
			
		||||
						yl_speak_up.get_fs_edit_option_dialog(
 | 
			
		||||
							player, yl_speak_up.speak_to[pname].n_id, d_id, o_id))
 | 
			
		||||
					return
 | 
			
		||||
				end
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user