heli_hud.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. local heli_hud_list = {}
  2. function update_heli_hud(player)
  3. --[[
  4. local player_name = player:get_player_name()
  5. hour = minetest.env:get_timeofday() * 24
  6. hour = math.ceil(hour)
  7. -- Get the dig and place count from storage, or default to 0
  8. local meta = player:get_meta()
  9. local time_text = "Time of day: " .. hour .. "h "
  10. local pos = player:get_pos()
  11. local altitude = math.ceil(pos.y)
  12. local altitude_text = "Altitude: " .. math.ceil(altitude)
  13. local ids = heli_hud_list[player_name]
  14. if ids then
  15. player:hud_change(ids["time"], "text", time_text)
  16. player:hud_change(ids["altitude"], "text", altitude_text)
  17. else
  18. local screen_pos_y = -250
  19. local screen_pos_x = -100
  20. ids = {}
  21. ids["bg"] = player:hud_add({
  22. hud_elem_type = "image",
  23. position = {x = 1, y = 0.5},
  24. offset = {x = -240 + screen_pos_x, y = -10 + screen_pos_y},
  25. text = "flight_info_bg.png",
  26. scale = { x = 1, y = 1},
  27. alignment = { x = 1, y = 0 },
  28. })
  29. ids["title"] = player:hud_add({
  30. hud_elem_type = "text",
  31. position = {x = 1, y = 0.5},
  32. offset = {x = -120 + screen_pos_x, y = -25 + screen_pos_y},
  33. text = "Flight Information",
  34. alignment = 0,
  35. scale = { x = 100, y = 30},
  36. number = 0xFFFFFF,
  37. })
  38. ids["time"] = player:hud_add({
  39. hud_elem_type = "text",
  40. position = {x = 1, y = 0.5},
  41. offset = {x = -180 + screen_pos_x, y = 0 + screen_pos_y},
  42. text = time_text,
  43. alignment = -1,
  44. scale = { x = 50, y = 10},
  45. number = 0xFFFFFF,
  46. })
  47. ids["altitude"] = player:hud_add({
  48. hud_elem_type = "text",
  49. position = {x = 1, y = 0.5},
  50. offset = {x = -70 + screen_pos_x, y = 0 + screen_pos_y},
  51. text = altitude_text,
  52. alignment = -1,
  53. scale = { x = 50, y = 10},
  54. number = 0xFFFFFF,
  55. })
  56. heli_hud_list[player_name] = ids
  57. end
  58. ]]--
  59. end
  60. function remove_heli_hud(player)
  61. --[[
  62. local player_name = player:get_player_name()
  63. local ids = heli_hud_list[player_name]
  64. player:hud_remove(ids["altitude"])
  65. player:hud_remove(ids["time"])
  66. player:hud_remove(ids["title"])
  67. player:hud_remove(ids["bg"])
  68. heli_hud_list[player_name] = nil
  69. ]]--
  70. end