From f8bc7847766054533abfa078899009f40f048afd Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 19 Jun 2021 18:16:52 +0200 Subject: [PATCH] implented action text_input --- fs_edit_actions.lua | 52 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/fs_edit_actions.lua b/fs_edit_actions.lua index 511efe1..07a5ca7 100644 --- a/fs_edit_actions.lua +++ b/fs_edit_actions.lua @@ -216,7 +216,8 @@ yl_speak_up.execute_action = function(player, n_id, o_id, a) yl_speak_up.show_fs(player, "action_npc_wants", a.a_value) return elseif(a.a_type == "text_input") then - yl_speak_up.show_fs(player, "action_text_input", a.a_value) + -- start with an empty answer + yl_speak_up.show_fs(player, "action_text_input", "") return elseif(a.a_type == "custom") then yl_speak_up.show_fs(player, "action_custom", a.a_value) @@ -533,12 +534,57 @@ end yl_speak_up.input_fs_action_text_input = function(player, formname, fields) - -- TODO implement text_input action + -- back from error_msg? then show the formspec again + if(fields.back_from_error_msg) then + -- the error message is only shown if the input was empty + yl_speak_up.show_fs(player, "action_text_input", "") + return + end + local pname = player:get_player_name() + local a_id = yl_speak_up.speak_to[pname].a_id + local a = yl_speak_up.get_action_by_player(player) + if(fields.back_to_talk) then + -- the action failed + yl_speak_up.execute_next_action(player, a_id, false) + return + end + if(fields.finished_action and fields.quest_answer and fields.quest_answer ~= "") then + -- is the answer correct? + -- TODO: strip leading and tailing blanks? + local success = not(not(fields.quest_answer and fields.quest_answer == a.a_value)) + -- the action was a either a success or failure + yl_speak_up.execute_next_action(player, a_id, success) + return + end + -- else show a message to the player + yl_speak_up.show_fs(player, "msg", { + input_to = "yl_speak_up:action_text_input", + formspec = "size[7,1.5]".. + "label[0.2,-0.2;".. + "Please answer the question and click on \"Send answer\"!\n".. + "If you don't know the answer, click on \"Back to talk\".]".. + "button[2,1.0;1.5,0.9;back_from_error_msg;Back]"}) end yl_speak_up.get_fs_action_text_input = function(player, param) - -- TODO implement text input formspec + local pname = player:get_player_name() + local dialog = yl_speak_up.speak_to[pname].dialog + local a = yl_speak_up.get_action_by_player(player) + if(not(a)) then + return "" + end + return "size[12.0,4.5]".. + "button[0.2,0.0;2.0,0.9;back_to_talk;Back to talk]".. + "button[2.0,3.7;3.0,0.9;finished_action;Send answer]".. + + "tooltip[back_to_talk;Click here if you don't know the answer.]".. + "tooltip[finished_action;Click here once you've entered the answer.]".. + "label[0.2,1.2;"..minetest.formspec_escape(a.a_question or "Your answer:").."]".. + "label[0.2,1.9;Answer:]".. + "field[1.6,2.2;10.0,0.6;quest_answer;;"..tostring(param or "").."]".. + "label[0.2,2.8;"..minetest.formspec_escape( + "["..(dialog.n_npc or "- ? -").." looks expectantly at you.]").."]" end