forked from your-land-mirror/yl_speak_up
allow to click on start/end/unconnected steps in list
This commit is contained in:
parent
d267560d2a
commit
c3d97233dd
@ -171,79 +171,98 @@ yl_speak_up.input_fs_manage_quest_steps = function(player, formname, fields)
|
|||||||
-- TODO: check if the player is allowed to access that quest
|
-- TODO: check if the player is allowed to access that quest
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
|
|
||||||
if(fields and fields.back) then
|
if(not(fields) or (fields and fields.back)) then
|
||||||
yl_speak_up.show_fs(player, "manage_quests")
|
yl_speak_up.show_fs(player, "manage_quests")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local res = yl_speak_up.player_is_working_on_quest(player)
|
local res = yl_speak_up.player_is_working_on_quest(player)
|
||||||
if(not(res.error_msg) and res.current_step) then
|
if(res.error_msg) then
|
||||||
|
yl_speak_up.show_fs(player, "msg", {
|
||||||
|
input_to = formname,
|
||||||
|
formspec = yl_speak_up.get_fs_quest_edit_error(error_msg, "back_from_error_msg")
|
||||||
|
})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local step_data = res.step_data or {}
|
||||||
|
|
||||||
|
-- which quest step to show next? (if any)
|
||||||
|
local show_step = ""
|
||||||
|
-- was a quest step selected from the start/end/unconnected lists?
|
||||||
|
local list = {}
|
||||||
|
local field_name = ""
|
||||||
|
if( fields.select_from_start_steps and fields.select_from_start_steps ~= "") then
|
||||||
|
-- selected a start quest step
|
||||||
|
list = yl_speak_up.quest_step_get_start_end_unconnected_lists(step_data).start_steps
|
||||||
|
field_name = "select_from_start_steps"
|
||||||
|
elseif(fields.select_from_end_steps and fields.select_from_end_steps ~= "") then
|
||||||
|
-- selected an end quest step
|
||||||
|
list = yl_speak_up.quest_step_get_start_end_unconnected_lists(step_data).end_steps
|
||||||
|
field_name = "select_from_end_steps"
|
||||||
|
elseif(fields.select_from_unconnected_steps and fields.select_from_unconnected_steps ~= "") then
|
||||||
|
-- selected an unconnected/unused quest step
|
||||||
|
list = yl_speak_up.quest_step_get_start_end_unconnected_lists(step_data).unconnected_steps
|
||||||
|
field_name = "select_from_unconnected_steps"
|
||||||
|
elseif(res.current_step and fields.one_step_required) then
|
||||||
|
list = step_data[res.current_step].one_step_required
|
||||||
|
field_name = "one_step_required"
|
||||||
|
elseif(res.current_step and fields.all_steps_required) then
|
||||||
|
list = step_data[res.current_step].all_steps_required
|
||||||
|
field_name = "all_steps_required"
|
||||||
|
elseif(res.current_step and fields.next_steps_show) then
|
||||||
|
list = yl_speak_up.quest_step_required_for(step_data, res.current_step)
|
||||||
|
field_name = "next_steps_show"
|
||||||
|
-- show prev logical step
|
||||||
|
elseif(fields.show_prev_step) then
|
||||||
|
if( #step_data[res.current_step].one_step_required > 0) then
|
||||||
|
show_step = step_data[res.current_step].one_step_required[1]
|
||||||
|
elseif(#step_data[res.current_step].all_steps_required > 0) then
|
||||||
|
show_step = step_data[res.current_step].all_steps_required[1]
|
||||||
|
end
|
||||||
|
-- show next logical step
|
||||||
|
elseif(fields.show_next_step) then
|
||||||
|
local list = yl_speak_up.quest_step_required_for(res.step_data, res.current_step)
|
||||||
|
if(list and #list > 0) then
|
||||||
|
show_step = list[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if(list and field_name) then
|
||||||
|
local selected = minetest.explode_table_event(fields[field_name])
|
||||||
|
-- these tables don't use header
|
||||||
|
if(selected and selected.row and selected.row > 0 and selected.row <= #list) then
|
||||||
|
show_step = list[selected.row]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- actually show the selected quest step
|
||||||
|
if(show_step and show_step ~= "") then
|
||||||
|
yl_speak_up.speak_to[pname].quest_step = show_step
|
||||||
|
yl_speak_up.show_fs(player, "manage_quest_steps", show_step)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if(res.current_step) then
|
||||||
-- forward input from that formspec...
|
-- forward input from that formspec...
|
||||||
if((yl_speak_up.speak_to[res.pname].quest_step_mode == "embedded_select")
|
if((yl_speak_up.speak_to[res.pname].quest_step_mode == "embedded_select")
|
||||||
and (fields.add_from_available
|
and (fields.add_from_available
|
||||||
or (fields.add_step and fields.add_quest_step))) then
|
or (fields.add_step and fields.add_quest_step))) then
|
||||||
return yl_speak_up.input_fs_add_quest_steps(player, "yl_speak_up:add_quest_steps", fields)
|
return yl_speak_up.input_fs_add_quest_steps(player, "yl_speak_up:add_quest_steps", fields)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
if(selected_from) then
|
|
||||||
local selected = minetest.explode_table_event(selected_from)
|
local modes = {"add_to_one_needed", "add_to_all_needed",
|
||||||
if(selected and selected.row and selected.row > 0 and selected.row <= #list) then
|
"insert_after_prev_step", "insert_before_next_step"}
|
||||||
-- show the selected quest step
|
for i, mode in ipairs(modes) do
|
||||||
yl_speak_up.speak_to[pname].quest_step = list[selected.row]
|
if(fields[mode] and fields[mode] ~= "") then
|
||||||
yl_speak_up.show_fs(player, "manage_quest_steps", list[selected.row])
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- show prev logical step
|
|
||||||
if(fields and fields.show_prev_step) then
|
|
||||||
if(#res.step_data[res.current_step].one_step_required > 0) then
|
|
||||||
yl_speak_up.show_fs(player, "manage_quest_steps",
|
|
||||||
res.step_data[res.current_step].one_step_required[1])
|
|
||||||
return
|
|
||||||
elseif(#res.step_data[res.current_step].all_steps_required > 0) then
|
|
||||||
yl_speak_up.show_fs(player, "manage_quest_steps",
|
|
||||||
res.step_data[res.current_step].all_steps_required[1])
|
|
||||||
return
|
|
||||||
end
|
|
||||||
-- show next logical step
|
|
||||||
elseif(fields and fields.show_next_step) then
|
|
||||||
local list = yl_speak_up.quest_step_required_for(res.step_data, res.current_step)
|
|
||||||
if(list and #list > 0) then
|
|
||||||
yl_speak_up.show_fs(player, "manage_quest_steps", list[1])
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if(fields
|
|
||||||
and (fields.add_to_one_needed or fields.add_to_all_needed
|
|
||||||
or fields.insert_after_prev_step or fields.insert_before_next_step)) then
|
|
||||||
-- let that function sort out what to do;
|
-- let that function sort out what to do;
|
||||||
-- yl_speak_up.speak_to[pname].q_id and yl_speak_up.speak_to[pname].quest_step
|
-- yl_speak_up.speak_to[pname].q_id and yl_speak_up.speak_to[pname].quest_step
|
||||||
-- ought to be set to the current quest and step by now
|
-- ought to be set to the current quest and step by now
|
||||||
if(fields.add_to_one_needed) then
|
yl_speak_up.speak_to[pname].quest_step_mode = mode
|
||||||
yl_speak_up.speak_to[pname].quest_step_mode = "add_to_one_needed"
|
|
||||||
elseif(fields.add_to_all_needed) then
|
|
||||||
yl_speak_up.speak_to[pname].quest_step_mode = "add_to_all_needed"
|
|
||||||
elseif(fields.insert_after_prev_step) then
|
|
||||||
yl_speak_up.speak_to[pname].quest_step_mode = "insert_after_prev_step"
|
|
||||||
elseif(fields.insert_before_next_step) then
|
|
||||||
yl_speak_up.speak_to[pname].quest_step_mode = "insert_before_next_step"
|
|
||||||
else
|
|
||||||
yl_speak_up.speak_to[pname].quest_step_mode = nil
|
|
||||||
end
|
|
||||||
yl_speak_up.show_fs(player, "add_quest_steps")
|
yl_speak_up.show_fs(player, "add_quest_steps")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local quest_step_list = yl_speak_up.get_sorted_quest_step_list(pname)
|
local quest_step_list = yl_speak_up.get_sorted_quest_step_list(pname)
|
||||||
local res = yl_speak_up.input_fs_manage_general(player, formname, fields,
|
local res = yl_speak_up.input_fs_manage_general(player, formname, fields,
|
||||||
-- what_is_the_list_about, min_length, max_length, function_add_new_entry,
|
-- what_is_the_list_about, min_length, max_length, function_add_new_entry,
|
||||||
@ -304,20 +323,20 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param)
|
|||||||
table.insert(formspec, "container_end[]")
|
table.insert(formspec, "container_end[]")
|
||||||
local lists = yl_speak_up.quest_step_get_start_end_unconnected_lists(step_data)
|
local lists = yl_speak_up.quest_step_get_start_end_unconnected_lists(step_data)
|
||||||
yl_speak_up.get_fs_show_list_in_box(formspec,
|
yl_speak_up.get_fs_show_list_in_box(formspec,
|
||||||
"Start steps:", "TODO_select_from_start_steps", lists.start_steps,
|
"Start steps:", "select_from_start_steps", lists.start_steps,
|
||||||
"0.1", "2.7", "5.6", "4.3", 0, nil, "#AAFFAA",
|
"0.1", "2.7", "5.6", "4.3", 0, nil, "#AAFFAA",
|
||||||
"The quest begins with this (or one of these) steps.\n"..
|
"The quest begins with this (or one of these) steps.\n"..
|
||||||
"You need at least one start step.",
|
"You need at least one start step.",
|
||||||
nil)
|
nil)
|
||||||
yl_speak_up.get_fs_show_list_in_box(formspec,
|
yl_speak_up.get_fs_show_list_in_box(formspec,
|
||||||
"Unconnected steps:", "TODO_select_from_unconnected_steps", lists.unconnected_steps,
|
"Unconnected steps:", "select_from_unconnected_steps", lists.unconnected_steps,
|
||||||
"0.1", "7.0", "5.6", "4.3", 0, nil, "#FFAAAA",
|
"0.1", "7.0", "5.6", "4.3", 0, nil, "#FFAAAA",
|
||||||
"These steps are not used yet. They are not required\n"..
|
"These steps are not used yet. They are not required\n"..
|
||||||
"by any other steps and do not require steps either.\n"..
|
"by any other step and do not require steps either.\n"..
|
||||||
"Please decide what to do with them!",
|
"Please decide what to do with them!",
|
||||||
nil)
|
nil)
|
||||||
yl_speak_up.get_fs_show_list_in_box(formspec,
|
yl_speak_up.get_fs_show_list_in_box(formspec,
|
||||||
"Quest ends with steps:", "TODO_select_from_end_steps", lists.end_steps,
|
"Quest ends with steps:", "select_from_end_steps", lists.end_steps,
|
||||||
"24", "2.7", "5.6", "8.5", "0.1", nil, "#AAFFAA",
|
"24", "2.7", "5.6", "8.5", "0.1", nil, "#AAFFAA",
|
||||||
"This quest ends with these steps. They are not required\n"..
|
"This quest ends with these steps. They are not required\n"..
|
||||||
"by any other steps and have no successor.\n"..
|
"by any other steps and have no successor.\n"..
|
||||||
|
@ -74,7 +74,7 @@ yl_speak_up.get_fs_manage_quests = function(player, param)
|
|||||||
"depend on and influence other quests.\n"..
|
"depend on and influence other quests.\n"..
|
||||||
"Progress for each player is stored in a variable. The name of "..
|
"Progress for each player is stored in a variable. The name of "..
|
||||||
"that variable cannot be changed after creation.]")
|
"that variable cannot be changed after creation.]")
|
||||||
if(true) then return formspec[1] end -- TODO: temporally disabled for YL
|
-- if(true) then return formspec[1] end -- TODO: temporally disabled for YL
|
||||||
local selected = yl_speak_up.get_fs_manage_general(player, param,
|
local selected = yl_speak_up.get_fs_manage_general(player, param,
|
||||||
formspec, quest_list,
|
formspec, quest_list,
|
||||||
"Create quest",
|
"Create quest",
|
||||||
|
Loading…
Reference in New Issue
Block a user