forked from Sokomine/yl_speak_up
added formspec for adding quest steps
This commit is contained in:
parent
1e4e3cbaef
commit
5ba53ba637
253
fs_add_quest_steps.lua
Normal file
253
fs_add_quest_steps.lua
Normal file
@ -0,0 +1,253 @@
|
||||
-- This order imposed here on the quest steps is the one in which the
|
||||
-- quest steps have to be solved - as far as we can tell (the quest
|
||||
-- may be in the process of beeing created and not logicly complete yet).
|
||||
yl_speak_up.get_sorted_quest_step_list_by_prev_step = function(pname, q_id)
|
||||
if(not(q_id) or not(yl_speak_up.quests[q_id]) or not(yl_speak_up.quests[q_id].step_data)) then
|
||||
return {}
|
||||
end
|
||||
|
||||
-- for now: sort alphabeticly
|
||||
local step_data = yl_speak_up.quests[q_id].step_data
|
||||
local liste = {}
|
||||
for k, v in pairs(step_data) do
|
||||
table.insert(liste, k)
|
||||
end
|
||||
table.sort(liste)
|
||||
return liste
|
||||
end
|
||||
|
||||
--[[ still belongs to the above function
|
||||
-- add back links (or rather: forward links to quest steps that get enabled)
|
||||
local connected = table.copy(step_data)
|
||||
for k, v in pairs(connected) do
|
||||
-- will store the inverse data
|
||||
connected[k].inv_one_step_required = {}
|
||||
connected[k].inv_all_steps_require = {}
|
||||
end
|
||||
for k, v in pairs(connected) do
|
||||
if(k and v and v.one_step_required) then
|
||||
for i, s in ipairs(v.one_step_required) do
|
||||
table.insert(connected[s].inv_one_step_required, k)
|
||||
end
|
||||
end
|
||||
if(k and v and v.all_steps_required) then
|
||||
for i, s in ipairs(v.all_steps_required) do
|
||||
table.insert(connected[s].inv_all_steps_required, k)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- get those quest steps that are not connected and not used yet
|
||||
local liste = {}
|
||||
for k, v in pairs(connected) do
|
||||
if(k and v
|
||||
and #v.one_step_required == 0 and #v.all_steps_required == 0
|
||||
and #v.inv_one_step_required == 0 and #v.inv_all_steps_required == 0) then
|
||||
table.insert(liste, k)
|
||||
end
|
||||
end
|
||||
-- sort alphabeticly
|
||||
table.sort(liste)
|
||||
-- remove those entries from our connection table (they're not connected anyway);
|
||||
-- we have already added them to the beginning of the list
|
||||
for i, v in ipairs(liste) do
|
||||
connected[v] = nil
|
||||
end
|
||||
|
||||
|
||||
return liste
|
||||
end
|
||||
--]]
|
||||
|
||||
|
||||
yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
|
||||
local pname = player:get_player_name()
|
||||
|
||||
if(fields and fields.back) then
|
||||
if(pname and yl_speak_up.speak_to[pname] and yl_speak_up.speak_to[pname].quest_step) then
|
||||
yl_speak_up.show_fs(player, "manage_quest_steps", yl_speak_up.speak_to[pname].quest_step)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- small helper function for yl_speak_up.get_fs_add_quest_steps;
|
||||
-- lists all the quest steps found in liste in the order they occour there
|
||||
yl_speak_up.quest_step_list_show_table = function(formspec, table_specs, liste, data, required_for_steps)
|
||||
local grey_if_zero = function(fs, n)
|
||||
if(n and n == 0) then
|
||||
table.insert(fs, "#444444")
|
||||
else
|
||||
table.insert(fs, "#FFFFFF")
|
||||
end
|
||||
table.insert(fs, minetest.formspec_escape(n))
|
||||
end
|
||||
|
||||
table.insert(formspec, "tablecolumns["..
|
||||
"color;text,align=right;".. -- #d.one_step_required
|
||||
"color;text,align=right;".. -- #d.all_steps_required
|
||||
"color;text,align=right;".. -- #required_for_steps (quest steps that need this one)
|
||||
"color;text,align=left".. -- name of quest step
|
||||
"]table[")
|
||||
table.insert(formspec, table_specs)
|
||||
local tmp = {}
|
||||
for i, s in ipairs(liste or {}) do
|
||||
local d = data[s]
|
||||
if(not(d.one_step_required) or type(d.one_step_required) ~= "table") then
|
||||
d.one_step_required = {}
|
||||
end
|
||||
grey_if_zero(tmp, #d.one_step_required)
|
||||
if(not(d.all_steps_required) or type(d.all_steps_required) ~= "table") then
|
||||
d.all_steps_required = {}
|
||||
end
|
||||
grey_if_zero(tmp, #d.all_steps_required)
|
||||
if(not(required_for_steps[s])) then
|
||||
required_for_steps[s] = {}
|
||||
end
|
||||
grey_if_zero(tmp, #required_for_steps[s])
|
||||
table.insert(tmp, "#AAFFAA")
|
||||
table.insert(tmp, minetest.formspec_escape(s))
|
||||
end
|
||||
table.insert(formspec, table.concat(tmp, ","))
|
||||
table.insert(formspec, ";]")
|
||||
end
|
||||
|
||||
|
||||
yl_speak_up.get_fs_add_quest_steps = function(player, param)
|
||||
local pname = player:get_player_name()
|
||||
if(not(pname) or not(yl_speak_up.speak_to[pname])) then
|
||||
return yl_speak_up.show_fs(player, "manage_quests")
|
||||
end
|
||||
local q_id = yl_speak_up.speak_to[pname].q_id
|
||||
-- TODO: check if the player can access that quest
|
||||
if(not(q_id)) then
|
||||
return yl_speak_up.show_fs(player, "manage_quests")
|
||||
end
|
||||
local quest = yl_speak_up.quests[q_id]
|
||||
if(not(quest)) then
|
||||
return yl_speak_up.show_fs(player, "manage_quests")
|
||||
end
|
||||
|
||||
local step_data = quest.step_data
|
||||
-- find out if a quest step is required by other quest steps
|
||||
local required_for_steps = {}
|
||||
for s, d in pairs(step_data) do
|
||||
required_for_steps[s] = {}
|
||||
end
|
||||
for s, d in pairs(step_data) do
|
||||
if(s and d and d.one_step_required and type(d.one_step_required) == "table") then
|
||||
for i, s2 in ipairs(d.one_step_required) do
|
||||
table.insert(required_for_steps[s2], s)
|
||||
end
|
||||
end
|
||||
if(s and d and d.all_steps_required and type(d.all_steps_required) == "table") then
|
||||
for i, s2 in ipairs(d.all_steps_required) do
|
||||
table.insert(required_for_steps[s2], s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local formspec = {}
|
||||
table.insert(formspec, "size[18,12]")
|
||||
-- add back button
|
||||
table.insert(formspec, "button[8,0;2,0.7;back;Back]")
|
||||
-- show which quest we're working at
|
||||
table.insert(formspec, "label[0.2,1.0;Quest ID:]")
|
||||
table.insert(formspec, "label[3.0,1.0;")
|
||||
table.insert(formspec, minetest.formspec_escape(q_id))
|
||||
table.insert(formspec, "]")
|
||||
table.insert(formspec, "label[0.2,1.5;Quest name:]")
|
||||
table.insert(formspec, "label[3.0,1.5;")
|
||||
table.insert(formspec, minetest.formspec_escape(quest.name or "- unknown -"))
|
||||
table.insert(formspec, "]")
|
||||
|
||||
-- add new quest step
|
||||
table.insert(formspec, "label[0.2,2.2;Add a new quest step named:]")
|
||||
table.insert(formspec, "field[1.0,2.4;10,0.7;add_quest_step;;]")
|
||||
|
||||
local current_step = nil
|
||||
local this_step_data = nil
|
||||
if(pname and yl_speak_up.speak_to[pname] and yl_speak_up.speak_to[pname].quest_step) then
|
||||
current_step = yl_speak_up.speak_to[pname].quest_step
|
||||
this_step_data = step_data[current_step]
|
||||
end
|
||||
local fields = nil
|
||||
if(param and type(param) == "table" and param.fields and type(param.fields) == "table") then
|
||||
fields = param.fields
|
||||
end
|
||||
local y_pos = 3.3
|
||||
if(fields and current_step and fields.insert_after_prev_step) then
|
||||
local prev_step = "-"
|
||||
if(this_step_data and this_step_data.one_step_required and #this_step_data.one_step_required > 0) then
|
||||
prev_step = #this_step_data.one_step_required[1]
|
||||
end
|
||||
table.insert(formspec, "label[0.2,3.3;between the previous step:]")
|
||||
table.insert(formspec, "label[1.0,3.7;")
|
||||
table.insert(formspec, minetest.colorize("#9999FF", minetest.formspec_escape(prev_step)))
|
||||
table.insert(formspec, "]")
|
||||
table.insert(formspec, "label[0.2,4.1;and the currently selected step:]")
|
||||
table.insert(formspec, "label[1.0,4.5;")
|
||||
table.insert(formspec, minetest.colorize("#FFFF00", minetest.formspec_escape(current_step)))
|
||||
table.insert(formspec, "]")
|
||||
y_pos = 5.3
|
||||
elseif(fields and current_step and fields.insert_before_next_step) then
|
||||
local next_step = "-"
|
||||
if(current_step and required_for_steps[current_step] and #required_for_steps[current_step] > 0) then
|
||||
next_step = #required_for_steps[current_step][1]
|
||||
end
|
||||
table.insert(formspec, "label[0.2,3.3;between the currently selected step:]")
|
||||
table.insert(formspec, "label[1.0,3.7;")
|
||||
table.insert(formspec, minetest.colorize("#FFFF00", minetest.formspec_escape(current_step)))
|
||||
table.insert(formspec, "]")
|
||||
table.insert(formspec, "label[0.2,4.1;and the next step:]")
|
||||
table.insert(formspec, "label[1.0,4.5;")
|
||||
table.insert(formspec, minetest.colorize("#AAFFAA", minetest.formspec_escape(next_step)))
|
||||
table.insert(formspec, "]")
|
||||
y_pos = 5.3
|
||||
elseif(fields and current_step and fields.add_to_one_needed) then
|
||||
table.insert(formspec, "label[0.2,3.3;as a requirement to the currently selected step:]")
|
||||
table.insert(formspec, "label[1.0,3.7;")
|
||||
table.insert(formspec, minetest.colorize("#FFFF00", minetest.formspec_escape(current_step)))
|
||||
table.insert(formspec, "]")
|
||||
table.insert(formspec, "label[0.2,4.1;so that "..
|
||||
minetest.colorize("#9999FF", "at least one")..
|
||||
" of these requirements is fulfilled:]")
|
||||
yl_speak_up.quest_step_list_show_table(formspec,
|
||||
"0.2,4.3;11.0,3.0;delete_from_one_step_required;",
|
||||
step_data[current_step].one_step_required,
|
||||
step_data, required_for_steps)
|
||||
table.insert(formspec, "label[0.2,7.5;(Click on an entry to delete it from the list above.)]")
|
||||
y_pos = 8.3
|
||||
elseif(fields and current_step and fields.add_to_all_needed) then
|
||||
table.insert(formspec, "label[0.2,3.3;as a requirement to the currently selected step:]")
|
||||
table.insert(formspec, "label[1.0,3.7;")
|
||||
table.insert(formspec, minetest.colorize("#FFFF00", minetest.formspec_escape(current_step)))
|
||||
table.insert(formspec, "]")
|
||||
table.insert(formspec, "label[0.2,4.1;so that "..
|
||||
minetest.colorize("#AAFFAA", "all")..
|
||||
" of these requirements are fulfilled:]")
|
||||
yl_speak_up.quest_step_list_show_table(formspec,
|
||||
"0.2,4.3;11.0,3.0;delete_from_all_steps_required;",
|
||||
step_data[current_step].all_steps_required,
|
||||
step_data, required_for_steps)
|
||||
table.insert(formspec, "label[0.2,7.5;(Click on an entry to delete it from the list above.)]")
|
||||
y_pos = 8.3
|
||||
end
|
||||
|
||||
-- TODO: temporary!
|
||||
local available_steps = {}
|
||||
for k, v in pairs(step_data) do
|
||||
table.insert(available_steps, k)
|
||||
end
|
||||
table.insert(formspec, "label[0.2,")
|
||||
table.insert(formspec, tostring(y_pos))
|
||||
table.insert(formspec, ";or select an existing quest step from the list below:]")
|
||||
yl_speak_up.quest_step_list_show_table(formspec,
|
||||
"0.2,"..tostring(y_pos + 0.2)..";11.0,3.0;add_from_available;",
|
||||
available_steps,
|
||||
step_data, required_for_steps)
|
||||
|
||||
-- TODO: write before which quest step we want to insert (if that is what is selected)
|
||||
return table.concat(formspec, "")
|
||||
end
|
@ -80,7 +80,7 @@ yl_speak_up.input_fs_manage_quest_steps = function(player, formname, fields)
|
||||
-- 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
|
||||
-- ought to be set to the current quest and step by now
|
||||
yl_speak_up.show_fs(player, "list_quest_steps", {fields=fields})
|
||||
yl_speak_up.show_fs(player, "add_quest_steps", {fields=fields})
|
||||
return
|
||||
end
|
||||
local quest_step_list = yl_speak_up.get_sorted_quest_step_list(pname)
|
||||
@ -232,7 +232,7 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param)
|
||||
table.insert(formspec, "container_end[]")
|
||||
|
||||
-- add buttons for inserting steps between this and the prev/next one
|
||||
if(not(step_data[selected].one_step_required) or #step_data[selected].one_step_required==1) then
|
||||
if(not(step_data[selected].one_step_required) or #step_data[selected].one_step_required <= 1) then
|
||||
table.insert(formspec,
|
||||
"button[3.0,11.3;6.0,0.6;insert_after_prev_step;"..
|
||||
"+ Insert step *before* this one]"..
|
||||
|
2
init.lua
2
init.lua
@ -220,6 +220,8 @@ yl_speak_up.reload = function(modpath, log_entry)
|
||||
dofile(modpath .. "fs_manage_quests.lua")
|
||||
-- GUI for adding/editing quest steps for the quests
|
||||
dofile(modpath .. "fs_manage_quest_steps.lua")
|
||||
-- used by the above
|
||||
dofile(modpath .. "fs_add_quest_steps.lua")
|
||||
-- setting skin, wielded item etc.
|
||||
dofile(modpath .. "fs_fashion.lua")
|
||||
-- properties for NPC without specific dialogs that want to make use of
|
||||
|
@ -973,8 +973,8 @@ yl_speak_up.quest_step_del_where = function(pname, q_id, quest_step_name, locati
|
||||
end
|
||||
|
||||
|
||||
-- TODO: quest_step: previous_step
|
||||
-- TODO: quest_step: further_required_steps
|
||||
-- TODO: quest_step: previous_step -> one_step_required
|
||||
-- TODO: quest_step: further_required_steps -> all_steps_required
|
||||
-- TODO: quest_step: offered_until_quest_step_reached
|
||||
|
||||
|
||||
|
@ -111,6 +111,10 @@ yl_speak_up.input_handler = function(player, formname, fields)
|
||||
elseif formname == "yl_speak_up:manage_quest_steps" then
|
||||
yl_speak_up.input_fs_manage_quest_steps(player, formname, fields)
|
||||
return true
|
||||
-- handled in fs_add_quest_steps.lua
|
||||
elseif formname == "yl_speak_up:add_quest_steps" then
|
||||
yl_speak_up.input_fs_add_quest_steps(player, formname, fields)
|
||||
return true
|
||||
-- handled in fs_alternate_text.lua
|
||||
elseif formname == "yl_speak_up:show_what_points_to_this_dialog" then
|
||||
yl_speak_up.input_fs_show_what_points_to_this_dialog(player, formname, fields)
|
||||
@ -418,6 +422,10 @@ yl_speak_up.show_fs = function(player, fs_name, param)
|
||||
yl_speak_up.show_fs_ver(pname, "yl_speak_up:manage_quest_steps",
|
||||
yl_speak_up.get_fs_manage_quest_steps(player, param))
|
||||
|
||||
elseif(fs_name == "add_quest_steps") then
|
||||
yl_speak_up.show_fs_ver(pname, "yl_speak_up:add_quest_steps",
|
||||
yl_speak_up.get_fs_add_quest_steps(player, param))
|
||||
|
||||
elseif(fs_name == "show_what_points_to_this_dialog") then
|
||||
yl_speak_up.show_fs_ver(pname, "yl_speak_up:show_what_points_to_this_dialog",
|
||||
yl_speak_up.show_what_points_to_this_dialog(player, param))
|
||||
|
Loading…
Reference in New Issue
Block a user