155 lines
7.4 KiB
Lua
155 lines
7.4 KiB
Lua
-- helper functions for yl_speak_up.input_fs_manage_quests(..)
|
|
-- returns the index of the new quest
|
|
yl_speak_up.input_fs_manage_quests_add_new_entry = function(pname, entry_name)
|
|
local res = yl_speak_up.add_quest(pname, entry_name,
|
|
"Name of your quest",
|
|
"Enter a longer description here for describing the quest "..
|
|
"to players who search for one.",
|
|
"Enter a short description here describing what the quest is about.",
|
|
"Room for comments/notes")
|
|
-- might make sense to show the error message somewhere
|
|
if(res ~= "OK") then
|
|
return res
|
|
end
|
|
-- the new entry will be somewhere in it
|
|
local quest_list = yl_speak_up.get_sorted_quest_list(pname)
|
|
return table.indexof(quest_list, entry_name)
|
|
end
|
|
|
|
-- helper functions for yl_speak_up.input_fs_manage_quests(..)
|
|
-- returns a text describing if deleting the quest worked
|
|
yl_speak_up.input_fs_manage_quests_del_old_entry = function(pname, entry_name)
|
|
-- get q_id from entry_name
|
|
local q_id = yl_speak_up.get_quest_id_by_var_name(entry_name, pname)
|
|
return yl_speak_up.del_quest(q_id, pname)
|
|
end
|
|
|
|
-- helper functions for yl_speak_up.input_fs_manage_quests(..)
|
|
-- implements all the functions that are specific to managing quests and not part of
|
|
-- general item management
|
|
yl_speak_up.input_fs_manage_quests_check_fields = function(player, formname, fields, quest_name, list_of_entries)
|
|
local pname = player:get_player_name()
|
|
if(not(quest_name)) then
|
|
quest_name = ""
|
|
end
|
|
if(fields and fields.show_variable) then
|
|
yl_speak_up.show_fs(player, "manage_variables", {var_name = quest_name})
|
|
return
|
|
end
|
|
-- this function didn't have anything to do
|
|
return "NOTHING FOUND"
|
|
end
|
|
|
|
|
|
-- makes use of yl_speak_up.input_fs_manage_general and is thus pretty short
|
|
yl_speak_up.input_fs_manage_quests = function(player, formname, fields)
|
|
local pname = player:get_player_name()
|
|
if(fields and fields.manage_quest_steps and fields.manage_quest_steps ~= "") then
|
|
-- the quest we're working at is stored in yl_speak_up.speak_to[pname].q_id
|
|
yl_speak_up.show_fs(player, "manage_quest_steps")
|
|
return
|
|
end
|
|
local quest_list = yl_speak_up.get_sorted_quest_list(pname)
|
|
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,
|
|
"quest", 2, 80,
|
|
yl_speak_up.input_fs_manage_quests_add_new_entry,
|
|
quest_list,
|
|
yl_speak_up.input_fs_manage_quests_del_old_entry,
|
|
yl_speak_up.input_fs_manage_quests_check_fields)
|
|
return true
|
|
end
|
|
|
|
|
|
yl_speak_up.get_fs_manage_quests = function(player, param)
|
|
local pname = player:get_player_name()
|
|
local quest_list = yl_speak_up.get_sorted_quest_list(pname)
|
|
local formspec = {}
|
|
if(param and param ~= "") then
|
|
local index = table.indexof(quest_list, param)
|
|
yl_speak_up.speak_to[pname].tmp_index_general = index + 1
|
|
end
|
|
table.insert(formspec, "size[18,12]"..
|
|
"label[0.2,1.2;A quest is a linear sequence of quest steps. Quests can "..
|
|
"depend on and influence other quests.\n"..
|
|
"Progress for each player is stored in a variable. The name of "..
|
|
"that variable cannot be changed after creation.]")
|
|
local selected = yl_speak_up.get_fs_manage_general(player, param,
|
|
formspec, quest_list,
|
|
"Create quest",
|
|
"Create a new varialbe with the name\n"..
|
|
"you entered in the field to the left.",
|
|
"quest",
|
|
"Enter the name of the new quest you want to create.\n"..
|
|
"You can't change this name afterwards. But you *can*\n"..
|
|
"add and change a human readable description later on.",
|
|
"If you click here, the selected quest will be deleted.\n"..
|
|
"This will only be possible if it's not used anywhere.")
|
|
if(not(selected) or selected == "") then
|
|
return table.concat(formspec, "")
|
|
end
|
|
local var_name = yl_speak_up.restore_complete_var_name(selected, pname)
|
|
local quest = {}
|
|
for q_id, data in pairs(yl_speak_up.quests) do
|
|
if(data and data.var_name and data.var_name == var_name) then
|
|
quest = data
|
|
end
|
|
end
|
|
local quest_state_selected = table.indexof({"created","testing","open","official"}, quest.state)
|
|
if(quest_state_selected == -1) then
|
|
quest_state_selected = 1
|
|
end
|
|
-- index 1 is "Add variable:"
|
|
|
|
table.insert(formspec, "button[12,2.15;4.5,0.6;show_variable;Show and edit this variable]")
|
|
|
|
table.insert(formspec, "scroll_container[0,3;18,8;scr0;vertical;1]")
|
|
table.insert(formspec, "button[12,0.15;4.5,0.6;manage_quest_steps;Manage quest steps]")
|
|
|
|
table.insert(formspec, "label[0.5,0.5;Quest ID:]")
|
|
table.insert(formspec, "label[3.5,0.5;"..minetest.formspec_escape(quest.id or "- ? -").."]")
|
|
table.insert(formspec, "label[0.5,1.1;State:]")
|
|
table.insert(formspec, "dropdown[3.5,0.8;4.0,0.5;quest_state;created,testing,open,official;"..tostring(quest_state_selected).."]")
|
|
table.insert(formspec, "label[0.5,1.7;Creator/Owner:]")
|
|
table.insert(formspec, "field[3.5,1.4;4.0,0.5;quest_owner;;"..minetest.formspec_escape(quest.owner or "- ? -").."]")
|
|
table.insert(formspec, "label[0.5,2.3;Name:]")
|
|
table.insert(formspec, "field[3.5,2.0;13.0,0.5;quest_name;;"..minetest.formspec_escape(quest.name or "- ? -").."]")
|
|
table.insert(formspec, "label[0.5,2.9;Short Description:]")
|
|
table.insert(formspec, "field[3.5,2.6;13.0,0.5;quest_short_desc;;"..minetest.formspec_escape(quest.short_desc or "- ? -").."]")
|
|
table.insert(formspec, "label[0.5,3.5;Full Description:]")
|
|
table.insert(formspec, "textarea[3.5,3.2;13.0,1.5;quest_desc;;"..minetest.formspec_escape(quest.description or "- ? -").."]")
|
|
table.insert(formspec, "label[0.5,5.1;Internal comment:]")
|
|
table.insert(formspec, "textarea[3.5,4.8;13.0,1.5;quest_comment;;"..minetest.formspec_escape(quest.comment or "- ? -").."]")
|
|
|
|
table.insert(formspec, "button[3.5,6.5;4.0,0.8;save_changes;TODO Save changes]")
|
|
table.insert(formspec, "scroll_container_end[]")
|
|
|
|
-- TODO: make the content of the fields and textareas more readable (more contrast)
|
|
-- TODO: actually process and store changed entries
|
|
--[[
|
|
-- TODO: entries that are not yet shown:
|
|
quest.var_name = var_name -- name of the variable where progress is stored for each player
|
|
quest.step_data = {} -- table containing information about a quest step (=key)
|
|
-- this may also be information about WHERE a quest step shall
|
|
-- take place
|
|
quest.subquests = {} -- list of other quest_ids that contribute to this quest
|
|
-- -> determined from quests.npcs and quests.locations
|
|
quest.is_subquest_of = {} -- list of quest_ids this quest contributes to
|
|
-- -> determined from quests.npcs and quests.locations
|
|
quest.npcs = {} -- list of NPC that contribute to this quest
|
|
-- -> derived from quest.var_name
|
|
quest.locations = {} -- list of locations that contribute to this quest
|
|
-- -> derived from quest.var_name
|
|
quest.items = {} -- data of quest items created and accepted
|
|
quest.rewards = {} -- list of rewards (item stacks) for this ques
|
|
quest.testers = {} -- list of player names that can test the quest
|
|
-- -> during the created/testing phase: any player for which
|
|
-- quest.var_name is set to a value
|
|
quest.solved_by = {} -- list of names of players that solved the quest at least once
|
|
--]]
|
|
|
|
-- store the quest ID so that we know what we're working at
|
|
yl_speak_up.speak_to[pname].q_id = quest.id
|
|
return table.concat(formspec, "")
|
|
end
|