From 47c7e7ab30132c823291b64da2bce6424a3ca962 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Tue, 3 Aug 2021 22:55:59 +0200 Subject: [PATCH] allow to show and change the value of a variable via the manage variables formspec --- fs_manage_variables.lua | 82 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 5 deletions(-) diff --git a/fs_manage_variables.lua b/fs_manage_variables.lua index 7a98423..94e5733 100644 --- a/fs_manage_variables.lua +++ b/fs_manage_variables.lua @@ -130,6 +130,45 @@ yl_speak_up.input_fs_manage_variables = function(player, formname, fields) table.concat(yl_speak_up.get_list_of_debugged_variables(pname), ",").."]".. "button[1.5,5.5;2,0.9;back_from_msg;Back]"}) return + + -- a player name was given; the value for that player shall be shown + elseif(fields and fields.show_stored_value_for_player and var_name + and fields.stored_value_for_player and fields.stored_value_for_player ~= "") then + yl_speak_up.show_fs(player, "manage_variables", fields.stored_value_for_player) + return + -- change the value for a player (possibly to nil) + elseif(fields and fields.store_new_value_for_player and var_name + and fields.stored_value_for_player and fields.stored_value_for_player ~= "") then + yl_speak_up.set_quest_variable_value(fields.stored_value_for_player, var_name, + fields.current_value_for_player) + yl_speak_up.show_fs(player, "msg", { + input_to = "yl_speak_up:manage_variables", + formspec = "size[10,2]".. + "label[0.2,0.0;Set variable \"".. + minetest.colorize("#FFFF00", + minetest.formspec_escape(tostring(var_name))).. + "\"\nfor player ".. + minetest.formspec_escape(fields.stored_value_for_player).. + "\nto new value ".. + minetest.colorize("#FFFF00", fields.current_value_for_player)..".]".. + "button[1.5,1.5;2,0.9;back_from_msg;Back]"}) + return + -- remove the value for a player (set to nil) + elseif(fields and fields.unset_value_for_player and var_name + and fields.stored_value_for_player and fields.stored_value_for_player ~= "") then + yl_speak_up.set_quest_variable_value(fields.stored_value_for_player, var_name, nil) + yl_speak_up.show_fs(player, "msg", { + input_to = "yl_speak_up:manage_variables", + formspec = "size[10,2]".. + "label[0.2,0.0;Unset variable \"".. + minetest.colorize("#FFFF00", + minetest.formspec_escape(tostring(var_name))).. + "\"\nfor player ".. + minetest.formspec_escape(fields.stored_value_for_player).. + ".]".. + "button[1.5,1.5;2,0.9;back_from_msg;Back]"}) + return + -- delete (empty) variable elseif(fields and ((fields.delete_variable and fields.delete_variable ~= "") @@ -342,24 +381,57 @@ yl_speak_up.get_fs_manage_variables = function(player, param) node_pos_users, ", ")) end end - local debug_button = "button[10.0,8.05;4.0,0.6;list_debug_mode;What am I debugging?]".. + local debug_button = "button[10.0,10.05;4.0,0.6;list_debug_mode;What am I debugging?]".. "tooltip[list_debug_mode;".. "Show for which variables you currently have ".. "\nactivated the debug mode.]" local debuggers = yl_speak_up.get_variable_metadata(k_long, "debug") local i = table.indexof(debuggers, pname) if(i and i > 0) then - debug_button = "button[5.0,8.05;4.0,0.6;disable_debug_mode;Deactivate debug mode]".. + debug_button = "button[5.0,10.05;4.0,0.6;disable_debug_mode;Deactivate debug mode]".. "tooltip[disable_debug_mode;".. "You will no longer receive a chat message ".. "\nwhen this value changes for a player.]"..debug_button else - debug_button = "button[5.0,8.05;4.0,0.6;enable_debug_mode;Activate debug mode]".. + debug_button = "button[5.0,10.05;4.0,0.6;enable_debug_mode;Activate debug mode]".. "tooltip[enable_debug_mode;".. "You will receive a chat message whenever the value ".. "\nof this variable changes for one player. The debug\n".. "messages will be sent even after relogin.]"..debug_button end + -- checking/changing debug value for one specific player + if(not(param)) then + param = "" + end + debug_button = debug_button.. + "label[0.2,8.05;Show stored value for player:]".. + "field[4.2,8.15;4.0,0.9;stored_value_for_player;;".. + minetest.formspec_escape(param).."]".. + "button[8.2,7.85;4.0,0.9;show_stored_value_for_player;Show value for this player]".. + "tooltip[stored_value_for_player;Enter the name of the player for which you\n".. + "want to check (or change) the stored value.]".. + "tooltip[show_stored_value_for_player;Click here to read and the current value".. + "\nstored for this player.]" + if(param and param ~= "") then + local v = yl_speak_up.get_quest_variable_value(param, k_long) or "" + debug_button = debug_button.. + "label[0.2,9.05;Found stored value:]".. + "field[4.2,9.15;4.0,0.9;current_value_for_player;;".. + minetest.formspec_escape(v).."]".. + "tooltip[current_value_for_player;You can see and change the current ".. + "value here.]".. + "button[8.2,8.85;4.0,0.9;store_new_value_for_player;".. + "Store this as new value]".. + "tooltip[store_new_value_for_player;".. + "Click here to update the stored value for this player.".. + "\nWARNING: Be very careful here and never do this without".. + "\n informing the player about this change!]".. + "button[12.5,8.85;3.0,0.9;unset_value_for_player;".. + "Remove this entry]".. + "tooltip[unset_value_for_player;Click here to delete the entry for this ".. + "player.\nSetting the entry to an empty string would not be ".. + "the same!]" + end additional_buttons = "button[11.4,1.9;2.5,0.9;show_var_usage;Where is it used?]".. "tooltip[show_var_usage;Show which NPC use this variable in which context.]".. -- offer a dropdown list and a text input field for new varialbe names for adding @@ -403,7 +475,7 @@ yl_speak_up.get_fs_manage_variables = function(player, param) minetest.colorize("#FFFF00", tostring(c2)).." node positions:\n\t".. -- those are only pos_to_string(..) - no need to formspec_escape that minetest.colorize("#FFFF00", list_of_node_pos_users)..".]".. - "button[0.2,8.05;4.0,0.6;show_stored_values_for_var;Show all stored values]".. + "button[0.2,10.05;4.0,0.6;show_stored_values_for_var;Show all stored values]".. "tooltip[show_stored_values_for_var;A diffrent value can be stored for each ".. "player.\nShow these values in a table.]".. debug_button @@ -428,5 +500,5 @@ yl_speak_up.get_fs_manage_variables = function(player, param) ).. additional_buttons.. "button[0.0,0.2;1.0,0.6;back;Back]".. - "button[6.0,11.0;1.0,0.6;back;Back]" + "button[6.5,11.0;1.0,0.6;back;Back]" end