forked from Sokomine/yl_speak_up
allow to turn alternate text into a new dialog
This commit is contained in:
parent
a4b6bc1d02
commit
53fd0d1827
@ -953,11 +953,13 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
||||
-- handle editing and changing of alternate texts for actions
|
||||
if( fields.button_edit_action_on_failure_text_change
|
||||
or fields.button_edit_effect_on_failure_text_change
|
||||
or fields.turn_alternate_text_into_new_dialog
|
||||
or fields.save_dialog_modification) then
|
||||
yl_speak_up.handle_edit_actions_alternate_text(
|
||||
player, pname, n_id, d_id, o_id, x_id, id_prefix,
|
||||
formspec_input_to, data, fields, tmp_data_cache)
|
||||
if(not(fields.save_dialog_modification)) then
|
||||
if(not(fields.save_dialog_modification)
|
||||
and not(fields.turn_alternate_text_into_new_dialog)) then
|
||||
return
|
||||
end
|
||||
was_changed = true
|
||||
@ -1140,6 +1142,10 @@ yl_speak_up.handle_edit_actions_alternate_text = function(
|
||||
if(data and data.action_failure_dialog) then
|
||||
failure_id = sorted_dialog_list[ data.action_failure_dialog ]
|
||||
end
|
||||
-- remember what we edit
|
||||
data.x_id = x_id
|
||||
data.id_prefix = id_prefix
|
||||
yl_speak_up.speak_to[pname].edit_alternate_text_for = data
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = yl_speak_up.get_fs_edit_dialog_modification(
|
||||
@ -1154,6 +1160,10 @@ yl_speak_up.handle_edit_actions_alternate_text = function(
|
||||
|
||||
-- edit alternate text for an on_failure effect
|
||||
elseif(fields.button_edit_effect_on_failure_text_change) then
|
||||
-- remember what we edit
|
||||
data.x_id = x_id
|
||||
data.id_prefix = id_prefix
|
||||
yl_speak_up.speak_to[pname].edit_alternate_text_for = data
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = yl_speak_up.get_fs_edit_dialog_modification(
|
||||
@ -1228,6 +1238,74 @@ yl_speak_up.handle_edit_actions_alternate_text = function(
|
||||
-- saved; finished editing
|
||||
yl_speak_up.speak_to[pname].edit_alternate_text_for = nil
|
||||
end
|
||||
-- turn this alternate answer into a new dialog
|
||||
elseif(fields.turn_alternate_text_into_new_dialog) then
|
||||
local target_element = yl_speak_up.speak_to[pname].edit_alternate_text_for
|
||||
if(target_element) then
|
||||
data = target_element
|
||||
if(data.id_prefix and data.x_id) then
|
||||
id_prefix = data.id_prefix
|
||||
x_id = data.x_id
|
||||
else
|
||||
id_prefix = "a_"
|
||||
x_id = target_element.a_id
|
||||
if(target_element.r_id) then
|
||||
id_prefix = "r_"
|
||||
x_id = target_element.r_id
|
||||
end
|
||||
end
|
||||
end
|
||||
-- create the new dialog
|
||||
local new_dialog_id = yl_speak_up.add_new_dialog(dialog, pname, nil)
|
||||
-- set the text (the previous alternate text)
|
||||
dialog.n_dialogs[ new_dialog_id ].d_text = data.alternate_text
|
||||
-- edit option: effect dialog - this is the normal progression from this dialog to the next
|
||||
if( data.r_id and data.r_type and data.r_type == "dialog") then
|
||||
data.r_value = new_dialog_id
|
||||
data.alternate_text = nil
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..d_id..": The alternate text for effect "..tostring(x_id)..
|
||||
" (dialog) of option "..tostring(o_id).." was turned into the new dialog "..
|
||||
tostring(new_dialog_id).." (edit option).")
|
||||
|
||||
-- edit option: the action failed
|
||||
elseif(data.a_id and data.a_on_failure) then
|
||||
data.a_on_failure = new_dialog_id
|
||||
data.alternate_text = nil
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..d_id..": The alternate text for action "..tostring(data.a_id)..
|
||||
" of option "..tostring(o_id).." was turned into the new dialog "..
|
||||
tostring(new_dialog_id).." (edit option).")
|
||||
|
||||
-- edit action: the action failed
|
||||
elseif(data.what and data.what == 6 and data.action_failure_dialog) then
|
||||
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
|
||||
data.action_failure_dialog = math.max(1,
|
||||
table.indexof(sorted_dialog_list, new_dialog_id))
|
||||
data.a_on_failure = new_dialog_id
|
||||
data.alternate_text = nil
|
||||
-- make sure its stored correctly
|
||||
dialog.n_dialogs[d_id].d_options[o_id].actions[x_id].a_on_failure = new_dialog_id
|
||||
dialog.n_dialogs[d_id].d_options[o_id].actions[x_id].alternate_text = nil
|
||||
yl_speak_up.speak_to[pname][ tmp_data_cache ] = data
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..d_id..": The alternate text for action "..tostring(x_id)..
|
||||
" of option "..tostring(o_id).." was turned into the new dialog "..
|
||||
tostring(new_dialog_id).." (edit action).")
|
||||
|
||||
-- edit effect: on_failure - the previous effect failed
|
||||
elseif(data.what and data.what == 5 and data.on_failure) then
|
||||
data.on_failure = new_dialog_id
|
||||
data.alternate_text = nil
|
||||
-- make sure its stored correctly
|
||||
dialog.n_dialogs[d_id].d_options[o_id].o_results[x_id].on_failure = new_dialog_id
|
||||
dialog.n_dialogs[d_id].d_options[o_id].o_results[x_id].alternate_text = nil
|
||||
yl_speak_up.speak_to[pname][ tmp_data_cache ] = data
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..d_id..": The alternate text for effect "..tostring(x_id)..
|
||||
" of option "..tostring(o_id).." was turned into the new dialog "..
|
||||
tostring(new_dialog_id).." (edit effect).")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1376,9 +1454,6 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
data.item_string = e[ "a_value"] -- stack name and count (as string)
|
||||
data.item_desc = e[ "a_item_desc" ]
|
||||
data.item_quest_id = e[ "a_item_quest_id" ]
|
||||
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
|
||||
data.action_failure_dialog = math.max(1,
|
||||
table.indexof(sorted_dialog_list, e[ "a_on_failure" ]))
|
||||
end
|
||||
|
||||
if(e[ "alternate_text"]) then
|
||||
@ -1411,6 +1486,9 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
end
|
||||
|
||||
|
||||
if(data.what) then
|
||||
yl_speak_up.speak_to[pname][ tmp_data_cache ] = data
|
||||
end
|
||||
-- "an internal state (i.e. of a quest)", -- 2
|
||||
-- (state is the second offered option in both preconditions and effects list)
|
||||
if(data.what and data.what == 2 and id_prefix ~= "a_") then
|
||||
@ -1847,6 +1925,7 @@ yl_speak_up.get_fs_edit_option_effect_on_failure = function(
|
||||
pname, dialog, formspec, data, id_prefix, save_button, e)
|
||||
if(e) then
|
||||
data.on_failure = e[ "r_value" ]
|
||||
data.alternate_text = e[ "alternate_text" ]
|
||||
end
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
|
||||
@ -2246,6 +2325,10 @@ yl_speak_up.show_colored_dialog_text = function(dialog, data, d_id, hypertext_po
|
||||
-- slightly blue in order to indicate that this is a modified text
|
||||
color = "333366"
|
||||
end
|
||||
-- fallback
|
||||
if(not(text)) then
|
||||
text = "ERROR: No dialog text found for dialog \""..tostring(d_id).."\"!"
|
||||
end
|
||||
-- display the variables in orange
|
||||
text = yl_speak_up.replace_vars_in_text(text,
|
||||
-- fake dialog; just adds the colors
|
||||
|
@ -60,7 +60,8 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
|
||||
-- want to edit the text that is shown when switching to the next dialog?
|
||||
if(fields.button_edit_action_failed_dialog
|
||||
or fields.button_edit_action_success_dialog
|
||||
or fields.save_dialog_modification) then
|
||||
or fields.save_dialog_modification
|
||||
or fields.turn_alternate_text_into_new_dialog) then
|
||||
if( yl_speak_up.handle_edit_actions_alternate_text(
|
||||
-- x_id, id_prefix, target_element and tmp_data_cache are nil here
|
||||
player, pname, n_id, d_id, o_id, nil, nil,
|
||||
|
Loading…
Reference in New Issue
Block a user