Merge pull request #8 from rubenwardy/betterui
Improve UI [Merge #7 first]
This commit is contained in:
commit
1659ed0aac
@ -16,5 +16,5 @@ read_globals = {
|
||||
"dump",
|
||||
|
||||
-- Deps
|
||||
"unified_inventory",
|
||||
"unified_inventory", "default",
|
||||
}
|
||||
|
1
api.lua
1
api.lua
@ -1,4 +1,3 @@
|
||||
mail.highlightedmessages = {}
|
||||
mail.messages = {}
|
||||
|
||||
mail.registered_on_receives = {}
|
||||
|
@ -1 +1,2 @@
|
||||
unified_inventory?
|
||||
default?
|
||||
|
146
gui.lua
146
gui.lua
@ -1,22 +1,30 @@
|
||||
selected_message_idxs = {}
|
||||
|
||||
mail.inbox_formspec = [[
|
||||
size[8,9;]
|
||||
local theme
|
||||
if minetest.get_modpath("default") then
|
||||
theme = default.gui_bg .. default.gui_bg_img
|
||||
else
|
||||
theme = ""
|
||||
end
|
||||
|
||||
mail.inbox_formspec = "size[8,9;]" .. theme .. [[
|
||||
button_exit[7.5,0;0.5,0.5;quit;X]
|
||||
button[6.25,1;1.5,0.5;new;New Message]
|
||||
button[6.25,2;1.5,0.5;read;Read]
|
||||
button[6.25,3;1.5,0.5;reply;Reply]
|
||||
button[6.25,4;1.5,0.5;forward;Forward]
|
||||
button[6.25,5;1.5,0.5;delete;Delete]
|
||||
button[6.25,6;1.5,0.5;markread;Mark Read]
|
||||
button[6.25,7;1.5,0.5;markunread;Mark Unread]
|
||||
button[6.25,8;1.5,0.5;about;About]
|
||||
textlist[0,0.5;6,8.5;message;
|
||||
]]
|
||||
button[6,1;2,0.5;new;New Message]
|
||||
button[6,2;2,0.5;read;Read]
|
||||
button[6,3;2,0.5;reply;Reply]
|
||||
button[6,4;2,0.5;forward;Forward]
|
||||
button[6,5;2,0.5;delete;Delete]
|
||||
button[6,6;2,0.5;markread;Mark Read]
|
||||
button[6,7;2,0.5;markunread;Mark Unread]
|
||||
button[6,8;2,0.5;about;About]
|
||||
tablecolumns[color;text;text]
|
||||
table[0,0;5.75,9;messages;#999,From,Subject]]
|
||||
|
||||
|
||||
function mail.show_about(name)
|
||||
local formspec = [[
|
||||
size[4,5;]
|
||||
button[3.5,0;0.5,0.5;back;X]
|
||||
size[8,5;]
|
||||
button[7.5,0;0.5,0.5;back;X]
|
||||
label[0,0;Mail]
|
||||
label[0,0.5;By cheapie]
|
||||
label[0,1;http://github.com/cheapie/mail]
|
||||
@ -25,55 +33,60 @@ function mail.show_about(name)
|
||||
label[0,3;is NOT guaranteed to be private!]
|
||||
label[0,3.5;Admins are able to view the messages]
|
||||
label[0,4;of any player.]
|
||||
]]
|
||||
]] .. theme
|
||||
|
||||
minetest.show_formspec(name, "mail:about", formspec)
|
||||
end
|
||||
|
||||
function mail.show_inbox(name)
|
||||
local formspec = mail.inbox_formspec
|
||||
local formspec = { mail.inbox_formspec }
|
||||
mail.messages[name] = mail.messages[name] or {}
|
||||
|
||||
if mail.messages[name][1] then
|
||||
for idx, message in ipairs(mail.messages[name]) do
|
||||
if idx ~= 1 then
|
||||
formspec = formspec .. ","
|
||||
end
|
||||
if message.unread then
|
||||
formspec = formspec .. "#FF8888"
|
||||
formspec[#formspec + 1] = ",#FFD700"
|
||||
else
|
||||
formspec[#formspec + 1] = ","
|
||||
end
|
||||
formspec = formspec .. "From: " .. minetest.formspec_escape(message.sender) .. " Subject: "
|
||||
formspec[#formspec + 1] = ","
|
||||
formspec[#formspec + 1] = minetest.formspec_escape(message.sender)
|
||||
formspec[#formspec + 1] = ","
|
||||
if message.subject ~= "" then
|
||||
if string.len(message.subject) > 30 then
|
||||
formspec = formspec ..
|
||||
minetest.formspec_escape(string.sub(message.subject, 1, 27)) ..
|
||||
"..."
|
||||
formspec[#formspec + 1] =
|
||||
minetest.formspec_escape(string.sub(message.subject, 1, 27))
|
||||
formspec[#formspec + 1] = "..."
|
||||
else
|
||||
formspec = formspec .. minetest.formspec_escape(message.subject)
|
||||
formspec[#formspec + 1] = minetest.formspec_escape(message.subject)
|
||||
end
|
||||
else
|
||||
formspec = formspec .. "(No subject)"
|
||||
formspec[#formspec + 1] = "(No subject)"
|
||||
end
|
||||
end
|
||||
formspec = formspec .. "]label[0,0;Welcome! You've got mail!]"
|
||||
if selected_message_idxs[name] then
|
||||
formspec[#formspec + 1] = ";"
|
||||
formspec[#formspec + 1] = tostring(selected_message_idxs[name] + 1)
|
||||
end
|
||||
formspec[#formspec + 1] = "]"
|
||||
else
|
||||
formspec = formspec .. "No mail :(]label[0,0;Welcome!]"
|
||||
formspec[#formspec + 1] = "]label[2,4.5;No mail]"
|
||||
end
|
||||
minetest.show_formspec(name, "mail:inbox", formspec)
|
||||
minetest.show_formspec(name, "mail:inbox", table.concat(formspec, ""))
|
||||
end
|
||||
|
||||
function mail.show_message(name, msgnumber)
|
||||
local message = mail.messages[name][msgnumber]
|
||||
local formspec = [[
|
||||
size[8,6]
|
||||
button[7.5,0;0.5,0.5;back;X]
|
||||
size[8,7.2]
|
||||
button[7,0;1,0.5;back;X]
|
||||
label[0,0;From: %s]
|
||||
label[0,0.5;Subject: %s]
|
||||
textarea[0.25,1;8,4;body;;%s]
|
||||
button[1,5;2,1;reply;Reply]
|
||||
button[3,5;2,1;forward;Forward]
|
||||
button[5,5;2,1;delete;Delete]
|
||||
]]
|
||||
textarea[0.25,1.25;8,6.25;;;%s]
|
||||
button[1,6.7;2,1;reply;Reply]
|
||||
button[3,6.7;2,1;forward;Forward]
|
||||
button[5,6.7;2,1;delete;Delete]
|
||||
]] .. theme
|
||||
|
||||
local sender = minetest.formspec_escape(message.sender)
|
||||
local subject = minetest.formspec_escape(message.subject)
|
||||
@ -84,14 +97,14 @@ end
|
||||
|
||||
function mail.show_compose(name, defaulttgt, defaultsubj, defaultbody)
|
||||
local formspec = [[
|
||||
size[8,8]
|
||||
size[8,7.2]
|
||||
field[0.25,0.5;4,1;to;To:;%s]
|
||||
field[0.25,1.5;4,1;subject;Subject:;%s]
|
||||
textarea[0.25,2.5;8,4;body;;%s]
|
||||
button[1,7;2,1;cancel;Cancel]
|
||||
button[7.5,0;0.5,0.5;cancel;X]
|
||||
button[5,7;2,1;send;Send]
|
||||
]]
|
||||
field[0.25,1.7;8,1;subject;Subject:;%s]
|
||||
textarea[0.25,2.4;8,5;body;;%s]
|
||||
button[0.5,6.7;3,1;cancel;Cancel]
|
||||
button[7,0;1,0.5;cancel;X]
|
||||
button[4.5,6.7;3,1;send;Send]
|
||||
]] .. theme
|
||||
|
||||
formspec = string.format(formspec,
|
||||
minetest.formspec_escape(defaulttgt),
|
||||
@ -112,43 +125,44 @@ function mail.handle_receivefields(player, formname, fields)
|
||||
end)
|
||||
elseif formname == "mail:inbox" then
|
||||
local name = player:get_player_name()
|
||||
if fields.message then
|
||||
local event = minetest.explode_textlist_event(fields.message)
|
||||
mail.highlightedmessages[name] = event.index
|
||||
if event.type == "DCL" and mail.messages[name][mail.highlightedmessages[name]] then
|
||||
mail.messages[name][mail.highlightedmessages[name]].unread = false
|
||||
mail.show_message(name, mail.highlightedmessages[name])
|
||||
if fields.messages then
|
||||
local evt = minetest.explode_table_event(fields.messages)
|
||||
selected_message_idxs[name] = evt.row - 1
|
||||
if evt.type == "DCL" and mail.messages[name][selected_message_idxs[name]] then
|
||||
mail.messages[name][selected_message_idxs[name]].unread = false
|
||||
mail.show_message(name, selected_message_idxs[name])
|
||||
end
|
||||
return true
|
||||
end
|
||||
if fields.read then
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
||||
mail.messages[name][mail.highlightedmessages[name]].unread = false
|
||||
mail.show_message(name, mail.highlightedmessages[name])
|
||||
if mail.messages[name][selected_message_idxs[name]] then
|
||||
mail.messages[name][selected_message_idxs[name]].unread = false
|
||||
mail.show_message(name, selected_message_idxs[name])
|
||||
end
|
||||
elseif fields.delete then
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
||||
table.remove(mail.messages[name], mail.highlightedmessages[name])
|
||||
if mail.messages[name][selected_message_idxs[name]] then
|
||||
table.remove(mail.messages[name], selected_message_idxs[name])
|
||||
end
|
||||
|
||||
mail.show_inbox(name)
|
||||
mail.save()
|
||||
elseif fields.reply and mail.messages[name][mail.highlightedmessages[name]] then
|
||||
local message = mail.messages[name][mail.highlightedmessages[name]]
|
||||
elseif fields.reply and mail.messages[name][selected_message_idxs[name]] then
|
||||
local message = mail.messages[name][selected_message_idxs[name]]
|
||||
local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body
|
||||
mail.show_compose(name, message.sender, "Re: "..message.subject,replyfooter)
|
||||
elseif fields.forward and mail.messages[name][mail.highlightedmessages[name]] then
|
||||
local message = mail.messages[name][mail.highlightedmessages[name]]
|
||||
elseif fields.forward and mail.messages[name][selected_message_idxs[name]] then
|
||||
local message = mail.messages[name][selected_message_idxs[name]]
|
||||
local fwfooter = "Type your message here.\n\n--Original message follows--\n" ..message.body
|
||||
mail.show_compose(name, "", "Fw: "..message.subject, fwfooter)
|
||||
elseif fields.markread then
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
||||
mail.messages[name][mail.highlightedmessages[name]].unread = false
|
||||
if mail.messages[name][selected_message_idxs[name]] then
|
||||
mail.messages[name][selected_message_idxs[name]].unread = false
|
||||
end
|
||||
mail.show_inbox(name)
|
||||
mail.save()
|
||||
elseif fields.markunread then
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
||||
mail.messages[name][mail.highlightedmessages[name]].unread = true
|
||||
if mail.messages[name][selected_message_idxs[name]] then
|
||||
mail.messages[name][selected_message_idxs[name]].unread = true
|
||||
end
|
||||
mail.show_inbox(name)
|
||||
mail.save()
|
||||
@ -167,16 +181,16 @@ function mail.handle_receivefields(player, formname, fields)
|
||||
if fields.back then
|
||||
mail.show_inbox(name)
|
||||
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
|
||||
mail.show_compose(name, message.sender, "Re: "..message.subject, replyfooter)
|
||||
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
|
||||
mail.show_compose(name, "", "Fw: "..message.subject, fwfooter)
|
||||
elseif fields.delete then
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
||||
table.remove(mail.messages[name],mail.highlightedmessages[name])
|
||||
if mail.messages[name][selected_message_idxs[name]] then
|
||||
table.remove(mail.messages[name],selected_message_idxs[name])
|
||||
end
|
||||
mail.show_inbox(name)
|
||||
mail.save()
|
||||
|
Loading…
x
Reference in New Issue
Block a user