hud.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. Hud = class()
  2. Hud.depth = -100
  3. local g = love.graphics
  4. function Hud:init()
  5. self.tooltip = nil
  6. self.tooltipRaw = ''
  7. self.u, self.v = ctx.view.frame.width, ctx.view.frame.height
  8. self.gooey = Gooey()
  9. self.health = HudHealth()
  10. self.upgrades = HudUpgrades()
  11. self.units = HudUnits()
  12. self.dead = _G['HudDead' .. ctx.mode:capitalize()](self)
  13. self.shruju = HudShruju()
  14. self.status = HudStatus()
  15. self.tooltip = Tooltip()
  16. self.pause = HudPause(self)
  17. love.filesystem.write('playedBefore', 'achievement unlocked.')
  18. ctx.view:register(self, 'gui')
  19. end
  20. function Hud:update()
  21. local p = ctx.player
  22. local oldTitle = self.tooltip.tooltipText and self.tooltip.tooltipText:sub(1, self.tooltip.tooltipText:find('\n'))
  23. self.tooltip:update()
  24. self.gooey:update()
  25. self.status:update()
  26. self.health:update()
  27. self.upgrades:update()
  28. self.shruju:update()
  29. self.units:update()
  30. self.dead:update()
  31. self.pause:update()
  32. local newTitle = self.tooltip.tooltipText and self.tooltip.tooltipText:sub(1, self.tooltip.tooltipText:find('\n'))
  33. if self.tooltip.active and oldTitle ~= newTitle then
  34. ctx.sound:play('menuHover', function(sound) sound:setVolume(2) end)
  35. end
  36. end
  37. function Hud:gui()
  38. local u, v = self.u, self.v
  39. local p = ctx.player
  40. if not ctx.ded then
  41. self.status:draw()
  42. self.health:draw()
  43. self.shruju:draw()
  44. self.units:draw()
  45. end
  46. self.dead:draw()
  47. self.tooltip:draw()
  48. self.pause:draw()
  49. end
  50. function Hud:keypressed(key)
  51. table.with(self.shrujuPatches, 'keypressed', key)
  52. self.upgrades:keypressed(key)
  53. self.dead:keypressed(key)
  54. end
  55. function Hud:keyreleased(key)
  56. table.with(self.shrujuPatches, 'keyreleased', key)
  57. self.upgrades:keyreleased(key)
  58. end
  59. function Hud:gamepadpressed(gamepad, button)
  60. local x, y = love.mouse.getPosition()
  61. if button == 'a' then
  62. self:mousereleased(x, y, 'l')
  63. end
  64. end
  65. function Hud:mousepressed(x, y, b)
  66. x, y = ctx.view:frameMouseX(), ctx.view:frameMouseY()
  67. self.gooey:mousepressed(x, y, b)
  68. end
  69. function Hud:mousereleased(x, y, b)
  70. x, y = ctx.view:frameMouseX(), ctx.view:frameMouseY()
  71. local p = ctx.player
  72. if self.upgrades.active then
  73. self.units:mousereleased(x, y, b)
  74. end
  75. self.gooey:mousereleased(x, y, b)
  76. end
  77. function Hud:mousemoved(x, y)
  78. x, y = ctx.view:frameMouseX(), ctx.view:frameMouseY()
  79. self.tooltip:dirty()
  80. self.status:mousemoved(x, y)
  81. self.units:mousemoved(x, y)
  82. self.shruju:mousemoved(x, y)
  83. self.dead:mousemoved(x, y)
  84. end
  85. function Hud:resize()
  86. self.u, self.v = ctx.view.frame.width, ctx.view.frame.height
  87. self.tooltip:resize()
  88. end
  89. function Hud:menuActive()
  90. local active = false
  91. active = active or self.upgrades.active
  92. return active
  93. end