hud.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. local function shorten(number, decimal)
  2. if number > 1000 then
  3. number = number / 1000
  4. local mult = 10^(decimal or 0)
  5. number = (math.floor(number * mult + 0.5) / mult)..' K'
  6. end
  7. return number
  8. end
  9. core.register_on_joinplayer(function(player)
  10. player:hud_set_flags({wielditem = false, minimap_radar = false, minimap = false})
  11. local name = player:get_player_name()
  12. local resources = kobo.resources[name]
  13. kobo.hud[name] = {
  14. background = player:hud_add({
  15. type = 'image',
  16. text = 'kobo_hud_bg.png',
  17. position = {x = 1, y = 0},
  18. offset = {x = 0, y = 0},
  19. alignment = {x = -1, y = 1},
  20. scale = {x = 1, y = 1},
  21. size = {x = 2},
  22. z_index = -100
  23. }),
  24. food = player:hud_add({
  25. type = 'text',
  26. position = {x = 1, y = 0},
  27. offset = {x = -850, y = 20},
  28. text = 'Food: '..shorten(resources.food, 2),
  29. alignment = {x = 1, y = 0},
  30. scale = {x = 100, y = 100},
  31. size = {x = 2}
  32. }),
  33. food_ico = player:hud_add({
  34. type = 'image',
  35. text = 'kobo_food.png',
  36. position = {x = 1, y = 0},
  37. offset = {x = -900, y = 20},
  38. alignment = {x = 1, y = 0},
  39. scale = {x = .3, y = .3},
  40. }),
  41. lumber = player:hud_add({
  42. type = 'text',
  43. position = {x = 1, y = 0},
  44. offset = {x = -850, y = 60},
  45. text = 'Lumber: '..shorten(resources.lumber, 2),
  46. alignment = {x = 1, y = 0},
  47. scale = {x = 100, y = 100},
  48. size = {x = 2}
  49. }),
  50. lumber_ico = player:hud_add({
  51. type = 'image',
  52. text = 'kobo_lumber.png',
  53. position = {x = 1, y = 0},
  54. offset = {x = -900, y = 60},
  55. alignment = {x = 1, y = 0},
  56. scale = {x = .3, y = .3},
  57. }),
  58. stone = player:hud_add({
  59. type = 'text',
  60. position = {x = 1, y = 0},
  61. offset = {x = -550, y = 20},
  62. text = 'Stone: '..shorten(resources.stone, 2),
  63. alignment = {x = 1, y = 0},
  64. scale = {x = 100, y = 100},
  65. size = {x = 2}
  66. }),
  67. stone_ico = player:hud_add({
  68. type = 'image',
  69. text = 'kobo_stone.png',
  70. position = {x = 1, y = 0},
  71. offset = {x = -600, y = 20},
  72. alignment = {x = 1, y = 0},
  73. scale = {x = .3, y = .3},
  74. }),
  75. metal = player:hud_add({
  76. type = 'text',
  77. position = {x = 1, y = 0},
  78. offset = {x = -550, y = 60},
  79. text = 'Metal: '..shorten(resources.metal, 2),
  80. alignment = {x = 1, y = 0},
  81. scale = {x = 100, y = 100},
  82. size = {x = 2}
  83. }),
  84. metal_ico = player:hud_add({
  85. type = 'image',
  86. text = 'kobo_metal.png',
  87. position = {x = 1, y = 0},
  88. offset = {x = -600, y = 60},
  89. alignment = {x = 1, y = 0},
  90. scale = {x = .3, y = .3},
  91. }),
  92. inv = player:hud_add({
  93. type = 'inventory',
  94. position = {x = .01, y = .5},
  95. offset = {x = 0, y = 0},
  96. size = {x = 8, y = 8},
  97. text = 'hand',
  98. number = 1,
  99. direction = 0,
  100. item = 1,
  101. }),
  102. map = player:hud_add({
  103. type = 'minimap',
  104. position = {x = 1, y = 0},
  105. size = {x = 650, y = 650},
  106. }),
  107. }
  108. end)
  109. function kobo.hud_refresh(player)
  110. local name = player:get_player_name()
  111. local resources = kobo.resources[name]
  112. local idx = kobo.hud[name]
  113. player:hud_change(idx.food, 'text', 'Food: '..shorten(resources.food, 2))
  114. player:hud_change(idx.lumber, 'text', 'Lumber: '..shorten(resources.lumber, 2))
  115. player:hud_change(idx.stone, 'text', 'Stone: '..shorten(resources.stone, 2))
  116. player:hud_change(idx.metal, 'text', 'Metal: '..shorten(resources.metal, 2))
  117. end