2020-07-31 23:51:13 +02:00
|
|
|
|
2020-08-12 11:20:48 +02:00
|
|
|
function mail.compile_contact_list(name, selected, playernames)
|
|
|
|
-- TODO: refactor this - not just compiles *a* list, but *the* list for the contacts screen (too inflexible)
|
|
|
|
local formspec = {}
|
2023-03-29 17:25:01 +02:00
|
|
|
local contacts = mail.get_contacts(name)
|
2020-07-31 23:51:13 +02:00
|
|
|
|
2020-08-12 11:20:48 +02:00
|
|
|
if playernames == nil then
|
2020-08-15 13:52:26 +02:00
|
|
|
local length = 0
|
2020-10-13 19:20:18 +02:00
|
|
|
for k, contact, i, l in mail.pairsByKeys(contacts) do
|
2020-08-15 13:52:26 +02:00
|
|
|
if i == 1 then length = l end
|
2020-08-12 11:20:48 +02:00
|
|
|
formspec[#formspec + 1] = ","
|
|
|
|
formspec[#formspec + 1] = ","
|
|
|
|
formspec[#formspec + 1] = minetest.formspec_escape(contact.name)
|
|
|
|
formspec[#formspec + 1] = ","
|
|
|
|
local note = contact.note
|
|
|
|
-- display an ellipsis if the note spans multiple lines
|
|
|
|
local idx = string.find(note, '\n')
|
|
|
|
if idx ~= nil then
|
|
|
|
note = string.sub(note, 1, idx-1) .. ' ...'
|
|
|
|
end
|
|
|
|
formspec[#formspec + 1] = minetest.formspec_escape(note)
|
|
|
|
if type(selected) == "string" then
|
2020-08-15 13:52:26 +02:00
|
|
|
if string.lower(selected) == k then
|
2020-08-12 11:20:48 +02:00
|
|
|
selected = i
|
|
|
|
end
|
|
|
|
end
|
2020-07-31 23:51:13 +02:00
|
|
|
end
|
2020-08-15 13:52:26 +02:00
|
|
|
if length > 0 then
|
|
|
|
if selected and type(selected) == "number" then
|
2020-08-12 11:20:48 +02:00
|
|
|
formspec[#formspec + 1] = ";"
|
|
|
|
formspec[#formspec + 1] = tostring(selected + 1)
|
|
|
|
end
|
|
|
|
formspec[#formspec + 1] = "]"
|
|
|
|
else
|
|
|
|
formspec[#formspec + 1] = "]label[2,4.5;No contacts]"
|
2020-08-10 18:41:05 +02:00
|
|
|
end
|
2020-08-12 11:20:48 +02:00
|
|
|
else
|
|
|
|
if type(playernames) == "string" then
|
|
|
|
playernames = mail.parse_player_list(playernames)
|
|
|
|
end
|
2020-08-15 13:52:26 +02:00
|
|
|
for i,c in ipairs(playernames) do
|
2020-08-12 11:20:48 +02:00
|
|
|
formspec[#formspec + 1] = ","
|
|
|
|
formspec[#formspec + 1] = ","
|
|
|
|
formspec[#formspec + 1] = minetest.formspec_escape(c)
|
|
|
|
formspec[#formspec + 1] = ","
|
|
|
|
if contacts[string.lower(c)] == nil then
|
|
|
|
formspec[#formspec + 1] = ""
|
|
|
|
else
|
|
|
|
local note = contacts[string.lower(c)].note
|
|
|
|
-- display an ellipsis if the note spans multiple lines
|
|
|
|
local idx = string.find(note, '\n')
|
|
|
|
if idx ~= nil then
|
|
|
|
note = string.sub(note, 1, idx-1) .. ' ...'
|
|
|
|
end
|
|
|
|
formspec[#formspec + 1] = minetest.formspec_escape(note)
|
|
|
|
end
|
|
|
|
if not selected then
|
|
|
|
if type(selected) == "string" then
|
2020-08-15 13:52:26 +02:00
|
|
|
if string.lower(selected) == string.lower(c) then
|
2020-08-12 11:20:48 +02:00
|
|
|
selected = i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-15 13:52:26 +02:00
|
|
|
if #playernames > 0 and selected and type(selected) == "number" then
|
2020-07-31 23:51:13 +02:00
|
|
|
formspec[#formspec + 1] = ";"
|
2020-08-10 18:41:05 +02:00
|
|
|
formspec[#formspec + 1] = tostring(selected + 1)
|
2020-07-31 23:51:13 +02:00
|
|
|
end
|
|
|
|
formspec[#formspec + 1] = "]"
|
|
|
|
end
|
2020-08-12 11:20:48 +02:00
|
|
|
return table.concat(formspec, "")
|
2020-10-13 19:15:58 +02:00
|
|
|
|
2019-09-16 08:06:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if minetest.get_modpath("unified_inventory") then
|
|
|
|
mail.receive_mail_message = mail.receive_mail_message ..
|
|
|
|
" or use the mail button in the inventory"
|
|
|
|
mail.read_later_message = mail.read_later_message ..
|
|
|
|
" or by using the mail button in the inventory"
|
|
|
|
|
|
|
|
unified_inventory.register_button("mail", {
|
|
|
|
type = "image",
|
|
|
|
image = "mail_button.png",
|
2023-03-29 17:25:01 +02:00
|
|
|
tooltip = "Mail",
|
|
|
|
action = function(player)
|
|
|
|
mail.show_mail_menu(player:get_player_name())
|
|
|
|
end
|
2019-09-16 08:06:54 +02:00
|
|
|
})
|
|
|
|
end
|