forked from your-land-mirror/yl_speak_up
42 lines
1.8 KiB
Lua
42 lines
1.8 KiB
Lua
|
|
-- helper function:
|
|
-- create a formspec dropdown list with player names (first entry: Add player) and
|
|
-- an option to delete players from that list
|
|
yl_speak_up.create_dropdown_playerlist = function(player, pname,
|
|
table_of_names, index_selected,
|
|
start_x, start_y, dropdown_name,
|
|
field_name_for_adding_player, explain_add_player,
|
|
field_name_for_deleting_player, explain_delete_player)
|
|
|
|
local text = "dropdown["..tostring(start_x)..","..tostring(start_y)..";3.8;"..
|
|
tostring(dropdown_name)..";Add player:"
|
|
-- table_of_names is a table with the playernames as keys
|
|
-- we want to work with indices later on; in order to be able to do that reliably, we
|
|
-- need a defined order of names
|
|
local tmp_list = yl_speak_up.sort_keys(table_of_names, true)
|
|
for i, p in ipairs(tmp_list) do
|
|
text = text..","..minetest.formspec_escape(p)
|
|
end
|
|
-- has an entry been selected?
|
|
if(not(index_selected) or index_selected < 0 or index_selected > #tmp_list+1) then
|
|
index_selected = 1
|
|
end
|
|
text = text..";"..tostring(index_selected)..";]"
|
|
if(index_selected == 1) then
|
|
-- first index "Add player" selected? Then offer a field for entering the name
|
|
text = text.."field["..tostring(start_x + 4.0)..","..tostring(start_y + 0.3)..";3.5,0.9;"..
|
|
tostring(field_name_for_adding_player)..";;]"..
|
|
"tooltip["..tostring(field_name_for_adding_player)..";"..
|
|
"Enter the name of the player whom you\n"..
|
|
"want to grant the right to "..tostring(explain_add_player).."]"
|
|
else
|
|
text = text.."button["..tostring(start_x + 3.8)..","..tostring(start_y)..";3.5,0.9;"..
|
|
tostring(field_name_for_deleting_player)..";"..
|
|
"Remove player from list]"..
|
|
"tooltip["..tostring(field_name_for_deleting_player)..";"..
|
|
"If you click here, the player will no\n"..
|
|
"longer be able to "..tostring(explain_delete_player).."]"
|
|
end
|
|
return text
|
|
end
|