From 4df6a56bf82e516a05c6b315aa66867b3babb0a4 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Wed, 2 Nov 2022 16:45:13 +0100 Subject: [PATCH] added quest_gui as custom action --- custom_functions_you_can_override.lua | 17 ++++++++++++++++ exec_actions.lua | 3 +++ fs_quest_gui.lua | 29 +++++++++++++++++++++++++++ init.lua | 2 ++ show_fs.lua | 10 ++++++++- 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 fs_quest_gui.lua diff --git a/custom_functions_you_can_override.lua b/custom_functions_you_can_override.lua index ed8d1ad..04997fd 100644 --- a/custom_functions_you_can_override.lua +++ b/custom_functions_you_can_override.lua @@ -335,6 +335,23 @@ yl_speak_up.custom_functions_a_[ "example function" ] = { end, } +-- example function for actions: +yl_speak_up.custom_functions_a_[ "quest maintenance" ] = { + description = "Create and maintain quests.", + -- the actual implementation of the function + -- note that what it shall return is a formspec + code = function(player, n_id, a) + return yl_speak_up.get_fs_quest_gui(player, n_id, a) + end, + -- this function will be called by the one that handles all custom input to actions + -- of the type "evaluate"; it can change the value of entries of the table "fields" + -- if necessary + code_input_handler = function(player, n_id, a, formname, fields) + -- the function has to return fields + return yl_speak_up.input_quest_gui(player, formname, fields) + end, +} + ----------------------------------------------------------------------------- -- Custom effects (of type "evaluate") diff --git a/exec_actions.lua b/exec_actions.lua index 20c114f..406843e 100644 --- a/exec_actions.lua +++ b/exec_actions.lua @@ -799,6 +799,9 @@ yl_speak_up.input_fs_action_evaluate = function(player, formname, fields) yl_speak_up.execute_next_action(player, a_id, true) return end + if(fields.quit) then + return + end -- else show a message to the player that he ought to decide yl_speak_up.show_fs(player, "msg", { input_to = "yl_speak_up:action_evaluate", diff --git a/fs_quest_gui.lua b/fs_quest_gui.lua new file mode 100644 index 0000000..6b9dd3d --- /dev/null +++ b/fs_quest_gui.lua @@ -0,0 +1,29 @@ +yl_speak_up.input_quest_gui = function(player, formname, fields) + -- this return value is necessary for custom actions + local ret = {quit = true} + + local pname = player:get_player_name() + if(fields and fields.back_from_msg) then + yl_speak_up.show_fs(player, "quest_gui") + return ret + end + + -- new variables have to be added (and deleted) somewhere after all + if(fields.manage_variables) then + -- remember which formspec we are comming from + yl_speak_up.speak_to[pname][ "working_at" ] = "quest_gui" + yl_speak_up.show_fs(player, "manage_variables") + return ret + end + -- the calling NPC shall no longer do anything + return ret +end + + +yl_speak_up.get_fs_quest_gui = function(player, param) + local pname = player:get_player_name() + + return "size[10,2]".. + "label[0,0.5;Hi. This is a quest admin gui.]".. + "button[0.2,1.0;4.0,0.6;manage_variables;Manage variables]" +end diff --git a/init.lua b/init.lua index 7a657e6..e2d30c5 100644 --- a/init.lua +++ b/init.lua @@ -120,6 +120,8 @@ yl_speak_up.reload = function(modpath, log_entry) dofile(modpath .. "fs_properties.lua") -- the main functionality of the mod dofile(modpath .. "functions.lua") + -- creating and maintaining quests + dofile(modpath .. "fs_quest_gui.lua") -- initialize and load all registered generic dialogs yl_speak_up.load_generic_dialogs() diff --git a/show_fs.lua b/show_fs.lua index e8bebce..d9ff277 100644 --- a/show_fs.lua +++ b/show_fs.lua @@ -100,6 +100,10 @@ yl_speak_up.input_handler = function(player, formname, fields) 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) return true + -- create and manage quests + elseif formname == "yl_speak_up:quest_gui" then + yl_speak_up.input_quest_gui(player, formname, fields) + return true end end @@ -376,7 +380,7 @@ yl_speak_up.show_fs = function(player, fs_name, param) elseif(fs_name == "action_evaluate") then yl_speak_up.show_fs_ver(pname, "yl_speak_up:action_evaluate", - yl_speak_up.get_fs_action_evaluate(player, param), 1) + yl_speak_up.get_fs_action_evaluate(player, param)) elseif(fs_name == "manage_variables") then yl_speak_up.show_fs_ver(pname, "yl_speak_up:manage_variables", @@ -386,6 +390,10 @@ yl_speak_up.show_fs = function(player, fs_name, param) 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)) + elseif(fs_name == "quest_gui") then + yl_speak_up.show_fs_ver(pname, "yl_speak_up:quest_gui", + yl_speak_up.get_fs_quest_gui(player, param)) + -- fallback in case of wrong call else minetest.chat_send_player(pname, "Error: Trying to show wrong "..