mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-11-01 04:43:07 +01:00
handled alternate texts centralized in yl_speak_up.input_edit_option_dialog
This commit is contained in:
parent
58b5aa2cbb
commit
fb2217d8cc
@ -1064,11 +1064,79 @@ end
|
||||
yl_speak_up.handle_edit_actions_alternate_text = function(
|
||||
player, pname, n_id, d_id, o_id, x_id, id_prefix,
|
||||
formspec_input_to, data, fields, tmp_data_cache)
|
||||
-- edit alternate text for an action
|
||||
if(fields.button_edit_action_on_failure_text_change) then
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
if(not(dialog)
|
||||
or not(dialog.n_dialogs)
|
||||
or not(dialog.n_dialogs[ d_id ])
|
||||
or not(dialog.n_dialogs[ d_id ].d_options)
|
||||
or not(dialog.n_dialogs[ d_id ].d_options[ o_id ])) then
|
||||
return
|
||||
end
|
||||
-- edit_dialog_options: these first two buttons can only be pressed in this dialog
|
||||
-- action failed: want to edit the text that is shown when switching to the next dialog?
|
||||
if(fields.button_edit_action_failed_dialog) then
|
||||
-- the target effect is the (failed) action
|
||||
local target_action = {}
|
||||
local actions = dialog.n_dialogs[ d_id ].d_options[ o_id ].actions
|
||||
if(actions) then
|
||||
for a_id, a in pairs(actions) do
|
||||
if(a and a.a_id) then
|
||||
target_action = a
|
||||
end
|
||||
end
|
||||
end
|
||||
if(not(target_action)) then
|
||||
return
|
||||
end
|
||||
-- remember what we're working at
|
||||
yl_speak_up.speak_to[pname].edit_alternate_text_for = target_action
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = yl_speak_up.get_fs_edit_dialog_modification(
|
||||
dialog, target_action.a_on_failure, target_action.alternate_text,
|
||||
"if the action \""..tostring(target_action.a_id)..
|
||||
"\" of option \""..tostring(o_id)..
|
||||
"\" of dialog \""..tostring(d_id)..
|
||||
"\" failed because the player did something wrong")
|
||||
})
|
||||
-- showing new formspec - the calling function shall return as well
|
||||
return true
|
||||
|
||||
-- action was successful: want to edit the text that is shown when switching to the next dialog?
|
||||
elseif(fields.button_edit_action_success_dialog) then
|
||||
-- the target effect is the "dialog" effect
|
||||
local target_effect = {}
|
||||
local results = dialog.n_dialogs[ d_id ].d_options[ o_id ].o_results
|
||||
if(results) then
|
||||
for r_id, r in pairs(results) do
|
||||
if(r and r.r_type and r.r_type == "dialog") then
|
||||
target_effect = r
|
||||
end
|
||||
end
|
||||
end
|
||||
if(not(target_effect)) then
|
||||
return
|
||||
end
|
||||
-- remember what we're working at
|
||||
yl_speak_up.speak_to[pname].edit_alternate_text_for = target_effect
|
||||
-- this only happens in edit_options_dialog; log it directly
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = yl_speak_up.get_fs_edit_dialog_modification(
|
||||
dialog, target_effect.r_value, target_effect.alternate_text,
|
||||
"if the action "..
|
||||
"of option \""..tostring(o_id)..
|
||||
"\" of dialog \""..tostring(d_id)..
|
||||
"\" was successful - or if there was no action")
|
||||
})
|
||||
-- showing new formspec - the calling function shall return as well
|
||||
return true
|
||||
|
||||
-- in edit action dialog: edit alternate text for a failed action
|
||||
elseif(fields.button_edit_action_on_failure_text_change) then
|
||||
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
|
||||
local failure_id = ""
|
||||
-- action is beeing edited; data.action_failure_dialog points to an index
|
||||
if(data and data.action_failure_dialog) then
|
||||
failure_id = sorted_dialog_list[ data.action_failure_dialog ]
|
||||
end
|
||||
@ -1081,10 +1149,11 @@ yl_speak_up.handle_edit_actions_alternate_text = function(
|
||||
"\" of dialog \""..tostring(d_id)..
|
||||
"\" failed because the player did something wrong")
|
||||
})
|
||||
return
|
||||
-- showing new formspec - the calling function shall return as well
|
||||
return true
|
||||
|
||||
-- edit alternate text for an on_failure effect
|
||||
elseif(fields.button_edit_effect_on_failure_text_change) then
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = yl_speak_up.get_fs_edit_dialog_modification(
|
||||
@ -1094,21 +1163,45 @@ yl_speak_up.handle_edit_actions_alternate_text = function(
|
||||
"\" of dialog \""..tostring(d_id)..
|
||||
"\" failed to execute correctly")
|
||||
})
|
||||
return
|
||||
-- showing new formspec - the calling function shall return as well
|
||||
return true
|
||||
-- save the changes
|
||||
elseif(fields.save_dialog_modification) then
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
local old_text = data.alternate_text
|
||||
local old_text = "-none-"
|
||||
local target_element = yl_speak_up.speak_to[pname].edit_alternate_text_for
|
||||
if(target_element) then
|
||||
data = target_element
|
||||
id_prefix = "a_"
|
||||
if(target_element.r_id) then
|
||||
id_prefix = "r_"
|
||||
end
|
||||
old_text = target_element.alternate_text
|
||||
else
|
||||
old_text = data.alternate_text
|
||||
end
|
||||
if(data and fields.d_text_new and fields.d_text_new ~= "$TEXT$"
|
||||
and fields.d_text_new ~= data.alternate_text) then
|
||||
-- store modification
|
||||
data.alternate_text = fields.d_text_new
|
||||
yl_speak_up.speak_to[pname][ tmp_data_cache ] = data
|
||||
-- not necessary for edit_option_dialog
|
||||
if(tmp_data_cache) then
|
||||
data.alternate_text = fields.d_text_new
|
||||
yl_speak_up.speak_to[pname][ tmp_data_cache ] = data
|
||||
else
|
||||
target_element.alternate_text = fields.d_text_new
|
||||
end
|
||||
if(id_prefix == "r_") then
|
||||
local failure_id = data.on_failure
|
||||
-- effect is beeing edited; data.on_failure contains the dialog name
|
||||
if(data and data.on_failure) then
|
||||
failure_id = data.on_failure
|
||||
-- edit_option_dialog: data.r_value contains the dialog name
|
||||
elseif(target_element and target_element.r_value) then
|
||||
failure_id = target_element.r_value
|
||||
end
|
||||
-- record the change
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..d_id..": The text displayed for dialog "..
|
||||
tostring(data.on_failure).." when selecting option "..
|
||||
tostring(failure_id).." when selecting option "..
|
||||
tostring(o_id).." in dialog "..tostring( d_id )..
|
||||
" and effect "..tostring(x_id).." failed "..
|
||||
" was changed from "..
|
||||
@ -1116,8 +1209,12 @@ yl_speak_up.handle_edit_actions_alternate_text = function(
|
||||
elseif(id_prefix == "a_") then
|
||||
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
|
||||
local failure_id = ""
|
||||
-- action is beeing edited; data.action_failure_dialog points to an index
|
||||
if(data and data.action_failure_dialog) then
|
||||
failure_id = sorted_dialog_list[ data.action_failure_dialog ]
|
||||
-- edit_option_dialog: data.a_on_failure contains the dialog name
|
||||
elseif(target_element and target_element.a_on_failure) then
|
||||
failure_id = target_element.a_on_failure
|
||||
end
|
||||
-- record the change
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
@ -1128,6 +1225,8 @@ yl_speak_up.handle_edit_actions_alternate_text = function(
|
||||
" failed, was changed from "..
|
||||
"["..tostring(old_text).."] to ["..tostring(fields.d_text_new).."].")
|
||||
end
|
||||
-- saved; finished editing
|
||||
yl_speak_up.speak_to[pname].edit_alternate_text_for = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -2202,5 +2301,6 @@ yl_speak_up.get_fs_edit_dialog_modification = function(dialog, d_id, alternate_d
|
||||
"textarea[1.2,7.6;18.0,4.5;d_text_new;;"..
|
||||
minetest.formspec_escape(alternate_dialog_text or "$TEXT$").."]"..
|
||||
"button[3.0,12.3;1,0.7;back_from_edit_dialog_modification;Abort]"..
|
||||
"button[6.0,12.3;1,0.7;save_dialog_modification;Save]"
|
||||
"button[6.0,12.3;1,0.7;save_dialog_modification;Save]"..
|
||||
"button[9.0,12.3;6,0.7;turn_alternate_text_into_new_dialog;Turn this into a new dialog]"
|
||||
end
|
||||
|
||||
@ -58,84 +58,21 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
|
||||
end
|
||||
|
||||
-- want to edit the text that is shown when switching to the next dialog?
|
||||
if(fields.button_edit_action_failed_dialog) then
|
||||
-- the target effect is the (failed) action
|
||||
local target_action = {}
|
||||
local actions = d_option.actions
|
||||
if(actions) then
|
||||
for a_id, a in pairs(actions) do
|
||||
if(a and a.a_id) then
|
||||
target_action = a
|
||||
end
|
||||
end
|
||||
if(fields.button_edit_action_failed_dialog
|
||||
or fields.button_edit_action_success_dialog
|
||||
or fields.save_dialog_modification) 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,
|
||||
"edit_option_dialog", nil, fields, nil)) then
|
||||
-- the function above showed a formspec already
|
||||
return
|
||||
else
|
||||
yl_speak_up.show_fs(player, "edit_option_dialog",
|
||||
{n_id = n_id, d_id = d_id, o_id = o_id,
|
||||
caller="back-from_edit_dialog_modifications"})
|
||||
return
|
||||
end
|
||||
-- remember what we're working at
|
||||
yl_speak_up.speak_to[pname].edit_alternate_text_for = target_action
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = formname,
|
||||
formspec = yl_speak_up.get_fs_edit_dialog_modification(
|
||||
dialog, target_action.a_on_failure, target_action.alternate_text,
|
||||
"if the action \""..tostring(target_action.a_id)..
|
||||
"\" of option \""..tostring(o_id)..
|
||||
"\" of dialog \""..tostring(d_id)..
|
||||
"\" failed because the player did something wrong")
|
||||
})
|
||||
return
|
||||
|
||||
elseif(fields.button_edit_action_success_dialog) then
|
||||
-- the target effect is the "dialog" effect
|
||||
local target_effect = {}
|
||||
local results = d_option.o_results
|
||||
if(results) then
|
||||
for r_id, r in pairs(results) do
|
||||
if(r and r.r_type and r.r_type == "dialog") then
|
||||
target_effect = r
|
||||
end
|
||||
end
|
||||
end
|
||||
-- remember what we're working at
|
||||
yl_speak_up.speak_to[pname].edit_alternate_text_for = target_effect
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = formname,
|
||||
formspec = yl_speak_up.get_fs_edit_dialog_modification(
|
||||
dialog, target_effect.r_value, target_effect.alternate_text,
|
||||
"if the action "..
|
||||
"of option \""..tostring(o_id)..
|
||||
"\" of dialog \""..tostring(d_id)..
|
||||
"\" was successful - or if there was no action")
|
||||
})
|
||||
return
|
||||
|
||||
-- save the alternate action/effect text for the next dialog
|
||||
elseif(fields.save_dialog_modification) then
|
||||
local target_element = yl_speak_up.speak_to[pname].edit_alternate_text_for
|
||||
local old_text = target_element.alternate_text
|
||||
if(target_element and fields.d_text_new and fields.d_text_new ~= "$TEXT$"
|
||||
and fields.d_text_new ~= target_element.alternate_text) then
|
||||
target_element.alternate_text = fields.d_text_new
|
||||
if(target_element and target_element.r_id) then
|
||||
-- record the change
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..d_id..": The text displayed for dialog "..
|
||||
tostring(target_element.r_value).." when selecting option "..
|
||||
tostring( o_id ).." in dialog "..tostring( d_id )..
|
||||
" was changed from "..
|
||||
"["..tostring(old_text).."] to ["..tostring(fields.d_text_new).."].")
|
||||
elseif(target_element and target_element.a_id) then
|
||||
-- record the change
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..d_id..": The text displayed for dialog "..
|
||||
tostring(target_element.a_on_failure).." when the action "..
|
||||
tostring(target_element.a_id).." of option "..
|
||||
tostring( o_id ).." in dialog "..tostring( d_id )..
|
||||
" failed, was changed from "..
|
||||
"["..tostring(old_text).."] to ["..tostring(fields.d_text_new).."].")
|
||||
end
|
||||
end
|
||||
|
||||
yl_speak_up.show_fs(player, "edit_option_dialog",
|
||||
{n_id = n_id, d_id = d_id, o_id = o_id, caller="back-from_edit_dialog_modifications"})
|
||||
return
|
||||
|
||||
elseif(fields.back_from_edit_dialog_modification) then
|
||||
-- no longer working on an alternate text
|
||||
|
||||
Loading…
Reference in New Issue
Block a user