mirror of
https://github.com/mt-mods/mail.git
synced 2025-04-30 08:21:44 -04:00
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
This commit is contained in:
parent
4240f4eb39
commit
31c97cc4f2
2 changed files with 12 additions and 30 deletions
36
ui/inbox.lua
36
ui/inbox.lua
|
@ -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.get_color("ias")
|
||||
else
|
||||
formspec[#formspec + 1] = "," .. mail.get_color("is")
|
||||
end
|
||||
else
|
||||
if not mail.player_in_list(name, message.to) and cc_color_enable then
|
||||
formspec[#formspec + 1] = "," .. mail.get_color("as")
|
||||
else
|
||||
formspec[#formspec + 1] = "," .. mail.get_color("s")
|
||||
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.get_color("ia")
|
||||
else
|
||||
formspec[#formspec + 1] = "," .. mail.get_color("i")
|
||||
end
|
||||
else
|
||||
if not mail.player_in_list(name, message.to) and cc_color_enable then
|
||||
formspec[#formspec + 1] = "," .. mail.get_color("a")
|
||||
else
|
||||
formspec[#formspec + 1] = ","
|
||||
end
|
||||
end
|
||||
displayed_color = displayed_color .. "s"
|
||||
end
|
||||
if not message.read and unread_color_enable then
|
||||
displayed_color = displayed_color .. "i"
|
||||
end
|
||||
if not mail.player_in_list(name, message.to) and cc_color_enable then
|
||||
displayed_color = displayed_color .. "a"
|
||||
end
|
||||
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
|
||||
formspec[#formspec + 1] = ","
|
||||
formspec[#formspec + 1] = minetest.formspec_escape(message.from)
|
||||
formspec[#formspec + 1] = ","
|
||||
|
|
|
@ -73,6 +73,7 @@ function mail.show_outbox(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.outbox[name] and #mail.selected_idxs.outbox[name] > 0 then
|
||||
for i, selected_msg in ipairs(mail.selected_idxs.outbox[name]) do
|
||||
|
@ -83,10 +84,9 @@ function mail.show_outbox(name, sortfieldindex, sortdirection, filter)
|
|||
end
|
||||
end
|
||||
if selected_id > 0 then
|
||||
formspec[#formspec + 1] = "," .. mail.get_color("s")
|
||||
else
|
||||
formspec[#formspec + 1] = ","
|
||||
displayed_color = displayed_color .. "s"
|
||||
end
|
||||
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
|
||||
formspec[#formspec + 1] = ","
|
||||
if string.len(message.to) > 20 then
|
||||
formspec[#formspec + 1] = minetest.formspec_escape(string.sub(message.to, 1, 17))
|
||||
|
|
Loading…
Add table
Reference in a new issue