From bea29aed26aa6e2df21872f3cf8e4de60abfc9db Mon Sep 17 00:00:00 2001 From: Sokomine Date: Thu, 8 Jul 2021 23:33:27 +0200 Subject: [PATCH] added show var usage (partially) --- fs_edit_general.lua | 48 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/fs_edit_general.lua b/fs_edit_general.lua index 28f6d70..ac6e075 100644 --- a/fs_edit_general.lua +++ b/fs_edit_general.lua @@ -702,7 +702,8 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, return end - if(fields.back_from_cannot_be_edited) then + if(fields.back_from_cannot_be_edited + or fields.back_from_show_var_usage) then yl_speak_up.show_fs(player, formspec_input_to, x_id) return end @@ -946,6 +947,37 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, was_changed = true end + -- show var usage - starting from clicking on a precondition or effect in the + -- edit options menu and viewing the list containing that selected element + if( fields.show_var_usage and x_id) then + local dialog = yl_speak_up.speak_to[pname].dialog + local element = dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ][ x_id ] + if(element and element[ id_prefix.."variable"]) then + -- TODO: actually implement/show usage of the variable as formspec + yl_speak_up.show_fs(player, "msg", { + input_to = "yl_speak_up:"..formspec_input_to, + formspec = "size[9,2]".. + "label[0.2,0.5;This ought to show usage of a variable.]".. + -- back to the list with that one precondition or effect + "button[1.5,1.5;2,0.9;back_from_show_var_usage;Back]"}) + return + end + -- show var usuage - but this time from the edit dialog for that precondition or effect + elseif(fields.show_var_usage_edit_element and x_id) then + local dialog = yl_speak_up.speak_to[pname].dialog + local element = dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ][ x_id ] + if(element and element[ id_prefix.."variable"]) then + -- TODO: actually implement/show usage of the variable as formspec + yl_speak_up.show_fs(player, "msg", { + input_to = "yl_speak_up:"..formspec_input_to, + formspec = "size[9,2]".. + "label[0.2,0.5;This ought to show usage of a variable.]".. + -- back to editing that particular precondition or effect + "button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) + return + end + 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 @@ -1108,6 +1140,16 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, x_id = table_click_result end + local show_var_usage = "" + if(x_id + and elements + and elements[ x_id ] + and elements[ x_id ][ id_prefix.."type"] + and elements[ x_id ][ id_prefix.."type"] == "state" + and elements[ x_id ][ id_prefix.."variable"]) then + show_var_usage = "button[12.0,1.8;6.5,0.9;show_var_usage;".. + "Show where this variable is used]" + end -- store which element we are talking about yl_speak_up.speak_to[pname][ id_prefix.."id" ] = x_id -- nothing selected yet @@ -1129,7 +1171,8 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, "button[2.0,1.8;1.5,0.9;delete_element;Delete]".. "button[4.0,1.8;1.5,0.9;change_element;Change]".. "button[6.0,1.8;5.5,0.9;back;Back to edit dialog option \"".. - tostring(o_id).."\"]" + tostring(o_id).."\"]".. + show_var_usage end end @@ -1365,6 +1408,7 @@ yl_speak_up.get_fs_edit_option_p_and_e_state = function( "label[11.2,4.3;"..text_select_value.."]".. field_for_value.. "button[0.2,6.0;4.0,0.6;manage_variables;Manage variables]".. + "button[4.7,6.0;6.5,0.6;show_var_usage_edit_element;Show where this variable is used]".. "hypertext[1.2,7.0;16.0,2.5;some_text;".. "Note: Each variable is player-specific and will be set and ".. "checked for the player that currently talks to your NPC.\n"..