improved manage_quest_steps formspec

This commit is contained in:
Sokomine 2023-09-18 21:51:03 +02:00
parent e879e1e67a
commit 1e4e3cbaef

View File

@ -22,7 +22,6 @@ yl_speak_up.get_sorted_quest_step_list = function(pname, q_id)
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)
@ -67,8 +66,23 @@ 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)
-- TODO: check if the player is allowed to access that quest
local pname = player:get_player_name()
if(fields and fields.change_prev_step) then
yl_speak_up.show_fs(player, "manage_quest_steps", " change_prev_step")
return
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;
-- 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})
return
end
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,
@ -81,7 +95,27 @@ yl_speak_up.input_fs_manage_quest_steps = function(player, formname, fields)
end
-- small helper function for yl_speak_up.get_fs_manage_quest_steps
yl_speak_up.quest_step_show_table = function(formspec, table_specs, liste)
table.insert(formspec, "tablecolumns[color;text]table[")
table.insert(formspec, table_specs)
local tmp = {}
for k, v in pairs(liste) do
table.insert(tmp, "#FFFFFF")
table.insert(tmp, minetest.formspec_escape(v))
end
table.insert(formspec, table.concat(tmp, ","))
table.insert(formspec, ";]")
end
yl_speak_up.get_fs_manage_quest_steps = function(player, param)
-- small helper function
local em = function(text)
return minetest.colorize("#9999FF", text)
end
-- TODO: check if the player is allowed to access that quest
local pname = player:get_player_name()
local formspec = {}
@ -94,7 +128,12 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param)
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]"..
local idx = yl_speak_up.speak_to[pname].tmp_index_general
if(idx and idx > 1) then
yl_speak_up.speak_to[pname].quest_step = quest_step_list[idx - 1]
end
table.insert(formspec, "size[30,12]"..
"container[6,0;18.5,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.]")
@ -108,13 +147,111 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param)
"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]")
"1.0")
table.insert(formspec, "container_end[]")
if(not(selected) or selected == "" or not(step_data) or not(step_data[selected])) then
return table.concat(formspec, "")
end
--]]
-- find out the next quest step
local required_for = {}
for s, d in pairs(step_data) do
if(s and d and d.one_step_required and type(d.one_step_required) == "table"
and table.indexof(d.one_step_required, selected) ~= -1) then
table.insert(required_for, s)
end
if(s and d and d.all_steps_required and type(d.all_steps_required) == "table"
and table.indexof(d.all_steps_required, selected) ~= -1) then
table.insert(required_for, s)
end
end
-- left side (previous quest step)
table.insert(formspec, "label[0.2,2.0;"..em("Required previous").."]"..
"label[0.2,2.4;quest step(s):]"..
"style[change_prev_step,insert_before_next_step,insert_after_prev_step,"..
"add_to_one_needed,add_to_all_needed;bgcolor=blue;textcolor=yellow]"..
"button[3.7,1.8;2.0,0.8;change_prev_step;Edit]"..
"tooltip[change_prev_step;"..
"Click here to add, set or change the previous\n"..
"and further required quest steps.]"..
"container[0.1,2.7;5.6,10.8]"..
"box[0,0;5.6,8.5;#666666]"..
"button[4.6,0.0;0.9,0.7;add_to_one_needed;Edit]"..
"tooltip[add_to_one_needed;Add or remove a quest step to this list.]"..
"label[0.1,0.5;"..em("One of").." these quest steps:]")
yl_speak_up.quest_step_show_table(formspec, "0.1,0.7;5.4,2.7;one_step_required;",
step_data[selected].one_step_required or {})
table.insert(formspec, "tooltip[one_step_required;"..
"At least "..em("one of").." these previous quest steps listed ".. "here has to be\n"..
"achieved by the player who is trying to solve this quest.\n"..
"Only then can the player try to achieve this current quest\n"..
"step that you are editing here.\n"..
"If this is empty, then it's usually the/a first step of the quest.\n"..
"If there is one entry, then that entry is the previous quest step.\n"..
"If there are multiple entries, then players have alternate ways\n"..
"to achieve this current quest step here.]")
table.insert(formspec, "label[0.1,4.0;"..em("All of").." these quest steps:]"..
"button[4.6,3.5;0.9,0.7;add_to_all_needed;Edit]"..
"tooltip[add_to_all_needed;Add or remove a quest step to this list.]")
yl_speak_up.quest_step_show_table(formspec, "0.1,4.2;5.4,4.0;all_steps_required;",
step_data[selected].all_steps_required or {})
table.insert(formspec, "tooltip[all_steps_required;"..
"Sometimes there may not be a particular order in which\n"..
"quest steps ought to be solved. Imagine for example getting\n"..
"indigrents for a cake and delivering them to an NPC.\n"..
"The quest steps listed here can be done in "..em("any order")..".\n"..
"They have "..em("all").." to be achieved first in order for this current\n"..
"quest step to become available.\n"..
"Usually this list is empty.]")
table.insert(formspec, "container_end[]")
-- right side (next quest step)
table.insert(formspec, "label[24.2,2.0;Achieving this quest step]"..
"label[24.2,2.4;"..em("helps").." the quester to:]"..
"container[24.2,2.7;5.6,10.8]"..
"box[0,0;5.6,8.5;#666666]"..
"label[0.1,0.5;get these quest step(s) "..em("next")..":]")
yl_speak_up.quest_step_show_table(formspec, "0.1,0.7;5.4,7.7;next_steps_show;",
needed_for or {})
table.insert(formspec, "tooltip[next_steps_show;"..
"Once the current quest step has been achieved by the\n"..
"player, the player can strive to achieve these next\n"..
"quest step(s).\n"..
"If this is empty, then it's either the/a last step (quest\n"..
"solved!) - or the quest is not properly set up.]")
table.insert(formspec, "container_end[]")
-- middle (this quest step)
table.insert(formspec, "container[6,2.7;12,10.8]"..
"label[0.2,0.5;This quest step:]"..
"dropdown[0.7,0.7;17,0.7;curr_step_show;")
table.insert(formspec, minetest.formspec_escape(selected))
table.insert(formspec, ";1;]")
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
table.insert(formspec,
"button[3.0,11.3;6.0,0.6;insert_after_prev_step;"..
"+ Insert step *before* this one]"..
"tooltip[insert_after_prev_step;"..
"Insert a new quest step between the *previous* step\n"..
"and the *current* (displayed here) step.\n"..
"Note: This only makes sense if there's just one\n"..
" previous step.]")
end
if(#required_for <= 1) then
table.insert(formspec,
"button[21.0,11.3;6.0,0.6;insert_before_next_step;"..
"Insert step *after* this one +]"..
"tooltip[insert_before_next_step;"..
"Insert a new quest step between this, the *currently*\n"..
"displayed step, and the *next one*.\n"..
"Note: This only makes sense if there's just one\n"..
" next step.]")
end
return table.concat(formspec, "")
end