mirror of
https://github.com/mt-mods/mail.git
synced 2025-04-30 16:31:43 -04:00
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
eae49e8897
commit
c8b8d0b43f
13 changed files with 41 additions and 39 deletions
|
@ -17,7 +17,7 @@ minetest.register_on_joinplayer(function(player)
|
||||||
|
|
||||||
if unreadcount > 0 and mail.get_setting(name, "onjoin_notifications") then
|
if unreadcount > 0 and mail.get_setting(name, "onjoin_notifications") then
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name,
|
||||||
minetest.colorize(mail.get_color("n"), "(" .. unreadcount .. ") " .. S("You have mail! Type /mail to read")))
|
minetest.colorize(mail.get_color("new"), "(" .. unreadcount .. ") " .. S("You have mail! Type /mail to read")))
|
||||||
end
|
end
|
||||||
end, player:get_player_name())
|
end, player:get_player_name())
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -21,8 +21,8 @@ function mail.show_about(name)
|
||||||
|
|
||||||
tablecolumns[color;text;text]
|
tablecolumns[color;text;text]
|
||||||
table[5,0.75;4.9,5.5;contributors;]] ..
|
table[5,0.75;4.9,5.5;contributors;]] ..
|
||||||
mail.get_color("h") .. [[,]] .. S("Contributors") .. [[,,]] ..
|
mail.get_color("header") .. [[,]] .. S("Contributors") .. [[,,]] ..
|
||||||
mail.get_color("i") .. [[,Cheapie,Initial idea/project,]] ..
|
mail.get_color("important") .. [[,Cheapie,Initial idea/project,]] ..
|
||||||
[[,Rubenwardy,Lua/UI improvements,]] ..
|
[[,Rubenwardy,Lua/UI improvements,]] ..
|
||||||
[[,BuckarooBanzay,Clean-ups\, Refactoring,]] ..
|
[[,BuckarooBanzay,Clean-ups\, Refactoring,]] ..
|
||||||
[[,Athozus,Boxes\, Maillists\, UI\, Settings,]] ..
|
[[,Athozus,Boxes\, Maillists\, UI\, Settings,]] ..
|
||||||
|
|
|
@ -9,7 +9,7 @@ local contacts_formspec = "size[8,9;]" .. mail.theme .. [[
|
||||||
button[6,1.60;2,0.5;delete;]] .. S("Delete") .. [[]
|
button[6,1.60;2,0.5;delete;]] .. S("Delete") .. [[]
|
||||||
button[6,8.25;2,0.5;back;]] .. S("Back") .. [[]
|
button[6,8.25;2,0.5;back;]] .. S("Back") .. [[]
|
||||||
tablecolumns[color;text;text]
|
tablecolumns[color;text;text]
|
||||||
table[0,0;5.75,9;contacts;]] .. mail.get_color("h") .. "," .. S("Name") .. "," .. S("Note")
|
table[0,0;5.75,9;contacts;]] .. mail.get_color("header") .. "," .. S("Name") .. "," .. S("Note")
|
||||||
|
|
||||||
|
|
||||||
function mail.show_contacts(name)
|
function mail.show_contacts(name)
|
||||||
|
|
|
@ -21,7 +21,7 @@ function mail.show_drafts(name)
|
||||||
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
|
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
|
||||||
|
|
||||||
tablecolumns[color;text;text]
|
tablecolumns[color;text;text]
|
||||||
table[0,0.7;5.75,9.35;drafts;]] .. mail.get_color("h") .. "," .. S("To") .. "," .. S("Subject")
|
table[0,0.7;5.75,9.35;drafts;]] .. mail.get_color("header") .. "," .. S("To") .. "," .. S("Subject")
|
||||||
|
|
||||||
local formspec = { drafts_formspec }
|
local formspec = { drafts_formspec }
|
||||||
local entry = mail.get_storage_entry(name)
|
local entry = mail.get_storage_entry(name)
|
||||||
|
|
10
ui/inbox.lua
10
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") .. [[]
|
button[3.5,9.5;2.5,0.5;selectall;]] .. S("(Un)select all") .. [[]
|
||||||
|
|
||||||
tablecolumns[color;text;text]
|
tablecolumns[color;text;text]
|
||||||
table[0,0.7;5.75,7.45;inbox;]] .. mail.get_color("h") .. "," .. 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 }
|
local formspec = { inbox_formspec }
|
||||||
|
|
||||||
mail.message_drafts[name] = nil
|
mail.message_drafts[name] = nil
|
||||||
|
@ -78,7 +78,7 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
|
||||||
if #messages > 0 then
|
if #messages > 0 then
|
||||||
for _, message in ipairs(messages) do
|
for _, message in ipairs(messages) do
|
||||||
local selected_id = 0
|
local selected_id = 0
|
||||||
local displayed_color = ""
|
local displayed_color = {}
|
||||||
-- check if message is in selection list and return its id
|
-- 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
|
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
|
for i, selected_msg in ipairs(mail.selected_idxs.inbox[name]) do
|
||||||
|
@ -89,13 +89,13 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if selected_id > 0 then
|
if selected_id > 0 then
|
||||||
displayed_color = displayed_color .. "s"
|
table.insert(displayed_color, "selected")
|
||||||
end
|
end
|
||||||
if not message.read and unread_color_enable then
|
if not message.read and unread_color_enable then
|
||||||
displayed_color = displayed_color .. "i"
|
table.insert(displayed_color, "important")
|
||||||
end
|
end
|
||||||
if not mail.player_in_list(name, message.to) and cc_color_enable then
|
if not mail.player_in_list(name, message.to) and cc_color_enable then
|
||||||
displayed_color = displayed_color .. "a"
|
table.insert(displayed_color, "additional")
|
||||||
end
|
end
|
||||||
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
|
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
|
||||||
formspec[#formspec + 1] = ","
|
formspec[#formspec + 1] = ","
|
||||||
|
|
|
@ -9,7 +9,7 @@ local maillists_formspec = "size[8,9;]" .. mail.theme .. [[
|
||||||
button[6,1.60;2,0.5;delete;]] .. S("Delete") .. [[]
|
button[6,1.60;2,0.5;delete;]] .. S("Delete") .. [[]
|
||||||
button[6,8.25;2,0.5;back;]] .. S("Back") .. [[]
|
button[6,8.25;2,0.5;back;]] .. S("Back") .. [[]
|
||||||
tablecolumns[color;text;text]
|
tablecolumns[color;text;text]
|
||||||
table[0,0;5.75,9;maillists;]] .. mail.get_color("h") .. "," .. S("Name") .. "," .. S("Note")
|
table[0,0;5.75,9;maillists;]] .. mail.get_color("header") .. "," .. S("Name") .. "," .. S("Note")
|
||||||
|
|
||||||
function mail.show_maillists(name)
|
function mail.show_maillists(name)
|
||||||
local formspec = { maillists_formspec }
|
local formspec = { maillists_formspec }
|
||||||
|
|
|
@ -15,7 +15,7 @@ function mail.show_message(name, id)
|
||||||
local formspec = [[
|
local formspec = [[
|
||||||
size[8,9]
|
size[8,9]
|
||||||
|
|
||||||
box[0,0;7,1.9;]] .. mail.get_color("H") .. [[]
|
box[0,0;7,1.9;]] .. mail.get_color("highlighted") .. [[]
|
||||||
|
|
||||||
button[7.25,0.15;0.75,0.5;back;X]
|
button[7.25,0.15;0.75,0.5;back;X]
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ function mail.show_outbox(name, sortfieldindex, sortdirection, filter)
|
||||||
button[3.5,9.5;2.5,0.5;selectall;]] .. S("(Un)select all") .. [[]
|
button[3.5,9.5;2.5,0.5;selectall;]] .. S("(Un)select all") .. [[]
|
||||||
|
|
||||||
tablecolumns[color;text;text]
|
tablecolumns[color;text;text]
|
||||||
table[0,0.7;5.75,7.45;outbox;]] .. mail.get_color("h") .. "," .. S("To") .. "," .. S("Subject")
|
table[0,0.7;5.75,7.45;outbox;]] .. mail.get_color("header") .. "," .. S("To") .. "," .. S("Subject")
|
||||||
local formspec = { outbox_formspec }
|
local formspec = { outbox_formspec }
|
||||||
|
|
||||||
mail.message_drafts[name] = nil
|
mail.message_drafts[name] = nil
|
||||||
|
@ -73,7 +73,7 @@ function mail.show_outbox(name, sortfieldindex, sortdirection, filter)
|
||||||
if #messages > 0 then
|
if #messages > 0 then
|
||||||
for _, message in ipairs(messages) do
|
for _, message in ipairs(messages) do
|
||||||
local selected_id = 0
|
local selected_id = 0
|
||||||
local displayed_color = ""
|
local displayed_color = {}
|
||||||
-- check if message is in selection list and return its id
|
-- 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
|
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
|
for i, selected_msg in ipairs(mail.selected_idxs.outbox[name]) do
|
||||||
|
@ -84,7 +84,7 @@ function mail.show_outbox(name, sortfieldindex, sortdirection, filter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if selected_id > 0 then
|
if selected_id > 0 then
|
||||||
displayed_color = displayed_color .. "s"
|
table.insert(displayed_color, "selected")
|
||||||
end
|
end
|
||||||
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
|
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
|
||||||
formspec[#formspec + 1] = ","
|
formspec[#formspec + 1] = ","
|
||||||
|
|
|
@ -9,7 +9,7 @@ function mail.show_receivers(name, id)
|
||||||
local formspec = [[
|
local formspec = [[
|
||||||
size[8,6]
|
size[8,6]
|
||||||
|
|
||||||
box[0,0;7,1.1;]] .. mail.get_color("H") .. [[]
|
box[0,0;7,1.1;]] .. mail.get_color("highlighted") .. [[]
|
||||||
|
|
||||||
button[7.25,0.15;0.75,0.5;back;X]
|
button[7.25,0.15;0.75,0.5;back;X]
|
||||||
|
|
||||||
|
@ -25,10 +25,10 @@ function mail.show_receivers(name, id)
|
||||||
|
|
||||||
local from = minetest.formspec_escape(message.from) or ""
|
local from = minetest.formspec_escape(message.from) or ""
|
||||||
local to = mail.parse_player_list(message.to or "")
|
local to = mail.parse_player_list(message.to or "")
|
||||||
local to_str = mail.get_color("h") .. "," .. S("To") .. ",,"
|
local to_str = mail.get_color("header") .. "," .. S("To") .. ",,"
|
||||||
to_str = to_str .. table.concat(to, ",,")
|
to_str = to_str .. table.concat(to, ",,")
|
||||||
local cc = mail.parse_player_list(message.cc or "")
|
local cc = mail.parse_player_list(message.cc or "")
|
||||||
local cc_str = mail.get_color("h") .. "," .. S("CC") .. ",,"
|
local cc_str = mail.get_color("header") .. "," .. S("CC") .. ",,"
|
||||||
cc_str = cc_str .. table.concat(cc, ",,")
|
cc_str = cc_str .. table.concat(cc, ",,")
|
||||||
local date = type(message.time) == "number"
|
local date = type(message.time) == "number"
|
||||||
and minetest.formspec_escape(os.date(mail.get_setting(name, "date_format"), message.time)) or ""
|
and minetest.formspec_escape(os.date(mail.get_setting(name, "date_format"), message.time)) or ""
|
||||||
|
|
|
@ -5,15 +5,15 @@ local FORMNAME = "mail:selectcontact"
|
||||||
|
|
||||||
local select_contact_formspec = "size[8,9;]" .. mail.theme .. [[
|
local select_contact_formspec = "size[8,9;]" .. mail.theme .. [[
|
||||||
tablecolumns[color;text;text]
|
tablecolumns[color;text;text]
|
||||||
table[0,0;3.5,9;contacts;]] .. mail.get_color("h") .. "," .. S("Name") .. "," .. S("Note") .. [[%s]
|
table[0,0;3.5,9;contacts;]] .. mail.get_color("header") .. "," .. S("Name") .. "," .. S("Note") .. [[%s]
|
||||||
button[3.55,2.00;1.75,0.5;toadd;→ ]] .. S("Add") .. [[]
|
button[3.55,2.00;1.75,0.5;toadd;→ ]] .. S("Add") .. [[]
|
||||||
button[3.55,2.75;1.75,0.5;toremove;← ]] .. S("Remove") .. [[]
|
button[3.55,2.75;1.75,0.5;toremove;← ]] .. S("Remove") .. [[]
|
||||||
button[3.55,6.00;1.75,0.5;ccadd;→ ]] .. S("Add") .. [[]
|
button[3.55,6.00;1.75,0.5;ccadd;→ ]] .. S("Add") .. [[]
|
||||||
button[3.55,6.75;1.75,0.5;ccremove;← ]] .. S("Remove") .. [[]
|
button[3.55,6.75;1.75,0.5;ccremove;← ]] .. S("Remove") .. [[]
|
||||||
tablecolumns[color;text;text]
|
tablecolumns[color;text;text]
|
||||||
table[5.15,0.0;2.75,4.5;to;]] .. mail.get_color("h") .. "," .. S("To") .. ":," .. S("Note") .. [[%s]
|
table[5.15,0.0;2.75,4.5;to;]] .. mail.get_color("header") .. "," .. S("To") .. ":," .. S("Note") .. [[%s]
|
||||||
tablecolumns[color;text;text]
|
tablecolumns[color;text;text]
|
||||||
table[5.15,4.6;2.75,4.5;cc;]] .. mail.get_color("h") .. "," .. S("CC") .. ":," .. S("Note") .. [[%s]
|
table[5.15,4.6;2.75,4.5;cc;]] .. mail.get_color("header") .. "," .. S("CC") .. ":," .. S("Note") .. [[%s]
|
||||||
button[3.55,8.25;1.75,0.5;back;]] .. S("Back") .. [[]
|
button[3.55,8.25;1.75,0.5;back;]] .. S("Back") .. [[]
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ function mail.show_settings(name)
|
||||||
tablecolumns[text]
|
tablecolumns[text]
|
||||||
table[0,0.775;3,4.5;groups;]] .. groups_str .. [[;]] .. group_index .. [[]
|
table[0,0.775;3,4.5;groups;]] .. groups_str .. [[;]] .. group_index .. [[]
|
||||||
|
|
||||||
box[3.5,0.8;3,0.45;]] .. mail.get_color("H") .. [[]
|
box[3.5,0.8;3,0.45;]] .. mail.get_color("highlighted") .. [[]
|
||||||
label[3.7,0.8;]] .. mail.settings_groups[group_index].label .. [[]
|
label[3.7,0.8;]] .. mail.settings_groups[group_index].label .. [[]
|
||||||
|
|
||||||
button[0,5.65;2.5,0.5;reset;]] .. S("Reset") .. [[]
|
button[0,5.65;2.5,0.5;reset;]] .. S("Reset") .. [[]
|
||||||
|
|
|
@ -16,7 +16,7 @@ local trash_formspec = "size[8.5,10;]" .. mail.theme .. [[
|
||||||
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
|
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
|
||||||
|
|
||||||
tablecolumns[color;text;text]
|
tablecolumns[color;text;text]
|
||||||
table[0,0.7;5.75,9.35;trash;]] .. mail.get_color("h") .. "," .. S("From/To") .. "," .. S("Subject")
|
table[0,0.7;5.75,9.35;trash;]] .. mail.get_color("header") .. "," .. S("From/To") .. "," .. S("Subject")
|
||||||
|
|
||||||
|
|
||||||
function mail.show_trash(name)
|
function mail.show_trash(name)
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
local function get_base_color(id)
|
local generic_colors = {
|
||||||
local colors = {
|
header = "#999999",
|
||||||
h = "#999999", -- header
|
selected = "#72FF63",
|
||||||
s = "#72FF63", -- selected
|
important = "#FFD700",
|
||||||
i = "#FFD700", -- important
|
additional = "#CCCCDD",
|
||||||
a = "#CCCCDD", -- additional
|
highlighted = "#608631",
|
||||||
H = "#608631", -- highlighted
|
new = "#00F529",
|
||||||
n = "#00F529" -- new
|
|
||||||
}
|
}
|
||||||
return colors[id]
|
|
||||||
|
local function get_base_color(c)
|
||||||
|
return generic_colors[c] or ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local function hex2rgb(hex)
|
local function hex2rgb(hex)
|
||||||
|
@ -39,15 +40,16 @@ local function rgbColorsMix(colors)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mail.get_color(mix)
|
function mail.get_color(mix)
|
||||||
if #mix == 1 then
|
if type(mix) == "string" then
|
||||||
return get_base_color(mix)
|
return get_base_color(mix)
|
||||||
|
elseif #mix == 1 then
|
||||||
|
return get_base_color(mix[1])
|
||||||
else
|
else
|
||||||
local colors = {}
|
local colors2mix = {}
|
||||||
for i = 1, #mix do
|
for _, c in ipairs(mix) do
|
||||||
local c = mix:sub(i,i)
|
colors2mix[#colors2mix+1] = hex2rgb(get_base_color(c))
|
||||||
colors[#colors+1] = hex2rgb(get_base_color(c))
|
|
||||||
end
|
end
|
||||||
local mixed_color = rgbColorsMix(colors)
|
local mixed_color = rgbColorsMix(colors2mix)
|
||||||
return rgb2hex(mixed_color)
|
return rgb2hex(mixed_color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue