show dialog for on_failure of actions; improved formspecs

This commit is contained in:
Sokomine 2021-06-20 02:18:32 +02:00
parent 73aaa15c44
commit 4085e87f29

View File

@ -909,17 +909,17 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
yl_speak_up.speak_to[pname][ tmp_data_cache ] = data yl_speak_up.speak_to[pname][ tmp_data_cache ] = data
end end
local save_button = "button[5.0,9.8;1,0.7;save_element;Save]" local save_button = "button[5.0,11.8;1,0.7;save_element;Save]"
local formspec = local formspec =
"formspec_version[3]".. "formspec_version[3]"..
"size[20,11]".. "size[20,13]"..
"label[5,0.5;Edit "..element_desc.." \""..minetest.formspec_escape(x_id).."\"]".. "label[5,0.5;Edit "..element_desc.." \""..minetest.formspec_escape(x_id).."\"]"..
"label[0.2,1.5;"..what_do_you_want_txt.."]".. "label[0.2,1.5;"..what_do_you_want_txt.."]"..
"label[0.2,2.0;Something regarding...]".. "label[0.2,2.0;Something regarding...]"..
"dropdown[4.0,1.8;14.0,0.6;select_what;".. "dropdown[4.0,1.8;14.0,0.6;select_what;"..
table.concat(check_what, ",")..";".. table.concat(check_what, ",")..";"..
tostring(data.what)..";]".. tostring(data.what)..";]"..
"button[3.0,9.8;1,0.7;back;Abort]" "button[3.0,11.8;1,0.7;back;Abort]"
if(id_prefix ~= "a_") then if(id_prefix ~= "a_") then
formspec = formspec.. formspec = formspec..
@ -1111,7 +1111,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"label[0.2,5.5;This will switch to dialog "..tostring(data.on_failure)..":]".. "label[0.2,5.5;This will switch to dialog "..tostring(data.on_failure)..":]"..
"hypertext[1.2,6.0;19.6,2.5;d_text;<normal>".. "hypertext[1.2,6.0;19.6,2.5;d_text;<normal>"..
minetest.formspec_escape(dialog.n_dialogs[ data.on_failure ].d_text or "?").. minetest.formspec_escape(dialog.n_dialogs[ data.on_failure ].d_text or "?")..
"\n</normal>".."]" "\n</normal>]"
end end
formspec = formspec.. formspec = formspec..
"label[0.2,3.3;If the *previous* effect failed,]".. "label[0.2,3.3;If the *previous* effect failed,]"..
@ -1123,23 +1123,24 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
-- "send a chat message to all players" -- 6 -- "send a chat message to all players" -- 6
elseif(data.what and id_prefix == "r_" and data.what == 6) then elseif(data.what and id_prefix == "r_" and data.what == 6) then
local text = "$NPC_NAME$ (owned by $OWNER_NAME$) announces: $PLAYER_NAME$ ".. local default_text = "$NPC_NAME$ (owned by $OWNER_NAME$) announces: $PLAYER_NAME$ "..
"- example; please enter the text -" "- example; please enter the text -"
if(data and data.chat_msg_text) then if(not(data)) then
text = data.chat_msg_text data = {}
end end
formspec = formspec.. formspec = formspec..
"label[0.2,3.3;Send the following chat message to *all* players:]".. "label[0.2,3.3;Send the following chat message to *all* players:]"..
"label[0.2,4.1;Message:]".. "label[0.2,4.1;Message:]"..
"field[2.0,3.8;16.0,0.6;chat_msg_text;;".. "field[2.0,3.8;16.0,0.6;chat_msg_text;;"..
minetest.formspec_escape(tostring(text)).."]".. minetest.formspec_escape(
data.chat_msg_text
or default_text).."]"..
"label[0.2,5.3;Note: Your chat message needs to contain the following placeholders,".. "label[0.2,5.3;Note: Your chat message needs to contain the following placeholders,"..
" which will be replaced automaticly like in dialog texts:".. " which will be replaced automaticly like in dialog texts:"..
"\n$NPC_NAME$, $PLAYER_NAME$ and $OWNER_NAME$.]" "\n$NPC_NAME$, $PLAYER_NAME$ and $OWNER_NAME$.]"
-- "Normal trade - one item(stack) for another item(stack).", -- 3 -- "Normal trade - one item(stack) for another item(stack).", -- 3
elseif(data.what and id_prefix == "a_" and data.what == 3) then elseif(data.what and id_prefix == "a_" and data.what == 3) then
local pname = player:get_player_name()
local dialog = yl_speak_up.speak_to[pname].dialog local dialog = yl_speak_up.speak_to[pname].dialog
local d_id = yl_speak_up.speak_to[pname].d_id local d_id = yl_speak_up.speak_to[pname].d_id
local o_id = yl_speak_up.speak_to[pname].o_id local o_id = yl_speak_up.speak_to[pname].o_id
@ -1153,7 +1154,6 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"item_image[5.15,4.35;0.7,0.7;"..tostring(data.pay).."]" "item_image[5.15,4.35;0.7,0.7;"..tostring(data.pay).."]"
end end
yl_speak_up.speak_to[pname].trade_id = data.trade_id yl_speak_up.speak_to[pname].trade_id = data.trade_id
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
formspec = formspec.. formspec = formspec..
"label[8,2.6;Your invnetory:]".. "label[8,2.6;Your invnetory:]"..
"list[current_player;main;8,3;8,4;]".. "list[current_player;main;8,3;8,4;]"..
@ -1165,57 +1165,38 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"label[4.0,3.8;"..minetest.formspec_escape(dialog.n_npc or "?").." sells:]".. "label[4.0,3.8;"..minetest.formspec_escape(dialog.n_npc or "?").." sells:]"..
-- show the second slot of said inventory -- show the second slot of said inventory
"list[detached:yl_speak_up_player_"..pname..";setup;5,4.2;1,1;1]".. "list[detached:yl_speak_up_player_"..pname..";setup;5,4.2;1,1;1]"..
"label[0.2,5.8;The player shall trade with the NPC at least once.\n".. bg_img..
"If he doesn't, go to dialog:]".. yl_speak_up.set_on_action_failure_dialog(pname, data,
"dropdown[4.3,6.0;2.8,0.6;select_on_action_failure;".. "The player shall trade at least once.")
"- current one -,"..
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"..
bg_img
-- "The NPC gives something to the player (i.e. a quest item).", -- 4 -- "The NPC gives something to the player (i.e. a quest item).", -- 4
-- (only for actions) -- (only for actions)
elseif(data.what and id_prefix == "a_" and data.what == 4) then elseif(data.what and id_prefix == "a_" and data.what == 4) then
local pname = player:get_player_name() if(not(data)) then
local dialog = yl_speak_up.speak_to[pname].dialog data = {}
local item_quest_id = "- none set -"
if(data and data.item_quest_id) then
item_quest_id = data.item_quest_id
end
local item_desc = "- no item set -"
if(data and data.item_desc) then
item_desc = data.item_desc
end
local nr = 1
if(data and data.action_failure_dialog) then
nr = data.action_failure_dialog + 1
end
local stack_name = ""
if(data and data.item_node_name) then
stack_name = data.item_node_name
end end
local bg_img = "" local bg_img = ""
if(data and data.item_string) then if(data and data.item_string) then
bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]" bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]"
end end
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
formspec = formspec.. formspec = formspec..
"label[8,2.6;Your invnetory:]".. "label[8,2.6;Your inventory:]"..
"list[current_player;main;8,3;8,4;]".. "list[current_player;main;8,3;8,4;]"..
"label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." gives:]".. "label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." gives:]"..
"list[detached:yl_speak_up_player_"..pname..";npc_gives;2,3.5;1,1;]".. "list[detached:yl_speak_up_player_"..pname..";npc_gives;2,3.5;1,1;]"..
"label[3.2,4.0;"..minetest.formspec_escape(stack_name).."]".. "label[3.2,4.0;"..
"label[1,4.9;The player shall take this offered item.\n".. minetest.formspec_escape(
"If he doesn't, go to dialog:]".. data.item_node_name
"dropdown[5.0,5.1;2.8,0.6;select_on_action_failure;".. or "- no item set -").."]"..
"- current one -,"..
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"..
"label[0.2,6.1;Set a description to turn the item into a special\n".. "label[0.2,6.1;Set a description to turn the item into a special\n"..
"quest item. Set a special ID (short text) so that\n".. "quest item. Set a special ID (short text) so that\n"..
"the player cannot create a fake item. Click on \n".. "the player cannot create a fake item. Click on \n"..
"\"Save\" to apply the changes.]".. "\"Save\" to apply the changes.]"..
"label[0.2,8.3;Special ID to set:]".. "label[0.2,8.3;Special ID to set:]"..
"field[3.2,8.0;14.5,0.6;action_item_quest_id;;".. "field[3.2,8.0;14.5,0.6;action_item_quest_id;;"..
minetest.formspec_escape(tostring(item_quest_id)).."]".. minetest.formspec_escape(
data.item_quest_id
or "- none set -").."]"..
"tooltip[action_item_quest_id;".. "tooltip[action_item_quest_id;"..
"Set this to a text that helps *you* to remember what this\n".. "Set this to a text that helps *you* to remember what this\n"..
"special quest item is for (i.e. \"quest_deliver_augusts_".. "special quest item is for (i.e. \"quest_deliver_augusts_"..
@ -1224,89 +1205,73 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"name of the player who got this item from the NPC.]".. "name of the player who got this item from the NPC.]"..
"label[0.2,9.0;Description to set:]".. "label[0.2,9.0;Description to set:]"..
"field[3.2,8.7;14.5,0.6;action_item_desc;;".. "field[3.2,8.7;14.5,0.6;action_item_desc;;"..
minetest.formspec_escape(tostring(item_desc)).."]".. minetest.formspec_escape(
data.item_desc
or "- no item set -").."]"..
"tooltip[action_item_desc;".. "tooltip[action_item_desc;"..
"Set this to a text that helps the *player* to remember what\n".. "Set this to a text that helps the *player* to remember what\n"..
"this special quest item is for (i.e. \"Letter from August to\n".. "this special quest item is for (i.e. \"Letter from August to\n"..
"Frederike\" for a piece of paper).\n".. "Frederike\" for a piece of paper).\n"..
"This description is shown in the inventory on mouseover.]".. "This description is shown in the inventory on mouseover.]"..
bg_img bg_img..
yl_speak_up.set_on_action_failure_dialog(pname, data,
"The player shall take this offered item.")
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5 -- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
-- (only for actions) -- (only for actions)
elseif(data.what and id_prefix == "a_" and data.what == 5) then elseif(data.what and id_prefix == "a_" and data.what == 5) then
local pname = player:get_player_name() if(not(data)) then
local dialog = yl_speak_up.speak_to[pname].dialog data = {}
local item_quest_id = "- none set -"
if(data and data.item_quest_id) then
item_quest_id = data.item_quest_id
end
local item_desc = "- no item set -"
if(data and data.item_desc) then
item_desc = data.item_desc
end
local nr = 1
if(data and data.action_failure_dialog) then
nr = data.action_failure_dialog + 1
end
local stack_name = ""
if(data and data.item_node_name) then
stack_name = data.item_node_name
end end
local bg_img = "" local bg_img = ""
if(data and data.item_string) then if(data and data.item_string) then
bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]" bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]"
end end
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
formspec = formspec.. formspec = formspec..
"label[8,2.6;Your invnetory:]".. "label[8,2.6;Your inventory:]"..
"list[current_player;main;8,3;8,4;]".. "list[current_player;main;8,3;8,4;]"..
"label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." wants:]".. "label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." wants:]"..
"list[detached:yl_speak_up_player_"..pname..";npc_wants;2,3.5;1,1;]".. "list[detached:yl_speak_up_player_"..pname..";npc_wants;2,3.5;1,1;]"..
"label[3.2,4.0;"..minetest.formspec_escape(stack_name).."]".. "label[3.2,4.0;"..
"label[1,4.9;The player shall give the NPC this item.\n".. minetest.formspec_escape(
"If he doesn't, go to dialog:]".. data.item_node_name
"dropdown[5.0,5.1;2.8,0.6;select_on_action_failure;".. or "- no item set -").."]"..
"- current one -,"..
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"..
"label[0.2,6.1;If you want a special ID and description, create\n".. "label[0.2,6.1;If you want a special ID and description, create\n"..
"those via the \"NPC gives something to the player\"\n".. "those via the \"NPC gives something to the player\"\n"..
"menu option first and insert that item here.]".. "menu option first and insert that item here.]"..
"label[0.2,8.3;Expected special ID:]".. "label[0.2,8.3;Expected special ID:]"..
"label[4.0,8.3;".. "label[4.0,8.3;"..
minetest.formspec_escape(tostring(item_quest_id)).."]".. minetest.formspec_escape(
data.item_quest_id
or "- none set -").."]"..
"label[0.2,9.0;Expected description:]".. "label[0.2,9.0;Expected description:]"..
"label[4.0,9.0;".. "label[4.0,9.0;"..
minetest.formspec_escape(tostring(item_desc)).."]".. minetest.formspec_escape(
bg_img data.item_desc
or "- none set -").."]"..
bg_img..
yl_speak_up.set_on_action_failure_dialog(pname, data,
"The player shall give the NPC this item.")
-- "The player has to manually enter a password or passphrase or some other text.", -- 6 -- "The player has to manually enter a password or passphrase or some other text.", -- 6
-- (only for actions) -- (only for actions)
elseif(data.what and id_prefix == "a_" and data.what == 6) then elseif(data.what and id_prefix == "a_" and data.what == 6) then
local question = "Your answer:" if(not(data)) then
if(data and data.quest_question) then data = {}
question = data.quest_question
end 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.. formspec = formspec..
"label[0.2,3.3;What to ask the player and which answer to expect:]".. "label[0.2,3.3;What to ask the player and which answer to expect:]"..
"label[0.2,4.0;Question to show:]".. "label[0.2,4.0;Question to show:]"..
"field[4.0,3.8;10.0,0.6;quest_question;;"..tostring(question).."]".. "field[4.0,3.8;10.0,0.6;quest_question;;"..
minetest.formspec_escape(
data.quest_question
or "Your answer:").."]"..
"label[0.2,5.0;Expected answer:]".. "label[0.2,5.0;Expected answer:]"..
"field[4.0,4.8;10.0,0.6;quest_answer;;"..tostring(answer).."]".. "field[4.0,4.8;10.0,0.6;quest_answer;;"..
"label[0.2,6.0;If the player gives the wrong answer, go to dialog:]".. minetest.formspec_escape(
"dropdown[8.0,5.7;2.8,0.6;select_on_action_failure;".. data.quest_answer
"- current one -,".. or "- Insert the correct answer here -").."]"..
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"..
"tooltip[quest_question;".. "tooltip[quest_question;"..
"This is just a short text that will be shown to remind\n".. "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".. "the player what he is asked for. Most of the question\n"..
@ -1320,29 +1285,24 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"a diffrent target dialog (i.e. with text \"No, that answer\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".. "was wrong, but please try again!\"). In such a case the\n"..
"effects/results of the current dialog option are *not*\n".. "effects/results of the current dialog option are *not*\n"..
"executed.]" "executed.]"..
yl_speak_up.set_on_action_failure_dialog(pname, data,
"The player shall enter the correct answer.")
-- "Call custom functions that are supposed to be overridden by the server.", -- 7 -- "Call custom functions that are supposed to be overridden by the server.", -- 7
-- (only for actions) -- (only for actions)
elseif(data.what and id_prefix == "a_" and data.what == 7) then elseif(data.what and id_prefix == "a_" and data.what == 7) then
local custom_param = "- Insert a text that is passed on to your function here -" if(not(data)) then
if(data and data.custom_param) then data = {}
custom_param = data.custom_param
end 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.. formspec = formspec..
"label[0.2,3.3;Note: Calling a custom function will require direct support ".. "label[0.2,3.3;Note: Calling a custom function will require direct support "..
"from the server.]".. "from the server.]"..
"label[0.2,4.0;Parameter for custom function:]".. "label[0.2,4.0;Parameter for custom function:]"..
"field[6.0,3.7;10.0,0.6;custom_param;;"..tostring(custom_param).."]".. "field[6.0,3.7;10.0,0.6;custom_param;;"..
"label[0.2,5.0;If the player fails at it, go to dialog:]".. minetest.formspec_escape(
"dropdown[6.0,4.7;2.8,0.6;select_on_action_failure;".. data.custom_param
"- current one -,".. or "- Insert a text that is passed on to your function here -").."]"..
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"..
"tooltip[custom_param;".. "tooltip[custom_param;"..
"The custom parameter may help whoever implements the\n".. "The custom parameter may help whoever implements the\n"..
"custom function to more easily see what it belongs to.\n".. "custom function to more easily see what it belongs to.\n"..
@ -1352,7 +1312,33 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"a diffrent target dialog (i.e. with text \"No, that answer\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".. "was wrong, but please try again!\"). In such a case the\n"..
"effects/results of the current dialog option are *not*\n".. "effects/results of the current dialog option are *not*\n"..
"executed.]" "executed.]"..
yl_speak_up.set_on_action_failure_dialog(pname, data,
"The player shall click on the right button.")
end end
return formspec..save_button return formspec..save_button
end end
-- helper function
yl_speak_up.set_on_action_failure_dialog = function(pname, data, instruction)
local dialog = yl_speak_up.speak_to[pname].dialog
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)
local on_failure_dialog =
"label[0.2,9.9;"..tostring(instruction).." If he doesn't, go to dialog:]"..
"dropdown[11.0,9.6;2.8,0.6;select_on_action_failure;"..
"- current one -,"..
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"
if(nr and nr > 1) then
local failure_d_id = sorted_dialog_list[ nr - 1]
on_failure_dialog = on_failure_dialog..
"hypertext[1.2,10.4.0;19.6,1.0;d_text;<normal>"..
minetest.formspec_escape(dialog.n_dialogs[ failure_d_id ].d_text or "?")..
"\n</normal>]"
end
return on_failure_dialog
end