2019-09-16 09:06:54 +03:00
|
|
|
|
|
|
|
local huddata = {}
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local data = {}
|
|
|
|
|
|
|
|
data.imageid = player:hud_add({
|
|
|
|
hud_elem_type = "image",
|
|
|
|
name = "MailIcon",
|
|
|
|
position = {x=0.52, y=0.52},
|
|
|
|
text="",
|
|
|
|
scale = {x=1,y=1},
|
|
|
|
alignment = {x=0.5, y=0.5},
|
|
|
|
})
|
|
|
|
|
|
|
|
data.textid = player:hud_add({
|
|
|
|
hud_elem_type = "text",
|
|
|
|
name = "MailText",
|
|
|
|
position = {x=0.55, y=0.52},
|
|
|
|
text= "",
|
|
|
|
scale = {x=1,y=1},
|
|
|
|
alignment = {x=0.5, y=0.5},
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
huddata[name] = data
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
huddata[name] = nil
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
2022-08-02 15:58:42 +03:00
|
|
|
function mail.hud_update(playername, messages)
|
2019-09-16 09:06:54 +03:00
|
|
|
local data = huddata[playername]
|
|
|
|
local player = minetest.get_player_by_name(playername)
|
|
|
|
|
|
|
|
if not data or not player then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local unreadcount = 0
|
|
|
|
for _, message in ipairs(messages) do
|
2023-04-01 20:14:53 +03:00
|
|
|
if not message.read then
|
2019-09-16 09:06:54 +03:00
|
|
|
unreadcount = unreadcount + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-05 12:38:19 +03:00
|
|
|
if unreadcount == 0 or (not mail.get_setting(playername, "hud_notifications")) then
|
2019-09-16 09:06:54 +03:00
|
|
|
player:hud_change(data.imageid, "text", "")
|
|
|
|
player:hud_change(data.textid, "text", "")
|
|
|
|
else
|
|
|
|
player:hud_change(data.imageid, "text", "email_mail.png")
|
|
|
|
player:hud_change(data.textid, "text", unreadcount .. " /mail")
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|