Set up dropdowns in dashboard
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
-- ===================================================================
|
||||
-- INTERACTIONS.LUA (for Minetest)
|
||||
|
||||
-- CONTEXTUAL STUFF
|
||||
-- ================
|
||||
|
||||
-- First, set up contexts to enable passing across formspecs
|
||||
-- https://rubenwardy.com/minetest_modding_book/en/players/formspecs.html#contexts
|
||||
@ -17,8 +19,26 @@ end)
|
||||
-- table of formspec field responses
|
||||
local formspec_fields = {}
|
||||
|
||||
-- ===================================================================
|
||||
|
||||
-- UTILITIES
|
||||
-- =========
|
||||
|
||||
-- Function: formspec_list
|
||||
-- for use generating option lists in formspecs from tables
|
||||
-- input: table of strings
|
||||
-- output: a formspec-ready list of the strings
|
||||
local function formspec_list(array)
|
||||
local escaped = {}
|
||||
for i = 1, #array do
|
||||
escaped[i] = minetest.formspec_escape(array[i])
|
||||
end
|
||||
return table.concat(escaped,",")
|
||||
end
|
||||
|
||||
|
||||
-- MAIN MODPOL DASHBOARD
|
||||
-- =====================
|
||||
|
||||
-- Function: modpol.interactions.dashboard(user)
|
||||
-- Params: user (string)
|
||||
-- Q: Should this return a menu of commands relevant to the specific user?
|
||||
@ -31,17 +51,22 @@ function modpol.interactions.dashboard(user)
|
||||
for key,value in pairs(command_list) do
|
||||
commands = commands .. "/" .. value .. " "
|
||||
end
|
||||
local orgs = "Orgs: " ..
|
||||
table.concat(modpol.orgs.list_all(), ", ")
|
||||
local users = "Players: "
|
||||
.. table.concat(modpol.list_users(), ", ")
|
||||
local all_orgs = modpol.orgs.list_all()
|
||||
local user_orgs = modpol.orgs.user_orgs(user)
|
||||
local all_users = modpol.list_users()
|
||||
-- set up formspec
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[10,8]",
|
||||
"label[0.5,0.5;", minetest.formspec_escape(commands), "]",
|
||||
"label[0.5,1.5;", minetest.formspec_escape(orgs), "]",
|
||||
"label[0.5,2.5;", minetest.formspec_escape(users), "]",
|
||||
"label[0.5,0.5;MODULAR POLITICS]",
|
||||
"label[0.5,2;All orgs:]",
|
||||
"dropdown[2,1.5;5,0.8;user_orgs;"..formspec_list(all_orgs)..";;]",
|
||||
"label[0.5,3;Your orgs:]",
|
||||
"dropdown[2,2.5;5,0.8;input;"..formspec_list(user_orgs)..";;]",
|
||||
"label[0.5,4;All users:]",
|
||||
"dropdown[2,3.5;5,0.8;input;"..formspec_list(all_users)..";;]",
|
||||
"label[0.5,5;Processes:]",
|
||||
"dropdown[2,4.5;5,0.8;input;TBA;;]",
|
||||
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
||||
"button[2,7;1,0.8;add_org;Add org]",
|
||||
"button[3.5,7;1.5,0.8;remove_org;Remove org]",
|
||||
@ -65,7 +90,9 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
end
|
||||
end)
|
||||
|
||||
-- BASIC INTERACTION FUNCTIONS --
|
||||
|
||||
-- BASIC INTERACTION FUNCTIONS
|
||||
-- ===========================
|
||||
|
||||
-- Function: modpol.interactions.message
|
||||
-- input: message (string)
|
||||
@ -103,16 +130,16 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
-- Function: dropdown_query
|
||||
-- input: user (string), label (string), options (table of strings)
|
||||
function modpol.interactions.dropdown_query(user, label, options)
|
||||
-- set up formspec
|
||||
local options_string = table.concat(options,",")
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[10,4]",
|
||||
"label[0.5,1;", minetest.formspec_escape(label), "]",
|
||||
"dropdown[0.5,1.25;9,0.8;input;".. minetest.formspec_escape(options_string)..";;]",
|
||||
"label[0.5,1;"..minetest.formspec_escape(label).."]",
|
||||
"dropdown[0.5,1.25;9,0.8;input;"..formspec_list(options)..";;]",
|
||||
"button[0.5,2.5;1,0.8;yes;OK]",
|
||||
}
|
||||
local formspec_string = table.concat(formspec, "")
|
||||
@ -190,7 +217,6 @@ function modpol.interactions.binary_poll_org(initiator, org)
|
||||
modpol.interactions.binary_poll_user(v, input)
|
||||
end
|
||||
_contexts[initiator] = nil
|
||||
modpol.interactions.dashboard(initiator)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user