forked from Sokomine/yl_speak_up
added new function yl_speak_up.prepare_new_dialog_for_option so that the dialog result/effect is present when first editing a new dialog
This commit is contained in:
parent
97384d7772
commit
17544df2a1
@ -31,7 +31,7 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
|
||||
return
|
||||
end
|
||||
|
||||
-- this meny is specific to an option for a dialog; if no dialog is selected, we really
|
||||
-- this menu is specific to an option for a dialog; if no dialog is selected, we really
|
||||
-- can't know what to do
|
||||
if(not(o_id) and d_id) then
|
||||
yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = d_id})
|
||||
@ -193,6 +193,15 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
|
||||
local list_of_effects = ""
|
||||
local results = d_option.o_results
|
||||
local count_effects = 0
|
||||
-- create a new dialog type option if needed
|
||||
if(not(results) or not(next(results))) then
|
||||
target_dialog = yl_speak_up.prepare_new_dialog_for_option(
|
||||
dialog, pname, n_id, d_id, o_id,
|
||||
yl_speak_up.text_new_dialog_id,
|
||||
results)
|
||||
-- make sure we are up to date (a new option was inserted)
|
||||
results = d_option.o_results
|
||||
end
|
||||
if(results) then
|
||||
local sorted_key_list = yl_speak_up.sort_keys(results)
|
||||
for i, k in ipairs(sorted_key_list) do
|
||||
|
@ -1776,6 +1776,50 @@ yl_speak_up.sort_keys = function(t)
|
||||
end
|
||||
|
||||
|
||||
-- helper function for yl_speak_up.edit_mode_apply_changes;
|
||||
-- makes sure the new dialog (and a result/effect "dialog" for each option) exist
|
||||
yl_speak_up.prepare_new_dialog_for_option = function(dialog, pname, n_id, d_id, o_id,target_dialog,o_results)
|
||||
-- is there a result/effect of the type "dialog" already? else use a fallback
|
||||
local result = {r_value = "-default-"}
|
||||
if(o_results) then
|
||||
for kr, vr in pairs(o_results) do
|
||||
if( vr.r_type == "dialog" ) then
|
||||
result = vr
|
||||
end
|
||||
end
|
||||
end
|
||||
-- this may also point to a new dialog
|
||||
if(target_dialog == yl_speak_up.text_new_dialog_id) then
|
||||
-- create a new dialog and show it as new target dialog - but do not display
|
||||
-- this dialog directly (the player may follow the -> button)
|
||||
target_dialog = yl_speak_up.add_new_dialog(dialog, pname, nil)
|
||||
elseif( result.r_value and result.r_value == target_dialog) then
|
||||
-- no problem - the right dialog is set already
|
||||
return target_dialog
|
||||
end
|
||||
-- store that a new option has been added to this dialog
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..d_id..": The target dialog for option "..
|
||||
tostring(o_id).." was changed from "..
|
||||
tostring(result.r_value or "-default-").." to "..
|
||||
tostring(target_dialog)..".")
|
||||
-- does the result/effect of type "dialog" exist already? then we're done
|
||||
if(result.r_type and result.r_type == "dialog") then
|
||||
-- actually change the target dialog
|
||||
result.r_value = target_dialog
|
||||
return target_dialog
|
||||
end
|
||||
-- create a new result (first the id, then the actual result)
|
||||
local future_r_id = yl_speak_up.add_new_result(dialog, d_id, o_id)
|
||||
-- actually store the new result
|
||||
dialog.n_dialogs[d_id].d_options[o_id].o_results[future_r_id] = {
|
||||
r_id = future_r_id,
|
||||
r_type = "dialog",
|
||||
r_value = target_dialog}
|
||||
return target_dialog
|
||||
end
|
||||
|
||||
|
||||
-- helper function for formspec "yl_speak_up:talk" *and* formspec "yl_speak_up:edit_option_dialog"
|
||||
-- when a parameter was changed in edit mode;
|
||||
-- this is called when the player is in edit_mode (editing the NPC);
|
||||
@ -1967,48 +2011,14 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
||||
|
||||
-- detect changes to d_id_<o_id>: target dialog for option <o_id>
|
||||
for k, v in pairs(dialog.n_dialogs[ d_id ].d_options) do
|
||||
if( fields[ "d_id_"..k ] and v.o_results) then
|
||||
for kr, vr in pairs(v.o_results) do
|
||||
if( vr.r_type == "dialog" and vr.r_value and vr.r_value ~= fields[ "d_id_"..k ]) then
|
||||
-- this may also point to a new dialog
|
||||
if(fields[ "d_id_"..k ] == yl_speak_up.text_new_dialog_id) then
|
||||
-- create a new dialog and show it as new target dialog - but do not display this dialog directly (the player may follow the -> button)
|
||||
fields[ "d_id_"..k ] = yl_speak_up.add_new_dialog(dialog, pname, nil)
|
||||
end
|
||||
-- store that there have been changes to this npc
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..d_id..": The target dialog for option "..
|
||||
tostring(k).." was changed from "..
|
||||
tostring(vr.r_value)..
|
||||
" to "..tostring(fields[ "d_id_"..k])..".")
|
||||
-- actually change the target dialog
|
||||
vr.r_value = fields[ "d_id_"..k ]
|
||||
-- in options edit menu: show this update
|
||||
result["show_next_option"] = k
|
||||
end
|
||||
if(fields[ "d_id_"..k ]) then
|
||||
local new_target_dialog = yl_speak_up.prepare_new_dialog_for_option(
|
||||
dialog, pname, n_id, d_id, k, fields[ "d_id_"..k ], v.o_results)
|
||||
if(new_target_dialog ~= fields[ "d_id_"..k ]) then
|
||||
fields[ "d_id_"..k ] = new_target_dialog
|
||||
-- in options edit menu: show this update
|
||||
result["show_next_option"] = k
|
||||
end
|
||||
-- this might be the first result
|
||||
elseif( fields["d_id_"..k ]) then
|
||||
-- this may also point to a new dialog
|
||||
if(fields[ "d_id_"..k ] == yl_speak_up.text_new_dialog_id) then
|
||||
-- create a new dialog and show it as new target dialog - but do not display this dialog directly (the player may follow the -> button)
|
||||
fields[ "d_id_"..k ] = yl_speak_up.add_new_dialog(dialog, pname, nil)
|
||||
end
|
||||
-- store that a new option has been added to this dialog
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..d_id..": The target dialog for option "..
|
||||
tostring(k).." was changed from -default- to "..
|
||||
tostring(fields[ "d_id_"..k])..".")
|
||||
|
||||
-- create a new result (first the id, then the actual result)
|
||||
local future_r_id = yl_speak_up.add_new_result(dialog, d_id, k)
|
||||
-- actually store the new result
|
||||
dialog.n_dialogs[d_id].d_options[k].o_results[future_r_id] = {
|
||||
r_id = future_r_id,
|
||||
r_type = "dialog",
|
||||
r_value = fields[ "d_id_"..k ]}
|
||||
-- in options edit menu: show this update
|
||||
result["show_next_option"] = k
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user