From 36ed71ae5665ef692123436087aac3dcbf841362 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 30 Sep 2023 13:16:30 +0200 Subject: [PATCH] display adding quest locations --- fs_add_quest_steps.lua | 35 ++++++++++++++++++++++++++++------- fs_manage_quests.lua | 4 +++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/fs_add_quest_steps.lua b/fs_add_quest_steps.lua index a008195..3c0f25c 100644 --- a/fs_add_quest_steps.lua +++ b/fs_add_quest_steps.lua @@ -131,7 +131,7 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields) local mode = yl_speak_up.speak_to[pname].quest_step_mode if(fields.back) then -- go back to quest overview - if(mode and mode == "manage_quest_npcs") then + if(mode and (mode == "manage_quest_npcs" or mode == "manage_quest_locations")) then return yl_speak_up.show_fs(player, "manage_quests") end return yl_speak_up.show_fs(player, "manage_quest_steps", current_step) @@ -365,7 +365,8 @@ yl_speak_up.quest_npc_show_table = function(formspec, table_specs, liste, step_d -- the n_id of the NPC table.insert(tmp, "#AAFFAA") if(is_location_list) then - table.insert(tmp, n_id) -- this already encodes the position + -- this already encodes the position but contains , and () + table.insert(tmp, minetest.formspec_escape(n_id)) else table.insert(tmp, "n_"..minetest.formspec_escape(n_id)) end @@ -403,8 +404,7 @@ yl_speak_up.quest_get_location_candidate_list = function(pname, quest_location_l and table.indexof(quest_location_liste or {}, n_id) == -1 -- and only those that the player can edit and (v.owner == pname or (v.may_edit and v.may_edit[pname]))) then - table.insert(location_list, k) - minetest.chat_send_player("singleplayer", "candidate: "..tostring(n_id)) + table.insert(location_list, n_id) end end table.sort(location_list) @@ -442,6 +442,8 @@ yl_speak_up.get_fs_add_quest_steps = function(player, param) local add_what = "Add a new quest step named:" if(mode == "manage_quest_npcs") then add_what = "Add the NPC with n_:" + elseif(mode == "manage_quest_locations") then + add_what = "Add a location by entering its ID directly:" end local formspec = {} @@ -537,17 +539,36 @@ yl_speak_up.get_fs_add_quest_steps = function(player, param) yl_speak_up.quest_npc_show_table(formspec, "0.2,0.2;17.0,3.0;delete_from_npc_list;", res.quest.npcs or {}, - step_data) + step_data, false) table.insert(formspec, "label[0.2,3.4;(Click on an entry to delete it from the list above.)]") local available_npcs = yl_speak_up.quest_get_npc_candidate_list(pname, res.quest.npcs or {}) yl_speak_up.speak_to[pname].list_available = available_npcs table.insert(formspec, "label[0.2,4.4;or select an NPC from the list below:]") yl_speak_up.quest_npc_show_table(formspec, "0.2,4.6;17.0,6.0;add_to_npc_list;", - available_npcs or {}, step_data) + available_npcs or {}, step_data, false) table.insert(formspec, "label[0.2,10.8;Used: Shows in how many quest steps this NPC is used.]") table.insert(formspec, "container_end[]") - y_pos = 4.2 + return table.concat(formspec, "") + -- which locations may contribute to the quest? + elseif(mode == "manage_quest_locations") then + table.insert(formspec, "container[0,3.3;18,6]") + table.insert(formspec, "label[0.2,0;so that the location ".. + minetest.colorize("#9999FF", "may contribute").. + " to the quest like these locations:]") + yl_speak_up.quest_npc_show_table(formspec, + "0.2,0.2;17.0,3.0;delete_from_location_list;", + res.quest.locations or {}, + step_data, true) + table.insert(formspec, "label[0.2,3.4;(Click on an entry to delete it from the list above.)]") + local available_locations = yl_speak_up.quest_get_location_candidate_list(pname, res.quest.locations or {}) + yl_speak_up.speak_to[pname].list_available = available_locations + table.insert(formspec, "label[0.2,4.4;or select a location from the list below:]") + yl_speak_up.quest_npc_show_table(formspec, + "0.2,4.6;17.0,6.0;add_to_location_list;", + available_locations or {}, step_data, true) + table.insert(formspec, "label[0.2,10.8;Used: Shows in how many quest steps this location is used.]") + table.insert(formspec, "container_end[]") return table.concat(formspec, "") end diff --git a/fs_manage_quests.lua b/fs_manage_quests.lua index 470bb0a..40135a1 100644 --- a/fs_manage_quests.lua +++ b/fs_manage_quests.lua @@ -51,8 +51,10 @@ yl_speak_up.input_fs_manage_quests = function(player, formname, fields) end -- show and edit NPCs that may contribute - if(fields and fields.edit_npcs) then + if( fields and fields.edit_npcs) then return yl_speak_up.show_fs(player, "add_quest_steps", "manage_quest_npcs") + elseif(fields and fields.edit_locations) then + return yl_speak_up.show_fs(player, "add_quest_steps", "manage_quest_locations") end -- show a particular quest step from the start/unconnected/end list?