implemented saving password input action

This commit is contained in:
Sokomine 2021-06-15 19:40:56 +02:00
parent dc69b71a33
commit 51e8e197b4
2 changed files with 90 additions and 3 deletions

View File

@ -105,7 +105,7 @@ yl_speak_up.show_action = function(a)
"\" (\""..tostring(a.a_value or "- ? -").."\") "..
"with ID \""..tostring(a.a_item_quest_id or "- no special ID -").."\"."
elseif(a.a_type == "text_input") then
return "text_input:" -- TODO show ation text
return "Q: \""..tostring(a.a_question).."\" A:\""..tostring(a.a_value).."\"."
elseif(a.a_type == "puzzle") then
return "puzzle:" -- TODO show ation text
elseif(a.a_type == "custom") then

View File

@ -265,6 +265,16 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
-- TODO: check if it diffrent from the default one of the stack
data.item_desc = fields.action_item_desc
end
if(fields.quest_question
and fields.quest_question ~= "") then
data.quest_question = fields.quest_question
end
-- quest question and answer can be given with the same press of the save button
if(fields.quest_answer
and fields.quest_answer ~= "- Insert the correct answer here -"
and fields.quest_answer ~= "") then
data.quest_answer = fields.quest_answer
end
-- the save button was pressed
if(fields.save_element and data and data.what and values_what[ data.what ]) then
@ -442,7 +452,12 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
"button[1.5,2.0;2,0.9;back_from_error_msg;Back]"})
return
end
v[ "a_on_failure" ] = data.action_failure_dialog
v[ "a_on_failure" ] = ""
if(data.action_failure_dialog) then
local dialog = yl_speak_up.speak_to[pname].dialog
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
v[ "a_on_failure" ] = sorted_dialog_list[ data.action_failure_dialog ]
end
-- change the node in the slot
local stack = trade_inv:get_stack( trade_inv_list, 1)
if(not(stack) or not(minetest.registered_items[ stack:get_name() ])) then
@ -527,6 +542,36 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
"label[0.2,0.5;The information was saved successfully.\n"..
"The item has been returned to your inventory.]"..
"button[1.5,2.0;2,0.9;back_from_error_msg;Back]"
-- "The player has to manually enter a password or passphrase or some other text.", -- 6
elseif(data.what and id_prefix == "a_" and data.what == 6) then
if(not(data.quest_question)) then
data.quest_question = "Your answer:"
end
v[ "a_question" ] = data.quest_question
-- the player setting this up needs to provide the correct answer
if(not(data.quest_answer)) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:"..formspec_input_to,
formspec = "size[9,2.5]"..
"label[0.2,0.5;Error: Please provide the correct answer!\n"..
"The answer the player gives is checked against this.]"..
"button[1.5,2.0;2,0.9;back_from_error_msg;Back]"})
return
end
v[ "a_value" ] = data.quest_answer
if(not(data.action_failure_dialog)) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:"..formspec_input_to,
formspec = "size[9,2.5]"..
"label[0.2,0.5;Error: Please provide a target dialog if "..
"the player gives the wrong answer.]"..
"button[1.5,2.0;2,0.9;back_from_error_msg;Back]"})
return
end
local dialog = yl_speak_up.speak_to[pname].dialog
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
v[ "a_on_failure" ] = sorted_dialog_list[ data.action_failure_dialog ]
end
-- only save if something was actually selected
@ -600,7 +645,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
yl_speak_up.speak_to[pname][ tmp_data_cache ].on_failure = fields.select_on_failure
elseif(fields.select_on_action_failure
and data and data.what and (data.what == 4 or data.what == 5) and id_prefix == "a_") then
and data and data.what and id_prefix == "a_") then
local dialog = yl_speak_up.speak_to[pname].dialog
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
local nr = table.indexof(sorted_dialog_list, fields.select_on_action_failure)
@ -1039,6 +1084,48 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"label[0.2,9.0;Expected description:]"..
"label[4.0,9.0;"..
minetest.formspec_escape(tostring(item_desc)).."]"
-- "The player has to manually enter a password or passphrase or some other text.", -- 6
-- (only for actions)
elseif(data.what and id_prefix == "a_" and data.what == 6) then
local question = "Your answer:"
if(data and data.quest_question) then
question = data.quest_question
end
local answer = "- Insert the correct answer here -"
if(data and data.quest_answer) then
answer = data.quest_answer
end
local nr = 1
if(data and data.action_failure_dialog) then
nr = data.action_failure_dialog + 1
end
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
formspec = formspec..
"label[0.2,3.3;What to ask the player and which answer to expect:]"..
"label[0.2,4.0;Question to show:]"..
"field[4.0,3.8;10.0,0.6;quest_question;;"..tostring(question).."]"..
"label[0.2,5.0;Expected answer:]"..
"field[4.0,4.8;10.0,0.6;quest_answer;;"..tostring(answer).."]"..
"label[0.2,6.0;If the player gives the wrong answer, go to dialog:]"..
"dropdown[8.0,5.7;2.8,0.6;select_on_action_failure;"..
"- current one -,"..
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"..
"tooltip[quest_question;"..
"This is just a short text that will be shown to remind\n"..
"the player what he is asked for. Most of the question\n"..
"ought to be part of the normal dialog of the NPC.]"..
"tooltip[quest_answer;"..
"The correct answer will not be shown to the player.\n"..
"What the player enters will be compared to this\n"..
"correct value.]"..
"tooltip[select_on_action_failure;"..
"If the player gives the wrong answer, you can show him\n"..
"a diffrent target dialog (i.e. with text \"No, that answer\n"..
"was wrong, but please try again!\"). In such a case the\n"..
"effects/results of the current dialog option are *not*\n"..
"executed.]"
end
return formspec..save_button
end