From 0ec51adf74e59c8a0d7d7b93e668502fbb016f30 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Fri, 22 Sep 2023 06:17:30 +0200 Subject: [PATCH] show step list when adding quest step --- fs_add_quest_steps.lua | 118 ++++++++++++++++---------------------- fs_manage_quest_steps.lua | 19 ++++-- 2 files changed, 65 insertions(+), 72 deletions(-) diff --git a/fs_add_quest_steps.lua b/fs_add_quest_steps.lua index eb9361d..f2de0b8 100644 --- a/fs_add_quest_steps.lua +++ b/fs_add_quest_steps.lua @@ -82,41 +82,31 @@ end yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields) - local pname = player:get_player_name() - - if(not(fields) or not(pname) or not(yl_speak_up.speak_to[pname])) then + if(not(fields) or not(player)) then return end + local res1 = yl_speak_up.player_is_working_on_quest(player) + if(res1.error_msg) then + yl_speak_up.show_fs(player, "msg", { + input_to = "yl_speak_up:add_quest_steps", + formspec = yl_speak_up.get_fs_quest_edit_error(res1.error_msg, "back")}) + end + local pname = res1.pname + local q_id = res1.q_id + local current_step = res1.current_step + local step_data = res1.step_data + if(fields.back_from_error_msg) then yl_speak_up.show_fs(player, "add_quest_steps") return end - if(fields.back) then - if(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 - 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 - if(not(step_data)) then - yl_speak_up.quests[q_id].step_data = {} - end - -- other values needed later on - local current_step = yl_speak_up.speak_to[pname].quest_step - local mode = "" - if(pname and yl_speak_up.speak_to[pname] and yl_speak_up.speak_to[pname].quest_step_mode) then - mode = yl_speak_up.speak_to[pname].quest_step_mode + if(fields.back and current_step) then + yl_speak_up.show_fs(player, "manage_quest_steps", current_step) + return end + local mode = yl_speak_up.speak_to[pname].quest_step_mode + -- has a quest step be selected? local work_step = nil if(fields.add_step and fields.add_quest_step) then @@ -174,14 +164,6 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields) end local required_for_steps = yl_speak_up.quest_step_get_required_for_steps(step_data) --- if(step_data[work_step] --- and step_data[work_step].one_step_required --- and #step_data[work_step].one_step_required < 1 --- and step_data[work_step].all_steps_required --- and #step_data[work_step].all_steps_required < 1 --- and #required_for_steps[work_step] < 1) then - -- this quest step is definitely suited --- minetest.chat_send_player("singleplayer","SELECTED ok: "..tostring(work_step)) -- TODO -- make sure we have a sane data structure for i, s in ipairs({current_step, work_step}) do @@ -212,6 +194,7 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields) table.insert(yl_speak_up.quests[q_id].step_data[current_step].one_step_required, 1, work_step) end + return yl_speak_up.show_fs(player, "manage_quest_steps", work_step) elseif(mode == "insert_before_next_step") then -- the work_step requires the current_step table.insert(yl_speak_up.quests[q_id].step_data[work_step].one_step_required, 1, current_step) @@ -228,6 +211,7 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields) yl_speak_up.quests[q_id].step_data[next_step].all_steps_required[i] =work_step end end + return yl_speak_up.show_fs(player, "manage_quest_steps", work_step) end yl_speak_up.save_quest(q_id) return yl_speak_up.show_fs(player, "add_quest_steps") @@ -288,44 +272,18 @@ yl_speak_up.quest_step_list_show_table = function(formspec, table_specs, liste, end +-- param is unused 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 res = yl_speak_up.player_is_working_on_quest(player) + if(res.error_msg) then + return yl_speak_up.get_fs_quest_edit_error(res.error_msg, "back") + end + local pname = res.pname + local step_data = res.step_data - local step_data = quest.step_data -- find out if a quest step is required by other quest steps local required_for_steps = yl_speak_up.quest_step_get_required_for_steps(step_data) - local formspec = {} - table.insert(formspec, "size[12.5,17.3]") - -- 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, "button[11.1,2.4;1.2,0.7;add_step;Add]") - 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 @@ -336,6 +294,30 @@ yl_speak_up.get_fs_add_quest_steps = function(player, param) if(pname and yl_speak_up.speak_to[pname] and yl_speak_up.speak_to[pname].quest_step_mode) then mode = yl_speak_up.speak_to[pname].quest_step_mode end + + local formspec = {} + if(mode and mode ~= "embedded_select") then + table.insert(formspec, "size[12.5,17.3]") + else + table.insert(formspec, "size[12.5,12.5]") + end + -- 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(res.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(res.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, "button[11.1,2.4;1.2,0.7;add_step;Add]") + table.insert(formspec, "field[1.0,2.4;10,0.7;add_quest_step;;]") + local y_pos = 3.3 if(current_step and mode == "insert_after_prev_step") then local prev_step = "-" diff --git a/fs_manage_quest_steps.lua b/fs_manage_quest_steps.lua index 402f3de..04b1660 100644 --- a/fs_manage_quest_steps.lua +++ b/fs_manage_quest_steps.lua @@ -29,6 +29,17 @@ yl_speak_up.player_is_working_on_quest = function(player) end +-- show the error message created above +yl_speak_up.get_fs_quest_edit_error = function(error_msg, back_button_name) + return "size[9,3]".. + "label[0.2,0.5;Error:]".. + "label[0.5,1.0;"..minetest.colorize("#FFFF00", + minetest.formspec_escape( + minetest.wrap_text(tostring(error_msg), 40))).. + "]button[3.5,2.0;2,0.9;"..tostring(back_button_name)..";Back]" +end + + -- for which other quest steps is this_step needed for? yl_speak_up.quest_step_required_for = function(step_data, this_step) -- find out the next quest step @@ -219,9 +230,7 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param) local res = yl_speak_up.player_is_working_on_quest(player) if(res.error_msg) then - return "size[9,2]".. - "label[0,0;"..minetest.formspec_escape("Error: "..tostring(res.error_msg)).."]".. - "button[1.5,1.5;2,0.9;back;Back]" + return yl_speak_up.get_fs_quest_edit_error(res.error_msg, "back") end local step_data = res.step_data local quest_step_list = yl_speak_up.get_sorted_quest_step_list(res.pname) @@ -254,7 +263,9 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param) table.insert(formspec, "container_end[]") if(not(selected) or selected == "" or not(step_data) or not(step_data[selected])) then - return table.concat(formspec, "") + -- insert a nicely formated list of quest steps + yl_speak_up.speak_to[res.pname].quest_step_mode = "embedded_select" + return yl_speak_up.get_fs_add_quest_steps(player, nil) end -- find out the next quest step local required_for = yl_speak_up.quest_step_required_for(step_data, selected)