icons.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. local Icons = class()
  2. local g = love.graphics
  3. local w, h = g.width, g.height
  4. function Icons:init()
  5. self.prevLabelAlphas = {}
  6. self.labelAlphas = {}
  7. for i = 1, 5 do
  8. self.prevLabelAlphas[i] = 0
  9. self.labelAlphas[i] = 0
  10. end
  11. end
  12. function Icons:update()
  13. local p = ctx.players:get(ctx.id)
  14. if p then
  15. for i = 1, 5 do
  16. self.prevLabelAlphas[i] = self.labelAlphas[i]
  17. if p.weapon == i or p.skill == i then
  18. self.labelAlphas[i] = math.lerp(self.labelAlphas[i], 1, math.min(10 * tickRate, 1))
  19. elseif p.slots[i].type == 'passive' then
  20. self.labelAlphas[i] = math.lerp(self.labelAlphas[i], .5, math.min(10 * tickRate, 1))
  21. else
  22. self.labelAlphas[i] = math.lerp(self.labelAlphas[i], .5, math.min(10 * tickRate, 1))
  23. end
  24. end
  25. end
  26. end
  27. function Icons:draw()
  28. local u, v = ctx.hud.u, ctx.hud.v
  29. local top = v * .1
  30. local p = ctx.players:get(ctx.id)
  31. if p then
  32. local width = data.media.graphics.icons[p.slots[1].code]:getWidth()
  33. local s = math.min(u, v) * .08 / width
  34. for i = 1, 5 do
  35. local icon = data.media.graphics.icons[p.slots[i].code]
  36. local alpha = math.min(math.lerp(self.prevLabelAlphas[i], self.labelAlphas[i], tickDelta / tickRate), 1) * 200
  37. local iconx = u * .5 - (math.min(u, v) * .25) + math.min(u, v) * (.125 * (i - 1))
  38. g.setColor(255, 255, 255, math.max(alpha, 100) * (255 / 200))
  39. g.draw(icon, iconx - (width * s / 2), top, 0, s, s)
  40. local prc = 0
  41. if p.slots[i].value then
  42. prc = p.slots[i].value(p.slots[i], p) * 100
  43. end
  44. g.setColor(0, 0, 0, 128)
  45. local x, y = iconx, top
  46. local points = {}
  47. local function insert(x, y)
  48. table.insert(points, x)
  49. table.insert(points, y + 1)
  50. end
  51. insert(x, y + (width * s / 2))
  52. insert(x, y)
  53. local function halp(val, xx, yy)
  54. if prc > val then
  55. x = x + (xx * s)--w(xx / 800)
  56. y = y + (yy * s)--w(yy / 800)
  57. prc = prc - val
  58. insert(x, y)
  59. return false
  60. else
  61. x = x + ((prc / val) * (xx * s))--w(xx / 800))
  62. y = y + ((prc / val) * (yy * s))--w(yy / 800))
  63. insert(x, y)
  64. return true
  65. end
  66. end
  67. while true do
  68. if halp(10.21, -18, 0) then break end
  69. if halp(4.25, -5, 5) then break end
  70. if halp(19.82, 0, 33) then break end
  71. if halp(6.35, 6, 6) then break end
  72. if halp(19.22, 34, 0) then break end
  73. if halp(6.35, 6, -6) then break end
  74. if halp(19.82, 0, -33) then break end
  75. if halp(3.4, -5, -5) then break end
  76. if halp(11.41, -19, 0) then break end
  77. break
  78. end
  79. g.polygon('fill', points)
  80. g.setFont('pixel', 8)
  81. local str = p.slots[i].name
  82. if p.slots[i].type == 'passive' then str = '[' .. str .. ']' end
  83. local strw, strh = g.getFont():getWidth(str), g.getFont():getHeight()
  84. g.setColor(0, 0, 0, alpha)
  85. g.rectangle('fill', iconx - ((strw + 3) / 2), top + (width * s) + 1, strw + 3, strh + 2)
  86. if p.slots[i].type == 'weapon' then g.setColor(255, 150, 150, alpha)
  87. elseif p.slots[i].type == 'skill' then g.setColor(150, 150, 255, alpha)
  88. else g.setColor(255, 255, 255, alpha) end
  89. g.printCenter(str, iconx, top + (width * s) + 2, true, false)
  90. end
  91. end
  92. end
  93. return Icons