G

NugEnergy.lua

public
Guest Jan 17, 2025 30 days 7
Clone
Lua NugEnergy.lua 629 lines (554 loc) | 22.86 KB
1
NugEnergy = CreateFrame("Frame", "NugEnergy")
2
media = LibStub("LibSharedMedia-3.0")
3
4
NugEnergy:SetScript("OnEvent", function(self, event, ...)
5
self[event](self, event, ...)
6
end)
7
8
NugEnergy:RegisterEvent("ADDON_LOADED")
9
function NugEnergy.ADDON_LOADED(_, _, addonName)
10
if addonName ~= "NugEnergy" then
11
return
12
end
13
14
NugEnergyDB = NugEnergyDB or {}
15
NugEnergyDB.posX = NugEnergyDB.posX or 0
16
NugEnergyDB.posY = NugEnergyDB.posY or 0
17
NugEnergyDB.align = NugEnergyDB.align or "CENTER"
18
NugEnergyDB.visibility = NugEnergyDB.visibility or "Always"
19
NugEnergyDB.font = NugEnergyDB.font or "Emblem"
20
NugEnergyDB.fontSize = NugEnergyDB.fontSize or 35
21
NugEnergyDB.energyColor = NugEnergyDB.energyColor or {1, 0.5, 0.1}
22
NugEnergyDB.rageColor = NugEnergyDB.rageColor or {1, 0.2, 0.2}
23
24
NugEnergyDB.ticker = NugEnergyDB.ticker or {}
25
NugEnergyDB.ticker.color = NugEnergyDB.ticker.color or {1, 0.8, 0.1}
26
NugEnergyDB.ticker.alphaBG = NugEnergyDB.ticker.alphaBG or 0.5
27
NugEnergyDB.ticker.offsetX = NugEnergyDB.ticker.offsetX or 0
28
NugEnergyDB.ticker.offsetY = NugEnergyDB.ticker.offsetY or -20
29
NugEnergyDB.ticker.width = NugEnergyDB.ticker.width or 60
30
NugEnergyDB.ticker.height = NugEnergyDB.ticker.height or 10
31
NugEnergyDB.ticker.texture = NugEnergyDB.ticker.texture or "Aluminium"
32
33
_, NugEnergy.class = UnitClass("player")
34
35
if NugEnergy.class == "ROGUE" then
36
NugEnergy.color = NugEnergyDB.energyColor
37
NugEnergy.frame, NugEnergy.text = NugEnergy.CreateFrame(60, 50, "NugEnergyFrame")
38
NugEnergy.ticker = NugEnergy.CreateTickerFrame("NugEnergyTicker")
39
NugEnergy:RegisterEvent("UNIT_ENERGY")
40
41
elseif NugEnergy.class == "WARRIOR" then
42
NugEnergy.color = NugEnergyDB.rageColor
43
NugEnergy.frame, NugEnergy.text = NugEnergy.CreateFrame(60, 50, "NugEnergyFrame")
44
NugEnergy:RegisterEvent("UNIT_RAGE")
45
NugEnergy.UNIT_RAGE = NugEnergy.UNIT_ENERGY
46
47
elseif NugEnergy.class == "DRUID" then
48
NugEnergy.color = NugEnergyDB.energyColor
49
NugEnergy.frame, NugEnergy.text = NugEnergy.CreateFrame(60, 50, "NugEnergyFrame")
50
NugEnergy.ticker = NugEnergy.CreateTickerFrame("NugEnergyTicker")
51
NugEnergy.UNIT_RAGE = NugEnergy.UNIT_ENERGY
52
53
else
54
return
55
end
56
57
NugEnergy.UpdateBehavior(NugEnergyDB.visibility)
58
NugEnergy:RegisterEvent("PLAYER_ENTERING_WORLD")
59
NugEnergy.PLAYER_ENTERING_WORLD = NugEnergy.UNIT_ENERGY
60
NugEnergy.MakeOptions()
61
end
62
63
function NugEnergy.UNIT_ENERGY()
64
--NugEnergy.text:SetText(UnitMana("player"))
65
local newEnergy = UnitMana("player")
66
67
if newEnergy > NugEnergy.currentEnergy then
68
if newEnergy >= NugEnergy.currentEnergy + 19 and newEnergy <= NugEnergy.currentEnergy + 21 then
69
NugEnergy.lastTime = GetTime()
70
end
71
end
72
73
NugEnergy.currentEnergy = UnitMana("player")
74
end
75
76
function NugEnergy.UpdateBehavior(state)
77
if NugEnergy.class == "WARRIOR" and state == "Stealth" then
78
state = "Combat"
79
end
80
81
if NugEnergy.class == "DRUID" then
82
if state == "Combat" then
83
state = "Stealth"
84
85
elseif state == "Always" then
86
NugEnergy:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
87
NugEnergy.UPDATE_SHAPESHIFT_FORM()
88
return
89
end
90
end
91
92
if state == "Stealth" then
93
NugEnergy:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
94
NugEnergy:RegisterEvent("PLAYER_REGEN_ENABLED")
95
NugEnergy:RegisterEvent("PLAYER_REGEN_DISABLED")
96
97
elseif state == "Combat" then
98
NugEnergy:UnregisterEvent("UPDATE_SHAPESHIFT_FORM")
99
NugEnergy:RegisterEvent("PLAYER_REGEN_ENABLED")
100
NugEnergy:RegisterEvent("PLAYER_REGEN_DISABLED")
101
102
elseif state == "Always" then
103
NugEnergy:UnregisterEvent("UPDATE_SHAPESHIFT_FORM")
104
NugEnergy:UnregisterEvent("PLAYER_REGEN_ENABLED")
105
NugEnergy:UnregisterEvent("PLAYER_REGEN_DISABLED")
106
NugEnergy.frame:Show()
107
NugEnergyTicker:Show()
108
end
109
end
110
111
function NugEnergy.UpdateHide(state)
112
local show = function()
113
if NugEnergy.class == "DRUID" then
114
local _, _, bear_active, _ = GetShapeshiftFormInfo(1)
115
local _, _, cat_active, _ = GetShapeshiftFormInfo(3)
116
117
if bear_active == 1 then
118
if not NugEnergy.frame:IsVisible() then
119
NugEnergy.frame:Show()
120
NugEnergyTicker:Hide()
121
end
122
123
elseif cat_active == 1 then
124
if not NugEnergy.frame:IsVisible() then
125
NugEnergy.frame:Show()
126
NugEnergyTicker:Show()
127
end
128
129
else
130
NugEnergy.frame:Hide()
131
NugEnergyTicker:Hide()
132
end
133
134
else
135
if not NugEnergy.frame:IsVisible() then
136
NugEnergy.frame:Show()
137
138
if NugEnergyTicker then
139
NugEnergyTicker:Show()
140
end
141
end
142
end
143
end
144
145
if state == "Stealth" and (NugEnergy.stealth or NugEnergy.combat) then
146
show()
147
return true
148
149
elseif state == "Combat" and NugEnergy.combat then
150
show()
151
return true
152
153
elseif state == "Always" then
154
show()
155
return true
156
157
else
158
NugEnergy.frame:Hide()
159
160
if NugEnergyTicker then
161
NugEnergyTicker:Hide()
162
end
163
end
164
return nil
165
end
166
167
function NugEnergy.UPDATE_SHAPESHIFT_FORM()
168
if NugEnergy.class == "ROGUE" then
169
local _, _, active, _ = GetShapeshiftFormInfo(1)
170
171
if active == 1 then
172
NugEnergy.stealth = true
173
else
174
NugEnergy.stealth = false
175
end
176
177
NugEnergy.UpdateHide(NugEnergyDB.visibility)
178
179
elseif NugEnergy.class == "DRUID" then
180
local _, _, bear_active, _ = GetShapeshiftFormInfo(1)
181
local _, _, cat_active, _ = GetShapeshiftFormInfo(2)
182
183
if bear_active == 1 then
184
NugEnergy:RegisterEvent("UNIT_RAGE")
185
NugEnergy:UnregisterEvent("UNIT_ENERGY")
186
NugEnergy:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
187
NugEnergy.color = NugEnergyDB.rageColor
188
NugEnergy.text:SetVertexColor(unpack(NugEnergy.color))
189
NugEnergy.UNIT_ENERGY()
190
NugEnergy.UpdateHide(NugEnergyDB.visibility)
191
192
elseif cat_active == 1 then
193
NugEnergy:UnregisterEvent("UNIT_RAGE")
194
NugEnergy:RegisterEvent("UNIT_ENERGY")
195
NugEnergy:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
196
NugEnergy.lastTime = GetTime()
197
NugEnergy.currentEnergy = UnitMana("player")
198
NugEnergy.color = NugEnergyDB.energyColor
199
NugEnergy.text:SetVertexColor(unpack(NugEnergy.color))
200
NugEnergy.UNIT_ENERGY()
201
NugEnergy.UpdateHide(NugEnergyDB.visibility)
202
203
else
204
NugEnergy:UnregisterEvent("UNIT_RAGE")
205
NugEnergy:UnregisterEvent("UNIT_ENERGY")
206
NugEnergy:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
207
NugEnergy.UpdateHide(NugEnergyDB.visibility)
208
end
209
end
210
end
211
212
function NugEnergy.PLAYER_REGEN_ENABLED()
213
NugEnergy.combat = false
214
NugEnergy.UpdateHide(NugEnergyDB.visibility)
215
end
216
217
function NugEnergy.PLAYER_REGEN_DISABLED()
218
NugEnergy.combat = true
219
NugEnergy.UpdateHide(NugEnergyDB.visibility)
220
end
221
222
function NugEnergy.COMBAT_LOG_EVENT_UNFILTERED(_, _, _, eventType, _, _, _, _, _, dstFlags, _, spellName, _, auraType)
223
local isDestPlayer = (bit.band(dstFlags, COMBATLOG_OBJECT_TYPE_PLAYER) == COMBATLOG_OBJECT_TYPE_PLAYER)
224
225
if not isDestPlayer then
226
return
227
end
228
229
if auraType == "BUFF" and string.find(spellName, "Prowl") ~= nil then
230
if eventType == "SPELL_AURA_APPLIED" then
231
NugEnergy.stealth = true
232
end
233
234
if eventType == "SPELL_AURA_REMOVED" or eventType == "SPELL_AURA_DISPELLED" then
235
NugEnergy.stealth = false
236
end
237
238
NugEnergy.UpdateHide(NugEnergyDB.visibility)
239
end
240
end
241
242
function NugEnergy.MakeOptions(self)
243
local alignValues = {
244
["LEFT"] = "Left",
245
["CENTER"] = "Center",
246
["RIGHT"] = "Right",
247
}
248
local visibilityValues = {
249
["Stealth"] = "Stealth",
250
["Combat"] = "Combat",
251
["Always"] = "Always",
252
}
253
254
local fonts,bars = {}, {}
255
256
for _, v in pairs(media:List('font')) do
257
fonts[v] = v
258
end
259
260
for _, v in pairs(media:List('statusbar')) do
261
bars[v] = v
262
end
263
264
media.RegisterCallback(NugEnergy, "LibSharedMedia_Registered",
265
function(_, mediatype, key)
266
if mediatype == "font" then
267
fonts[key] = key
268
269
if key == NugEnergyDB.font then
270
NugEnergy.text:SetFont(media:Fetch("font", NugEnergyDB.font), NugEnergyDB.fontSize)
271
end
272
273
elseif mediatype == "statusbar" then
274
bars[key] = key
275
276
if key == NugEnergyDB.ticker.texture then
277
if NugEnergyTickerBar then
278
NugEnergyTickerBar:SetTexture(media:Fetch("statusbar", NugEnergyDB.ticker.texture))
279
end
280
end
281
end
282
end)
283
284
local opt = {
285
type = "group",
286
name = "NugEnergy",
287
args = {},
288
}
289
290
opt.args.general = {
291
type = "group",
292
name = "General",
293
order = 1,
294
args = {
295
showPositon = {
296
type = "group",
297
name = "Frame Position",
298
guiInline = true,
299
order = 1,
300
args = {
301
posX = {
302
name = "Pos X",
303
type = "range",
304
desc = "Horizontal position, relative to center",
305
get = function(info) return NugEnergyDB.posX end,
306
set = function(info, s) NugEnergyDB.posX = s; NugEnergy.frame:SetPoint("CENTER", UIParent, "CENTER", NugEnergyDB.posX, NugEnergyDB.posY); end,
307
min = -900,
308
max = 900,
309
step = 5
310
},
311
posY = {
312
name = "Pos Y",
313
type = "range",
314
desc = "Vertical position, relative to center",
315
get = function(info) return NugEnergyDB.posY end,
316
set = function(info, s) NugEnergyDB.posY = s; NugEnergy.frame:SetPoint("CENTER", UIParent, "CENTER", NugEnergyDB.posX, NugEnergyDB.posY); end,
317
min = -700,
318
max = 700,
319
step = 5
320
}
321
}
322
},
323
showScale = {
324
type = "group",
325
name = "Scale & Font",
326
guiInline = true,
327
order = 2,
328
args = {
329
align = {
330
type = "select",
331
name = "Align",
332
desc = "Align of text",
333
values = alignValues,
334
get = function()
335
return NugEnergyDB.align
336
end,
337
set = function(_, s)
338
NugEnergyDB.align = s
339
NugEnergy.text:SetJustifyH(NugEnergyDB.align)
340
end
341
},
342
font = {
343
type = "select",
344
name = "Font",
345
desc = "Choose font",
346
values = fonts,
347
order = 1,
348
get = function()
349
return NugEnergyDB.font
350
end,
351
set = function(_, s)
352
NugEnergyDB.font = s
353
NugEnergy.text:SetFont(media:Fetch("font", NugEnergyDB.font),NugEnergyDB.fontSize)
354
end
355
},
356
fontSize = {
357
name = "Font Size",
358
type = "range",
359
order = 2,
360
get = function()
361
return NugEnergyDB.fontSize
362
end,
363
set = function(_, s)
364
NugEnergyDB.fontSize = s
365
NugEnergy.text:SetFont(media:Fetch("font", NugEnergyDB.font),NugEnergyDB.fontSize)
366
end,
367
min = 10,
368
max = 35,
369
step = 1
370
},
371
visibility = {
372
type = "select",
373
name = "Visible when...",
374
desc = "",
375
values = visibilityValues,
376
get = function()
377
return NugEnergyDB.visibility
378
end,
379
set = function(_, s)
380
NugEnergyDB.visibility = s
381
NugEnergy.UpdateBehavior(NugEnergyDB.visibility)
382
end
383
}
384
}
385
},
386
showColors = {
387
type = "group",
388
name = "Colors",
389
guiInline = true,
390
order = 3,
391
args = {
392
energyColor = {
393
name = "Energy Color",
394
type = "color",
395
desc = "energy color",
396
order = 1,
397
get = function()
398
local r, g, b = unpack(NugEnergyDB.energyColor)
399
return r, g, b
400
end,
401
set = function(_, r, g, b)
402
NugEnergyDB.energyColor = { r, g, b }
403
404
if NugEnergy.class == "ROGUE" then
405
NugEnergy.text:SetVertexColor(r, g, b)
406
end
407
end
408
},
409
rageColor = {
410
name = "Rage Color",
411
type = "color",
412
desc = "rage color",
413
order = 2,
414
get = function()
415
local r, g, b = unpack(NugEnergyDB.rageColor)
416
return r, g, b
417
end,
418
set = function(_, r, g, b)
419
NugEnergyDB.rageColor = { r, g, b }
420
421
if NugEnergy.class == "WARRIOR" then
422
NugEnergy.text:SetVertexColor(r, g, b)
423
end
424
end
425
},
426
tickerColor = {
427
name = "Ticker Color",
428
type = "color",
429
desc = "TickBar color",
430
order = 3,
431
get = function()
432
local r, g, b = unpack(NugEnergyDB.ticker.color)
433
return r, g, b
434
end,
435
set = function(_, r, g, b)
436
NugEnergyDB.ticker.color = { r, g, b }
437
438
if NugEnergy.class == "ROGUE" then
439
NugEnergyTickerBar:SetVertexColor(r, g, b)
440
end
441
end
442
},
443
tickeralphaBG = {
444
name = "Ticker BG alpha",
445
type = "range",
446
desc = "...",
447
order = 4,
448
get = function()
449
return NugEnergyDB.ticker.alphaBG
450
end,
451
set = function(_, s)
452
NugEnergyDB.ticker.alphaBG = s
453
NugEnergyTickerBackground:SetTexture(0, 0, 0, NugEnergyDB.ticker.alphaBG)
454
end,
455
min = 0,
456
max = 1,
457
step = 0.1
458
}
459
}
460
},
461
tickerOpts = {
462
type = "group",
463
name = "Ticker",
464
guiInline = true,
465
order = 4,
466
args = {
467
offsetX = {
468
name = "Offset X",
469
type = "range",
470
desc = "Horizontal offset, relative to main frame",
471
order = 1,
472
get = function()
473
return NugEnergyDB.ticker.offsetX
474
end,
475
set = function(_, s)
476
NugEnergyDB.ticker.offsetX = s
477
NugEnergyTicker:SetPoint("CENTER", NugEnergy.frame, "CENTER", NugEnergyDB.ticker.offsetX,NugEnergyDB.ticker.offsetY)
478
end,
479
min = -900,
480
max = 900,
481
step = 1
482
},
483
offsetY = {
484
name = "Offset Y",
485
type = "range",
486
desc = "Vertical offset, relative to main frame",
487
order = 2,
488
get = function()
489
return NugEnergyDB.ticker.offsetY
490
end,
491
set = function(_, s)
492
NugEnergyDB.ticker.offsetY = s
493
NugEnergyTicker:SetPoint("CENTER", NugEnergy.frame, "CENTER", NugEnergyDB.ticker.offsetX, NugEnergyDB.ticker.offsetY)
494
end,
495
min = -700,
496
max = 700,
497
step = 1
498
},
499
width = {
500
name = "Width",
501
type = "range",
502
desc = "ppc",
503
order = 3,
504
get = function()
505
return NugEnergyDB.ticker.width
506
end,
507
set = function(_, s)
508
NugEnergyDB.ticker.width = s
509
NugEnergyTicker:SetWidth(NugEnergyDB.ticker.width)
510
end,
511
min = 20,
512
max = 800,
513
step = 1
514
},
515
height = {
516
name = "Height",
517
type = "range",
518
desc = "eh",
519
order = 4,
520
get = function()
521
return NugEnergyDB.ticker.height
522
end,
523
set = function(_, s)
524
NugEnergyDB.ticker.height = s
525
NugEnergyTicker:SetHeight(NugEnergyDB.ticker.height)
526
end,
527
min = 2,
528
max = 100,
529
step = 2
530
},
531
texure = {
532
type = "select",
533
name = "Texture",
534
desc = "Choose ticker texture",
535
values = bars,
536
order = 5,
537
get = function()
538
return NugEnergyDB.ticker.texture
539
end,
540
set = function(_, s)
541
NugEnergyDB.ticker.texture = s
542
NugEnergyTickerBar:SetTexture(media:Fetch("statusbar", NugEnergyDB.ticker.texture))
543
end
544
}
545
}
546
}
547
}
548
}
549
550
local Config = LibStub("AceConfigRegistry-3.0")
551
local Dialog = LibStub("AceConfigDialog-3.0")
552
553
Config:RegisterOptionsTable("NugEnergy-Bliz", { name = "NugEnergy", type = "group", args = {} })
554
Dialog:SetDefaultSize("NugEnergy-Bliz", 600, 400)
555
556
Config:RegisterOptionsTable("NugEnergy-General", opt.args.general)
557
Dialog:AddToBlizOptions("NugEnergy-General", "NugEnergy")
558
559
SLASH_NESLASH1 = "/ne";
560
SLASH_NESLASH2 = "/nugenergy";
561
SlashCmdList["NESLASH"] = function()
562
InterfaceOptionsFrame_OpenToFrame("NugEnergy")
563
end
564
end
565
566
function NugEnergy.CreateFrame(width, height, frameName)
567
local f = CreateFrame("Frame",frameName,UIParent)
568
f:SetFrameStrata("MEDIUM")
569
f:SetWidth(width)
570
f:SetHeight(height)
571
f:SetPoint("CENTER", UIParent, "CENTER", NugEnergyDB.posX, NugEnergyDB.posY)
572
573
text = f:CreateFontString(nil, "OVERLAY");
574
text:SetFont(media:Fetch("font", NugEnergyDB.font), NugEnergyDB.fontSize)
575
text:ClearAllPoints()
576
text:SetWidth(width)
577
text:SetHeight(height)
578
text:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", 0, 0)
579
text:SetJustifyH(NugEnergyDB.align)
580
text:SetVertexColor(unpack(NugEnergy.color))
581
582
NugEnergy.currentEnergy = 0
583
584
f:Hide()
585
return f, text
586
end
587
588
589
function NugEnergy.CreateTickerFrame(frameName)
590
local f = CreateFrame("Frame", frameName, UIParent)
591
f:SetFrameStrata("MEDIUM")
592
f:SetWidth(NugEnergyDB.ticker.width)
593
f:SetHeight(NugEnergyDB.ticker.height)
594
f:SetPoint("CENTER", NugEnergy.frame, "CENTER", NugEnergyDB.ticker.offsetX, NugEnergyDB.ticker.offsetY)
595
596
local bg = f:CreateTexture(frameName .. "Background", "BACKGROUND")
597
bg:SetWidth(NugEnergyDB.ticker.width)
598
bg:SetHeight(NugEnergyDB.ticker.height)
599
bg:SetTexture(0, 0, 0, NugEnergyDB.ticker.alphaBG)
600
bg:SetAllPoints(f)
601
602
local b = f:CreateTexture(frameName .. "Bar", "ARTWORK")
603
b:SetWidth(NugEnergyDB.ticker.width)
604
b:SetHeight(NugEnergyDB.ticker.height)
605
b:SetTexture(media:Fetch("statusbar", NugEnergyDB.ticker.texture))
606
b:SetPoint("TOPLEFT", f, "TOPLEFT", 0, 0)
607
b:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 0, 0)
608
b:SetVertexColor(unpack(NugEnergyDB.ticker.color))
609
610
NugEnergy.lastTime = GetTime()
611
NugEnergy.OnUpdate = function ()
612
local now = GetTime()
613
614
if now > NugEnergy.lastTime + 2 then
615
NugEnergy.lastTime = now
616
end
617
618
local width = (GetTime() - NugEnergy.lastTime) * NugEnergyDB.ticker.width / 2
619
620
if width > 0 then
621
NugEnergyTickerBar:SetWidth(width)
622
end
623
end
624
625
f:SetScript("OnUpdate", NugEnergy.OnUpdate)
626
627
f:Hide()
628
return f
629
end