forked from doadin/PlexusStatusExternals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpellsWidget.lua
284 lines (234 loc) · 9.95 KB
/
SpellsWidget.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
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
local AceGUI = LibStub("AceGUI-3.0")
do
local widgetType = "PSE-SpellsConfig"
local widgetVersion = 1
local SPELL_HEIGHT = 24
local function GetSpellPriority(self, spellid)
for p, s in ipairs(self.active_spellids) do
if s == spellid then
return p
end
end
return false
end
local function GetSpellClass(self, spellid)
for class, buffs in pairs(self.spells) do
for _, s in ipairs(buffs) do
if s == spellid then
return class
end
end
end
return nil
end
local function SetContainerSpell(self, i, spellid, class, active)
local sname, _, sicon = GetSpellInfo(spellid)
if sicon == nil then
sname = "bad spellid"
sicon = "bad spellid"
end
self.spell_containers[i].spellid = spellid
self.spell_containers[i].label:SetText(string.format(" |T%s:20|t |cFF%02x%02x%02x%s|r", sicon, RAID_CLASS_COLORS[class].r * 0xff, RAID_CLASS_COLORS[class].g * 0xff, RAID_CLASS_COLORS[class].b * 0xff, sname))
if active then
self.spell_containers[i].check.checktex:Show()
self.spell_containers[i].upbtn:Enable()
self.spell_containers[i].downbtn:Enable()
else
self.spell_containers[i].check.checktex:Hide()
self.spell_containers[i].upbtn:Disable()
self.spell_containers[i].downbtn:Disable()
end
end
local function UpdateSpells(self)
local i = 1
for _, spellid in ipairs(self.active_spellids) do
SetContainerSpell(self, i, spellid, GetSpellClass(self, spellid), true)
i = i + 1
end
for class, buffs in pairs(self.spells) do
for _, spellid in pairs(buffs) do
if not GetSpellPriority(self, spellid) then
SetContainerSpell(self, i, spellid, class, false)
i = i + 1
end
end
end
end
local function CheckBox_OnClick(frame)
local self = frame.obj.obj
local spellid = frame.obj.spellid
local i = GetSpellPriority(self, spellid)
if i then
table.remove(self.active_spellids, i)
self.inactive_spellids[spellid] = i
else
local pos
if self.inactive_spellids[spellid] and self.inactive_spellids[spellid] <= (#self.active_spellids + 1) then
pos = self.inactive_spellids[spellid]
else
pos = #self.active_spellids+1
end
table.insert(self.active_spellids, pos, spellid)
end
UpdateSpells(self)
local PlexusStatusExternals = Plexus:GetModule("PlexusStatus"):GetModule("PlexusStatusExternals")
PlexusStatusExternals:UpdateAllUnits()
end
local function UpButton_Click(frame)
local self = frame.obj.obj
local i = GetSpellPriority(self, frame.obj.spellid)
if i and i > 1 then
if IsLeftShiftKeyDown() then
local tmp = self.active_spellids[i]
table.remove(self.active_spellids, i)
table.insert(self.active_spellids, 1, tmp)
else
local tmp = self.active_spellids[i-1]
self.active_spellids[i-1] = self.active_spellids[i]
self.active_spellids[i] = tmp
end
UpdateSpells(self)
local PlexusStatusExternals = Plexus:GetModule("PlexusStatus"):GetModule("PlexusStatusExternals")
PlexusStatusExternals:UpdateAllUnits()
end
end
local function DownButton_Click(frame)
local self = frame.obj.obj
local i = GetSpellPriority(self, frame.obj.spellid)
if i and i < #self.active_spellids then
if IsLeftShiftKeyDown() then
local tmp = self.active_spellids[i]
table.remove(self.active_spellids, i)
table.insert(self.active_spellids, #self.active_spellids+1, tmp)
else
local tmp = self.active_spellids[i+1]
self.active_spellids[i+1] = self.active_spellids[i]
self.active_spellids[i] = tmp
end
UpdateSpells(self)
local PlexusStatusExternals = Plexus:GetModule("PlexusStatus"):GetModule("PlexusStatusExternals")
PlexusStatusExternals:UpdateAllUnits()
end
end
local function LabelFrame_OnEnter(frame)
-- HACK: replaces tooltips of some spells for other more descriptive spellids..
local spellfilters = {
-- [63087] = 63086 -- Raptor Strike => Glyph of Raptor Strike
}
GameTooltip:SetOwner(frame, "ANCHOR_NONE")
GameTooltip:SetPoint("BOTTOMLEFT", frame, "BOTTOMRIGHT")
GameTooltip:SetSpellByID(spellfilters[frame.spellid] or frame.spellid, true, true)
GameTooltip:Show()
end
local function LabelFrame_OnLeave(frame) --luacheck: ignore 212
GameTooltip:Hide()
end
local function LabelFrame_OnMouseUp(frame)
if IsModifiedClick("CHATLINK") then
ChatEdit_InsertLink(GetSpellLink(frame.spellid))
end
end
local function OnAcquire(self)
UpdateSpells(self)
end
-- These are required by AceConfigDialog
local function SetLabel(self, label) --luacheck: ignore 212
end
local function SetText(self, text) --luacheck: ignore 212
end
local function SetDisabled(self, disabled) --luacheck: ignore 212
end
local function Constructor()
local widget = {
type = widgetType,
OnAcquire = OnAcquire,
SetLabel = SetLabel,
SetText = SetText,
SetDisabled = SetDisabled,
}
-- Create spell containers
local PlexusStatusExternals = Plexus:GetModule("PlexusStatus"):GetModule("PlexusStatusExternals")
local spells = PlexusStatusExternals.tankingbuffs
local spell_count = 0
for _, cspells in pairs(spells) do
spell_count = spell_count + #cspells
end
spell_containers = {} --luacheck: ignore 111
local frame = CreateFrame("Frame")
frame:SetWidth(200)
frame:SetHeight(spell_count * SPELL_HEIGHT)
frame.obj = self
local spell_containers = { }
for i = 1, spell_count do
-- checkbox
local check = CreateFrame("Button", nil, frame)
check:SetPoint("TOPLEFT", 0, (i - 1) * -SPELL_HEIGHT)
check:SetWidth(24)
check:SetHeight(SPELL_HEIGHT)
check:Show()
check:SetScript("OnClick", CheckBox_OnClick)
local checkbg = check:CreateTexture(nil, "ARTWORK")
checkbg:SetAllPoints()
checkbg:SetTexture("Interface\\Buttons\\UI-CheckBox-Up")
local checktex = check:CreateTexture(nil, "OVERLAY")
checktex:SetAllPoints(checkbg)
checktex:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
check.checktex = checktex
local highlight = check:CreateTexture(nil, "HIGHLIGHT")
highlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
highlight:SetBlendMode("ADD")
highlight:SetAllPoints(checkbg)
-- up button
local upbtn = CreateFrame("Button", nil, frame)
upbtn:SetPoint("TOPLEFT", check, "TOPRIGHT")
upbtn:SetWidth(24)
upbtn:SetHeight(24)
upbtn:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollUp-Up")
upbtn:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollUp-Down")
upbtn:SetDisabledTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollUp-Disabled")
upbtn:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight", "ADD")
upbtn:SetScript("OnClick", UpButton_Click)
-- down button
local downbtn = CreateFrame("Button", nil, frame)
downbtn:SetPoint("TOPLEFT", upbtn, "TOPRIGHT")
downbtn:SetWidth(24)
downbtn:SetHeight(24)
downbtn:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Up")
downbtn:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Down")
downbtn:SetDisabledTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Disabled")
downbtn:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight", "ADD")
downbtn:SetScript("OnClick", DownButton_Click)
-- label
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("TOPLEFT", downbtn, "TOPRIGHT")
label:SetWidth(200)
label:SetHeight(SPELL_HEIGHT)
label:SetJustifyH("LEFT")
label:SetJustifyV("MIDDLE")
-- label frame
local label_frame = CreateFrame("Frame", nil, frame)
label_frame:SetAllPoints(label)
label_frame:EnableMouse()
label_frame:SetScript("OnEnter", LabelFrame_OnEnter)
label_frame:SetScript("OnLeave", LabelFrame_OnLeave)
label_frame:SetScript("OnMouseUp", LabelFrame_OnMouseUp)
check.obj = label_frame
upbtn.obj = label_frame
downbtn.obj = label_frame
label_frame.obj = widget
label_frame.check = check
label_frame.label = label
label_frame.upbtn = upbtn
label_frame.downbtn = downbtn
spell_containers[i] = label_frame
end
widget.frame = frame
widget.spell_containers = spell_containers
widget.spells = spells
widget.active_spellids = PlexusStatusExternals.db.profile.alert_externals.active_spellids
widget.inactive_spellids = PlexusStatusExternals.db.profile.alert_externals.inactive_spellids
AceGUI:RegisterAsWidget(widget)
return widget
end
AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)
end