controller.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. local Hud = class()
  2. local g = love.graphics
  3. function Hud:init()
  4. self._debug = false
  5. self.players = app.ui.hud.players()
  6. self.blood = app.ui.hud.blood()
  7. self.left = app.ui.hud.left()
  8. self.health = app.ui.hud.health()
  9. self.icons = app.ui.hud.icons()
  10. self.right = app.ui.hud.right()
  11. self.buffs = app.ui.hud.buffs()
  12. self.feed = app.ui.hud.feed()
  13. self.chat = app.ui.hud.chat()
  14. self.scoreboard = app.ui.hud.scoreboard()
  15. self.dead = app.ui.hud.dead()
  16. self.killPopup = app.ui.hud.killPopup()
  17. self.gameOver = app.ui.hud.gameOver()
  18. self.classSelect = app.ui.hud.classSelect()
  19. self.debug = app.ui.hud.debug()
  20. ctx.event:on(app.net.events.chat, function(data) self.chat:add(data) end)
  21. ctx.view:register(self, 'gui')
  22. self.u = ctx.view.frame.width
  23. self.v = ctx.view.frame.height
  24. end
  25. function Hud:update()
  26. ctx.input.keyboardEnabled = not self.chat.active and not self.classSelect.active
  27. ctx.input.mouseEnabled = not self.classSelect.active
  28. if self.classSelect.active then return self.classSelect:update() end
  29. self.left:update()
  30. self.health:update()
  31. self.chat:update()
  32. self.feed:update()
  33. self.icons:update()
  34. self.scoreboard:update()
  35. self.killPopup:update()
  36. self.gameOver:update()
  37. end
  38. function Hud:gui()
  39. if not ctx.id then return self:connecting() end
  40. if self.classSelect.active then return self.classSelect:draw() end
  41. self.players:draw()
  42. self.blood:draw()
  43. self.left:draw()
  44. self.health:draw()
  45. self.icons:draw()
  46. self.right:draw()
  47. self.buffs:draw()
  48. self.feed:draw()
  49. self.chat:draw()
  50. self.scoreboard:draw()
  51. self.dead:draw()
  52. self.killPopup:draw()
  53. self.gameOver:draw()
  54. self:crosshair()
  55. if self._debug then self.debug:draw() end
  56. end
  57. function Hud:mousepressed(x, y, button)
  58. return self.classSelect:mousepressed(x, y, button)
  59. end
  60. function Hud:mousereleased(x, y, button)
  61. return self.classSelect:mousereleased(x, y, button)
  62. end
  63. function Hud:textinput(character)
  64. self.chat:textinput(character)
  65. end
  66. function Hud:keypressed(key)
  67. if self.chat:keypressed(key) then return true
  68. elseif self.classSelect:keypressed(key) then return true
  69. elseif key == '`' then self._debug = not self._debug end
  70. end
  71. function Hud:keyreleased(key)
  72. if self.chat.active or self.classSelect.active then return true end
  73. end
  74. function Hud:resize()
  75. self.u = ctx.view.frame.width
  76. self.v = ctx.view.frame.height
  77. self.feed:resize()
  78. self.chat:resize()
  79. end
  80. function Hud:connecting()
  81. g.setColor(0, 0, 0)
  82. g.rectangle('fill', 0, 0, self.u, self.v)
  83. g.setColor(255, 255, 255)
  84. g.setFont('pixel', 8)
  85. local str = 'Connecting...'
  86. if tick > 6 / tickRate then str = str .. '\noshit' end
  87. if tick > 7 / tickRate then str = str .. ' oshit' end
  88. if tick > (7 / tickRate) + 5 then str = str .. ' oshit' end
  89. if tick > (7 / tickRate) + 10 then str = str .. ' oshit' end
  90. if tick > 10 / tickRate then str = str .. '\n' str = str .. string.rep('fuck', math.min(10, (tick - (10 / tickRate)) / 3)) end
  91. local _, lines = g.getFont():getWrap(str, self.u)
  92. g.printf(str, 0, self.v * .5 - g.getFont():getHeight() * lines * .5, self.u, 'center')
  93. end
  94. function Hud:crosshair()
  95. local p = ctx.players:get(ctx.id)
  96. if p then
  97. local weapon = p.slots[p.weapon]
  98. if not p.ded and weapon.crosshair then
  99. if love.mouse.isVisible() then love.mouse.setVisible(false) end
  100. weapon:crosshair()
  101. else
  102. if not love.mouse.isVisible() then love.mouse.setVisible(true) end
  103. end
  104. end
  105. end
  106. return Hud