broke long formspec strings into table.concat lists (editor/fs/fs_edit_options_dialog.lua)

This commit is contained in:
Sokomine 2024-02-13 02:24:43 +01:00
parent 94a1d1092a
commit 71e08eac08

View File

@ -238,16 +238,19 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
tostring(data.name)
end
end
quest_step_text = "box[4.9,0.0;14.0,1.1;#BB77BB]"..
"label[0.2,0.3;This is quest step:]"..
"label[5.0,0.3;"..
quest_step_text = table.concat({"box[4.9,0.0;14.0,1.1;#BB77BB]",
"label[0.2,0.3;This is quest step:]",
"label[5.0,0.3;",
minetest.colorize("#00FFFF",
minetest.formspec_escape(d_option.quest_step)).."]"..
"label[0.2,0.8;of the quest:]"..
"label[5.0,0.8;"..
minetest.formspec_escape(d_option.quest_step)),
"]",
"label[0.2,0.8;of the quest:]",
"label[5.0,0.8;",
minetest.colorize("#CCCCFF",
minetest.formspec_escape(quest_name)).."]"..
minetest.formspec_escape(quest_name)),
"]",
"button[19.4,0.1;2.0,0.9;assign_quest_step;Change]"
}, "")
end
@ -284,26 +287,32 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
"label[0.2,0.0;..this option will be selected automaticly.]"
end
if(answer_mode == 0 and (d_id ~= "d_got_item" and d_id ~= "d_trade")) then
answer_text = answer_text..
"label[1.2,0.8;A:]"..
"field[1.7,0.3;19.6,0.9;text_option_"..minetest.formspec_escape(o_id)..";;"..
minetest.formspec_escape(d_option.o_text_when_prerequisites_met).."]"..
answer_text = table.concat({answer_text,
"label[1.2,0.8;A:]",
"field[1.7,0.3;19.6,0.9;text_option_",
minetest.formspec_escape(o_id),
";;",
minetest.formspec_escape(d_option.o_text_when_prerequisites_met),
"]",
"tooltip[option_text_met;This is the answer the player may choose if the "..
"preconditions are all fulfilled.]"..
"preconditions are all fulfilled.]",
-- dropdown for selecting weather to show the alternate answer or not
"label[0.2,1.7;..but if at least one pre(C)ondition is not fulfilled, then...]"..
"dropdown[12.0,1.3;9.3,0.7;hide_or_grey_or_alternate_answer;"..
"..hide this answer.,"..
"..grey out the following answer:,"..
"..display the following alternate answer:;"..
alternate_answer_option..";]"..
"label[0.2,1.7;..but if at least one pre(C)ondition is not fulfilled, then...]",
"dropdown[12.0,1.3;9.3,0.7;hide_or_grey_or_alternate_answer;",
"..hide this answer.,",
"..grey out the following answer:,",
"..display the following alternate answer:;",
alternate_answer_option,
";]",
-- alternate answer
"label[1.2,2.5;A:]"..
"field[1.7,2.0;19.6,0.9;option_text_not_met;;"..
minetest.formspec_escape(d_option.o_text_when_prerequisites_not_met).."]"..
"label[1.2,2.5;A:]",
"field[1.7,2.0;19.6,0.9;option_text_not_met;;",
minetest.formspec_escape(d_option.o_text_when_prerequisites_not_met),
"]",
"tooltip[option_text_not_met;This is the answer the player may choose if the "..
"preconditions are NOT all fulfilled.]"..
"preconditions are NOT all fulfilled.]",
"container_end[]"
}, "")
elseif(answer_mode == 1) then
answer_text = answer_text..
"label[1.2,0.8;This option will not be shown but will be selected automaticly if all "..
@ -550,18 +559,22 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
if(not(timer_data)) then
timer_data = {}
end
action_text = action_text..tab_list..";3;true;true]"..
action_text = table.concat({action_text,
tab_list,
";3;true;true]",
-- allow to switch between successful and failed actions
"label[0.4,0.6;"..
"Apply the following time-based restrictions to limit wild guessing:]"..
"label[0.4,0.6;",
"Apply the following time-based restrictions to limit wild guessing:]",
-- timer for failed actions
"label[0.4,1.6;The player can make]"..
"field[4.9,1.0;1.5,0.9;timer_max_attempts_on_failure;;"..
tostring(timer_data[ "max_attempts" ] or 0).."]"..
"label[6.7,1.6;attempts to complete this action successfully each]"..
"field[17.5,1.0;1.5,0.9;timer_max_seconds_on_failure;;"..
tostring(timer_data[ "duration" ] or 0).."]"..
"label[19.2,1.6;seconds.]"..
"label[0.4,1.6;The player can make]",
"field[4.9,1.0;1.5,0.9;timer_max_attempts_on_failure;;",
tostring(timer_data[ "max_attempts" ] or 0),
"]",
"label[6.7,1.6;attempts to complete this action successfully each]",
"field[17.5,1.0;1.5,0.9;timer_max_seconds_on_failure;;",
tostring(timer_data[ "duration" ] or 0),
"]",
"label[19.2,1.6;seconds.]",
"label[0.4,2.2;Hint: 3 attempts per 1200 seconds (=20 minutes or one MineTest day)"..
" may be good values to\navoid wild guessing while not making the player "..
"having to wait too long to try again.]"..
@ -576,7 +589,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
"\nhas to wait some time before guessing again.]"..
"container[0.0,3.2]"..
"label[0.4,0.4;The NPC will explain his unwillingness to accept more "..
"guesses "..
"guesses ",
yl_speak_up.show_colored_dialog_text(
dialog,
{alternate_text = (timer_data[ "alternate_text" ]
@ -585,8 +598,9 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
"1.2,0.7;19.6,2.5;d_text_next",
"with the following text",
":]",
"button_edit_limit_action_failed_repeat")..
"button_edit_limit_action_failed_repeat"),
"container_end[]"
}, "")
-- show time-based restrictions (time between repeating this action successfully)
elseif( caller == "show_tab_limit_repeating") then
local timer_name = "timer_on_success_"..tostring(d_id).."_"..tostring(o_id)
@ -594,35 +608,42 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
if(not(timer_data)) then
timer_data = {}
end
action_text = action_text..tab_list..";4;true;true]"..
"label[0.4,0.6;"..
"Apply the following time-based restrictions to limit too quick repeating:]"..
action_text = table.concat({action_text,
tab_list,
";4;true;true]",
"label[0.4,0.6;",
"Apply the following time-based restrictions to limit too quick repeating:]",
-- timer for successful actions
"label[0.4,1.6;If the player completed the action successfully, he shall have to"..
" wait]"..
"field[15.0,1.0;1.5,0.9;timer_max_seconds_on_success;;"..
tostring(timer_data[ "duration" ] or 0).."]"..
"label[16.7,1.6;seconds until he]"..
"label[0.4,2.1;can repeat the action. Hint: 1200 seconds (=20 minutes or one "..
"MineTest day) may be a good value.]"..
"tooltip[timer_max_seconds_on_success;"..minetest.formspec_escape(
" wait]",
"field[15.0,1.0;1.5,0.9;timer_max_seconds_on_success;;",
tostring(timer_data[ "duration" ] or 0),
"]",
"label[16.7,1.6;seconds until he]",
"label[0.4,2.1;can repeat the action. Hint: 1200 seconds (=20 minutes or one ",
"MineTest day) may be a good value.]",
"tooltip[timer_max_seconds_on_success;",
minetest.formspec_escape(
"If you hand out a quest item, you may not want the player"..
"\nto immediately repeat the action countless times, thus"..
"\nemptying the NPC's storage and using the quest item for"..
"\nother purposes. On the other hand, quest items may get "..
"\nlost, so the player needs a way to repeat each step."..
"\n1200 seconds may be a good value here as well.").."]"..
"\n1200 seconds may be a good value here as well."),
"]",
-- ..and what the NPC will explain in such a case
"tooltip[1.2,3.9;19.6,2.5;"..minetest.formspec_escape(
"tooltip[1.2,3.9;19.6,2.5;",
minetest.formspec_escape(
"This is what the NPC will say next when the player"..
"\nwants to repeat the action too soon for the NPC's"..
"\ntaste - after all the NPC does not have infinite "..
"\ninventory ressources, and the player may abuse the "..
"\nquest item for entirely diffrent purposes..").."]"..
"container[0.0,3.2]"..
"\nquest item for entirely diffrent purposes.."),
"]",
"container[0.0,3.2]",
-- this will lead back to the same dialog
"label[0.4,0.4;The NPC will explain his unwillingness to repeat the "..
"action so soon "..
"action so soon ",
yl_speak_up.show_colored_dialog_text(
dialog,
{alternate_text = (timer_data[ "alternate_text" ]
@ -631,8 +652,9 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
"1.2,0.7;19.6,2.5;d_text_next",
"with the following text",
":]",
"button_edit_limit_action_success_repeat")..
"button_edit_limit_action_success_repeat"),
"container_end[]"
}, "")
-- show what happens if the action was successful
else
-- no action defined
@ -643,41 +665,51 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
"There is no (A)ction defined. Directly apply the following (Ef)fects:]"
else
-- allow to switch between successful and failed actions
action_text = action_text..tab_list..";1;true;true]"..
"label[0.4,0.6;"..
action_text = table.concat({action_text,
tab_list,
";1;true;true]",
"label[0.4,0.6;",
"If the player completed the above action successfully, "..
"apply the following (Ef)fects:]"
}, "")
end
action_text = action_text..
action_text = table.concat({action_text,
-- list of effects
"tablecolumns[text;color,span=1;text;text]"..
"table[1.2,0.9;19.6,2.0;table_of_effects;"..
list_of_effects..";0]"..
"tablecolumns[text;color,span=1;text;text]",
"table[1.2,0.9;19.6,2.0;table_of_effects;",
list_of_effects,
";0]",
"tooltip[1.2,0.9;19.6,2.0;"..
"*All* (Ef)fects are executed after the action (if there is\n"..
"one defined in this option) has been completed successfully\n"..
"by the player. If there is no action defined, then the\n"..
"(Ef)fects will always be executed when this option here is\n"..
"selected.\n"..
"Please click on an (Ef)fect in order to edit or delete it!]"..
"container[0.0,3.2]"..
"Please click on an (Ef)fect in order to edit or delete it!]",
"container[0.0,3.2]",
"label[0.4,0.4;The NPC will react to this answer with dialog:]"
}, "")
if(d_id == "d_trade") then
action_text = action_text..
"label[13.5,0.4;..by showing his trade list.]"..
"container_end[]"
else
action_text = action_text..
action_text = table.concat({action_text,
-- allow to change the target dialog via a dropdown menu
"dropdown[10.2,0.0;3.0,0.7;d_id_"..minetest.formspec_escape(o_id)..";"..
dialog_list..";"..dialog_selected..",]"..
"dropdown[10.2,0.0;3.0,0.7;d_id_",
minetest.formspec_escape(o_id),
";",
dialog_list,
";",
dialog_selected,
",]",
"tooltip[10.2,0.0;3.0,0.7;Select the target dialog with which the NPC shall react "..
"to this answer. Currently, dialog \""..
minetest.formspec_escape(target_dialog)..
"\" is beeing displayed.;#FFFFFF;#000000]"..
"to this answer. Currently, dialog \"",
minetest.formspec_escape(target_dialog),
"\" is beeing displayed.;#FFFFFF;#000000]",
-- ..and what the NPC will reply to that answer
"tooltip[1.2,0.7;19.6,2.5;This is what the NPC will say next when the player has "..
"selected this answer here.]"..
"selected this answer here.]",
yl_speak_up.show_colored_dialog_text(
dialog,
-- this is either the "dialog" effect or an empty fallback
@ -687,28 +719,34 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
"1.2,0.7;19.6,2.5;d_text",
"label[13.5,0.4;with the following *modified* text:]",
"",
"button_edit_action_success_dialog")..
"button_edit_action_success_dialog"),
"container_end[]"
}, "")
end
end
action_text = action_text.."container_end[]"
-- build up the formspec
local formspec = ""..
"size[22,22]"..
"bgcolor[#00000000;false]"..
local formspec = table.concat({
"size[22,22]",
"bgcolor[#00000000;false]",
-- button back to the current dialog (of which this is an option)
"button[16.4,0.2;5.0,0.9;show_current_dialog;Back to dialog "..
minetest.formspec_escape(d_id).."]"..
"tooltip[show_current_dialog;Go back to dialog "..
minetest.formspec_escape(d_id).." and continue editing that dialog.]"..
"button[16.4,0.2;5.0,0.9;show_current_dialog;Back to dialog ",
minetest.formspec_escape(d_id),
"]",
"tooltip[show_current_dialog;Go back to dialog ",
minetest.formspec_escape(d_id),
" and continue editing that dialog.]",
-- tell the player what this formspec is about
"label[6.5,0.4;You are editing dialog option \""..tostring(o_id).."\":]"..
"label[6.5,0.4;You are editing dialog option \"",
tostring(o_id),
"\":]",
-- the text the NPC says
"container[0.0,0.9]"..
"label[0.2,0.0;NPC says "..
minetest.formspec_escape("[dialog \""..tostring(d_id).."\"]:").."]"..
"container[0.0,0.9]",
"label[0.2,0.0;NPC says ",
minetest.formspec_escape("[dialog \""..tostring(d_id).."\"]:"),
"]",
yl_speak_up.show_colored_dialog_text(
dialog,
{r_id = "", r_type = "dialog"},
@ -716,62 +754,67 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
"1.2,0.3;20.2,2.5;d_text",
"", -- no modifications possible at this step
"",
"").. -- no edit button here as this text cannot be changed here
"tooltip[1.2,0.3;20.2,3.0;This is what the NPC says to the player.]"..
"container_end[]"..
""), -- no edit button here as this text cannot be changed here
"tooltip[1.2,0.3;20.2,3.0;This is what the NPC says to the player.]",
"container_end[]",
"container[0.0,3.9]"..
quest_step_text..
"container_end[]"..
"container[0.0,3.9]",
quest_step_text,
"container_end[]",
-- list the preconditions
"container[0.0,5.4]"..
"label[0.2,0.0;If all of the following pre(C)onditions are fulfilled:]"..
"tablecolumns[text;color,span=1;text;text]"..
"table[1.2,0.3;20.2,2.0;table_of_preconditions;"..
list_of_preconditions..";0]"..
"tooltip[1.2,0.3;20.2,2.0;"..
"container[0.0,5.4]",
"label[0.2,0.0;If all of the following pre(C)onditions are fulfilled:]",
"tablecolumns[text;color,span=1;text;text]",
"table[1.2,0.3;20.2,2.0;table_of_preconditions;",
list_of_preconditions,
";0]",
"tooltip[1.2,0.3;20.2,2.0;",
"*All* pre(C)onditions need to be true in order\n"..
"for the option to be offered to the player.\n"..
"Please click on a pre(C)ondition in order\n"..
"to edit or delete it!]"..
"container_end[]"..
"to edit or delete it!]",
"container_end[]",
-- answer of the player (the actual option)
answer_text..
answer_text,
-- list of (A)ctions (there can only be one per option; i.e. a trade)
action_list_text..
action_list_text,
-- list effects and target dialog for successful - and target dialog for unsuccessful
-- actions (including a toggle button)
action_text..
action_text,
-- container for the buttons/footer
"container[0.0,20.9]"..
"container[0.0,20.9]",
-- button: delete
"button[0.2,0.0;2.0,0.9;del_option;Delete]"..
"tooltip[del_option;Delete this option/answer.]"..
"button[0.2,0.0;2.0,0.9;del_option;Delete]",
"tooltip[del_option;Delete this option/answer.]",
-- button: add new
button_add..
button_add,
-- button: save
"button[4.6,0.0;2.0,0.9;save_option;Save]"..
"tooltip[save_option;Save what you canged (or discard it).]"..
"button[4.6,0.0;2.0,0.9;save_option;Save]",
"tooltip[save_option;Save what you canged (or discard it).]",
-- button: prev/next
button_prev..
button_next..
button_prev,
button_next,
-- button: go back to dialog (repeated from top of the page)
"button[15.8,0.0;5.0,0.9;show_current_dialog;Back to dialog "..
minetest.formspec_escape(d_id).."]"..
"tooltip[show_current_dialog;Go back to dialog "..
minetest.formspec_escape(d_id).." and continue editing that dialog.]"..
"button[15.8,0.0;5.0,0.9;show_current_dialog;Back to dialog ",
minetest.formspec_escape(d_id),
"]",
"tooltip[show_current_dialog;Go back to dialog ",
minetest.formspec_escape(d_id),
" and continue editing that dialog.]",
-- allow to enter o_sort
"label[10.1,0.5;Sort:]"..
"field[11.1,0.0;1.0,0.9;edit_option_o_sort;;"..
minetest.formspec_escape(d_option.o_sort).."]"..
"label[10.1,0.5;Sort:]",
"field[11.1,0.0;1.0,0.9;edit_option_o_sort;;",
minetest.formspec_escape(d_option.o_sort),
"]",
"tooltip[edit_option_o_sort;o_sort: The lower the number, the higher up in the "..
"list this option goes\nNegative values are ignored;#FFFFFF;#000000]"..
"list this option goes\nNegative values are ignored;#FFFFFF;#000000]",
"container_end[]"
}, "")
return formspec
end