limited number of preconditions and options per dialog

This commit is contained in:
Sokomine 2021-06-07 04:19:10 +02:00
parent 8157512e6b
commit 0bea918686
3 changed files with 29 additions and 2 deletions

View File

@ -29,3 +29,8 @@ yl_speak_up.max_number_of_options_per_dialog = 15
-- how many rows and cols shall be used for the trade overview list?
yl_speak_up.trade_max_rows = 10
yl_speak_up.trade_max_cols = 4
-- how many prerequirements can the player define per dialog option?
yl_speak_up.max_prerequirements = 12
-- how many effects can the player define per dialog option?
yl_speak_up.max_result_effects = 6

View File

@ -145,6 +145,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id)
-- are there any preconditions?
local list_of_preconditions = ""
local prereq = d_option.o_prerequisites
local count_prereq = 0
if(prereq) then
local sorted_key_list = yl_speak_up.sort_keys(prereq)
for i, k in ipairs(sorted_key_list) do
@ -154,9 +155,15 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id)
minetest.formspec_escape(v.p_type)..","..
minetest.formspec_escape(
yl_speak_up.show_precondition(v))..","
count_prereq = count_prereq + 1
end
end
list_of_preconditions = list_of_preconditions..",#00FF00,add,Add a new pre(C)ondition"
if(count_prereq < yl_speak_up.max_prerequirements) then
list_of_preconditions = list_of_preconditions..",#00FF00,add,Add a new pre(C)ondition"
else
list_of_preconditions = list_of_preconditions..",#AAAAAA,-,"..
"Maximum amount of pre(C)onditions per option reached!"
end
local list_of_actions = ""
if(dialog.trades and dialog.trades[ tostring(d_id).." "..tostring(o_id) ]) then
@ -176,6 +183,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id)
-- and build the list of effects
local list_of_effects = ""
local results = d_option.o_results
local count_effects = 0
if(results) then
local sorted_key_list = yl_speak_up.sort_keys(results)
for i, k in ipairs(sorted_key_list) do
@ -193,9 +201,15 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id)
minetest.formspec_escape(v.r_type)..","..
minetest.formspec_escape(v.r_value)..","
end
count_effects = count_effects + 1
end
end
list_of_effects = list_of_effects..",#00FF00,add,Add a new (Ef)fect"
if(count_effects < yl_speak_up.max_result_effects) then
list_of_effects = list_of_effects..",#00FF00,add,Add a new (Ef)fect"
else
list_of_effects = list_of_effects..",#AAAAAA,-,"..
"Maximum amount of allowed (Ef)fects per option reached!"
end
-- if no target dialog has been selected: default is to go to the dialog with d_sort 0
if(not(target_dialog) or target_dialog == "" or not(dialog.n_dialogs[target_dialog])) then

View File

@ -393,6 +393,14 @@ yl_speak_up.get_fs_edit_preconditions = function(player, table_click_result)
and selected.row <= #sorted_key_list) then
p_id = sorted_key_list[ selected.row ]
end
if( p_id == "new" and #sorted_key_list >= yl_speak_up.max_prerequirements) then
return "size[9,1.5]"..
"label[0.2,0.0;There are only up to "..
minetest.formspec_escape(yl_speak_up.max_prerequirements)..
" pre(C)onditions allowed per dialog option.]"..
"button[2.0,0.8;1.0,0.9;back;Back]"
end
else
-- allow to directly specify a p_id to show
p_id = table_click_result