builtin.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. HUD_IW_MAX = 8
  2. HUD_IW_TICK = 0.4
  3. if minetest.is_singleplayer() == true then
  4. HUD_IW_TICK = 0.2
  5. end
  6. HUD_SB_SIZE = {x = 24, y = 24}
  7. HUD_HEALTH_POS = {x = 0.5,y = 1}
  8. HUD_HEALTH_OFFSET = {x = -262, y = -87}
  9. HUD_AIR_POS = {x = 0.5, y = 1}
  10. HUD_AIR_OFFSET = {x = 15, y = -87}
  11. HUD_HUNGER_POS = {x = 0.5, y = 1}
  12. HUD_HUNGER_OFFSET = {x = 15, y = -110}
  13. HUD_ARMOR_POS = {x = 0.5, y = 1}
  14. HUD_ARMOR_OFFSET = {x = -262, y = -110}
  15. -- Reorder everything when using ItemWeel
  16. hud.item_wheel = minetest.setting_getbool("hud_item_wheel")
  17. if hud.item_wheel then
  18. HUD_HEALTH_POS = {x = 0.5,y = 1}
  19. HUD_HEALTH_OFFSET = {x = -385, y = -77}
  20. HUD_AIR_POS = {x = 0.5, y = 1}
  21. HUD_AIR_OFFSET = {x = 150, y = -77}
  22. HUD_HUNGER_POS = {x = 0.5, y = 1}
  23. HUD_HUNGER_OFFSET = {x = 180, y = -44}
  24. HUD_ARMOR_POS = {x = 0.5, y = 1}
  25. HUD_ARMOR_OFFSET = {x = -415, y = -44}
  26. end
  27. -- read hud.conf settings
  28. hud.read_conf()
  29. local damage_enabled = minetest.setting_getbool("enable_damage")
  30. hud.show_hunger = minetest.get_modpath("hunger") ~= nil
  31. hud.show_armor = minetest.get_modpath("3d_armor") ~= nil
  32. -- check if some settings are invalid
  33. local enable_hunger = minetest.setting_getbool("hud_hunger_enable")
  34. if (enable_hunger == true or HUD_ENABLE_HUNGER == true) and not hud.show_hunger then
  35. hud.notify_hunger(5)
  36. end
  37. if damage_enabled then
  38. hud.register("health", {
  39. hud_elem_type = "statbar",
  40. position = HUD_HEALTH_POS,
  41. size = HUD_SB_SIZE,
  42. text = "hud_heart_fg.png",
  43. number = 20,
  44. alignment = {x = -1, y = -1},
  45. offset = HUD_HEALTH_OFFSET,
  46. background = "hud_heart_bg.png",
  47. events = {
  48. {
  49. type = "damage",
  50. func = function(player)
  51. hud.change_item(player, "health", {number = player:get_hp()})
  52. end
  53. }
  54. },
  55. })
  56. hud.register("air", {
  57. hud_elem_type = "statbar",
  58. position = HUD_AIR_POS,
  59. size = HUD_SB_SIZE,
  60. text = "hud_air_fg.png",
  61. number = 0,
  62. alignment = {x = -1, y = -1},
  63. offset = HUD_AIR_OFFSET,
  64. background = nil,
  65. events = {
  66. {
  67. type = "breath",
  68. func = function(player)
  69. local air = player:get_breath()
  70. if air > 10 then
  71. air = 0
  72. end
  73. hud.change_item(player, "air", {number = air * 2})
  74. end
  75. }
  76. },
  77. })
  78. hud.register("armor", {
  79. hud_elem_type = "statbar",
  80. position = HUD_ARMOR_POS,
  81. size = HUD_SB_SIZE,
  82. text = "hud_armor_fg.png",
  83. number = 0,
  84. alignment = {x = -1, y = -1},
  85. offset = HUD_ARMOR_OFFSET,
  86. background = "hud_armor_bg.png",
  87. autohide_bg = true,
  88. max = 20,
  89. })
  90. hud.register("hunger", {
  91. hud_elem_type = "statbar",
  92. position = HUD_HUNGER_POS,
  93. size = HUD_SB_SIZE,
  94. text = "hud_hunger_fg.png",
  95. number = 0,
  96. alignment = {x = -1, y = -1},
  97. offset = HUD_HUNGER_OFFSET,
  98. background = "hud_hunger_bg.png",
  99. max = 0,
  100. })
  101. else
  102. hud.show_armor = false
  103. end