forked from your-land-mirror/yl_speak_up
		
	make quest step in quest step list clickable
This commit is contained in:
		
							parent
							
								
									fd525a950f
								
							
						
					
					
						commit
						83f92f1a49
					
				@ -1,4 +1,53 @@
 | 
			
		||||
 | 
			
		||||
-- returns a table with helpful information *if* the player is working on a quest;
 | 
			
		||||
-- else error_msg is set
 | 
			
		||||
yl_speak_up.player_is_working_on_quest = function(player)
 | 
			
		||||
	if(not(player)) then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	local t = {}
 | 
			
		||||
	t.pname = player:get_player_name()
 | 
			
		||||
	if(not(t.pname)) then
 | 
			
		||||
		return {error_msg = "Player not found."}
 | 
			
		||||
	end
 | 
			
		||||
	if(not(yl_speak_up.speak_to or not(yl_speak_up.speak_to[t.pname]))) then
 | 
			
		||||
		return {error_msg = "Player not working on a quest."}
 | 
			
		||||
	end
 | 
			
		||||
	t.q_id = yl_speak_up.speak_to[t.pname].q_id
 | 
			
		||||
	if(not(t.q_id) or not(yl_speak_up.quests) or not(yl_speak_up.quests[t.q_id])) then
 | 
			
		||||
		return {error_msg = "No quest selected or quest not found."}
 | 
			
		||||
	end
 | 
			
		||||
	t.quest = yl_speak_up.quests[t.q_id]
 | 
			
		||||
	if(not(t.quest.step_data) or type(t.quest.step_data) ~= "table") then
 | 
			
		||||
		yl_speak_up.quests[t.q_id].step_data = {}
 | 
			
		||||
	end
 | 
			
		||||
	-- TODO: check if the player has access to that data
 | 
			
		||||
	t.step_data = yl_speak_up.quests[t.q_id].step_data
 | 
			
		||||
	t.current_step = yl_speak_up.speak_to[t.pname].quest_step
 | 
			
		||||
	-- t contains pname, q_id, quest, step_data and current_step - or error_msg
 | 
			
		||||
	return t
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- for which other quest steps is this_step needed for?
 | 
			
		||||
yl_speak_up.quest_step_required_for = function(step_data, this_step)
 | 
			
		||||
	-- find out the next quest step
 | 
			
		||||
	local required_for = {}
 | 
			
		||||
	for s, d in pairs(step_data) do
 | 
			
		||||
		if(s and d and d.one_step_required and type(d.one_step_required) == "table"
 | 
			
		||||
		  and table.indexof(d.one_step_required, this_step) ~= -1) then
 | 
			
		||||
			table.insert(required_for, s)
 | 
			
		||||
		end
 | 
			
		||||
		if(s and d and d.all_steps_required and type(d.all_steps_required) == "table"
 | 
			
		||||
		  and table.indexof(d.all_steps_required, this_step) ~= -1) then
 | 
			
		||||
			table.insert(required_for, s)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	table.sort(required_for)
 | 
			
		||||
	return required_for
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- Imposing an order on the quest steps is...tricky as best as what will
 | 
			
		||||
-- be more important to the players will be the order in which the
 | 
			
		||||
-- quest steps have to be solved/done - and not an alphabetical order.
 | 
			
		||||
@ -69,10 +118,29 @@ yl_speak_up.input_fs_manage_quest_steps = function(player, formname, fields)
 | 
			
		||||
	-- TODO: check if the player is allowed to access that quest
 | 
			
		||||
	local pname = player:get_player_name()
 | 
			
		||||
 | 
			
		||||
	if(fields and fields.change_prev_step) then
 | 
			
		||||
		yl_speak_up.show_fs(player, "manage_quest_steps", " change_prev_step")
 | 
			
		||||
		return
 | 
			
		||||
 | 
			
		||||
	local res = yl_speak_up.player_is_working_on_quest(player)
 | 
			
		||||
	if(not(res.error_msg) and res.current_step) then
 | 
			
		||||
		local selected_from = nil
 | 
			
		||||
		local list = {}
 | 
			
		||||
		if(    fields and fields.one_step_required) then
 | 
			
		||||
			selected_from = fields.one_step_required
 | 
			
		||||
			list = res.step_data[res.current_step].one_step_required
 | 
			
		||||
		elseif(fields and fields.all_steps_required) then
 | 
			
		||||
			selected_from = fields.all_steps_required
 | 
			
		||||
			list = res.step_data[res.current_step].all_steps_required
 | 
			
		||||
		elseif(fields and fields.next_steps_show) then
 | 
			
		||||
			selected_from = fields.next_steps_show
 | 
			
		||||
			list = yl_speak_up.quest_step_required_for(res.step_data, res.current_step)
 | 
			
		||||
		end
 | 
			
		||||
		if(selected_from) then
 | 
			
		||||
			local selected = minetest.explode_table_event(selected_from)
 | 
			
		||||
			if(selected and selected.row and selected.row > 0 and selected.row <= #list) then
 | 
			
		||||
				-- show the selected quest step
 | 
			
		||||
				yl_speak_up.speak_to[pname].quest_step = list[selected.row]
 | 
			
		||||
				yl_speak_up.show_fs(player, "manage_quest_steps", list[selected.row])
 | 
			
		||||
				return
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	if(fields
 | 
			
		||||
	  and (fields.add_to_one_needed or fields.add_to_all_needed
 | 
			
		||||
@ -165,26 +233,13 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param)
 | 
			
		||||
		return table.concat(formspec, "")
 | 
			
		||||
	end
 | 
			
		||||
	-- find out the next quest step
 | 
			
		||||
	local required_for = {}
 | 
			
		||||
	for s, d in pairs(step_data) do
 | 
			
		||||
		if(s and d and d.one_step_required and type(d.one_step_required) == "table"
 | 
			
		||||
		  and table.indexof(d.one_step_required, selected) ~= -1) then
 | 
			
		||||
			table.insert(required_for, s)
 | 
			
		||||
		end
 | 
			
		||||
		if(s and d and d.all_steps_required and type(d.all_steps_required) == "table"
 | 
			
		||||
		  and table.indexof(d.all_steps_required, selected) ~= -1) then
 | 
			
		||||
			table.insert(required_for, s)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	local required_for = yl_speak_up.quest_step_required_for(step_data, selected)
 | 
			
		||||
 | 
			
		||||
	-- left side (previous quest step)
 | 
			
		||||
	table.insert(formspec,  "label[0.2,2.0;"..em("Required previous").."]"..
 | 
			
		||||
				"label[0.2,2.4;quest step(s):]"..
 | 
			
		||||
				"style[insert_before_next_step,insert_after_prev_step,"..
 | 
			
		||||
					"add_to_one_needed,add_to_all_needed;bgcolor=blue;textcolor=yellow]"..
 | 
			
		||||
				"tooltip[change_prev_step;"..
 | 
			
		||||
					"Click here to add, set or change the previous\n"..
 | 
			
		||||
					"and further required quest steps.]"..
 | 
			
		||||
				"container[0.1,2.7;5.6,10.8]"..
 | 
			
		||||
				"box[0,0;5.6,8.5;#666666]"..
 | 
			
		||||
				"button[4.6,0.0;0.9,0.7;add_to_one_needed;Edit]"..
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user