Add settings

This commit is contained in:
Athozus 2023-05-04 12:14:18 +02:00
parent a8632255b3
commit d51b363cbc
No known key found for this signature in database
GPG key ID: B50895022E8484BF
16 changed files with 335 additions and 101 deletions

View file

@ -1,17 +1,21 @@
-- translation
local S = minetest.get_translator("mail")
local FORMNAME = "mail:about"
function mail.show_about(name)
local formspec = [[
size[10,6;]
tabheader[0.3,1;optionstab;]] .. S("Settings") .. "," .. S("About") .. [[;2;false;false]
button[9.35,0;0.75,0.5;back;X]
label[0,0;Mail]
label[0,0.4;Provided my mt-mods]
label[0,0.8;Version: 1.1.4]
label[0,1.4;Licenses:]
label[0.2,1.8;Expat (code), WTFPL (textures)]
label[0,2.4;https://github.com/mt-mods/mail]
label[0,2.8;https://content.minetest.net/packages/mt-mods/mail]
textarea[0.5,4.0;4,5.5;;Note;]] ..
label[0,0.8;Mail]
label[0,1.2;Provided my mt-mods]
label[0,1.6;Version: 1.2.0-dev]
label[0,2.2;Licenses:]
label[0.2,2.6;Expat (code), WTFPL (textures)]
label[0,3.2;https://github.com/mt-mods/mail]
label[0,3.6;https://content.minetest.net/packages/mt-mods/mail]
textarea[0.5,4.8;4,5.5;;Note;]] ..
[[NOTE: Communication using this system is NOT guaranteed to be private!]] ..
[[ Admins are able to view the messages of any player.]
@ -42,8 +46,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end
local playername = player:get_player_name()
if fields.back then
local playername = player:get_player_name()
mail.show_mail_menu(playername)
elseif fields.optionstab == "1" then
mail.selected_idxs.optionstab[playername] = 1
mail.show_settings(playername)
elseif fields.optionstab == "2" then
mail.selected_idxs.optionstab[playername] = 2
mail.show_about(playername)
end
end)

View file

@ -9,7 +9,7 @@ local drafts_formspec = "size[8.5,10;]" .. mail.theme .. [[
button[6,1.70;2.5,0.5;delete;]] .. S("Delete") .. [[]
button[6,6.8;2.5,0.5;contacts;]] .. S("Contacts") .. [[]
button[6,7.6;2.5,0.5;maillists;]] .. S("Mail lists") .. [[]
button[6,8.7;2.5,0.5;about;]] .. S("About") .. [[]
button[6,8.7;2.5,0.5;options;]] .. S("Options") .. [[]
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
tablecolumns[color;text;text]

View file

@ -249,8 +249,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif fields.maillists then
mail.show_maillists(name)
elseif fields.about then
mail.show_about(name)
elseif fields.options then
mail.show_options(name)
elseif fields.selectall then
if formname == "mail:inbox" then

View file

@ -1,10 +1,9 @@
-- translation
local S = minetest.get_translator("mail")
function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
sortfieldindex = tonumber(sortfieldindex or mail.selected_idxs.sortfield[name]) or 3
sortdirection = sortdirection or mail.selected_idxs.sortdirection[name] or "1"
sortfieldindex = tonumber(sortfieldindex or mail.selected_idxs.sortfield[name]) or mail.get_setting(name, "defaultsortfield") or 3
sortdirection = sortdirection or mail.selected_idxs.sortdirection[name] or tostring(mail.get_setting(name, "defaultsortdirection")) or "1"
filter = filter or mail.selected_idxs.filter[name] or ""
mail.selected_idxs.inbox[name] = mail.selected_idxs.inbox[name] or {}
@ -21,7 +20,7 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
button[6,5.55;2.5,0.5;markunread;]] .. S("Mark Unread") .. [[]
button[6,6.8;2.5,0.5;contacts;]] .. S("Contacts") .. [[]
button[6,7.6;2.5,0.5;maillists;]] .. S("Mail lists") .. [[]
button[6,8.7;2.5,0.5;about;]] .. S("About") .. [[]
button[6,8.7;2.5,0.5;options;]] .. S("Options") .. [[]
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
dropdown[0,8.4;2,0.5;sortfield;]] ..
@ -58,28 +57,28 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
end
end
if selected_id > 0 then
if not message.read then
if not mail.player_in_list(name, message.to) then
if not message.read and mail.get_setting(name, "unreadcolorenable") then
if not mail.player_in_list(name, message.to) and mail.get_setting(name, "cccolorenable") then
formspec[#formspec + 1] = ",#A39E5D"
else
formspec[#formspec + 1] = ",#A39E19"
end
else
if not mail.player_in_list(name, message.to) then
if not mail.player_in_list(name, message.to) and mail.get_setting(name, "cccolorenable") then
formspec[#formspec + 1] = ",#899888"
else
formspec[#formspec + 1] = ",#466432"
end
end
else
if not message.read then
if not mail.player_in_list(name, message.to) then
if not message.read and mail.get_setting(name, "unreadcolorenable") then
if not mail.player_in_list(name, message.to) and mail.get_setting(name, "cccolorenable") then
formspec[#formspec + 1] = ",#FFD788"
else
formspec[#formspec + 1] = ",#FFD700"
end
else
if not mail.player_in_list(name, message.to) then
if not mail.player_in_list(name, message.to) and mail.get_setting(name, "cccolorenable") then
formspec[#formspec + 1] = ",#CCCCDD"
else
formspec[#formspec + 1] = ","

13
ui/options.lua Normal file
View file

@ -0,0 +1,13 @@
-- helper function for tabbed options
function mail.show_options(playername)
local index = mail.selected_idxs.optionstab[playername] or 1
if not mail.selected_idxs.optionstab[playername] then
mail.selected_idxs.optionstab[playername] = 1
end
if index == 1 then
mail.show_settings(playername)
elseif index == 2 then
mail.show_about(playername)
end
end

View file

@ -1,7 +1,6 @@
-- translation
local S = minetest.get_translator("mail")
function mail.show_sent(name, sortfieldindex, sortdirection, filter)
sortfieldindex = tonumber(sortfieldindex or mail.selected_idxs.sortfield[name]) or 3
sortdirection = sortdirection or mail.selected_idxs.sortdirection[name] or "1"
@ -19,7 +18,7 @@ function mail.show_sent(name, sortfieldindex, sortdirection, filter)
button[6,3.95;2.5,0.5;delete;]] .. S("Delete") .. [[]
button[6,6.8;2.5,0.5;contacts;]] .. S("Contacts") .. [[]
button[6,7.6;2.5,0.5;maillists;]] .. S("Mail lists") .. [[]
button[6,8.7;2.5,0.5;about;]] .. S("About") .. [[]
button[6,8.7;2.5,0.5;options;]] .. S("Options") .. [[]
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
dropdown[0,8.4;2,0.5;sortfield;]] ..

106
ui/settings.lua Normal file
View file

@ -0,0 +1,106 @@
-- translation
local S = minetest.get_translator("mail")
local FORMNAME = "mail:settings"
function mail.show_settings(name)
local formspec = [[
size[10,6;]
tabheader[0.3,1;optionstab;]] .. S("Settings") .. "," .. S("About") .. [[;1;false;false]
button[9.35,0;0.75,0.5;back;X]
box[0,0.8;3,0.45;#466432]
label[0.2,0.8;]] .. S("Notifications") .. [[]
checkbox[0,1.2;chatnotif;]] .. S("Chat notifications") .. [[;]] ..
tostring(mail.get_setting(name, "chatnotif")) .. [[]
checkbox[0,1.6;onjoinnotif;]] .. S("On join notifications") .. [[;]] ..
tostring(mail.get_setting(name, "onjoinnotif")) .. [[]
checkbox[0,2.0;hudnotif;]] .. S("HUD notifications") .. [[;]] ..
tostring(mail.get_setting(name, "hudnotif")) .. [[]
box[5,0.8;3,0.45;#466432]
label[5.2,0.8;]] .. S("Message list") .. [[]
checkbox[5,1.2;unreadcolorenable;]] .. S("Show unread in different color") .. [[;]] ..
tostring(mail.get_setting(name, "unreadcolorenable")) .. [[]
checkbox[5,1.6;cccolorenable;]] .. S("Show CC/BCC in different color") .. [[;]] ..
tostring(mail.get_setting(name, "cccolorenable")) .. [[]
label[5,2.6;]] .. S("Default sorting fields") .. [[]
dropdown[5.5,3.0;2,0.5;defaultsortfield;]] ..
S("From/To") .. "," .. S("Subject") .. "," .. S("Date") .. [[;]] ..
mail.get_setting(name, "defaultsortfield") .. [[;true]
dropdown[7.5,3.0;2,0.5;defaultsortdirection;]] ..
S("Ascending") .. "," .. S("Descending") .. [[;]] ..
mail.get_setting(name, "defaultsortdirection") .. [[;true]
button[0,5.5;2.5,0.5;reset;]] .. S("Reset") .. [[]
]] .. mail.theme
minetest.show_formspec(name, FORMNAME, formspec)
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then
return
end
local playername = player:get_player_name()
mail.set_setting(playername, { name = "defaultsortfield", value = tonumber(fields.defaultsortfield) } )
mail.set_setting(playername, { name = "defaultsortdirection", value = tonumber(fields.defaultsortdirection) } )
if fields.back then
mail.show_mail_menu(playername)
return
elseif fields.reset then
mail.reset_settings(playername)
elseif fields.optionstab == "1" then
mail.selected_idxs.optionstab[playername] = 1
elseif fields.optionstab == "2" then
mail.selected_idxs.optionstab[playername] = 2
mail.show_about(playername)
return
elseif fields.chatnotif then
local setting = {
name = "chatnotif",
value = fields.chatnotif == "true",
}
mail.set_setting(playername, setting)
elseif fields.onjoinnotif then
local setting = {
name = "onjoinnotif",
value = fields.onjoinnotif == "true",
}
mail.set_setting(playername, setting)
elseif fields.hudnotif then
local setting = {
name = "hudnotif",
value = fields.hudnotif == "true",
}
mail.set_setting(playername, setting)
mail.hud_update(playername, mail.get_storage_entry(playername).inbox)
elseif fields.unreadcolorenable then
local setting = {
name = "unreadcolorenable",
value = fields.unreadcolorenable == "true",
}
mail.set_setting(playername, setting)
elseif fields.cccolorenable then
local setting = {
name = "cccolorenable",
value = fields.cccolorenable == "true",
}
mail.set_setting(playername, setting)
end
mail.show_settings(playername)
return
end)