hud.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. local hudkit = dofile(minetest.get_modpath("email") .. "/hudkit.lua")
  2. email.hud = hudkit()
  3. function email.update_hud(player)
  4. local name = player:get_player_name()
  5. -- ICON only shows for players that have a key of citizenship.
  6. if passport.player_has_key(name) then
  7. local inbox = email.get_inbox(name)
  8. if inbox and #inbox > 0 then
  9. if email.hud:exists(player, "email:text") then
  10. email.hud:change(player, "email:text", "text", "(" .. #inbox .. ")")
  11. else
  12. email.hud:add(player, "email:icon", {
  13. hud_elem_type = "image",
  14. name = "MailIcon",
  15. position = {x=0.52, y=0.52},
  16. text="email_mail.png",
  17. scale = {x=1,y=1},
  18. alignment = {x=0.5, y=0.5},
  19. })
  20. email.hud:add(player, "email:text", {
  21. hud_elem_type = "text",
  22. name = "MailText",
  23. position = {x=0.55, y=0.52},
  24. text= "(" .. #inbox .. ")",
  25. scale = {x=1,y=1},
  26. alignment = {x=0.5, y=0.5},
  27. })
  28. end
  29. else
  30. email.hud:remove(player, "email:icon")
  31. email.hud:remove(player, "email:text")
  32. end
  33. end
  34. end
  35. minetest.register_on_leaveplayer(function(player)
  36. local pname = player:get_player_name()
  37. email.hud.players[pname] = nil
  38. -- Email will be refetched from database when player next joins.
  39. -- In the meantime, free the inbox (in case it is very large).
  40. email.inboxes[pname] = nil
  41. end)
  42. function email.update_all_hud()
  43. local players = minetest.get_connected_players()
  44. for _, player in pairs(players) do
  45. email.update_hud(player)
  46. end
  47. minetest.after(11, email.update_all_hud)
  48. end
  49. minetest.after(11, email.update_all_hud)