Added user_dashboard and message_user to modpol_minetest
This commit is contained in:
parent
de8ad25b2f
commit
18a29d674c
@ -211,11 +211,8 @@ function modpol.interactions.user_dashboard(viewer, user, completion)
|
||||
local sel = io.read()
|
||||
|
||||
if sel == "M" or sel == "m" then
|
||||
print("Enter your message for "..user..":")
|
||||
sel = io.read()
|
||||
print("Sending message")
|
||||
modpol.interactions.message_user(
|
||||
viewer, user, sel)
|
||||
viewer, user)
|
||||
completion()
|
||||
else
|
||||
completion()
|
||||
@ -237,14 +234,15 @@ function modpol.interactions.message(user, message)
|
||||
end
|
||||
|
||||
--- Function: modpol.interactions.message_user
|
||||
-- Sends a message from one user to another
|
||||
-- Gets and sends a message from one user to another
|
||||
-- @param sender Name of user sending (string)
|
||||
-- @param recipient Name of user receiving (string)
|
||||
-- @param message Message to be sent (string)
|
||||
function modpol.interactions.message_user(sender, recipient, message)
|
||||
function modpol.interactions.message_user(sender, recipient)
|
||||
print("Enter your message for "..recipient..":")
|
||||
local sel = io.read()
|
||||
modpol.interactions.message(
|
||||
recipient,
|
||||
message.." [from "..sender.."]")
|
||||
sel.." [from "..sender.."]")
|
||||
end
|
||||
|
||||
--- Function: modpol.interactions.display
|
||||
|
@ -89,7 +89,15 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
minetest.close_formspec(pname, formname)
|
||||
elseif fields.refresh then
|
||||
modpol.interactions.dashboard(pname)
|
||||
-- Put all dropdowns at the end
|
||||
-- Put all dropdowns at the end
|
||||
elseif fields.all_users then
|
||||
modpol.interactions.user_dashboard(
|
||||
pname,
|
||||
fields.all_users,
|
||||
function()
|
||||
modpol.interactions.dashboard(pname)
|
||||
end
|
||||
)
|
||||
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)
|
||||
@ -169,7 +177,7 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
minetest.formspec_escape(org.name)..membership_toggle(org.name).."]",
|
||||
"label[0.5,1;Parent: "..parent..membership_toggle(parent).."]",
|
||||
"label[0.5,2;Members:]",
|
||||
"dropdown[2,1.5;7,0.8;user_orgs;"..formspec_list(org.members)..";;]",
|
||||
"dropdown[2,1.5;7,0.8;members;"..formspec_list(org.members)..";;]",
|
||||
"label[0.5,3;Child orgs:]",
|
||||
"dropdown[2,2.5;7,0.8;children;"..formspec_list(children)..";;]",
|
||||
"label[0.5,4;Modules:]",
|
||||
@ -198,10 +206,19 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
elseif fields.back then
|
||||
modpol.interactions.dashboard(pname)
|
||||
elseif fields.refresh then
|
||||
modpol.interactions.org_dashboard(pname,org.name)
|
||||
modpol.interactions.org_dashboard(pname, org.name)
|
||||
|
||||
-- Put all dropdowns at the end
|
||||
-- Receiving modules
|
||||
-- Receiving modules
|
||||
elseif fields.members then
|
||||
modpol.interactions.user_dashboard(
|
||||
pname,
|
||||
fields.members,
|
||||
function()
|
||||
modpol.interactions.org_dashboard(
|
||||
pname, org.name)
|
||||
end
|
||||
)
|
||||
elseif fields.modules
|
||||
and fields.modules ~= "View..." then
|
||||
local module = nil
|
||||
@ -244,17 +261,60 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
end
|
||||
end)
|
||||
|
||||
--- Function: modpol.interactions.user_dashboard
|
||||
-- Displays a dashboard about a particular user
|
||||
-- @param viewer Name of user viewing the dashboard (string)
|
||||
-- @param user Name of user being viewed (string)
|
||||
-- @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...")
|
||||
|
||||
-- Function: modpol.interactions.policy_dashboard
|
||||
-- input: user (string), org_id (int), policy (string)
|
||||
-- output: opens a dashboard for viewing/editing policy details
|
||||
-- TODO
|
||||
function modpol.interactions.policy_dashboard(
|
||||
user, org_id, policy)
|
||||
modpol.interactions.message(
|
||||
user,
|
||||
"Not yet implemented: " .. policy)
|
||||
-- set player context
|
||||
local user_context = {}
|
||||
user_context["viewer"] = viewer
|
||||
user_context["user"] = user
|
||||
user_context["completion"] = completion
|
||||
_contexts[viewer] = user_context
|
||||
-- set up formspec
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[10,8]",
|
||||
"label[0.5,0.5;User: "..user.."]",
|
||||
"label[0.5,2;User's orgs:]",
|
||||
"dropdown[2,1.5;7,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
||||
"button[0.5,7;1.5,0.8;message;Message]",
|
||||
"button_exit[8.5,7;1,0.8;close;Close]",
|
||||
}
|
||||
local formspec_string = table.concat(formspec, "")
|
||||
-- present to player
|
||||
minetest.show_formspec(viewer, "modpol:user_dashboard", formspec_string)
|
||||
end
|
||||
-- receive input
|
||||
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
if formname == "modpol:user_dashboard" then
|
||||
local contexts = _contexts[player:get_player_name()]
|
||||
-- check fields
|
||||
if nil then
|
||||
elseif fields.message then
|
||||
modpol.interactions.message_user(
|
||||
contexts.viewer, contexts.user
|
||||
)
|
||||
elseif fields.back then
|
||||
if contexts.completion then
|
||||
completion()
|
||||
else
|
||||
modpol.interactions.dashboard(
|
||||
contexts.viewer)
|
||||
end
|
||||
-- dropdown fields
|
||||
elseif fields.user_orgs
|
||||
and fields.user_orgs ~= "View..." then
|
||||
modpol.interactions.org_dashboard(
|
||||
contexts.viewer, fields.user_orgs)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
-- INTERACTION PRIMITIVES
|
||||
@ -271,6 +331,22 @@ function modpol.interactions.message(user, message)
|
||||
end
|
||||
|
||||
|
||||
--- Function: modpol.interactions.message_user
|
||||
-- Gets and sends a message from one user to another
|
||||
-- @param sender Name of user sending (string)
|
||||
-- @param recipient Name of user receiving (string)
|
||||
function modpol.interactions.message_user(sender, recipient)
|
||||
modpol.interactions.text_query(
|
||||
sender,
|
||||
"Message for "..recipient..":",
|
||||
function(input)
|
||||
modpol.interactions.message(
|
||||
recipient,
|
||||
input.." [from "..sender.."]")
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
--- Function: modpol.interactions.display
|
||||
-- Displays complex data to a user
|
||||
-- @param user Name of target user (string)
|
||||
|
Loading…
x
Reference in New Issue
Block a user