From 3d4141e786bd57ad00e9c769aca3b4516762934f Mon Sep 17 00:00:00 2001 From: Sokomine Date: Thu, 1 Jul 2021 22:33:19 +0200 Subject: [PATCH] allow to edit and store alternate texts for dialogs when comming from a particular option/failed effect --- fs_edit_general.lua | 107 +++++++++++++++++++++++++++++++++++-- fs_edit_options_dialog.lua | 82 +++++++++++++++++++++++++++- 2 files changed, 183 insertions(+), 6 deletions(-) diff --git a/fs_edit_general.lua b/fs_edit_general.lua index 01e8116..e326d85 100644 --- a/fs_edit_general.lua +++ b/fs_edit_general.lua @@ -640,7 +640,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, yl_speak_up.show_fs(player, "msg", { input_to = "yl_speak_up:"..formspec_input_to, formspec = "size[9,2.5]".. - "label[0.2,0.5;Please insert an item first! Your NPC".. + "label[0.2,0.5;Please insert an item first! Your NPC ".. "needs\nto know what it shall give to the player.]".. "button[1.5,2.0;2,0.9;back_from_error_msg;Back]"}) return @@ -787,6 +787,8 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, end end + v[ "alternate_text" ] = data.alternate_text + -- only save if something was actually selected if(v[ id_prefix.."value"]) then if(not(dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ])) then @@ -873,6 +875,72 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, return end + -- edit alternate text for an action + if(fields.button_edit_action_on_failure_text_change) then + was_changed = true + local dialog = yl_speak_up.speak_to[pname].dialog + local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) + local failure_id = "" + if(data and data.action_failure_dialog) then + failure_id = sorted_dialog_list[ data.action_failure_dialog ] + end + 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, failure_id, data.alternate_text) + }) + return + -- edit alternate text for an on_failure effect + elseif(fields.button_edit_effect_on_failure_text_change) then + was_changed = true + 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( + dialog, data.on_failure, data.alternate_text) + }) + return + -- save the changes + elseif(fields.save_dialog_modification) then + was_changed = true + local dialog = yl_speak_up.speak_to[pname].dialog + local old_text = data.alternate_text + 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 + if(id_prefix == "r_") then + -- 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(o_id).." in dialog "..tostring( d_id ).. + " and effect "..tostring(x_id).." failed ".. + " was changed from ".. + "["..tostring(old_text).."] to ["..tostring(fields.d_text_new).."].") + elseif(id_prefix == "a_") then + local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) + local failure_id = "" + if(data and data.action_failure_dialog) then + failure_id = sorted_dialog_list[ data.action_failure_dialog ] + end + -- record the change + table.insert(yl_speak_up.npc_was_changed[ n_id ], + "Dialog "..d_id..": The text displayed for dialog ".. + tostring(failure_id).." when the action ".. + tostring(x_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 + -- just back; nothing special (but definitely a legitimate button) + elseif(fields.back_from_edit_dialog_modification) then + was_changed = true + end + + -- the player wants to change/edit a precondition or effect if(not(fields.back) and (fields.change_element or fields.select_what or fields.select_trade @@ -1124,6 +1192,10 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, data.lua_code = e[ id_prefix.."value" ] end end + + if(e[ "alternate_text"]) then + data.alternate_text = e[ "alternate_text" ] + end -- write that data back yl_speak_up.speak_to[pname][ tmp_data_cache ] = data end @@ -1411,7 +1483,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, "1.2,5.8;18.0,2.0;d_text", ", but with the following *modified* text", ":]", - "button_effect_on_failure_text_change") + "button_edit_effect_on_failure_text_change") end formspec = formspec.. "label[0.2,3.3;If the *previous* effect failed,]".. @@ -1655,14 +1727,14 @@ yl_speak_up.set_on_action_failure_dialog = function(pname, data, instruction) "1.2,10.2;18.0,1.8;d_text", "label[13.8,9.9;and show the following *modified* text:]", "", - "button_action_on_failure_text_change") + "button_edit_action_on_failure_text_change") end return on_failure_dialog end yl_speak_up.show_colored_dialog_text = function(dialog, data, d_id, hypertext_pos, - alternate_text, postfix, button_name) + alternate_label_text, postfix, button_name) if(not(data)) then return "" end @@ -1680,7 +1752,7 @@ yl_speak_up.show_colored_dialog_text = function(dialog, data, d_id, hypertext_po text = dialog.n_dialogs[ d_id ].d_text end if(data and data.alternate_text and data.alternate_text ~= "") then - add_info_alternate_text = alternate_text + add_info_alternate_text = alternate_label_text -- replace $TEXT$ with the normal dialog text and make the new text yellow text = "