Add settings (#85)

* Add settings

* Fix luacheck

* Fix unupdatable sorting fields values (settings)

* Better settings names

* Better sort settings behaviour

* Rework set_setting()

* Rework settings storage

* Better get sorting filters (inbox/outbox)

* Fix reseting/saving settings
This commit is contained in:
Athozus 2023-05-05 11:38:19 +02:00 committed by GitHub
parent a8632255b3
commit 720029a73e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 322 additions and 103 deletions

View file

@ -1,10 +1,11 @@
-- 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 = tostring(sortdirection or mail.selected_idxs.sortdirection[name]
or 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 +22,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 +59,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] = ","