-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSkillBar.lua
164 lines (139 loc) · 4.5 KB
/
SkillBar.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
-- SkillBar
SkillBar = Class:extend
{
-- skill nrs
skills = {
"/assets/graphics/action_icons/unknown.png",
"/assets/graphics/action_icons/unknown.png",
"/assets/graphics/action_icons/unknown.png",
"/assets/graphics/action_icons/unknown.png",
"/assets/graphics/action_icons/unknown.png",
"/assets/graphics/action_icons/unknown.png",
"/assets/graphics/action_icons/unknown.png",
"/assets/graphics/action_icons/unknown.png",
},
-- contains references to SkillIcon
skillIcons = {},
-- inactive overlay tiles
skillInactiveIcons = {},
-- timeout texts
skillTimerText = {},
-- inactive overlay tiles
skillSelectedIcons = {},
-- position
x = love.graphics.getWidth() / 2 - SkillIcon.width / 2 * 8 - 11, -- to-do: erste 6 ersetzen durch table.getn(skills) oder ähnliche zählmethode
y = love.graphics.getHeight() - SkillIcon.height,
onNew = function (self)
for index, skillImage in pairs(self.skills) do
-- telling the skill icon its color
local myColors = {}
for k,v in pairs(the.player.skills[index]) do
if k == "iconColor" then
for key, value in pairs(v) do
myColors[key] = utils.mapIntoRange(value, 0, 255, 0, 1)
end
end
end
local icon = SkillIcon:new { x = 0, y = 0, color = myColors}
the.hud:add(icon)
self.skillIcons[index] = icon
-- black inactive overlay
local overlay = Tile:new{
width = 32, height = 32, image = "/assets/graphics/skills_inactive_overlay.png",
}
self.skillInactiveIcons[index] = overlay
the.hud:add(overlay)
-- yellow overlay for selected skills
local overlay_selected = Tile:new{
width = 32, height = 32, image = "/assets/graphics/skills_selected_overlay.png",
}
self.skillSelectedIcons[index] = overlay_selected
the.hud:add(overlay_selected)
-- timeout text
local t = Text:new{
tint = {1,1,0},
font = 14,
text = "X",
}
self.skillTimerText[index] = t
the.hud:add(t)
end
self:setPosition (self.x, self.y)
self:setSkills (self.skills)
end,
setPosition = function (self, x, y)
self.x = x
self.y = y
for index, skillIcon in pairs(self.skillIcons) do
local space = 0
if index >=3 and index <=6 then space = 10 end
if index >=7 then space = 20 end
skillIcon.x = (index - 1) * 32 + self.x + space
skillIcon.y = self.y
self.skillInactiveIcons[index].x = skillIcon.x
self.skillInactiveIcons[index].y = skillIcon.y
self.skillSelectedIcons[index].x = skillIcon.x
self.skillSelectedIcons[index].y = skillIcon.y
self.skillTimerText[index].x = skillIcon.x + 8
self.skillTimerText[index].y = skillIcon.y + 8
end
end,
setSkills = function (self, skills)
self.skills = skills
for index, skillImage in pairs(self.skills) do
self.skillIcons[index]:setSkill(skillImage)
end
end,
onUpdate = function (self, elapsed)
-- mark inactive skill as inactive
for index, overlay in pairs(self.skillInactiveIcons) do
if the.player and the.player.skills and the.player.skills[index] then
local skill = the.player.skills[index]
overlay.visible = skill:isCasting() == false and skill:isPossibleToUse() == false
end
end
-- mark selected skill as selected
for index, overlay in pairs(self.skillSelectedIcons) do
overlay.visible = false
if the.player and the.player.skills and the.player.skills[index] then
local skill = the.player.skills[index]
--~ overlay.visible = skill:isCasting() == false and skill:isPossibleToUse() == false
--~ print(skill)
if index == the.player.selectedSkill then
--~ overlay.visible = true
else
overlay.visible = false
end
end
end
-- show timeout
for index, timeout in pairs(self.skillTimerText) do
if the.player and the.player.skills and the.player.skills[index] then
local skill = the.player.skills[index]
timeout.visible = skill:isCasting() or skill:isPossibleToUse() == false
local c = skill:timeTillCastFinished()
local t = skill:timeTillPossibleToUse()
if c > 0 then t = c end
if t >= 10 then
timeout.text = string.format("%0.0f", t)
else
timeout.text = string.format("%0.1f", t)
end
end
end
for index, skillIcon in pairs(self.skillIcons) do
local skill = the.player.skills[index]
local highlight = self.skillSelectedIcons[index]
local t = skill:timeTillPossibleToUse()
if t < 0.25 then
highlight.visible = true
end
if t == 0 or t > 3 then
skillIcon.y = self.y
highlight.visible = false
else
skillIcon.y = self.y - 80 * t
end
end
end,
}