Improve Inbox GUI
This commit is contained in:
parent
6900ddeea7
commit
1c255c5c9f
1
api.lua
1
api.lua
@ -1,4 +1,3 @@
|
|||||||
mail.highlightedmessages = {}
|
|
||||||
mail.messages = {}
|
mail.messages = {}
|
||||||
|
|
||||||
mail.registered_on_receives = {}
|
mail.registered_on_receives = {}
|
||||||
|
86
gui.lua
86
gui.lua
@ -1,17 +1,19 @@
|
|||||||
|
selected_message_idxs = {}
|
||||||
|
|
||||||
mail.inbox_formspec = [[
|
mail.inbox_formspec = [[
|
||||||
size[8,9;]
|
size[8,9;]
|
||||||
button_exit[7.5,0;0.5,0.5;quit;X]
|
button_exit[7.5,0;0.5,0.5;quit;X]
|
||||||
button[6.25,1;1.5,0.5;new;New Message]
|
button[6,1;2,0.5;new;New Message]
|
||||||
button[6.25,2;1.5,0.5;read;Read]
|
button[6,2;2,0.5;read;Read]
|
||||||
button[6.25,3;1.5,0.5;reply;Reply]
|
button[6,3;2,0.5;reply;Reply]
|
||||||
button[6.25,4;1.5,0.5;forward;Forward]
|
button[6,4;2,0.5;forward;Forward]
|
||||||
button[6.25,5;1.5,0.5;delete;Delete]
|
button[6,5;2,0.5;delete;Delete]
|
||||||
button[6.25,6;1.5,0.5;markread;Mark Read]
|
button[6,6;2,0.5;markread;Mark Read]
|
||||||
button[6.25,7;1.5,0.5;markunread;Mark Unread]
|
button[6,7;2,0.5;markunread;Mark Unread]
|
||||||
button[6.25,8;1.5,0.5;about;About]
|
button[6,8;2,0.5;about;About]
|
||||||
textlist[0,0.5;6,8.5;message;
|
tablecolumns[color;text;text]
|
||||||
]]
|
table[0,0;5.75,9;messages;#999,From,Subject]]
|
||||||
|
|
||||||
|
|
||||||
function mail.show_about(name)
|
function mail.show_about(name)
|
||||||
local formspec = [[
|
local formspec = [[
|
||||||
@ -36,13 +38,12 @@ function mail.show_inbox(name)
|
|||||||
|
|
||||||
if mail.messages[name][1] then
|
if mail.messages[name][1] then
|
||||||
for idx, message in ipairs(mail.messages[name]) do
|
for idx, message in ipairs(mail.messages[name]) do
|
||||||
if idx ~= 1 then
|
if message.unread then
|
||||||
|
formspec = formspec .. ",#FFD700"
|
||||||
|
else
|
||||||
formspec = formspec .. ","
|
formspec = formspec .. ","
|
||||||
end
|
end
|
||||||
if message.unread then
|
formspec = formspec .. "," .. minetest.formspec_escape(message.sender) .. ","
|
||||||
formspec = formspec .. "#FF8888"
|
|
||||||
end
|
|
||||||
formspec = formspec .. "From: " .. minetest.formspec_escape(message.sender) .. " Subject: "
|
|
||||||
if message.subject ~= "" then
|
if message.subject ~= "" then
|
||||||
if string.len(message.subject) > 30 then
|
if string.len(message.subject) > 30 then
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
@ -55,9 +56,12 @@ function mail.show_inbox(name)
|
|||||||
formspec = formspec .. "(No subject)"
|
formspec = formspec .. "(No subject)"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
formspec = formspec .. "]label[0,0;Welcome! You've got mail!]"
|
if selected_message_idxs[name] then
|
||||||
|
formspec = formspec .. ";" .. (selected_message_idxs[name] + 1)
|
||||||
|
end
|
||||||
|
formspec = formspec .. "]"
|
||||||
else
|
else
|
||||||
formspec = formspec .. "No mail :(]label[0,0;Welcome!]"
|
formspec = formspec .. "]label[2,4.5;No mail]"
|
||||||
end
|
end
|
||||||
minetest.show_formspec(name, "mail:inbox", formspec)
|
minetest.show_formspec(name, "mail:inbox", formspec)
|
||||||
end
|
end
|
||||||
@ -112,43 +116,45 @@ function mail.handle_receivefields(player, formname, fields)
|
|||||||
end)
|
end)
|
||||||
elseif formname == "mail:inbox" then
|
elseif formname == "mail:inbox" then
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if fields.message then
|
if fields.messages then
|
||||||
local event = minetest.explode_textlist_event(fields.message)
|
local evt = minetest.explode_table_event(fields.messages)
|
||||||
mail.highlightedmessages[name] = event.index
|
selected_message_idxs[name] = evt.row - 1
|
||||||
if event.type == "DCL" and mail.messages[name][mail.highlightedmessages[name]] then
|
print(dump(evt))
|
||||||
mail.messages[name][mail.highlightedmessages[name]].unread = false
|
if evt.type == "DCL" and mail.messages[name][selected_message_idxs[name]] then
|
||||||
mail.show_message(name, mail.highlightedmessages[name])
|
mail.messages[name][selected_message_idxs[name]].unread = false
|
||||||
|
mail.show_message(name, selected_message_idxs[name])
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
if fields.read then
|
if fields.read then
|
||||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
if mail.messages[name][selected_message_idxs[name]] then
|
||||||
mail.messages[name][mail.highlightedmessages[name]].unread = false
|
mail.messages[name][selected_message_idxs[name]].unread = false
|
||||||
mail.show_message(name, mail.highlightedmessages[name])
|
mail.show_message(name, selected_message_idxs[name])
|
||||||
end
|
end
|
||||||
elseif fields.delete then
|
elseif fields.delete then
|
||||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
if mail.messages[name][selected_message_idxs[name]] then
|
||||||
table.remove(mail.messages[name], mail.highlightedmessages[name])
|
table.remove(mail.messages[name], selected_message_idxs[name])
|
||||||
end
|
end
|
||||||
|
|
||||||
mail.show_inbox(name)
|
mail.show_inbox(name)
|
||||||
mail.save()
|
mail.save()
|
||||||
elseif fields.reply and mail.messages[name][mail.highlightedmessages[name]] then
|
elseif fields.reply and mail.messages[name][selected_message_idxs[name]] then
|
||||||
local message = mail.messages[name][mail.highlightedmessages[name]]
|
local message = mail.messages[name][selected_message_idxs[name]]
|
||||||
local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body
|
local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body
|
||||||
mail.show_compose(name, message.sender, "Re: "..message.subject,replyfooter)
|
mail.show_compose(name, message.sender, "Re: "..message.subject,replyfooter)
|
||||||
elseif fields.forward and mail.messages[name][mail.highlightedmessages[name]] then
|
elseif fields.forward and mail.messages[name][selected_message_idxs[name]] then
|
||||||
local message = mail.messages[name][mail.highlightedmessages[name]]
|
local message = mail.messages[name][selected_message_idxs[name]]
|
||||||
local fwfooter = "Type your message here.\n\n--Original message follows--\n" ..message.body
|
local fwfooter = "Type your message here.\n\n--Original message follows--\n" ..message.body
|
||||||
mail.show_compose(name, "", "Fw: "..message.subject, fwfooter)
|
mail.show_compose(name, "", "Fw: "..message.subject, fwfooter)
|
||||||
elseif fields.markread then
|
elseif fields.markread then
|
||||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
if mail.messages[name][selected_message_idxs[name]] then
|
||||||
mail.messages[name][mail.highlightedmessages[name]].unread = false
|
mail.messages[name][selected_message_idxs[name]].unread = false
|
||||||
end
|
end
|
||||||
mail.show_inbox(name)
|
mail.show_inbox(name)
|
||||||
mail.save()
|
mail.save()
|
||||||
elseif fields.markunread then
|
elseif fields.markunread then
|
||||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
if mail.messages[name][selected_message_idxs[name]] then
|
||||||
mail.messages[name][mail.highlightedmessages[name]].unread = true
|
mail.messages[name][selected_message_idxs[name]].unread = true
|
||||||
end
|
end
|
||||||
mail.show_inbox(name)
|
mail.show_inbox(name)
|
||||||
mail.save()
|
mail.save()
|
||||||
@ -167,16 +173,16 @@ function mail.handle_receivefields(player, formname, fields)
|
|||||||
if fields.back then
|
if fields.back then
|
||||||
mail.show_inbox(name)
|
mail.show_inbox(name)
|
||||||
elseif fields.reply then
|
elseif fields.reply then
|
||||||
local message = mail.messages[name][mail.highlightedmessages[name]]
|
local message = mail.messages[name][selected_message_idxs[name]]
|
||||||
local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body
|
local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body
|
||||||
mail.show_compose(name, message.sender, "Re: "..message.subject, replyfooter)
|
mail.show_compose(name, message.sender, "Re: "..message.subject, replyfooter)
|
||||||
elseif fields.forward then
|
elseif fields.forward then
|
||||||
local message = mail.messages[name][mail.highlightedmessages[name]]
|
local message = mail.messages[name][selected_message_idxs[name]]
|
||||||
local fwfooter = "Type your message here.\n\n--Original message follows--\n" ..message.body
|
local fwfooter = "Type your message here.\n\n--Original message follows--\n" ..message.body
|
||||||
mail.show_compose(name, "", "Fw: "..message.subject, fwfooter)
|
mail.show_compose(name, "", "Fw: "..message.subject, fwfooter)
|
||||||
elseif fields.delete then
|
elseif fields.delete then
|
||||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
if mail.messages[name][selected_message_idxs[name]] then
|
||||||
table.remove(mail.messages[name],mail.highlightedmessages[name])
|
table.remove(mail.messages[name],selected_message_idxs[name])
|
||||||
end
|
end
|
||||||
mail.show_inbox(name)
|
mail.show_inbox(name)
|
||||||
mail.save()
|
mail.save()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user