-
Notifications
You must be signed in to change notification settings - Fork 0
/
skillpane.lua
72 lines (59 loc) · 1.61 KB
/
skillpane.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--Modular-if-inflexible solution for the skills listing
-- sp = Skillpane.new(x,y,skillLevels) {5,3,5,2[,1...]}
-- hotLevel = sp:getMousedOverElem(mx, my)
-- sp:draw()
local lg = _G.love.graphics
local S = {}
local function makeQuads(skill_strengths)
local sq = _G.quads.skills
local t = {}
for i=1,7 do
local l = skill_strengths[i] or 1
t[i] = sq[l][i] -- abuse of data encapsulation; oh, well
end
return t
end
local function makeCanvas(quads)
local atlas = _G.atlases.skills
local c = lg.newCanvas(200, 278)
lg.setCanvas(c)
lg.setColor(0xff, 0xff, 0xff)
for i,q in ipairs(quads) do
lg.draw(atlas, q, 0, (i-1)*40)
end
lg.setCanvas()
return c
end
local draw = function(self)
lg.setColor(0xff, 0xff, 0xff)
if self.canvas then
lg.draw(self.canvas, self.x, self.y)
else
local atlas = _G.atlases.skills
for i,q in ipairs(self.quads) do
lg.draw(atlas, q, 0, (i-1)*40)
end
end
end
local getMousedOverElem = function(self, mx,my)
mx = mx - self.x
my = my - self.y
if mx < 0 or mx > 200 or my < 0 or my > 278 then return nil end
for i=1, #self.quads do
if my <= i*40 then return i end
end
return nil
end
S.new = function(ulx, uly, skill_strengths)
local quads = makeQuads(skill_strengths)
local pane = {x = ulx,
y = uly,
quads = quads}
if lg.isSupported("canvas") then
pane.canvas = makeCanvas(quads)
end
pane.draw = draw
pane.getMousedOverElem = getMousedOverElem
return pane
end
return S