yl_speak_up/fs_manage_quest_steps.lua
2023-09-15 00:52:51 +02:00

121 lines
4.5 KiB
Lua

-- 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.
-- But we need an order here for a dropdown menu to select each
-- quest step even if it hasn't been assigned any place in the chain
-- of quest steps yet. So - alphabetical order.
yl_speak_up.get_sorted_quest_step_list = function(pname, q_id)
local quest_step_list = {}
if(not(pname) or not(yl_speak_up.speak_to[pname])) then
return {}
end
local q_id = yl_speak_up.speak_to[pname].q_id
if(q_id and yl_speak_up.quests[q_id] and yl_speak_up.quests[q_id].step_data) then
for step_id, v in pairs(yl_speak_up.quests[q_id].step_data) do
table.insert(quest_step_list, step_id)
end
end
table.sort(quest_step_list)
return quest_step_list
end
-- helper functions for yl_speak_up.input_fs_manage_quest_steps(..)
-- returns the index of the new quest step
yl_speak_up.input_fs_manage_quest_steps_add_new_entry = function(pname, entry_name)
local q_id = yl_speak_up.speak_to[pname].q_id
local res = yl_speak_up.quest_step_add_quest_step(pname, q_id, entry_name)
-- 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_step_list = yl_speak_up.get_sorted_quest_step_list(pname)
return table.indexof(quest_step_list, entry_name)
end
-- helper functions for yl_speak_up.input_fs_manage_quest_steps(..)
-- returns a text describing if deleting the quest worked
yl_speak_up.input_fs_manage_quest_steps_del_old_entry = function(pname, entry_name)
local q_id = yl_speak_up.speak_to[pname].q_id
return yl_speak_up.quest_step_del_quest_step(pname, q_id, entry_name)
end
-- helper functions for yl_speak_up.input_fs_manage_quest_steps(..)
-- implements all the functions that are specific to managing quest steps and not part of
-- general item management
yl_speak_up.input_fs_manage_quest_steps_check_fields = function(player, formname, fields, quest_step_name, list_of_entries)
local pname = player:get_player_name()
if(not(quest_step_name)) then
quest_step_name = ""
end
--[[ TODO: implement some back button functionality?
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_quest_steps = function(player, formname, fields)
local pname = player:get_player_name()
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,
-- what_is_the_list_about, min_length, max_length, function_add_new_entry,
"quest step", 2, 70,
yl_speak_up.input_fs_manage_quest_steps_add_new_entry,
quest_step_list,
yl_speak_up.input_fs_manage_quest_steps_del_old_entry,
yl_speak_up.input_fs_manage_quest_steps_check_fields)
return true
end
yl_speak_up.get_fs_manage_quest_steps = function(player, param)
local pname = player:get_player_name()
local formspec = {}
local q_id = yl_speak_up.speak_to[pname].q_id
local quest = yl_speak_up.quests[q_id]
local step_data = quest.step_data
local quest_step_list = yl_speak_up.get_sorted_quest_step_list(pname)
if(param and param ~= "") then
local index = table.indexof(quest_step_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 step is a single thing a player may do in a quest - "..
"like talking to an NPC.\n"..
"Usually not all quest steps can be done/solved at all times.]")
local selected = yl_speak_up.get_fs_manage_general(player, param,
formspec, quest_step_list,
"Create quest step",
"Create a new quest step for this quest.",
"quest step",
"Enter the name of the new quest step you want to create.\n"..
"This is an internal text shown only to yourself.\n"..
"Players cannot see the names of quest steps.",
"If you click here, the selected quest step will be deleted.\n"..
"This will only be possible if it's not used anywhere.",
"0.2")
--[[
if(selected and selected ~= "") then
local k = selected
-- index 1 is "Add variable:"
table.insert(formspec, "button[12,2.15;4.5,0.6;show_variable;Show and edit this variable]")
end
--]]
return table.concat(formspec, "")
end