81 lines
3.1 KiB
Lua
81 lines
3.1 KiB
Lua
|
|
-- ===================================================================
|
|
-- Function: modpol.dashboard(user)
|
|
-- Params: user (string)
|
|
-- Q: Should this return a menu of commands relevant to the specific user?
|
|
-- Output: Displays a menu of commands to the user
|
|
-- TKTK currently a manually curated list---needs major improvement
|
|
modpol.dashboard = function(user)
|
|
-- prepare data
|
|
-- to add: my orgs, nested orgs map
|
|
local commands = "Command list: "
|
|
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(), ", ")
|
|
-- 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), "]",
|
|
"button[0.5,7;1,0.8;yes;Done]",
|
|
}
|
|
local formspec_string = table.concat(formspec, "")
|
|
-- present to player
|
|
minetest.show_formspec(user, "modpol:dashboard", formspec_string)
|
|
end
|
|
|
|
-- ===================================================================
|
|
-- Function: modpol.binary_poll_user(user, question)
|
|
-- Overwrites function at /interactions.lua
|
|
-- presents a yes/no/abstain poll to a user, returns answer
|
|
modpol.binary_poll_user = function(user, question)
|
|
-- set up formspec
|
|
local text = "Poll: " .. question
|
|
local formspec = {
|
|
"formspec_version[4]",
|
|
"size[5,3]",
|
|
"label[0.375,0.5;", minetest.formspec_escape(text), "]",
|
|
"button[1,1.5;1,0.8;yes;Yes]",
|
|
"button[2,1.5;1,0.8;no;No]",
|
|
"button[3,1.5;1,0.8;abstain;Abstain]"
|
|
--TKTK can we enable text wrapping?
|
|
--TKTK we could use scroll boxes to contain the text
|
|
}
|
|
local formspec_string = table.concat(formspec, "")
|
|
-- present to player
|
|
minetest.show_formspec(user, "modpol:binary_poll", formspec_string)
|
|
end
|
|
|
|
-- ===================================================================
|
|
-- Register input fields from forms
|
|
-- Minetest-specific; does not overwrite
|
|
-- separate this out into discrete functions?
|
|
-- how do we ensure this is maximally modular?
|
|
-- Perhaps create a table of possible formnames and their associated functions
|
|
-- Then we can easily add to the table of possible options
|
|
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
-- modpol:binary_poll
|
|
if formname == "modpol:binary_poll" then
|
|
local pname = player:get_player_name()
|
|
local vote = nil
|
|
if fields.yes then vote = fields.yes
|
|
elseif fields.no then vote = fields.no
|
|
elseif fields.abstain then vote = fields.abstain
|
|
end
|
|
if vote then
|
|
minetest.chat_send_all(pname .. " voted " .. vote)
|
|
--TKTK : we should send the message to all in that org, definately not to all players
|
|
end
|
|
minetest.close_formspec(pname, formname)
|
|
return vote
|
|
else -- if the form is not a recognized name
|
|
return
|
|
end
|
|
end)
|