forked from your-land-mirror/yl_speak_up
yl_speak_up.add_new_option added
This commit is contained in:
parent
403911ef81
commit
4cb12c2d2d
@ -138,17 +138,8 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
|||||||
|
|
||||||
-- add a new option/answer
|
-- add a new option/answer
|
||||||
if(fields[ "add_option"]) then
|
if(fields[ "add_option"]) then
|
||||||
-- count the options/answers so that the limit is not exceeded
|
local future_o_id = yl_speak_up.add_new_option(dialog, pname, nil, d_id, "")
|
||||||
local anz_options = 0
|
if(not(future_o_id)) then
|
||||||
local future_o_id = "o_" .. yl_speak_up.find_next_id(dialog.n_dialogs[d_id].d_options)
|
|
||||||
if dialog.n_dialogs[d_id].d_options == nil then
|
|
||||||
dialog.n_dialogs[d_id].d_options = {}
|
|
||||||
else
|
|
||||||
local sorted_list = yl_speak_up.get_sorted_options(dialog.n_dialogs[d_id].d_options, "o_sort")
|
|
||||||
anz_options = #sorted_list
|
|
||||||
end
|
|
||||||
-- we don't want an infinite amount of answers per dialog
|
|
||||||
if(anz_options >= yl_speak_up.max_number_of_options_per_dialog) then
|
|
||||||
-- this is already checked earlier on and the button only shown if
|
-- this is already checked earlier on and the button only shown if
|
||||||
-- options can be added; so this can reamin a chat message
|
-- options can be added; so this can reamin a chat message
|
||||||
minetest.chat_send_player(pname, "Sorry. Only "..
|
minetest.chat_send_player(pname, "Sorry. Only "..
|
||||||
@ -156,19 +147,6 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
|||||||
" options/answers are allowed per dialog.")
|
" options/answers are allowed per dialog.")
|
||||||
fields.add_option = nil
|
fields.add_option = nil
|
||||||
else
|
else
|
||||||
dialog.n_dialogs[d_id].d_options[future_o_id] = {
|
|
||||||
o_id = future_o_id,
|
|
||||||
o_hide_when_prerequisites_not_met = "false",
|
|
||||||
o_grey_when_prerequisites_not_met = "false",
|
|
||||||
o_sort = -1,
|
|
||||||
o_text_when_prerequisites_not_met = "",
|
|
||||||
o_text_when_prerequisites_met = "",
|
|
||||||
}
|
|
||||||
-- necessary in order for it to work
|
|
||||||
local s = yl_speak_up.sanitize_sort(dialog.n_dialogs[d_id].d_options, yl_speak_up.speak_to[pname].o_sort)
|
|
||||||
dialog.n_dialogs[d_id].d_options[future_o_id].o_sort = s
|
|
||||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
|
||||||
"Dialog "..d_id..": Added new option/answer "..future_o_id..".")
|
|
||||||
-- give this new dialog a dialog result that leads back to this dialog
|
-- give this new dialog a dialog result that leads back to this dialog
|
||||||
-- (which is more helpful than creating tons of empty dialogs)
|
-- (which is more helpful than creating tons of empty dialogs)
|
||||||
local new_target_dialog = yl_speak_up.prepare_new_dialog_for_option(
|
local new_target_dialog = yl_speak_up.prepare_new_dialog_for_option(
|
||||||
|
@ -234,6 +234,46 @@ yl_speak_up.add_new_dialog = function(dialog, pname, next_id)
|
|||||||
return future_d_id
|
return future_d_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- add a new option/answer to dialog d_id with option_text (or default "")
|
||||||
|
yl_speak_up.add_new_option = function(dialog, pname, next_id, d_id, option_text)
|
||||||
|
if(not(dialog) or not(dialog.n_dialogs) or not(dialog.n_dialogs[d_id])) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if dialog.n_dialogs[d_id].d_options == nil then
|
||||||
|
-- make sure d_options exists
|
||||||
|
dialog.n_dialogs[d_id].d_options = {}
|
||||||
|
else
|
||||||
|
-- we don't want an infinite amount of answers per dialog
|
||||||
|
local sorted_list = yl_speak_up.get_sorted_options(dialog.n_dialogs[d_id].d_options, "o_sort")
|
||||||
|
local anz_options = #sorted_list
|
||||||
|
if(anz_options >= yl_speak_up.max_number_of_options_per_dialog) then
|
||||||
|
-- nothing added
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if(not(next_id)) then
|
||||||
|
next_id = yl_speak_up.find_next_id(dialog.n_dialogs[d_id].d_options)
|
||||||
|
end
|
||||||
|
local future_o_id = "o_" .. next_id
|
||||||
|
dialog.n_dialogs[d_id].d_options[future_o_id] = {
|
||||||
|
o_id = future_o_id,
|
||||||
|
o_hide_when_prerequisites_not_met = "false",
|
||||||
|
o_grey_when_prerequisites_not_met = "false",
|
||||||
|
o_sort = -1,
|
||||||
|
o_text_when_prerequisites_not_met = "",
|
||||||
|
o_text_when_prerequisites_met = (option_text or ""),
|
||||||
|
}
|
||||||
|
-- necessary in order for it to work
|
||||||
|
local s = yl_speak_up.sanitize_sort(dialog.n_dialogs[d_id].d_options, yl_speak_up.speak_to[pname].o_sort)
|
||||||
|
dialog.n_dialogs[d_id].d_options[future_o_id].o_sort = s
|
||||||
|
-- log only in edit mode
|
||||||
|
if(yl_speak_up.npc_was_changed[ n_id ]) then
|
||||||
|
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||||
|
"Dialog "..d_id..": Added new option/answer "..future_o_id..".")
|
||||||
|
end
|
||||||
|
return future_o_id
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- add a new result to option o_id of dialog d_id
|
-- add a new result to option o_id of dialog d_id
|
||||||
yl_speak_up.add_new_result = function(dialog, d_id, o_id)
|
yl_speak_up.add_new_result = function(dialog, d_id, o_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user