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:
Athozus 2023-11-05 17:11:36 +01:00
parent 4240f4eb39
commit 31c97cc4f2
No known key found for this signature in database
GPG key ID: B50895022E8484BF
2 changed files with 12 additions and 30 deletions

View file

@ -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] = ","

View file

@ -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))