mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-05 14:10:31 -04:00
Add colors utilities (#121)
* Add colors utilities Local function get_base_color(), conversions hex <=> rgb, rgb color mixer, and global function get_color() * Round numbers to avoid eventual float in string.format * Simplify inbox/outbox mixing of color Use a single if statement for each property and concatenate to displayed_color then execute mail.get_color(displayed_color) instead of making many combined if statements * Convert 3-chars hex colors to 6-chars hex colors Could break the code, the hex convert to rgb always run on 6-chars * Rework color utility using tables Instead of one-letter symbols, it now supports tables of identifiers or single strings
This commit is contained in:
parent
802f9f727b
commit
3bad371353
15 changed files with 86 additions and 61 deletions
38
ui/inbox.lua
38
ui/inbox.lua
|
@ -67,7 +67,7 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
|
|||
button[3.5,9.5;2.5,0.5;selectall;]] .. S("(Un)select all") .. [[]
|
||||
|
||||
tablecolumns[color;text;text]
|
||||
table[0,0.7;5.75,7.45;inbox;]] .. mail.colors.header .. "," .. S("From") .. "," .. S("Subject")
|
||||
table[0,0.7;5.75,7.45;inbox;]] .. mail.get_color("header") .. "," .. S("From") .. "," .. S("Subject")
|
||||
local formspec = { inbox_formspec }
|
||||
|
||||
mail.message_drafts[name] = nil
|
||||
|
@ -78,6 +78,7 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
|
|||
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
|
||||
|
@ -88,34 +89,15 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
|
|||
end
|
||||
end
|
||||
if selected_id > 0 then
|
||||
if not message.read and unread_color_enable then
|
||||
if not mail.player_in_list(name, message.to) and cc_color_enable then
|
||||
formspec[#formspec + 1] = "," .. mail.colors.imp_add_sel
|
||||
else
|
||||
formspec[#formspec + 1] = "," .. mail.colors.imp_sel
|
||||
end
|
||||
else
|
||||
if not mail.player_in_list(name, message.to) and cc_color_enable then
|
||||
formspec[#formspec + 1] = "," .. mail.colors.add_sel
|
||||
else
|
||||
formspec[#formspec + 1] = "," .. mail.colors.selected
|
||||
end
|
||||
end
|
||||
else
|
||||
if not message.read and unread_color_enable then
|
||||
if not mail.player_in_list(name, message.to) and cc_color_enable then
|
||||
formspec[#formspec + 1] = "," .. mail.colors.imp_add
|
||||
else
|
||||
formspec[#formspec + 1] = "," .. mail.colors.important
|
||||
end
|
||||
else
|
||||
if not mail.player_in_list(name, message.to) and cc_color_enable then
|
||||
formspec[#formspec + 1] = "," .. mail.colors.additional
|
||||
else
|
||||
formspec[#formspec + 1] = ","
|
||||
end
|
||||
end
|
||||
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
|
||||
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
|
||||
formspec[#formspec + 1] = ","
|
||||
formspec[#formspec + 1] = minetest.formspec_escape(message.from)
|
||||
formspec[#formspec + 1] = ","
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue