forked from Sokomine/yl_speak_up
added fs_show_all_var_values.lua
This commit is contained in:
parent
18b8529b3b
commit
420452e4ff
@ -86,8 +86,15 @@ yl_speak_up.input_fs_manage_variables = function(player, formname, fields)
|
||||
end
|
||||
|
||||
|
||||
-- show all stored values for a variable in a table
|
||||
if(fields and fields.show_stored_values_for_var) then
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:manage_variables",
|
||||
formspec = yl_speak_up.fs_show_all_var_values(player, pname, var_name)
|
||||
})
|
||||
return
|
||||
-- delete (empty) variable
|
||||
if(fields
|
||||
elseif(fields
|
||||
and ((fields.delete_variable and fields.delete_variable ~= "")
|
||||
or (fields.delete_unused_variable and fields.delete_unused_variable ~= ""))
|
||||
and var_name) then
|
||||
@ -341,9 +348,12 @@ yl_speak_up.get_fs_manage_variables = function(player, param)
|
||||
"label[0.2,7.05;This variable is used by the following "..
|
||||
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)..".]"
|
||||
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]"..
|
||||
"tooltip[show_stored_values_for_var;A diffrent value can be stored for each "..
|
||||
"player.\nShow these values in a table.]"
|
||||
end
|
||||
return "size[16,8.5]"..
|
||||
return "size[16,11.5]"..
|
||||
"label[5.0,0.0;* Manage your variables *]"..
|
||||
"label[0.2,0.8;Note: Each variable will store a diffrent value for each player who "..
|
||||
"interacts with the NPC.\n"..
|
||||
@ -363,7 +373,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,8.0;1.0,0.6;back;Back]"
|
||||
"button[6.0,11.0;1.0,0.6;back;Back]"
|
||||
end
|
||||
|
||||
|
||||
|
64
fs_show_all_var_values.lua
Normal file
64
fs_show_all_var_values.lua
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
-- called only by mange_variables formspec
|
||||
yl_speak_up.fs_show_all_var_values = function(player, pname, var_name)
|
||||
-- wrong parameters? no need to show an error message here
|
||||
if(not(var_name) or not(pname) or not(player)) then
|
||||
return ""
|
||||
end
|
||||
-- TODO: check if the player really has read access to this variable
|
||||
var_name = yl_speak_up.restore_complete_var_name(var_name, pname)
|
||||
|
||||
-- player names with values as key; normally the player name is the key and
|
||||
-- the value the value - but that would be a too long list to display, and
|
||||
-- so we rearrange the array for display here
|
||||
local players_with_value = {}
|
||||
-- the diffrent values that exist
|
||||
local values = {}
|
||||
local var_data = yl_speak_up.player_vars[ var_name ]
|
||||
local count_players = 0
|
||||
for player_name, v in pairs(var_data) do
|
||||
-- metadata is diffrent and not of relevance here
|
||||
if(player_name and player_name ~= "$META$" and v) then
|
||||
if(not(players_with_value[ v ])) then
|
||||
players_with_value[ v ] = {}
|
||||
table.insert(values, v)
|
||||
end
|
||||
table.insert(players_with_value[ v ], player_name)
|
||||
count_players = count_players + 1
|
||||
end
|
||||
end
|
||||
-- the values ought to be shown in a sorted way
|
||||
table.sort(values)
|
||||
|
||||
-- construct the lines that shall form the table
|
||||
local lines = {"#FFFFFF,Value:,#FFFFFF,Players for which this value is stored:"}
|
||||
for i, v in ipairs(values) do
|
||||
table.insert(lines,
|
||||
"#FFFF00,"..minetest.formspec_escape(v)..",#CCCCCC,"..
|
||||
-- text, prefix, line_length, max_lines
|
||||
yl_speak_up.wrap_long_lines_for_table(
|
||||
table.concat(players_with_value[ v ], ", "),
|
||||
",,,#CCCCCC,", 80, 8))
|
||||
end
|
||||
-- true here means: lines are already sorted;
|
||||
-- ",": don't insert blank lines between entries
|
||||
local formspec = yl_speak_up.print_as_table_prepare_formspec(lines, "table_of_variable_values",
|
||||
"back_from_msg", "Back", true, ",",
|
||||
"color,span=1;text;color,span=1;text") -- the table columns
|
||||
table.insert(formspec,
|
||||
"label[18.0,1.8;"..
|
||||
minetest.formspec_escape("For variable \""..
|
||||
minetest.colorize("#FFFF00", tostring(var_name or "- ? -"))..
|
||||
"\", these values are stored:").."]")
|
||||
|
||||
if(values and #values > 0) then
|
||||
table.insert(formspec,
|
||||
"label[18.0,31.0;The variable holds "..
|
||||
minetest.colorize("#FFFF00", tostring(#values)).." diffrent values for "..
|
||||
minetest.colorize("#FFFF00", tostring(count_players)).." diffrent players.]")
|
||||
else
|
||||
table.insert(formspec,
|
||||
"label[18.0,31.0;The variable does not currently hold any stored values.]")
|
||||
end
|
||||
return table.concat(formspec, "\n")
|
||||
end
|
2
init.lua
2
init.lua
@ -53,6 +53,8 @@ dofile(modpath .. "trade_simple.lua")
|
||||
dofile(modpath .. "trade_list.lua")
|
||||
-- as the name says: list which npc acesses a variable how and in which context
|
||||
dofile(modpath .. "fs_get_list_of_usage_of_variable.lua")
|
||||
-- show which values are stored for which player in a quest variable
|
||||
dofile(modpath .. "fs_show_all_var_values.lua")
|
||||
-- manage quest variables: add, delete, manage access rights etc.
|
||||
dofile(modpath .. "fs_manage_variables.lua")
|
||||
-- handle variables for quests for player-owned NPC
|
||||
|
Loading…
Reference in New Issue
Block a user