-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabilityclickable.lua
More file actions
69 lines (58 loc) · 2.64 KB
/
abilityclickable.lua
File metadata and controls
69 lines (58 loc) · 2.64 KB
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
require "button"
AbilityClickable = {}
AbilityClickable.__index = AbilityClickable
function AbilityClickable:create(ability, listPosition)
local abilityClickable = {}
setmetatable(abilityClickable, AbilityClickable)
abilityClickable.linkedAbility = ability
abilityClickable.clickable = Clickable:create(1400, -500, 450, 200) -- init on unclickable region?
abilityClickable.clickable.fixed = true
function abilityClickable.clickable:clicked()
abilityClickable:upgradeAbility()
end
function abilityClickable.clickable:hoveredCallback()
love.mouse.setCursor(hand_cursor_point)
end
abilityClickable.listPosition = listPosition
return abilityClickable
end
function AbilityClickable:upgradeAbility()
if money >= self.linkedAbility.cost then
money = money - self.linkedAbility.cost
self.linkedAbility:upgrade()
end
end
function AbilityClickable:draw(scrollPosition, tab)
if tab ~= 1 or self.listPosition < scrollPosition or (self.listPosition - scrollPosition) >= 3 then
return
end
love.graphics.setColor(255,255,255)
love.graphics.rectangle("fill", 1400+pos, self.clickable.y, self.clickable.width, self.clickable.height)
love.graphics.setColor(0,0,0)
love.graphics.rectangle("line", 1400+pos, self.clickable.y, self.clickable.width, self.clickable.height)
love.graphics.setFont(fonts["30"])
love.graphics.printf(self.linkedAbility.name .. " Lvl. " .. (self.linkedAbility.level + 1), 1400+pos, self.clickable.y, self.clickable.width)
love.graphics.setFont(fonts["26"])
love.graphics.printf(self.linkedAbility.explanation, 1400+pos, self.clickable.y +36, self.clickable.width)
love.graphics.printf("Cost: " .. (self.linkedAbility.cost), 1400+pos, self.clickable.y+150, self.clickable.width, "right")
love.graphics.setFont(fonts["26"])
end
function AbilityClickable:updatePosition(scrollPosition)
if self.listPosition >= scrollPosition and (self.listPosition - scrollPosition) < 3 then
self.clickable.y = 400 + (self.listPosition - scrollPosition) * 200
else
self.clickable.y = -500
end
end
function AbilityClickable:mousemoved(x, y, dx, dy, istouch, scrollPosition, tab)
if tab ~= 1 or self.listPosition < scrollPosition or (self.listPosition - scrollPosition) >= 3 then
return
end
self.clickable:mousemoved(x,y,dx,dy,istouch)
end
function AbilityClickable:mousepressed(x, y, button, istouch, presses, scrollPosition, tab)
if tab ~= 1 or self.listPosition < scrollPosition or (self.listPosition - scrollPosition) >= 3 then
return
end
self.clickable:mousepressed(x,y,button,istouch, presses)
end