From 31c97cc4f24c8c7a69a2cae075c9c25e478a4639 Mon Sep 17 00:00:00 2001 From: Athozus Date: Sun, 5 Nov 2023 17:11:36 +0100 Subject: [PATCH] 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 --- ui/inbox.lua | 36 +++++++++--------------------------- ui/outbox.lua | 6 +++--- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/ui/inbox.lua b/ui/inbox.lua index 05293d8..9c18c58 100644 --- a/ui/inbox.lua +++ b/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] = "," diff --git a/ui/outbox.lua b/ui/outbox.lua index 0e85404..dc3e41e 100644 --- a/ui/outbox.lua +++ b/ui/outbox.lua @@ -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))