-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPallyPowerLite.lua
More file actions
726 lines (625 loc) · 21 KB
/
Copy pathPallyPowerLite.lua
File metadata and controls
726 lines (625 loc) · 21 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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
PallyPowerLite = LibStub("AceAddon-3.0"):NewAddon("PallyPowerLite", "AceConsole-3.0", "AceEvent-3.0", "AceBucket-3.0", "AceComm-3.0")
--Lib variable
local LS = LibStub("LibSerialize")
--local LD = LibStub("LibDeflate")
-- Saved variable
PallyPowerLiteSelfAssignment = {}
PPL_DebugEnabled = false
-- Main variable
player = UnitName("player")
isPally = false
isBattleground = false
roster = {}
classList = {}
pallysData = {}
-- Support variable
local partyUnits = {}
local raidUnits = {}
do
table.insert(partyUnits, "player")
for i = 1, MAX_PARTY_MEMBERS do
table.insert(partyUnits, ("party%d"):format(i))
end
for i = 1, MAX_RAID_MEMBERS do
table.insert(raidUnits, ("raid%d"):format(i))
end
end
local lastMessage = ""
-------------------------------
-- Self Functions
-------------------------------
function PallyPowerLite:Debug(s)
if (PPL_DebugEnabled) then
DEFAULT_CHAT_FRAME:AddMessage("|cffffd100[PPL]|r |cff3fc7eb"..tostring(s).."|r", 1, 0, 0)
if type(s) ~= "string" then
DevTools_Dump(s)
end
end
end
function PallyPowerLite:OnInitialize()
self:RegisterComm(PallyPowerLite.commPrefix)
-- For first init state
--self:Debug(PallyPowerLiteSelfAssignment)
if not PallyPowerLiteSelfAssignment.buff then
PallyPowerLiteSelfAssignment = table.copy(self.pallyDataTemplate.assignment)
end
-- Initialize options
self.db = LibStub("AceDB-3.0"):New("PallyPowerLiteDB", {
profile = {
minimap = {
hide = false
},
overlayLock = false,
overlayPos = {
x = 0,
y = 0
},
overlayShowRF = true,
freeAssign = false
},
})
self.prof = self.db.profile
LibStub("AceConfig-3.0"):RegisterOptionsTable("PallyPowerLite", self.options)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("PallyPowerLite", "PallyPower Lite")
-- Initialize minimap icon
self.MinimapIcon = LibStub("LibDBIcon-1.0")
self.LDB =
LibStub("LibDataBroker-1.1"):NewDataObject(
"PallyPowerLite",
{
["type"] = "data source",
["text"] = "PallyPowerLite",
["icon"] = "Interface\\Icons\\spell_holy_championsbond",
["OnTooltipShow"] = function(tooltip)
tooltip:SetText(PALLYPOWERLIGHT_NAME)
tooltip:AddLine(L["|cffffffff[Left-Click]|r Open Assignments Menu"])
tooltip:Show()
end,
["OnClick"] = function(_, button)
if (button == "LeftButton") then
PallyPowerLiteAssignmentFrame_Toggle()
end
end
}
)
self.MinimapIcon:Register("PallyPowerLite", self.LDB, self.prof.minimap)
C_Timer.After(
2.0,
function()
PallyPowerLite.MinimapIcon:Show("PallyPowerLite")
end
)
self:RegisterChatCommand("ppl", PallyPowerLiteAssignmentFrame_Toggle)
self:RegisterChatCommand("pallypowerlite", PallyPowerLiteAssignmentFrame_Toggle)
local c = _G["PPLOverlayFrame"]
c:ClearAllPoints()
c:SetPoint("CENTER", "UIParent", "CENTER", self.prof.overlayPos.x, self.prof.overlayPos.y)
if not PPL_DebugEnabled then
PPL_DebugEnabled = true
self:Debug(PALLYPOWERLIGHT_NAME.." loaded")
PPL_DebugEnabled = false
else
self:Debug(PALLYPOWERLIGHT_NAME.." loaded")
end
end
function PallyPowerLite:OnEnable()
--self:Debug("Start Enable")
isPally = select(2, UnitClass("player")) == "PALADIN"
isBattleground = IsInGroup(LE_PARTY_CATEGORY_INSTANCE) and IsInInstance()
--self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self:RegisterEvent("UNIT_AURA")
self:RegisterEvent("GROUP_JOINED")
self:RegisterEvent("GROUP_LEFT")
self:RegisterBucketEvent({"ACTIVE_TALENT_GROUP_CHANGED", "PLAYER_ROLES_ASSIGNED"}, 1, "ACTIVE_TALENT_GROUP_CHANGED")
self:RegisterBucketEvent("PLAYER_ENTERING_WORLD", 2, "PLAYER_ENTERING_WORLD")
self:RegisterBucketEvent({"GROUP_ROSTER_UPDATE", "PLAYER_REGEN_ENABLED"}, 2, "GROUP_ROSTER_UPDATE")
if isPally then
local c = _G["PPLOverlayFrame"]:Show()
end
self:UpdateSeflData()
self:UpdateRoster()
self:UpdateOverlayAnchorLayout()
self:UpdateOverlayLayout()
end
function PallyPowerLite:OnDisable()
--self:Debug("Start Disable")
self:UnregisterAllEvents()
self:UnregisterAllBuckets()
end
function PallyPowerLite:IsTrackedSpell(spellID)
local res = false
for _, currentSpellID in pairs(self.Buffs) do
if spellID == currentSpellID then
res = true
break
end
end
for _, currentSpellID in pairs(self.Auras) do
if spellID == currentSpellID then
res = true
break
end
end
for _, currentSpellID in pairs(self.Seals) do
if spellID == currentSpellID then
res = true
break
end
end
return res
end
function PallyPowerLite:UpdateSeflData()
if not isPally then return end
local selfData = table.copy(self.pallyDataTemplate)
selfData.role = UnitGroupRolesAssigned("player")
selfData.talents.holy = select(5, GetTalentTabInfo(1))
selfData.talents.prot = select(5, GetTalentTabInfo(2))
selfData.talents.retri = select(5, GetTalentTabInfo(3))
selfData.assignment = table.copy(PallyPowerLiteSelfAssignment)
selfData.freeAssign = self.prof.freeAssign
pallysData[player] = selfData
self:SendPallyData(player)
end
function PallyPowerLite:UpdateRoster()
isBattleground = IsInGroup(LE_PARTY_CATEGORY_INSTANCE) and IsInInstance()
table.wipe(roster)
for i = 1, PALLYPOWERLIGHT_MAXCLASSES do
if self.ClassID[i] then
classList[i] = 0
end
end
for _, unitID in pairs(IsInRaid() and raidUnits or partyUnits) do
if unitID and UnitExists(unitID) then
local unitInfo = {}
unitInfo.unitID = unitID
unitInfo.class = UnitClassBase(unitID)
if unitInfo.class then
unitName = GetUnitName(unitID, true)
unitInfo.classID = self.ClassToID[unitInfo.class]
unitInfo.role = UnitGroupRolesAssigned(unitID)
unitInfo.isLeader = UnitIsGroupLeader(unitID)
unitInfo.isPally = unitInfo.class == "PALADIN"
unitInfo.hasBuff = false
unitInfo.dead = false
roster[unitName] = unitInfo
classList[unitInfo.classID] = classList[unitInfo.classID] + 1
end
end
end
-- Clean pallys data who not in roster anymore
for pallyName in pairs(pallysData) do
if pallyName ~= player and not roster[pallyName] then
table.removekey(pallysData, pallyName)
end
end
self:UpdateRosterBuffs()
end
function PallyPowerLite:UpdateRosterBuffs()
if not PallyPowerLiteSelfAssignment or self.Buffs[PallyPowerLiteSelfAssignment.buff] == "" then return end
for _, unitInfo in pairs(roster) do
unitInfo.hasBuff = false
local j=1
local currentBuffID = select(10, UnitBuff(unitInfo.unitID, j))
while currentBuffID do
if currentBuffID == self.Buffs[PallyPowerLiteSelfAssignment.buff] then
unitInfo.hasBuff = true
end
j=j+1
currentBuffID = select(10, UnitBuff(unitInfo.unitID, j))
end
end
end
function PallyPowerLite:UpdateAssignmentFrameLayout()
local mainFrame = _G["PPLAssignmentFrame"]
if not mainFrame or not mainFrame:IsVisible() then return end
local frameHeight = 100 -- Start Height with only header
local rowHeight = _G[mainFrame:GetName().."Row1"]:GetHeight()
for i=1, PALLYPOWERLIGHT_MAXCLASSES do
local frameName = mainFrame:GetName().."HeaderClassFrameInfo"..tostring(i)
if _G[frameName] then
local icon = PallyPowerLite.ClassIcons[i]
if icon then
_G[frameName.."Icon"]:SetTexture(icon)
end
local classCount = classList[i]
if classCount then
_G[frameName.."Counter"]:SetText(tostring(classCount))
end
end
end
-- Hide all pallys rows
for i=1, PALLYPOWERLIGHT_MAXPALLYS do
local rowFrame = _G[mainFrame:GetName().."Row"..tostring(i)]
if rowFrame then
rowFrame:Hide()
end
end
-- Fill rows with pallys data and show
-- Our pally always show first
i=1
for pallyName, pallyData in fpairs(pallysData, player) do
if i > PALLYPOWERLIGHT_MAXPALLYS then break end
local rowFrameName = mainFrame:GetName().."Row"..tostring(i)
local rowFrame = _G[rowFrameName]
if rowFrame then
-- Pally info
local infoFrameName = rowFrameName.."PallyInfo"
_G[infoFrameName.."NameText"]:SetText(pallyName)
_G[infoFrameName.."HolyTalentCount"]:SetText(pallyData.talents.holy)
_G[infoFrameName.."ProtTalentCount"]:SetText(pallyData.talents.prot)
_G[infoFrameName.."RetriTalentCount"]:SetText(pallyData.talents.retri)
local roleIconCoord = PallyPowerLite.RoleIconCoords[
pallyData.role ~= "NONE" and pallyData.role
or pallyData.talents.holy > 30 and "HEALER"
or pallyData.talents.prot > 30 and "TANK"
or pallyData.talents.retri > 30 and "DAMAGER"
]
if roleIconCoord then
_G[infoFrameName.."RoleIcon"]:SetTexCoord(roleIconCoord[1], roleIconCoord[2], roleIconCoord[3], roleIconCoord[4])
else
_G[infoFrameName.."RoleIcon"]:SetTexCoord(0, 0, 0, 0)
end
-- Pally assignment
_G[rowFrameName.."PallyAuraButtonIcon"]:SetTexture(PallyPowerLite.AurasIcons[pallyData.assignment.aura])
_G[rowFrameName.."PallyBuffButtonIcon"]:SetTexture(PallyPowerLite.BuffsIcons[pallyData.assignment.buff])
i = i + 1
frameHeight = frameHeight + rowHeight
rowFrame:Show()
end
end
-- Footer visibility
local footerFrame = _G[mainFrame:GetName().."Footer"]
if footerFrame then
local freeAssignmentButton = _G[footerFrame:GetName().."FreeAssign"]
if isPally then
freeAssignmentButton:Show()
freeAssignmentButton:SetChecked(pallysData[player].freeAssign)
else
freeAssignmentButton:Hide()
footerFrame:Hide() -- For now hide footer, 'cause no more buttons is there
end
if footerFrame:IsVisible() then
frameHeight = frameHeight + footerFrame:GetHeight()
end
end
mainFrame:SetHeight(frameHeight)
end
function PallyPowerLite:UpdateOverlayLayout()
if not PallyPowerLiteSelfAssignment then return end
local auraID = self.Auras[PallyPowerLiteSelfAssignment.aura]
local auraColor = auraID == "" and {r=0, g=0, b=0, a=0.5} or {r=1, g=0, b=0, a=0.4}
local sealID = self.Seals[PallyPowerLiteSelfAssignment.seal]
local sealColor = sealID == "" and {r=0, g=0, b=0, a=0.5} or {r=1, g=0, b=0, a=0.4}
local rfColor = {r=1, g=0, b=0, a=0.4}
local i=1
local currentBuffSource, _, _, currentBuffID = select(7, UnitBuff("player", i))
while currentBuffID do
if currentBuffSource == "player" and currentBuffID == auraID then
auraColor = {r=0, g=1, b=0, a=0.4}
end
if currentBuffSource == "player" and currentBuffID == sealID then
sealColor = {r=0, g=1, b=0, a=0.4}
end
if currentBuffSource == "player" and currentBuffID == 25780 then
rfColor = {r=0, g=1, b=0, a=0.4}
end
i=i+1
currentBuffSource, _, _, currentBuffID = select(7, UnitBuff("player", i))
end
-- Righteous Fury buff
local buttonName = "PPLOverlayFrameButtonRF";
_G[buttonName]:SetBackdropColor(rfColor["r"], rfColor["g"], rfColor["b"], rfColor["a"])
if not InCombatLockdown() then
if UnitGroupRolesAssigned("player") == "TANK" and self.prof.overlayShowRF then
_G[buttonName]:Show()
else
_G[buttonName]:Hide()
end
end
-- Aura and Seal
local buttonName = "PPLOverlayFrameButtonAura";
_G[buttonName]:SetBackdropColor(auraColor["r"], auraColor["g"], auraColor["b"], auraColor["a"])
_G[buttonName.."Icon"]:SetTexture(self.AurasIcons[PallyPowerLiteSelfAssignment.aura])
if not InCombatLockdown() then -- Attribute can be updated only not in combat
_G[buttonName]:SetAttribute("spell", (not auraID or auraID == "") and "" or GetSpellInfo(auraID))
end
local buttonName = "PPLOverlayFrameButtonSeal";
_G[buttonName]:SetBackdropColor(sealColor["r"], sealColor["g"], sealColor["b"], sealColor["a"])
_G[buttonName.."Icon"]:SetTexture(self.SealsIcons[PallyPowerLiteSelfAssignment.seal])
if not InCombatLockdown() then -- Attribute can be updated only not in combat
_G[buttonName]:SetAttribute("spell", (not sealID or sealID == "") and "" or GetSpellInfo(sealID))
end
-- Buff
local coutHasBuff = 0
for unitName, unitInfo in pairs(roster) do
if unitInfo.hasBuff then
coutHasBuff = coutHasBuff + 1
end
end
local buffID = self.Buffs[PallyPowerLiteSelfAssignment.buff]
local buffColor = buffID == "" and {r=0, g=0, b=0, a=0.5}
or coutHasBuff == 0 and {r=1, g=0, b=0, a=0.4}
or coutHasBuff < table.length(roster) and {r=1, g=1, b=0, a=0.4}
or {r=0, g=1, b=0, a=0.4}
local buttonName = "PPLOverlayFrameButtonBuff";
_G[buttonName]:SetBackdropColor(buffColor["r"], buffColor["g"], buffColor["b"], buffColor["a"])
_G[buttonName.."Icon"]:SetTexture(self.BuffsIcons[PallyPowerLiteSelfAssignment.buff])
_G[buttonName.."Counter"]:SetText((coutHasBuff == table.length(roster) or buffID == "") and "" or table.length(roster) - coutHasBuff)
if not InCombatLockdown() then -- Attribute can be updated only not in combat
_G[buttonName]:SetAttribute("spell", (not buffID or buffID == "") and "" or GetSpellInfo(buffID))
end
end
function PallyPowerLite:UpdateOverlayAnchorLayout()
if not isPally then return end
local c = _G["PPLOverlayFrameButtonAnchorBackground"]
if not c then return end
if self.prof.overlayLock then
c:SetColorTexture(1, 0, 0, 1)
else
c:SetColorTexture(0, 1, 0, 1)
end
end
function PallyPowerLite:CycleThroughSpell(pallyName, spellType, forward)
if InCombatLockdown() then return end -- Can't change assignment in combat
local pallyData = pallysData[pallyName]
if not pallyData or not spellType
or (not pallyData.freeAssign and pallyName ~= player) then return end
local spellData = nil
local currentSpell = 0
if spellType == "Buff" then
spellsData = PallyPowerLite.Buffs
currentSpell = pallyData.assignment.buff or 0
elseif spellType == "Aura" then
spellsData = PallyPowerLite.Auras
currentSpell = pallyData.assignment.aura or 0
else
spellsData = PallyPowerLite.Seals
currentSpell = pallyData.assignment.seal or 0
end
if forward then
currentSpell = table.length(spellsData) == currentSpell+1 and 0 or currentSpell+1
else
currentSpell = currentSpell == 0 and table.length(spellsData)-1 or currentSpell-1
end
if spellType == "Buff" then
pallyData.assignment.buff = currentSpell
elseif spellType == "Aura" then
pallyData.assignment.aura = currentSpell
else
pallyData.assignment.seal = currentSpell
end
if pallyName == player then
PallyPowerLiteSelfAssignment = table.copy(pallyData.assignment)
self:UpdateRoster()
end
self:UpdateAssignmentFrameLayout()
self:UpdateOverlayLayout()
self:SendPallyData(pallyName)
end
function PallyPowerLite:SendPallyData(pallyName, target)
currentData = pallyName and {[pallyName] = pallysData[pallyName]} or pallysData
self:SendMessage("PALLYDATA", currentData, target)
end
function PallyPowerLite:SendMessage(messageType, messageData, target)
if GetNumGroupMembers() <= 0 or not messageType or isBattleground then return end
local message = {
["messageType"] = messageType,
["messageData"] = messageData
}
local chanel = "WHISPER"
if not target then
if IsInGroup(LE_PARTY_CATEGORY_INSTANCE) and IsInInstance() then
chanel = "INSTANCE_CHAT"
elseif IsInRaid() then
chanel = "RAID"
else
chanel = "PARTY"
end
end
local outcomeData = LS:Serialize(message)
if lastMessage ~= outcomeData then
self:SendCommMessage(self.commPrefix, outcomeData, chanel, target)
end
end
function PallyPowerLite:OnCommReceived(prefix, payload, distribution, sender)
if prefix ~= self.commPrefix or isBattleground then return end
if sender == player then return end
--self:Debug("["..prefix.."] "..sender.." : "..payload);
local success, incomeData = LS:Deserialize(payload)
if success then
self:ProcessIncomeData(incomeData)
else
self:Debug("Can't deserialize message")
end
end
function PallyPowerLite:ProcessIncomeData(incomeData, sender)
if not incomeData.messageType then return end
if incomeData.messageType == "PALLYDATA" then
if incomeData.messageData then
for pallyName, pallyData in pairs(incomeData.messageData) do
if pallyName and pallyData and roster[pallyName] then
pallysData[pallyName] = pallyData
if pallyName == player then
PallyPowerLiteSelfAssignment = table.copy(pallyData.assignment)
self:UpdateRoster()
self:UpdateOverlayLayout()
end
end
end
self:UpdateAssignmentFrameLayout()
end
elseif incomeData.messageType == "REQDATA" then
if isPally and pallysData[player] then
self:SendPallyData(player, sender)
end
end
end
-------------------------------
-- Event Handlers
-------------------------------
function PallyPowerLite:UNIT_AURA(event, unitTarget, updateInfo)
local unitName = GetUnitName(unitTarget, true)
if isPally and PallyPowerLiteSelfAssignment and roster[unitName] then
local needUpdate = false
if updateInfo.addedAuras then
for _, currentAura in pairs(updateInfo.addedAuras) do
if self:IsTrackedSpell(currentAura.spellId) then
if currentAura.spellId == self.Buffs[PallyPowerLiteSelfAssignment.buff] then
roster[unitName].hasBuff = true
end
needUpdate = true
break
end
end
end
if updateInfo.removedAuraInstanceIDs then
-- Because I don't want to cache aura instances data and GetAuraDataByAuraInstanceID doesn't work on removed aura
-- always call frame update, but updating full roster only out of combat
if not InCombatLockdown() then
self:UpdateRoster()
else
self:UpdateRosterBuffs()
end
needUpdate = true
end
if needUpdate then
self:UpdateOverlayLayout()
end
end
end
function PallyPowerLite:GROUP_JOINED()
self:UpdateSeflData()
self:UpdateRoster()
self:SendMessage("REQDATA")
self:UpdateOverlayLayout()
self:UpdateAssignmentFrameLayout()
end
function PallyPowerLite:GROUP_LEFT()
self:UpdateRoster()
self:UpdateOverlayLayout()
self:UpdateAssignmentFrameLayout()
end
function PallyPowerLite:GROUP_ROSTER_UPDATE()
self:UpdateRoster()
self:UpdateOverlayLayout()
self:UpdateAssignmentFrameLayout()
end
function PallyPowerLite:PLAYER_ENTERING_WORLD()
self:UpdateSeflData()
self:UpdateRoster()
self:SendMessage("REQDATA")
self:UpdateOverlayLayout()
self:UpdateAssignmentFrameLayout()
end
function PallyPowerLite:ACTIVE_TALENT_GROUP_CHANGED()
self:UpdateSeflData()
self:UpdateAssignmentFrameLayout()
self:UpdateOverlayLayout()
end
-------------------------------
-- Frame Event Functions
-------------------------------
function PallyPowerLite:RowButton_OnClick(button, mouseButton)
local rowNumber = tonumber(string.match(button:GetName(), "%d+"))
if not rowNumber then return end
local isBuff = string.match(button:GetName(), "Buff") ~= nil
local pallyName = _G["PPLAssignmentFrameRow"..rowNumber.."PallyInfoNameText"]:GetText()
if not pallyName then return end
PallyPowerLite:CycleThroughSpell(pallyName, isBuff and "Buff" or "Aura", mouseButton == "LeftButton")
end
function PallyPowerLite:RowButton_OnMouseWheel(button, deltaScroll)
-- -1 = mouse wheel down = lift click
self:RowButton_OnClick(button, deltaScroll == -1 and "LeftButton" or "RightButton")
end
function PallyPowerLite:OverlayButton_OnLoad(button)
if BackdropTemplateMixin then
Mixin(button, BackdropTemplateMixin)
end
button:SetBackdrop(PALLYPOWERLIGHT_BACKDROP_LAYOUT_16_16)
if BackdropTemplateMixin then
Mixin(button, BackdropTemplateMixin)
end
button:SetBackdropColor(0, 0, 0, 0.5)
end
function PallyPowerLite:OverlayButton_OnMouseWheel(button, deltaScroll)
local spellType = nil
if string.match(button:GetName(), "Buff") ~= nil then
spellType = "Buff"
elseif string.match(button:GetName(), "Aura") ~= nil then
spellType = "Aura"
elseif string.match(button:GetName(), "Seal") ~= nil then
spellType = "Seal"
end
-- -1 = mouse wheel down = lift click
PallyPowerLite:CycleThroughSpell(player, spellType, deltaScroll == -1)
end
function PallyPowerLite:OverlayAnchorButton_OnClick(button, mouseButton)
if mouseButton == "LeftButton" then
self.prof.overlayLock = not self.prof.overlayLock
self:UpdateOverlayAnchorLayout()
end
end
function PallyPowerLite:OverlayAnchorButton_OnDragStart(button, mouseButton)
if not self.prof.overlayLock then
local c = _G["PPLOverlayFrame"]
c:StartMoving()
c:SetClampedToScreen(true)
end
end
function PallyPowerLite:OverlayAnchorButton_OnDragStop(button)
_G["PPLOverlayFrame"]:StopMovingOrSizing()
end
function PallyPowerLite:FooterButtonFreeAssign_OnClick(button)
self.prof.freeAssign = button:GetChecked()
self:UpdateSeflData()
end
-------------------------------
-- Global Functions
-------------------------------
function PallyPowerLiteAssignmentFrame_Toggle()
if PPLAssignmentFrame:IsVisible() then
PPLAssignmentFrame:Hide()
else
local c = _G["PPLAssignmentFrame"]
c:ClearAllPoints()
c:SetPoint("CENTER", "UIParent", "CENTER", 0, 0)
PPLAssignmentFrame:Show()
PallyPowerLite:UpdateAssignmentFrameLayout()
end
end
-------------------------------
-- Support Functions
-------------------------------
function table.copy(obj, seen)
if type(obj) ~= 'table' then return obj end
if seen and seen[obj] then return seen[obj] end
local s = seen or {}
local res = setmetatable({}, getmetatable(obj))
s[obj] = res
for k, v in pairs(obj) do res[table.copy(k, s)] = table.copy(v, s) end
return res
end
function table.length(obj)
local res = 0
for _ in pairs(obj) do res = res + 1 end
return res
end
function table.removekey(table, key)
local element = table[key]
table[key] = nil
return element
end
function fpairs(obj, first)
if table.length(obj) == 0 or not obj[first] then return pairs(obj) end
-- set first and collect other the keys
local keys = first and {first} or {}
for k in pairs(obj) do if k ~= first then keys[#keys+1] = k end end
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], obj[keys[i]]
end
end
end