144 lines
5.3 KiB
Lua
144 lines
5.3 KiB
Lua
-- assign a quest step to a dialog option/answe
|
|
-- This is the formspec where this is handled.
|
|
|
|
yl_speak_up.input_fs_assign_quest_step = function(player, formname, fields)
|
|
if(not(player)) then
|
|
return ""
|
|
end
|
|
local pname = player:get_player_name()
|
|
-- what are we talking about?
|
|
local n_id = yl_speak_up.speak_to[pname].n_id
|
|
local d_id = yl_speak_up.speak_to[pname].d_id
|
|
local o_id = yl_speak_up.speak_to[pname].o_id
|
|
|
|
if(not(n_id) or yl_speak_up.edit_mode[pname] ~= n_id) then
|
|
return
|
|
end
|
|
local dialog = yl_speak_up.speak_to[pname].dialog
|
|
if(not(dialog) or not(dialog.n_dialogs)
|
|
or not(d_id) or not(o_id)
|
|
or not(dialog.n_dialogs[d_id])
|
|
or not(dialog.n_dialogs[d_id].d_options)
|
|
or not(dialog.n_dialogs[d_id].d_options[o_id])) then
|
|
return
|
|
end
|
|
|
|
-- go back to edit options field
|
|
if((fields and fields.quit)
|
|
or (fields and fields.back and fields.back ~= "")) then
|
|
yl_speak_up.show_fs(player, "edit_option_dialog",
|
|
{n_id = n_id, d_id = d_id, o_id = o_id})
|
|
return
|
|
elseif(fields and fields.back_from_error_msg) then
|
|
yl_speak_up.show_fs(player, "assign_quest_step", nil)
|
|
return
|
|
-- show manage quests formspec
|
|
elseif(fields and fields.manage_quests) then
|
|
-- store information so that the back button can work
|
|
yl_speak_up.speak_to[pname][ "working_at" ] = "assign_quest_step"
|
|
yl_speak_up.show_fs(player, "manage_quests", nil)
|
|
return
|
|
elseif(fields.delete and fields.delete ~= "") then
|
|
dialog.n_dialogs[d_id].d_options[o_id].quest_id = nil
|
|
dialog.n_dialogs[d_id].d_options[o_id].quest_step = nil
|
|
if(not(yl_speak_up.npc_was_changed[ n_id ])) then
|
|
yl_speak_up.npc_was_changed[ n_id ] = {}
|
|
end
|
|
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
|
"Dialog "..d_id..": Option "..tostring(o_id)..
|
|
" no longer provides quest step \""..
|
|
tostring(fields.quest_step).."\" for quest \""..tostring(fields.quest_id).."\".")
|
|
yl_speak_up.show_fs(player, "edit_option_dialog",
|
|
{n_id = n_id, d_id = d_id, o_id = o_id})
|
|
return
|
|
elseif(not(fields) or not(fields.save)) then
|
|
return
|
|
end
|
|
-- actually store the data
|
|
local error_msg = ""
|
|
-- check if the quest exists
|
|
local quest_list = yl_speak_up.get_sorted_quest_list(pname)
|
|
local idx = table.indexof(quest_list, fields.quest_id or "")
|
|
if(not(fields.quest_id) or fields.quest_id == "" or idx < 1) then
|
|
error_msg = "Quest not found."
|
|
elseif(not(fields.quest_step)
|
|
or string.len(fields.quest_step) < 1
|
|
or string.len(fields.quest_step) > 80) then
|
|
error_msg = "The name of the quest step has to be between\n"..
|
|
"1 and 80 characters long."
|
|
end
|
|
if(error_msg ~= "") then
|
|
yl_speak_up.show_fs(player, "msg", {
|
|
input_to = "yl_speak_up:assign_quest_step",
|
|
formspec = "size[9,2]"..
|
|
"label[0.2,0.5;Error: "..minetest.formspec_escape(error_msg).."]"..
|
|
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
|
|
return
|
|
end
|
|
dialog.n_dialogs[d_id].d_options[o_id].quest_id = fields.quest_id
|
|
dialog.n_dialogs[d_id].d_options[o_id].quest_step = fields.quest_step
|
|
if(not(yl_speak_up.npc_was_changed[ n_id ])) then
|
|
yl_speak_up.npc_was_changed[ n_id ] = {}
|
|
end
|
|
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
|
"Dialog "..d_id..": Option "..tostring(o_id)..
|
|
" has been set as quest step \""..
|
|
tostring(fields.quest_step).."\" for quest \""..tostring(fields.quest_id).."\".")
|
|
yl_speak_up.show_fs(player, "edit_option_dialog",
|
|
{n_id = n_id, d_id = d_id, o_id = o_id})
|
|
end
|
|
|
|
|
|
yl_speak_up.get_fs_assign_quest_step = function(player, param)
|
|
if(not(player)) then
|
|
return ""
|
|
end
|
|
local pname = player:get_player_name()
|
|
local n_id = yl_speak_up.speak_to[pname].n_id
|
|
local d_id = yl_speak_up.speak_to[pname].d_id
|
|
local o_id = yl_speak_up.speak_to[pname].o_id
|
|
-- this only works in edit mode
|
|
if(not(n_id) or yl_speak_up.edit_mode[pname] ~= n_id) then
|
|
return "size[1,1]label[0,0;You cannot edit this NPC.]"
|
|
end
|
|
local dialog = yl_speak_up.speak_to[pname].dialog
|
|
if(not(dialog) or not(dialog.n_dialogs)
|
|
or not(d_id) or not(o_id)
|
|
or not(dialog.n_dialogs[d_id])
|
|
or not(dialog.n_dialogs[d_id].d_options)
|
|
or not(dialog.n_dialogs[d_id].d_options[o_id])) then
|
|
return "size[4,1]label[0,0;Dialog option does not exist.]"
|
|
end
|
|
|
|
local d_option = dialog.n_dialogs[d_id].d_options[o_id]
|
|
local quest_id = d_option.quest_id or ""
|
|
local quest_step = d_option.quest_step or ""
|
|
|
|
local selected = 1
|
|
local quest_list = yl_speak_up.get_sorted_quest_list(pname)
|
|
for i, v in ipairs(quest_list) do
|
|
quest_list[i] = minetest.formspec_escape(v)
|
|
if(quest_id and v == quest_id) then
|
|
selected = i
|
|
end
|
|
end
|
|
local delete_button = ""
|
|
if(quest_step and quest_step ~= "" and quest_id and quest_id ~= "") then
|
|
delete_button = "button[4.0,3.0;2.0,0.8;delete;Delete]"
|
|
end
|
|
return "size[14,4]"..
|
|
"label[4.0,0.5;Using this option/answer shall be a quest step.]"..
|
|
"label[0.2,1.4;Select a quest:]"..
|
|
"dropdown[4.0,1.0;9.5,0.8;quest_id;"..
|
|
table.concat(quest_list, ',')..";"..
|
|
tostring(selected)..",]"..
|
|
"label[0.2,2.4;Name of the quest step:]"..
|
|
"field[4.0,2.0;9.5,0.8;quest_step;;"..
|
|
minetest.formspec_escape(quest_step).."]"..
|
|
"button[0.2,3.0;3.6,0.8;manage_quests;Manage Quests]"..
|
|
delete_button..
|
|
"button[6.5,3.0;2.0,0.8;save;Save]"..
|
|
"button[9.0,3.0;2.0,0.8;back;Abort]"..
|
|
"button[11.5,3.0;2.0,0.8;back;Back]"
|
|
end
|