allow to show and change the value of a variable via the manage variables formspec

This commit is contained in:
Sokomine 2021-08-03 22:55:59 +02:00
parent c5aca7d9a8
commit 47c7e7ab30

View File

@ -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), ",").."]".. table.concat(yl_speak_up.get_list_of_debugged_variables(pname), ",").."]"..
"button[1.5,5.5;2,0.9;back_from_msg;Back]"}) "button[1.5,5.5;2,0.9;back_from_msg;Back]"})
return 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 -- delete (empty) variable
elseif(fields elseif(fields
and ((fields.delete_variable and fields.delete_variable ~= "") 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, ", ")) node_pos_users, ", "))
end end
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;".. "tooltip[list_debug_mode;"..
"Show for which variables you currently have ".. "Show for which variables you currently have "..
"\nactivated the debug mode.]" "\nactivated the debug mode.]"
local debuggers = yl_speak_up.get_variable_metadata(k_long, "debug") local debuggers = yl_speak_up.get_variable_metadata(k_long, "debug")
local i = table.indexof(debuggers, pname) local i = table.indexof(debuggers, pname)
if(i and i > 0) then 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;".. "tooltip[disable_debug_mode;"..
"You will no longer receive a chat message ".. "You will no longer receive a chat message "..
"\nwhen this value changes for a player.]"..debug_button "\nwhen this value changes for a player.]"..debug_button
else 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;".. "tooltip[enable_debug_mode;"..
"You will receive a chat message whenever the value ".. "You will receive a chat message whenever the value "..
"\nof this variable changes for one player. The debug\n".. "\nof this variable changes for one player. The debug\n"..
"messages will be sent even after relogin.]"..debug_button "messages will be sent even after relogin.]"..debug_button
end 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?]".. 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.]".. "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 -- 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".. minetest.colorize("#FFFF00", tostring(c2)).." node positions:\n\t"..
-- those are only pos_to_string(..) - no need to formspec_escape that -- those are only pos_to_string(..) - no need to formspec_escape that
minetest.colorize("#FFFF00", list_of_node_pos_users)..".]".. 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 ".. "tooltip[show_stored_values_for_var;A diffrent value can be stored for each "..
"player.\nShow these values in a table.]".. "player.\nShow these values in a table.]"..
debug_button debug_button
@ -428,5 +500,5 @@ yl_speak_up.get_fs_manage_variables = function(player, param)
).. )..
additional_buttons.. additional_buttons..
"button[0.0,0.2;1.0,0.6;back;Back]".. "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 end