Загрузить файлы в «ui»

This commit is contained in:
Nomad Senaxsys 2024-09-28 22:39:39 +03:00
parent be479fd9f1
commit ce11e9a180
5 changed files with 741 additions and 0 deletions

86
ui/edit_maillists.lua Normal file
View File

@ -0,0 +1,86 @@
-- translation
local S = mail.S
local FORMNAME = "mail:editmaillist"
function mail.show_edit_maillist(playername, maillist_name, desc, players, illegal_name_hint)
local formspec = [[
size[6,7]
button[4,6.25;2,0.5;back;]] .. S("Back") .. [[]
field[0.25,0.5;4,1;name;]] .. S("Maillist name") .. [[:;%s]
textarea[0.25,1.6;4,2;desc;]] .. S("Desc") .. [[:;%s]
textarea[0.25,3.6;4,4.25;players;]] .. S("Players") .. [[:;%s]
button[4,0.10;2,1;save;]] .. S("Save") .. [[]
]]
if illegal_name_hint == "collision" then
formspec = formspec .. [[
textarea[4.25,1;2.5,6;;;]] ..
S("That name is already in your mailing lists.") .. [[]
]]
elseif illegal_name_hint == "empty" then
formspec = formspec .. [[
textarea[4.25,1;2.5,6;;;]] ..
S("The mailing list name cannot be empty.") .. [[]
]]
end
formspec = formspec .. mail.theme
formspec = string.format(formspec,
minetest.formspec_escape(maillist_name or ""),
minetest.formspec_escape(desc or ""),
minetest.formspec_escape(players or ""))
minetest.show_formspec(playername, FORMNAME, formspec)
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then
return
end
local name = player:get_player_name()
local maillists = mail.get_maillists(name)
if fields.save then
local old_maillist = maillists[mail.selected_idxs.maillists[name]] or {name = ""}
if mail.selected_idxs.maillists[name] then
if old_maillist.name ~= fields.name or fields.name == "" then
-- name changed!
if #fields.name == 0 then
mail.show_edit_maillist(name, old_maillist.name, fields.desc, fields.players, "empty")
return true
elseif mail.get_maillist_by_name(name, fields.name) then
mail.show_edit_maillist(name, old_maillist.name, fields.desc, fields.players, "collision")
return true
else
mail.update_maillist(name, {
owner = name,
name = fields.name,
desc = fields.desc,
players = mail.parse_player_list(fields.players)
}, old_maillist.name)
end
else
mail.update_maillist(name, {
owner = name,
name = fields.name,
desc = fields.desc,
players = mail.parse_player_list(fields.players)
}, old_maillist.name)
end
else
mail.update_maillist(name, {
owner = name,
name = fields.name,
desc = fields.desc,
players = mail.parse_player_list(fields.players)
}, old_maillist.name)
end
mail.show_maillists(name)
elseif fields.back then
mail.show_maillists(name)
end
return true
end)

374
ui/events.lua Normal file
View File

@ -0,0 +1,374 @@
-- Getter to filter and sort messages on demand
local function message_getter(messages, sortfield, ascending, filter)
local results
return function()
if not results then
results = mail.sort_messages(messages, sortfield, ascending, filter)
end
return results
end
end
local function nonempty(x)
return ((type(x)=="table")and(#x>0))
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "mail:inbox" and formname ~= "mail:outbox"
and formname ~= "mail:drafts" and formname ~= "mail:trash" then
return
end
if fields.quit then
return true
end
-- Get player name and handle / convert common input fields
local name = player:get_player_name()
local filter = (fields.search and fields.filter) or mail.selected_idxs.filter[name] or ""
local sortfieldindex = tonumber(fields.sortfield or mail.selected_idxs.sortfield[name]) or 3
local sortdirection = fields.sortdirection or mail.selected_idxs.sortdirection[name] or "1"
local inboxsortfield = ({"from","subject","time"})[sortfieldindex]
local outboxsortfield = ({"to","subject","time"})[sortfieldindex]
-- Be sure that inbox/outbox selected idxs aren't nil
mail.selected_idxs.inbox[name] = mail.selected_idxs.inbox[name] or {}
mail.selected_idxs.outbox[name] = mail.selected_idxs.outbox[name] or {}
-- Store common player configuration for reuse
mail.selected_idxs.sortfield[name] = sortfieldindex
mail.selected_idxs.sortdirection[name] = sortdirection
mail.selected_idxs.filter[name] = filter
if fields.multipleselection then
mail.selected_idxs.multipleselection[name] = fields.multipleselection == "true"
end
-- Avoid several selected after disabling the multiple selection
if not mail.selected_idxs.multipleselection[name] then
mail.selected_idxs.inbox[name] = { mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]] }
mail.selected_idxs.outbox[name] = { mail.selected_idxs.outbox[name][#mail.selected_idxs.outbox[name]] }
end
-- split inbox and outbox msgs for different tests
local entry = mail.get_storage_entry(name)
local messagesDrafts = entry.drafts
local messagesTrash = entry.trash
local getInbox = message_getter(entry.inbox, inboxsortfield, sortdirection == "2", filter)
local getOutbox = message_getter(entry.outbox, outboxsortfield, sortdirection == "2", filter)
-- Hanmdle formspec event
if fields.inbox then -- inbox table
local evt = minetest.explode_table_event(fields.inbox)
if evt.row == 1 then -- header
if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction
mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2"
end
mail.selected_idxs.sortfield[name] = evt.column-1 -- update column
mail.show_mail_menu(name)
return true
end
local inbox = getInbox()[evt.row-1]
if not inbox then
mail.show_mail_menu(name)
return true
end
if mail.selected_idxs.multipleselection[name] then
if not mail.selected_idxs.inbox[name] then
mail.selected_idxs.inbox[name] = {}
end
local selected_id = 0
if mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.inbox[name]) do
if inbox.id == selected_msg then
selected_id = i
table.remove(mail.selected_idxs.inbox[name], i)
break
end
end
end
if selected_id == 0 then
table.insert(mail.selected_idxs.inbox[name], inbox.id)
mail.selected_idxs.message[name] = inbox.id
end
else
mail.selected_idxs.inbox[name] = { inbox.id }
mail.selected_idxs.message[name] = inbox.id
end
if evt.type == "DCL" then
mail.selected_idxs.message[name] = inbox.id
mail.show_message(name, inbox.id)
else
mail.show_mail_menu(name)
end
return true
end
if fields.outbox then -- outbox table
local evt = minetest.explode_table_event(fields.outbox)
if evt.row == 1 then -- header
if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction
mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2"
end
mail.selected_idxs.sortfield[name] = evt.column-1 -- update column
mail.show_mail_menu(name)
return true
end
local outbox = getOutbox()[evt.row-1]
if not outbox then
mail.show_mail_menu(name)
return true
end
if mail.selected_idxs.multipleselection[name] then
if not mail.selected_idxs.outbox[name] then
mail.selected_idxs.outbox[name] = {}
end
local selected_id = 0
if mail.selected_idxs.outbox[name] and #mail.selected_idxs.outbox[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.outbox[name]) do
if outbox.id == selected_msg then
selected_id = i
table.remove(mail.selected_idxs.outbox[name], i)
break
end
end
end
if selected_id == 0 then
table.insert(mail.selected_idxs.outbox[name], outbox.id)
mail.selected_idxs.message[name] = outbox.id
end
else
mail.selected_idxs.outbox[name] = { outbox.id }
mail.selected_idxs.message[name] = outbox.id
end
if evt.type == "DCL" then
mail.selected_idxs.message[name] = outbox.id
mail.show_message(name, outbox.id)
else
mail.show_mail_menu(name)
end
return true
end
if fields.drafts then -- drafts table
local evt = minetest.explode_table_event(fields.drafts)
if evt.row == 1 then -- header
if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction
mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2"
end
mail.selected_idxs.sortfield[name] = evt.column-1 -- update column
mail.show_mail_menu(name)
return
end
mail.selected_idxs.drafts[name] = evt.row - 1
if evt.type == "DCL" and messagesDrafts[mail.selected_idxs.drafts[name]] then
mail.selected_idxs.message[name] = messagesDrafts[mail.selected_idxs.drafts[name]].id
mail.show_compose(name,
messagesDrafts[mail.selected_idxs.drafts[name]].to,
messagesDrafts[mail.selected_idxs.drafts[name]].subject,
messagesDrafts[mail.selected_idxs.drafts[name]].body,
messagesDrafts[mail.selected_idxs.drafts[name]].cc,
messagesDrafts[mail.selected_idxs.drafts[name]].bcc,
messagesDrafts[mail.selected_idxs.drafts[name]].id
)
end
return true
end
if fields.trash then -- trash table
local evt = minetest.explode_table_event(fields.trash)
if evt.row == 1 then -- header
if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction
mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2"
end
mail.selected_idxs.sortfield[name] = evt.column-1 -- update column
mail.show_mail_menu(name)
return
end
mail.selected_idxs.trash[name] = evt.row - 1
if evt.type == "DCL" and messagesTrash[mail.selected_idxs.trash[name]] then
mail.selected_idxs.message[name] = messagesTrash[mail.selected_idxs.trash[name]].id
mail.show_message(name, messagesTrash[mail.selected_idxs.trash[name]].id)
end
return true
end
if fields.boxtab == "1" then
mail.selected_idxs.boxtab[name] = 1
mail.show_inbox(name, sortfieldindex, sortdirection, filter)
elseif fields.boxtab == "2" then
mail.selected_idxs.boxtab[name] = 2
mail.show_outbox(name, sortfieldindex, sortdirection, filter)
elseif fields.boxtab == "3" then
mail.selected_idxs.boxtab[name] = 3
mail.show_drafts(name)
elseif fields.boxtab == "4" then
mail.selected_idxs.boxtab[name] = 4
mail.show_trash(name)
elseif fields.read then
if formname == "mail:inbox" and nonempty(mail.selected_idxs.inbox[name]) then -- inbox table
mail.selected_idxs.message[name] = mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]]
elseif formname == "mail:outbox" and nonempty(mail.selected_idxs.outbox[name]) then -- outbox table
mail.selected_idxs.message[name] = mail.selected_idxs.outbox[name][#mail.selected_idxs.outbox[name]]
elseif formname == "mail:trash" and messagesTrash[mail.selected_idxs.trash[name]] then
mail.selected_idxs.message[name] = messagesTrash[mail.selected_idxs.trash[name]].id
end
if mail.selected_idxs.message[name] then
mail.show_message(name, mail.selected_idxs.message[name])
end
elseif fields.edit then
if formname == "mail:drafts" and messagesDrafts[mail.selected_idxs.drafts[name]] then
mail.show_compose(name,
messagesDrafts[mail.selected_idxs.drafts[name]].to,
messagesDrafts[mail.selected_idxs.drafts[name]].subject,
messagesDrafts[mail.selected_idxs.drafts[name]].body,
messagesDrafts[mail.selected_idxs.drafts[name]].cc,
messagesDrafts[mail.selected_idxs.drafts[name]].bcc,
messagesDrafts[mail.selected_idxs.drafts[name]].id
)
end
elseif fields.delete then
local trash_enabled = mail.get_setting(name, "trash_move_enable")
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then -- inbox table
if trash_enabled then
mail.trash_mail(name, mail.selected_idxs.inbox[name])
else
mail.delete_mail(name, mail.selected_idxs.inbox[name])
end
mail.selected_idxs.inbox[name] = {}
elseif formname == "mail:outbox" and mail.selected_idxs.outbox[name] then -- outbox table
if trash_enabled then
mail.trash_mail(name, mail.selected_idxs.outbox[name])
else
mail.delete_mail(name, mail.selected_idxs.outbox[name])
end
mail.selected_idxs.outbox[name] = {}
elseif formname == "mail:drafts" and messagesDrafts[mail.selected_idxs.drafts[name]] then -- drafts table
if trash_enabled then
mail.trash_mail(name, messagesDrafts[mail.selected_idxs.drafts[name]].id)
else
mail.delete_mail(name, messagesDrafts[mail.selected_idxs.drafts[name]].id)
end
mail.selected_idxs.drafts[name] = nil
elseif formname == "mail:trash" and messagesTrash[mail.selected_idxs.trash[name]] then -- trash table
mail.delete_mail(name, messagesTrash[mail.selected_idxs.trash[name]].id, true)
end
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
elseif fields.restore then
if messagesTrash[mail.selected_idxs.trash[name]] then
mail.restore_mail(name, messagesTrash[mail.selected_idxs.trash[name]].id)
end
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
elseif fields.reply then
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then
local message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
mail.reply(name, message)
elseif
formname == "mail:outbox" and mail.selected_idxs.outbox[name] and #mail.selected_idxs.outbox[name] > 0 then
local message = mail.get_message(name, mail.selected_idxs.outbox[name][#mail.selected_idxs.outbox[name]])
mail.reply(name, message)
end
elseif fields.replyall then
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then
local message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
mail.replyall(name, message)
elseif
formname == "mail:outbox" and mail.selected_idxs.outbox[name] and #mail.selected_idxs.outbox[name] > 0 then
local message = mail.get_message(name, mail.selected_idxs.outbox[name][#mail.selected_idxs.outbox[name]])
mail.replyall(name, message)
end
elseif fields.forward then
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then
local message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
mail.forward(name, message)
elseif
formname == "mail:outbox" and mail.selected_idxs.outbox[name] and #mail.selected_idxs.outbox[name] > 0 then
local message = mail.get_message(name, mail.selected_idxs.outbox[name][#mail.selected_idxs.outbox[name]])
mail.forward(name, message)
end
elseif fields.markread then
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then
mail.mark_read(name, mail.selected_idxs.inbox[name])
end
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
elseif fields.markunread then
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then
mail.mark_unread(name, mail.selected_idxs.inbox[name])
end
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
elseif fields.markspam then
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then
mail.mark_spam(name, mail.selected_idxs.inbox[name])
end
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
elseif fields.unmarkspam then
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then
mail.unmark_spam(name, mail.selected_idxs.inbox[name])
end
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
elseif fields.new then
mail.show_compose(name)
elseif fields.empty then
mail.empty_trash(name)
mail.show_mail_menu(name)
elseif fields.contacts then
mail.show_contacts(name)
elseif fields.maillists then
mail.show_maillists(name)
elseif fields.options then
mail.show_options(name)
elseif fields.selectall then
if formname == "mail:inbox" then
local selected_number = #mail.selected_idxs.inbox[name]
mail.selected_idxs.inbox[name] = {} -- reset for select, unselect and not existing
mail.selected_idxs.multipleselection[name] = true -- enable as the button were pressed
if selected_number < #getInbox() then -- then populate it if selection isn't full
for _, msg in ipairs(getInbox()) do
table.insert(mail.selected_idxs.inbox[name], msg.id)
end
end
elseif formname == "mail:outbox" then
local selected_number = #mail.selected_idxs.outbox[name]
mail.selected_idxs.outbox[name] = {} -- reset for select, unselect and not existing
mail.selected_idxs.multipleselection[name] = true -- enable as the button were pressed
if selected_number < #getOutbox() then -- then populate it if selection isn't full
for _, msg in ipairs(getOutbox()) do
table.insert(mail.selected_idxs.outbox[name], msg.id)
end
end
end
mail.show_mail_menu(name)
elseif fields.sortfield or fields.sortdirection or fields.filter then
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
end
return true
end)

131
ui/inbox.lua Normal file
View File

@ -0,0 +1,131 @@
-- translation
local S = mail.S
function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
sortfieldindex = tonumber(sortfieldindex or mail.selected_idxs.sortfield[name])
or mail.get_setting(name, "defaultsortfield") or 3
sortdirection = tostring(sortdirection or mail.selected_idxs.sortdirection[name]
or mail.get_setting(name, "defaultsortdirection") or "1")
filter = filter or mail.selected_idxs.filter[name] or ""
mail.selected_idxs.inbox[name] = mail.selected_idxs.inbox[name] or {}
local entry = mail.get_storage_entry(name)
local sortfield = ({"from","subject","time"})[sortfieldindex]
local messages = mail.sort_messages(entry.inbox, sortfield, sortdirection == "2", filter)
if mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.inbox[name]) do
local is_present = false
for _, msg in ipairs(messages) do
if msg.id == selected_msg then
is_present = true
break
end
end
if not is_present then
table.remove(mail.selected_idxs.inbox[name], i)
end
end
end
local trash_tab = ""
if mail.get_setting(name, "trash_move_enable") then
trash_tab = "," .. S("Trash")
end
local inbox_formspec = "size[8.5,11;]" .. mail.theme .. [[
tabheader[0.3,1;boxtab;]] ..
S("Inbox") .. "," .. S("Outbox").. "," .. S("Drafts") .. trash_tab .. [[;1;false;false]
button[6,0.10;2.5,0.5;new;]] .. S("New") .. [[]
button[6,0.95;2.5,0.5;read;]] .. S("Read") .. [[]
button[6,1.70;2.5,0.5;reply;]] .. S("Reply") .. [[]
button[6,2.45;2.5,0.5;replyall;]] .. S("Reply all") .. [[]
button[6,3.20;2.5,0.5;forward;]] .. S("Forward") .. [[]
button[6,3.95;2.5,0.5;delete;]] .. S("Delete") .. [[]
button[6,4.85;2.5,0.5;markread;]] .. S("Mark Read") .. [[]
button[6,5.55;2.5,0.5;markunread;]] .. S("Mark Unread") .. [[]
button[6,6.4;2.5,0.5;markspam;]] .. S("Mark Spam") .. [[]
button[6,7.1;2.5,0.5;unmarkspam;]] .. S("Unmark Spam") .. [[]
button[6,8.0;2.5,0.5;contacts;]] .. S("Contacts") .. [[]
button[6,8.8;2.5,0.5;maillists;]] .. S("Mail lists") .. [[]
button[6,9.7;2.5,0.5;options;]] .. S("Options") .. [[]
button_exit[6,10.5;2.5,0.5;quit;]] .. S("Close") .. [[]
tooltip[reply;]] .. S("Reply only to the sender") .. [[]
tooltip[replyall;]] .. S("Reply to all involved people") .. [[]
tooltip[forward;]] .. S("Transfer message to other people") .. [[]
dropdown[0,9.5;2,0.5;sortfield;]] ..
S("From") .. "," .. S("Subject") .. "," .. S("Date") .. [[;]] .. sortfieldindex .. [[;true]
dropdown[2.0,9.5;2,0.5;sortdirection;]] ..
S("Ascending") .. "," .. S("Descending") .. [[;]] .. sortdirection .. [[;true]
field[4.25,9.95;1.4,0.5;filter;]] .. S("Filter") .. [[:;]] .. filter .. [[]
image_button[5.14,9.5;0.85,0.85;search.png;search;]
checkbox[0,10.1;multipleselection;]] .. S("Allow multiple selection") .. [[;]] ..
tostring(mail.selected_idxs.multipleselection[name]) .. [[]
label[0,10.65;]] ..
S("@1 of @2 selected", tostring(#mail.selected_idxs.inbox[name]), tostring(#messages)) .. [[]
button[3.5,10.5;2.5,0.5;selectall;]] .. S("(Un)select all") .. [[]
tablecolumns[color;text;text]
table[0,0.7;5.75,8.45;inbox;]] .. mail.get_color("header") .. "," .. S("From") .. "," .. S("Subject")
local formspec = { inbox_formspec }
mail.message_drafts[name] = nil
local unread_color_enable = mail.get_setting(name, "unreadcolorenable")
local cc_color_enable = mail.get_setting(name, "cccolorenable")
local mute_list = mail.get_setting(name, "mute_list")
if #messages > 0 then
for _, message in ipairs(messages) do
local selected_id = 0
local displayed_color = {}
-- check if message is in selection list and return its id
if mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.inbox[name]) do
if message.id == selected_msg then
selected_id = i
break
end
end
end
if selected_id > 0 then
table.insert(displayed_color, "selected")
end
if not message.read and unread_color_enable then
table.insert(displayed_color, "important")
end
if not mail.player_in_list(name, message.to) and cc_color_enable then
table.insert(displayed_color, "additional")
end
if message.spam then
table.insert(displayed_color, "warning")
end
if table.indexof(mute_list, message.from) >= 1 then
table.insert(displayed_color, "muted")
end
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
formspec[#formspec + 1] = ","
formspec[#formspec + 1] = minetest.formspec_escape(message.from)
formspec[#formspec + 1] = ","
if message.subject ~= "" then
if string.len(message.subject) > 30 then
formspec[#formspec + 1] = minetest.formspec_escape(string.sub(message.subject, 1, 27))
formspec[#formspec + 1] = "..."
else
formspec[#formspec + 1] = minetest.formspec_escape(message.subject)
end
else
formspec[#formspec + 1] = S("(No subject)")
end
end
formspec[#formspec + 1] = "]"
else
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No mail") .. "]"
end
minetest.show_formspec(name, "mail:inbox", table.concat(formspec, ""))
end

37
ui/init.lua Normal file
View File

@ -0,0 +1,37 @@
-- sub files
local MP = minetest.get_modpath(minetest.get_current_modname())
dofile(MP .. "/ui/inbox.lua")
dofile(MP .. "/ui/outbox.lua")
dofile(MP .. "/ui/drafts.lua")
dofile(MP .. "/ui/trash.lua")
dofile(MP .. "/ui/message.lua")
dofile(MP .. "/ui/receivers.lua")
dofile(MP .. "/ui/events.lua")
dofile(MP .. "/ui/contacts.lua")
dofile(MP .. "/ui/edit_contact.lua")
dofile(MP .. "/ui/select_contact.lua")
dofile(MP .. "/ui/maillists.lua")
dofile(MP .. "/ui/edit_maillists.lua")
dofile(MP .. "/ui/compose.lua")
dofile(MP .. "/ui/options.lua")
dofile(MP .. "/ui/settings.lua")
dofile(MP .. "/ui/about.lua")
-- helper function for tabbed overview
function mail.show_mail_menu(playername, sortfield, sortdirection, filter)
local index = mail.selected_idxs.boxtab[playername] or 1
if not mail.selected_idxs.boxtab[playername] then
mail.selected_idxs.boxtab[playername] = 1
end
if index == 1 then
mail.show_inbox(playername, sortfield, sortdirection, filter)
elseif index == 2 then
mail.show_outbox(playername, sortfield, sortdirection, filter)
elseif index == 3 then
mail.show_drafts(playername)
elseif index == 4 then
mail.show_trash(playername)
end
end

113
ui/maillists.lua Normal file
View File

@ -0,0 +1,113 @@
-- translation
local S = mail.S
local FORMNAME = "mail:maillists"
local maillists_formspec = "size[8,9;]" .. mail.theme .. [[
button[6,0.10;2,0.5;new;]] .. S("New") .. [[]
button[6,0.85;2,0.5;edit;]] .. S("Edit") .. [[]
button[6,1.60;2,0.5;delete;]] .. S("Delete") .. [[]
button[6,8.25;2,0.5;back;]] .. S("Back") .. [[]
tablecolumns[color;text;text]
table[0,0;5.75,9;maillists;]] .. mail.get_color("header") .. "," .. S("Name") .. "," .. S("Note")
function mail.show_maillists(name)
local formspec = { maillists_formspec }
local maillists = mail.get_maillists(name)
if maillists[1] then
for _, maillist in ipairs(maillists) do
formspec[#formspec + 1] = ","
formspec[#formspec + 1] = ","
formspec[#formspec + 1] = "@" .. minetest.formspec_escape(maillist.name)
formspec[#formspec + 1] = ","
if maillist.desc ~= "" then
if string.len(maillist.desc or "") > 30 then
formspec[#formspec + 1] = minetest.formspec_escape(string.sub(maillist.desc, 1, 27))
formspec[#formspec + 1] = "..."
else
formspec[#formspec + 1] = minetest.formspec_escape(maillist.desc)
end
else
formspec[#formspec + 1] = S("(No description)")
end
end
if mail.selected_idxs.maillists[name] then
formspec[#formspec + 1] = ";"
formspec[#formspec + 1] = mail.selected_idxs.maillists[name]
end
formspec[#formspec + 1] = "]"
else
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No maillist") .. "]"
end
minetest.show_formspec(name, FORMNAME, table.concat(formspec, ""))
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then
return
end
local name = player:get_player_name()
local maillists = mail.get_maillists(name)
if fields.maillists then
local evt = minetest.explode_table_event(fields.maillists)
mail.selected_idxs.maillists[name] = evt.row - 1
if evt.type == "DCL" and maillists[mail.selected_idxs.maillists[name]] then
local maillist = mail.get_maillist_by_name(name, maillists[mail.selected_idxs.maillists[name]].name)
local players_string = mail.concat_player_list(maillist.players)
mail.show_edit_maillist(
name,
maillists[mail.selected_idxs.maillists[name]].name,
maillists[mail.selected_idxs.maillists[name]].desc,
players_string
)
end
elseif fields.new then
mail.selected_idxs.maillists[name] = "#NEW#"
mail.show_edit_maillist(name, "", "", "Player1, Player2, Player3")
elseif fields.edit and maillists[mail.selected_idxs.maillists[name]] then
local maillist = mail.get_maillist_by_name(name, maillists[mail.selected_idxs.maillists[name]].name)
local players_string = mail.concat_player_list(maillist.players)
mail.show_edit_maillist(
name,
maillists[mail.selected_idxs.maillists[name]].name,
maillists[mail.selected_idxs.maillists[name]].desc,
players_string
)
elseif fields.delete then
if maillists[mail.selected_idxs.maillists[name]] then
-- delete the maillist and set the selected to the next in the list,
-- except if it was the last. Then determine the new last
local found = false
local last = nil
for k in mail.pairs_by_keys(maillists) do
if found then
mail.selected_idxs.maillists[name] = k
break
elseif k == mail.selected_idxs.maillists[name] then
mail.delete_maillist(name, maillists[mail.selected_idxs.maillists[name]].name)
mail.selected_idxs.maillists[name] = nil
found = true
else
last = k
end
end
if found and not mail.selected_idxs.maillists[name] then
-- was the last in the list, so take the previous (new last)
mail.selected_idxs.maillists[name] = last
end
end
mail.show_maillists(name)
elseif fields.back then
mail.show_mail_menu(name)
end
return true
end)