Added modpol.interactions.display and display_processes module, as well as a bunch of bugfixes
This commit is contained in:
@ -49,7 +49,6 @@ function modpol.interactions.dashboard(user)
|
||||
local user_orgs = modpol.orgs.user_orgs(user)
|
||||
local all_users = modpol.instance:list_members()
|
||||
-- pending list
|
||||
local user_pending = {"View..."}
|
||||
local user_pending_count = 0
|
||||
for k,v in ipairs(modpol.orgs.array) do
|
||||
if v.pending and v.pending[user] then
|
||||
@ -64,15 +63,15 @@ function modpol.interactions.dashboard(user)
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[10,8]",
|
||||
"label[0.5,0.5;M O D P O L]",
|
||||
"hypertext[0.5,0.5;9,1;title;<big>Org dashboard</big>]",
|
||||
"label[0.5,2;All orgs:]",
|
||||
"dropdown[2,1.5;7,0.8;all_orgs;"..formspec_list(all_orgs)..";;]",
|
||||
"dropdown[2,1.5;7,0.8;all_orgs;View...,"..formspec_list(all_orgs)..";;]",
|
||||
"label[0.5,3;Your orgs:]",
|
||||
"dropdown[2,2.5;7,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
||||
"dropdown[2,2.5;7,0.8;user_orgs;View...,"..formspec_list(user_orgs)..";;]",
|
||||
"label[0.5,4;All users:]",
|
||||
"dropdown[2,3.5;7,0.8;all_users;"..formspec_list(all_users)..";;]",
|
||||
"dropdown[2,3.5;7,0.8;all_users;View...,"..formspec_list(all_users)..";;]",
|
||||
"label[0.5,5;Pending ("..user_pending_count.."):]",
|
||||
"dropdown[2,4.5;7,0.8;pending;"..formspec_list(user_pending)..";;]",
|
||||
"dropdown[2,4.5;7,0.8;pending;View...,"..formspec_list(user_pending)..";;]",
|
||||
"button[0.5,7;1,0.8;refresh;Refresh]",
|
||||
"button_exit[8.5,7;1,0.8;close;Close]",
|
||||
}
|
||||
@ -90,7 +89,8 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
elseif fields.refresh then
|
||||
modpol.interactions.dashboard(pname)
|
||||
-- Put all dropdowns at the end
|
||||
elseif fields.all_users then
|
||||
elseif fields.all_users
|
||||
and fields.all_users ~= "View..." then
|
||||
modpol.interactions.user_dashboard(
|
||||
pname,
|
||||
fields.all_users,
|
||||
@ -100,7 +100,10 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
)
|
||||
elseif fields.all_orgs or fields.user_orgs or fields.pending then
|
||||
local org_name = fields.all_orgs or fields.user_orgs or fields.pending
|
||||
modpol.interactions.org_dashboard(pname, org_name)
|
||||
if org_name ~= "View..." then
|
||||
modpol.interactions.org_dashboard(
|
||||
pname, org_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
@ -129,6 +132,9 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
if parent then parent = parent.name
|
||||
else parent = "none" end
|
||||
|
||||
-- prepare members menu
|
||||
local members = org.members
|
||||
|
||||
-- prepare children menu
|
||||
local children = {}
|
||||
for k,v in ipairs(org.children) do
|
||||
@ -136,7 +142,6 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
table.insert(children, this_child.name)
|
||||
end
|
||||
table.sort(children)
|
||||
table.insert(children,1,"View...")
|
||||
|
||||
-- prepare modules menu
|
||||
local modules = {}
|
||||
@ -149,7 +154,6 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
end
|
||||
end
|
||||
table.sort(modules)
|
||||
table.insert(modules,1,"View...")
|
||||
|
||||
-- prepare pending menu
|
||||
local pending = {}
|
||||
@ -163,7 +167,6 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
end
|
||||
end
|
||||
table.sort(pending)
|
||||
table.insert(pending,1,"View...")
|
||||
|
||||
-- set player context
|
||||
local user_context = {}
|
||||
@ -173,17 +176,17 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[10,8]",
|
||||
"label[0.5,0.5;Org: "..
|
||||
minetest.formspec_escape(org.name)..membership_toggle(org.name).."]",
|
||||
"label[0.5,1;Parent: "..parent..membership_toggle(parent).."]",
|
||||
"hypertext[0.5,0.5;9,1;title;<big>Org: <b>"..
|
||||
minetest.formspec_escape(org.name).."</b>"..membership_toggle(org.name).."</big>]",
|
||||
"label[0.5,1.25;Parent: "..parent..membership_toggle(parent).."]",
|
||||
"label[0.5,2;Members:]",
|
||||
"dropdown[2,1.5;7,0.8;members;"..formspec_list(org.members)..";;]",
|
||||
"dropdown[2,1.5;7,0.8;members;View...,"..formspec_list(members)..";;]",
|
||||
"label[0.5,3;Child orgs:]",
|
||||
"dropdown[2,2.5;7,0.8;children;"..formspec_list(children)..";;]",
|
||||
"dropdown[2,2.5;7,0.8;children;View...,"..formspec_list(children)..";;]",
|
||||
"label[0.5,4;Modules:]",
|
||||
"dropdown[2,3.5;7,0.8;modules;"..formspec_list(modules)..";;]",
|
||||
"dropdown[2,3.5;7,0.8;modules;View...,"..formspec_list(modules)..";;]",
|
||||
"label[0.5,5;Pending ("..num_pending.."):]",
|
||||
"dropdown[2,4.5;7,0.8;pending;"..formspec_list(pending)..";;]",
|
||||
"dropdown[2,4.5;7,0.8;pending;View...,"..formspec_list(pending)..";;]",
|
||||
"button[0.5,7;1,0.8;refresh;Refresh]",
|
||||
"button[8.5,7;1,0.8;back;Back]",
|
||||
}
|
||||
@ -210,7 +213,8 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
|
||||
-- Put all dropdowns at the end
|
||||
-- Receiving modules
|
||||
elseif fields.members then
|
||||
elseif fields.members
|
||||
and fields.members ~= "View..." then
|
||||
modpol.interactions.user_dashboard(
|
||||
pname,
|
||||
fields.members,
|
||||
@ -268,7 +272,6 @@ end)
|
||||
-- @param completion Optional function to call on Done button
|
||||
function modpol.interactions.user_dashboard(viewer, user, completion)
|
||||
local user_orgs = modpol.orgs.user_orgs(user)
|
||||
table.insert(user_orgs,1,"View...")
|
||||
|
||||
-- set player context
|
||||
local user_context = {}
|
||||
@ -280,9 +283,9 @@ function modpol.interactions.user_dashboard(viewer, user, completion)
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[10,8]",
|
||||
"label[0.5,0.5;User: "..user.."]",
|
||||
"hypertext[0.5,0.5;9,1;title;<big>User: <b>"..user.."</b></big>]",
|
||||
"label[0.5,2;User's orgs:]",
|
||||
"dropdown[2,1.5;7,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
||||
"dropdown[2,1.5;7,0.8;user_orgs;View...,"..formspec_list(user_orgs)..";;]",
|
||||
"button[0.5,7;1.5,0.8;message;Message]",
|
||||
"button_exit[8.5,7;1,0.8;close;Close]",
|
||||
}
|
||||
@ -350,10 +353,51 @@ end
|
||||
--- Function: modpol.interactions.display
|
||||
-- Displays complex data to a user
|
||||
-- @param user Name of target user (string)
|
||||
-- @param title Title of display (string)
|
||||
-- @param message Content of message (string or table of strings)
|
||||
-- @param done Optional function for what happens when user is done
|
||||
|
||||
|
||||
-- @param completion Optional function for what happens when user is done
|
||||
function modpol.interactions.display(
|
||||
user, title, message, completion)
|
||||
-- set up contexts
|
||||
_contexts[user]["completion"] = completion
|
||||
-- set up output
|
||||
local output = ""
|
||||
if type(message) == "table" then
|
||||
output = table.concat(message,"\n")
|
||||
elseif type(message) == "string" then
|
||||
output = message
|
||||
elseif type(message) == "number" then
|
||||
output = message
|
||||
else
|
||||
modpol.interactions.message(
|
||||
self.initiator, "Error: message not typed for display")
|
||||
if completion then completion() else
|
||||
modpol.intereactions.dashboard(user)
|
||||
end
|
||||
return
|
||||
end
|
||||
-- set up formspec
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[10,8]",
|
||||
"label[0.5,0.5;"..title.."]",
|
||||
"hypertext[0.5,1;9,5.5;display;<global background=black margin=10>"..output.."]",
|
||||
"button_exit[8.5,7;1,0.8;done;Done]",
|
||||
}
|
||||
local formspec_string = table.concat(formspec, "")
|
||||
-- present to player
|
||||
minetest.show_formspec(user, "modpol:display", formspec_string)
|
||||
end
|
||||
-- receive fields
|
||||
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
local pname = player:get_player_name()
|
||||
if formname == "modpol:display" then
|
||||
if fields.done and _contexts[pname].completion then
|
||||
minetest.close_formspec(pname, formname)
|
||||
_contexts[pname].completion()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Function: modpol.interactions.text_query
|
||||
-- Overrides function at modpol/interactions.lua
|
||||
@ -399,14 +443,12 @@ end)
|
||||
-- func input: choice (string)
|
||||
-- output: calls func on user choice
|
||||
function modpol.interactions.dropdown_query(user, label, options, func)
|
||||
-- Add "View..." to the top of the list
|
||||
table.insert(options,1,"View...")
|
||||
-- set up formspec
|
||||
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;"..formspec_list(options)..";;]",
|
||||
"dropdown[0.5,1.25;9,0.8;input;View...,"..formspec_list(options)..";;]",
|
||||
"button[0.5,2.5;1,0.8;cancel;Cancel]",
|
||||
}
|
||||
local formspec_string = table.concat(formspec, "")
|
||||
|
Reference in New Issue
Block a user