From ea5bbb0e7a5110b5015c8ef9c74c2f46daad6b76 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Wed, 30 Jun 2021 23:12:39 +0200 Subject: [PATCH] added yl_speak_up.show_colored_dialog_text for edit menus --- fs_edit_general.lua | 75 +++++++++++++++++++++++++++++++++----- fs_edit_options_dialog.lua | 59 +++++++++++++++++++----------- 2 files changed, 102 insertions(+), 32 deletions(-) diff --git a/fs_edit_general.lua b/fs_edit_general.lua index e3b75c7..fc512a5 100644 --- a/fs_edit_general.lua +++ b/fs_edit_general.lua @@ -1402,10 +1402,15 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, local on_failure_dialog = "" if(dialog and dialog.n_dialogs and dialog.n_dialogs[ data.on_failure ]) then on_failure_dialog = - "label[0.2,5.5;This will switch to dialog "..tostring(data.on_failure)..":]".. - "hypertext[1.2,6.0;18.0,2.0;d_text;".. - minetest.formspec_escape(dialog.n_dialogs[ data.on_failure ].d_text or "?").. - "\n]" + "label[0.2,5.5;This will switch to dialog \"".. + minetest.formspec_escape(tostring(data.on_failure)).."\"".. + yl_speak_up.show_colored_dialog_text( + dialog, + data, + data.on_failure, + "1.2,5.8;18.0,2.0;d_text;", + ", but with the following *modified* text", + ":]") end formspec = formspec.. "label[0.2,3.3;If the *previous* effect failed,]".. @@ -1633,18 +1638,68 @@ yl_speak_up.set_on_action_failure_dialog = function(pname, data, instruction) if(data and data.action_failure_dialog) then nr = data.action_failure_dialog + 1 end + local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) local on_failure_dialog = "label[0.2,9.9;"..tostring(instruction).." If he doesn't, go to dialog:]".. - "dropdown[11.0,9.6;2.8,0.6;select_on_action_failure;".. + "dropdown[11.0,9.6;2.7,0.6;select_on_action_failure;".. "- current one -,".. table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]" if(nr and nr > 1) then - local failure_d_id = sorted_dialog_list[ nr - 1] - on_failure_dialog = on_failure_dialog.. - "hypertext[1.2,10.2.0;18.0,1.8;d_text;".. - minetest.formspec_escape(dialog.n_dialogs[ failure_d_id ].d_text or "?").. - "\n]" + return on_failure_dialog.. + yl_speak_up.show_colored_dialog_text( + dialog, + data, + sorted_dialog_list[ nr - 1], + "1.2,10.2.0;18.0,1.8;d_text", + "label[13.8,9.9;and show the following *modified* text:]", + "") end return on_failure_dialog end + + +yl_speak_up.show_colored_dialog_text = function(dialog, data, d_id, hypertext_pos, alternate_text, postfix) + if(not(data)) then + return "" + end + -- if(math.random(1,2)==1) then data.alternate_text = "This is an alternate text.\n$TEXT$" end + -- slightly red in order to indicate that this is an on_failure dialog + local color = "776666" + -- ..except for normal redirecting to the next dialog with the dialog effect + -- (slightly yellow there) + if(data.r_id and data.r_type and data.r_type == "dialog") then + color = "777766" + end + local add_info_alternate_text = "" + local text = "" + if(dialog and dialog.n_dialogs and dialog.n_dialogs[ d_id ]) then + 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 + -- replace $TEXT$ with the normal dialog text and make the new text yellow + text = "").. + "" + -- slightly blue in order to indicate that this is a modified text + color = "333366" + end + -- display the variables in orange + text = yl_speak_up.replace_vars_in_text(text, + -- fake dialog; just adds the colors + -- also MY_NAME..but we can easily replace just one + { n_npc = "", + npc_owner = ""}, + -- pname + "") + + return add_info_alternate_text.. + postfix.. + "hypertext["..hypertext_pos..";".. + minetest.formspec_escape(text or "?").. + "\n]" +end diff --git a/fs_edit_options_dialog.lua b/fs_edit_options_dialog.lua index 78a23e5..e187306 100644 --- a/fs_edit_options_dialog.lua +++ b/fs_edit_options_dialog.lua @@ -186,6 +186,9 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle -- find the right target dialog for this option (if it exists) local target_dialog = nil + -- which effect holds the information about the target dialog? + -- set this to a fallback for yl_speak_up.show_colored_dialog_text + local target_effect = {r_id = "-?-", r_type = "dialog"} -- and build the list of effects local list_of_effects = "" local results = d_option.o_results @@ -202,6 +205,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle yl_speak_up.show_effect(v)).."," -- there may be more than one in the data structure target_dialog = v.r_value + target_effect = v elseif v.r_type ~= "dialog" then list_of_effects = list_of_effects.. minetest.formspec_escape(v.r_id)..",#FFFF00,".. @@ -227,11 +231,6 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle end end end - -- this is the text the NPC will say in reaction to this answer - local next_text = "" - if(target_dialog and dialog.n_dialogs[target_dialog]) then - next_text = dialog.n_dialogs[target_dialog].d_text - end -- build the list of available dialogs for the dropdown list(s) local dialog_list = yl_speak_up.text_new_dialog_id local dialog_selected = "1" @@ -312,14 +311,18 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle and dialog.n_dialogs and dialog.n_dialogs[ action_data.a_on_failure]) then action_text = action_text.. -- ..and what the NPC will reply to that answer + "tooltip[1.2,15.5;19.6,2.5;This is what the NPC will say next when ".. + "the player has failed to complete the action.]".. "label[0.2,15.1;..the NPC will react to this failed action with the ".. - "following dialog \""..tostring(action_data.a_on_failure).."\":]".. - "hypertext[1.2,15.5;19.6,2.5;d_text_next;".. - ""..minetest.formspec_escape(tostring( - dialog.n_dialogs[ action_data.a_on_failure ].d_text)).. - "\n]".. - "tooltip[1.2,16.8;21.0,2.5;This is what the NPC will say next when ".. - "the player has failed to complete the action.]" + "following dialog \""..tostring(action_data.a_on_failure).. + "\"".. + yl_speak_up.show_colored_dialog_text( + dialog, + action_data, + action_data.a_on_failure, + "1.2,15.5;19.6,2.5;d_text_next", + "with the *modified* text", + ":]") else action_text = action_text.. "label[0.2,15.1;..go back to the initial dialog.]" @@ -338,17 +341,24 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle "selected.\n".. "Please click on an (Ef)fect in order to edit or delete it!]".. -- allow to change the target dialog via a dropdown menu - "dropdown[12.5,14.7;7.5,0.7;d_id_"..minetest.formspec_escape(o_id)..";".. + "dropdown[12.3,14.7;2.8,0.7;d_id_"..minetest.formspec_escape(o_id)..";".. dialog_list..";"..dialog_selected..",]".. - "tooltip[12.5,14.7;7.5,0.7;Select the target dialog with which the NPC shall react ".. - "to this answer. Currently, dialog "..minetest.formspec_escape(target_dialog).. - " is beeing displayed.;#FFFFFF;#000000]".. + "tooltip[12.3,14.7;2.8,0.7;Select the target dialog with which the NPC shall react ".. + "to this answer. Currently, dialog \""..minetest.formspec_escape(target_dialog).. + "\" is beeing displayed.;#FFFFFF;#000000]".. -- ..and what the NPC will reply to that answer + "tooltip[1.2,15.5;19.6,2.5;This is what the NPC will say next when the player has ".. + "selected this answer here.]".. "label[0.2,15.1;The NPC will react to this answer with the following dialog:]".. - "hypertext[1.2,15.5;19.6,2.5;d_text_next;".. - minetest.formspec_escape(next_text) .. "\n]".. - "tooltip[1.2,16.8;21.0,2.5;This is what the NPC will say next when the player has ".. - "selected this answer here.]" + yl_speak_up.show_colored_dialog_text( + dialog, + -- this is either the "dialog" effect or an empty fallback + target_effect, + -- this is the text the NPC will say in reaction to this answer + target_dialog, + "1.2,15.5;19.6,2.5;d_text", + "label[15.2,15.1;with the *modified* text:]", + "") end -- build up the formspec @@ -366,8 +376,13 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle -- the text the NPC says "label[0.2,0.6;NPC says ".. minetest.formspec_escape("[dialog \""..tostring(d_id).."\"]:").."]".. - "hypertext[1.2,1.2;19.6,2.5;d_text;".. - minetest.formspec_escape(n_dialog.d_text) .. "\n]".. + yl_speak_up.show_colored_dialog_text( + dialog, + target_effect, + d_id, + "1.2,1.2;19.6,2.5;d_text", + "", -- no modifications possible at this step + "").. "tooltip[1.2,1.2;19.6,3.0;This is what the NPC says to the player.]".. -- list the preconditions "label[0.2,4.2;If all of the following pre(C)onditions are fulfilled:]"..