hud.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. local huddata = {}
  2. minetest.register_on_joinplayer(function(player)
  3. local name = player:get_player_name()
  4. local data = {}
  5. data.imageid = player:hud_add({
  6. hud_elem_type = "image",
  7. name = "MailIcon",
  8. position = {x=0.52, y=0.52},
  9. text="",
  10. scale = {x=1,y=1},
  11. alignment = {x=0.5, y=0.5},
  12. })
  13. data.textid = player:hud_add({
  14. hud_elem_type = "text",
  15. name = "MailText",
  16. position = {x=0.55, y=0.52},
  17. text= "",
  18. scale = {x=1,y=1},
  19. alignment = {x=0.5, y=0.5},
  20. })
  21. huddata[name] = data
  22. end)
  23. minetest.register_on_leaveplayer(function(player)
  24. local name = player:get_player_name()
  25. huddata[name] = nil
  26. end)
  27. mail.hud_update = function(playername, messages)
  28. local data = huddata[playername]
  29. local player = minetest.get_player_by_name(playername)
  30. if not data or not player then
  31. return
  32. end
  33. local unreadcount = 0
  34. for _, message in ipairs(messages) do
  35. if message.unread then
  36. unreadcount = unreadcount + 1
  37. end
  38. end
  39. if unreadcount == 0 then
  40. player:hud_change(data.imageid, "text", "")
  41. player:hud_change(data.textid, "text", "")
  42. else
  43. player:hud_change(data.imageid, "text", "email_mail.png")
  44. player:hud_change(data.textid, "text", unreadcount .. " /mail")
  45. end
  46. end