-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerBar.lua
More file actions
440 lines (403 loc) · 11.1 KB
/
PowerBar.lua
File metadata and controls
440 lines (403 loc) · 11.1 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
PowerBar = LibStub("AceAddon-3.0"):NewAddon("PowerBar", "AceEvent-3.0", "AceConsole-3.0", "AceHook-3.0", "AceTimer-3.0", "LibBars-1.0")
local bars = LibStub("LibBars-1.0")
local media = LibStub("LibSharedMedia-3.0")
local mod = PowerBar
local bar, group
local db
local classIcons = {
["WARRIOR"] = {0, 0.25, 0, 0.25},
["MAGE"] = {0.25, 0.49609375, 0, 0.25},
["ROGUE"] = {0.49609375, 0.7421875, 0, 0.25},
["DRUID"] = {0.7421875, 0.98828125, 0, 0.25},
["HUNTER"] = {0, 0.25, 0.25, 0.5},
["SHAMAN"] = {0.25, 0.49609375, 0.25, 0.5},
["PRIEST"] = {0.49609375, 0.7421875, 0.25, 0.5},
["WARLOCK"] = {0.7421875, 0.98828125, 0.25, 0.5},
["PALADIN"] = {0, 0.25, 0.5, 0.75},
["DEATHKNIGHT"] = {0.25, 0.49609375, 0.5, 0.75},
}
local classPowerColors = {
{48/255, 113/255, 191/255 }, -- mana
{226/255, 45/255, 75/255 }, -- rage
{1, 210/255, 0 }, -- focus
{1, 220/255, 25/255 }, -- energy
{1, 1, 1}, -- happiness
{1, 1, 1}, -- runes
{0, 209/255, 1 } -- runic power
}
local defaults = {
char = {
direction = bars.LEFT_TO_RIGHT,
font = "Fritz Quadrata",
fontsize = 12,
background = {r = 0, g = 0, b = 0, a = 0.5},
length = 100,
thickness = 20,
tickWidth = 2,
color = {},
tickcolor = {},
bgcolor = {},
tickSpells = {},
hideWhenFull = true,
flashAtFull = true
}
}
---- Config
local options = {
type = "group",
args = {
display = {
type = "group",
name = "Display Options",
args = {
hideWhenFull = {
type = "toggle",
name = "Hide when full",
order = 2,
get = function() return db.hideWhenFull end,
set = function(info, v)
db.hideWhenFull = v
end
},
flashAtFiveCP = {
type = "toggle",
name = "Flash at 5 CP",
order = 3,
get = function() return db.flashAtFull end,
set = function(info, v)
db.flashAtFull = v
end
},
colorHeader = {
type = "header",
name = "Colors",
order = 50
},
lock = {
type = "toggle",
name = "Lock PowerBar",
order = 1,
get = function() return db.locked end,
set = function(info, v)
db.locked = v
mod:UpdateDisplay()
end
},
direction = {
type = "select",
name = "Bar direction",
order = 105,
values = {
[bars.LEFT_TO_RIGHT] ="Left to right",
[bars.BOTTOM_TO_TOP] ="Bottom to top",
[bars.RIGHT_TO_LEFT] ="Right to left",
[bars.TOP_TO_BOTTOM] ="Top to bottom"
},
get = function()
return db.direction
end,
set = function(info, v)
db.direction = v
mod:UpdateDisplay()
mod:AddTickLines()
end
},
font = {
type = "select",
name ="Font",
dialogControl = 'LSM30_Font',
order = 106,
values = AceGUIWidgetLSMlists.font,
get = function() return db.font end,
set = function(info, v)
db.font = v
mod:UpdateDisplay()
end
},
texture = {
type = "select",
name ="Texture",
order = 107,
values = AceGUIWidgetLSMlists.statusbar,
dialogControl = 'LSM30_Statusbar',
get = function() return db.texture end,
set = function(info, v)
db.texture = v
mod:UpdateDisplay()
end
},
fontsize = {
type = "range",
name ="Font Size",
min = 4,
max = 30,
step = 1,
bigStep = 1,
get = function() return db.fontsize end,
set = function(info, v)
db.fontsize = v
mod:UpdateDisplay()
end
},
sizeHeader = {
type = "header",
name ="Bar Size",
order = 60,
},
length = {
type = "range",
name ="Bar length",
min = 5,
max = 600,
order = 61,
step = 1,
bigStep = 1,
get = function() return db.length end,
set = function(info, v)
db.length = v
mod:UpdateDisplay()
end
},
thickness = {
type = "range",
name ="Bar thickness",
min = 5,
max = 600,
order = 62,
step = 1,
bigStep = 1,
get = function() return db.thickness end,
set = function(info, v)
db.thickness = v
mod:UpdateDisplay()
end
},
barcolor = {
type = "color",
name ="Bar color",
order = 51,
hasAlpha = true,
get = function() return db.color.r, db.color.g, db.color.b, db.color.a end,
set = function(info, r, g, b, a)
db.color.r, db.color.g, db.color.b, db.color.a = r, g, b, a
mod:UpdateDisplay()
end
},
bgcolor = {
type = "color",
name ="Background color",
order = 52,
hasAlpha = true,
get = function() return db.bgcolor.r, db.bgcolor.g, db.bgcolor.b, db.bgcolor.a end,
set = function(info, r, g, b, a)
db.bgcolor.r, db.bgcolor.g, db.bgcolor.b, db.bgcolor.a = r, g, b, a
mod:UpdateDisplay()
end
}
}
},
ticks = {
type = "group",
name ="Ticks",
args = {
tickcolor = {
type = "color",
name ="Tick color",
hasAlpha = true,
get = function() return db.tickcolor.r, db.tickcolor.g, db.tickcolor.b, db.tickcolor.a end,
set = function(info, r, g, b, a)
db.tickcolor.r, db.tickcolor.g, db.tickcolor.b, db.tickcolor.a = r, g, b, a
mod:AddTickLines()
end
},
tickThickness = {
type = "range",
name ="Tick thickness",
min = 1,
max = 5,
step = 1,
bigStep = 1,
get = function() return db.tickWidth end,
set = function(info, v)
db.tickWidth = v
mod:AddTickLines()
end
},
spells = {
type = "group",
name ="Show ticks for...",
inline = true,
args = {
}
}
}
}
}
}
function mod:LibSharedMedia_Registered()
self:UpdateDisplay()
end
function mod:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("PowerBarDB", defaults)
db = self.db.char
group = self:NewBarGroup("PowerBarGroup", nil, 100, 10, "PowerBarGroup")
bar = group:NewCounterBar("Energy", "Energy", 0, 1)
local class = classIcons[select(2, UnitClass("player"))]
bar:SetIcon("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes")
bar.icon:SetTexCoord(class[1], class[2], class[3], class[4])
bar:SetLength(100)
bar:SetThickness(10)
bar:SetMaxValue(100)
bar:SetValue(50)
self:HookScript(bar, "OnSizeChanged", "AddTickLines")
self.bar = bar
self:SetupOptions()
end
function mod:InjectSpells()
local names = {}
for i = 1, 999 do
local name, rank = GetSpellName(i, BOOKTYPE_SPELL)
if not name then break end
names[name] = true
end
local t = options.args.ticks.args.spells.args
for k, v in pairs(names) do
local name, rank, icon, cost = GetSpellInfo(k)
if cost and cost > 0 then
t[name:gsub(" ", "_")] = {
type = "toggle",
name = name,
icon = icon,
get = function()
return db.tickSpells[name] ~= nil
end,
set = function(info, v)
db.tickSpells[name] = v and cost or nil
mod:AddTickLines()
end
}
end
end
end
local spellsScanned = false
function mod:OnEnable()
self:RegisterEvent("UNIT_MAXENERGY")
self:RegisterEvent("UNIT_MAXRAGE", "UNIT_MAXENERGY")
self:RegisterEvent("UNIT_MAXMANA", "UNIT_MAXENERGY")
self:RegisterEvent("UNIT_MAXRUNIC_POWER", "UNIT_MAXENERGY")
self:ScheduleRepeatingTimer("UNIT_ENERGY", 0.05, "player")
self:UNIT_MAXENERGY(nil, "player")
media.RegisterCallback(mod, "LibSharedMedia_Registered")
self:LibSharedMedia_Registered()
self:UpdateDisplay()
self:AddTickLines()
if not spellsScanned then
self:InjectSpells()
spellsScanned = true
end
end
function mod:UpdateDisplay()
bar:SetFont(media:Fetch("font", db.font), db.fontsize)
group:SetTexture(media:Fetch("statusbar", db.texture))
local r, g, b = unpack(classPowerColors[UnitPowerType("player")])
local xr, xg, xb, xa = db.color.r or r, db.color.g or g, db.color.b or b, db.color.a or 1
group:UnsetAllColors()
group:SetColorAt(1.0, xr, xg, xb, xa)
group:SetLength(db.length)
group:SetThickness(db.thickness)
group:SetOrientation(db.direction)
xr, xg, xb, xa = db.bgcolor.r or (r / 2), db.bgcolor.g or (g / 2), db.bgcolor.b or (b / 2), db.bgcolor.a or 0.5
bar:SetBackgroundColor(xr, xg, xb, xa)
if db.locked then
group:HideAnchor()
else
group:ShowAnchor()
end
end
do
local tickTextures = {}
local newTextures = {}
function mod:AddTickLines()
for _, v in ipairs(tickTextures) do v:Hide() end
for k, _ in pairs(db.tickSpells) do
local v = select(4, GetSpellInfo(k))
local t = tremove(tickTextures)
if not t then
t = bar:CreateTexture(nil, "OVERLAY")
t:SetTexture([[Interface\Buttons\WHITE8X8]])
end
tinsert(newTextures, t)
t:Show()
t:SetVertexColor(db.tickcolor.r or 0, db.tickcolor.g or 0, db.tickcolor.b or 0, db.tickcolor.a or 0.5)
t:SetHeight(db.tickWidth)
t:SetWidth(db.tickWidth)
t:ClearAllPoints()
if db.direction == 1 or db.direction == 3 then
t:SetPoint("TOP", bar, "TOP", 0, 0)
t:SetPoint("BOTTOM", bar, "BOTTOM", 0, 0)
if db.direction == 1 then
t:SetPoint("LEFT", bar, "LEFT", bar:GetWidth() * (v/100), 0)
else
t:SetPoint("RIGHT", bar, "RIGHT", bar:GetWidth() * (v/100) * -1, 0)
end
else
t:SetPoint("LEFT", bar, "LEFT", 0, 0)
t:SetPoint("RIGHT", bar, "RIGHT", 0, 0)
if db.direction == 2 then
t:SetPoint("BOTTOM", bar, "BOTTOM", 0, bar:GetHeight() * (v/100))
else
t:SetPoint("TOP", bar, "TOP", 0, bar:GetHeight() * (v/100) * -1)
end
end
end
for _, v in ipairs(newTextures) do
tinsert(tickTextures, v)
end
for i = 1, #newTextures do
tremove(newTextures)
end
end
end
do
local function flashBar(self)
self:SetAlpha((0.25 * math.sin(GetTime() * 7)) + 0.75)
end
local MAX_CP = 5
function mod:UNIT_ENERGY(token)
if UnitIsUnit("player", token) then
bar:SetLabel(UnitMana(token))
local cp = GetComboPoints("player")
bar:SetTimerLabel(cp .. "|cffffcc44CP")
if cp >= MAX_CP and db.flashAtFull and not self.flasher then
self.flasher = true
bar:AddOnUpdate(flashBar)
elseif cp < MAX_CP and self.flasher then
bar:RemoveOnUpdate(flashBar)
self.flasher = false
bar:SetAlpha(1)
end
bar:SetValue(UnitMana(token))
if UnitMana(token) == UnitManaMax(token) and not InCombatLockdown() and db.hideWhenFull then
group:Hide()
else
group:Show()
end
end
end
end
function mod:FlashBar(arg)
end
function mod:UNIT_MAXENERGY(event, token)
if UnitIsUnit("player", token) then
bar:SetValue(UnitManaMax(token))
end
end
function mod:SetupOptions()
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("PowerBar", options)
LibStub("AceConfig-3.0"):RegisterOptionsTable("PowerBar", options, "powerbar")
local ACD3 = LibStub("AceConfigDialog-3.0")
ACD3:AddToBlizOptions("PowerBar", nil, nil, "display")
-- ACD3:AddToBlizOptions("PowerBar", "Display Options", "PowerBar", "display")
ACD3:AddToBlizOptions("PowerBar", "Tick Options", "PowerBar", "ticks")
-- LibStub("AceConfigDialog-3.0"):AddToBlizOptions("PowerBar", "Tick Options", "PowerBar", ticks)
end