/
core.lua
354 lines (294 loc) · 10.9 KB
/
core.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
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
-- rButtonTemplate: core
-- zork, 2016
-----------------------------
-- Variables
-----------------------------
local A, L = ...
-----------------------------
-- rButtonTemplate Global
-----------------------------
rButtonTemplate = {}
rButtonTemplate.addonName = A
-----------------------------
-- Init
-----------------------------
local function CallElementFunction(element, func, ...)
if element and func and element[func] then
element[func](element, ...)
end
end
local function ResetNormalTexture(self, file)
if not self.__normalTextureFile then return end
if file == self.__normalTextureFile then return end
self:SetNormalTexture(self.__normalTextureFile)
end
local function ResetTexture(self, file)
if not self.__textureFile then return end
if file == self.__textureFile then return end
self:SetTexture(self.__textureFile)
end
local function ResetVertexColor(self,r,g,b,a)
if not self.__vertexColor then return end
local r2,g2,b2,a2 = unpack(self.__vertexColor)
if not a2 then a2 = 1 end
if r ~= r2 or g ~= g2 or b ~= b2 or a ~= a2 then
self:SetVertexColor(r2,g2,b2,a2)
end
end
local function ApplyPoints(self, points)
if not points then return end
self:ClearAllPoints()
for i, point in next, points do
self:SetPoint(unpack(point))
end
end
local function ApplyTexCoord(texture,texCoord)
if not texCoord then return end
texture:SetTexCoord(unpack(texCoord))
end
local function ApplyVertexColor(texture,color)
if not color then return end
texture.__vertexColor = color
texture:SetVertexColor(unpack(color))
hooksecurefunc(texture, "SetVertexColor", ResetVertexColor)
end
local function ApplyAlpha(region,alpha)
if not alpha then return end
region:SetAlpha(alpha)
end
local function ApplyFont(fontString,font)
if not font then return end
fontString:SetFont(unpack(font))
end
local function ApplyTexture(texture,file)
if not file then return end
texture.__textureFile = file
texture:SetTexture(file)
hooksecurefunc(texture, "SetTexture", ResetTexture)
end
local function ApplyNormalTexture(button,file)
if not file then return end
button.__normalTextureFile = file
button:SetNormalTexture(file)
hooksecurefunc(button, "SetNormalTexture", ResetNormalTexture)
end
local function SetupTexture(texture,cfg,fileFunc,fileObj)
if not texture or not cfg then return end
ApplyTexCoord(texture,cfg.texCoord)
ApplyPoints(texture,cfg.points)
ApplyVertexColor(texture,cfg.color)
ApplyAlpha(texture,cfg.alpha)
if fileFunc == "SetTexture" then
ApplyTexture(texture,cfg.file)
elseif fileFunc == "SetNormalTexture" then
ApplyNormalTexture(fileObj,cfg.file)
elseif cfg.file then
CallObjectFunction(fileObj,fileFunc,cfg.file)
end
end
local function SetupFontString(fontString,cfg)
if not fontString or not cfg then return end
ApplyPoints(fontString, cfg.points)
ApplyFont(fontString,cfg.font)
ApplyAlpha(fontString,cfg.alpha)
end
local function SetupCooldown(cooldown,cfg)
if not cfg then return end
ApplyPoints(cooldown, cfg.points)
end
local function SetupBackdrop(button,backdrop)
if not backdrop then return end
local bg = CreateFrame("Frame", nil, button)
ApplyPoints(bg, backdrop.points)
bg:SetFrameLevel(button:GetFrameLevel()-1)
bg:SetBackdrop(backdrop)
if backdrop.backgroundColor then
bg:SetBackdropColor(unpack(backdrop.backgroundColor))
end
if backdrop.borderColor then
bg:SetBackdropBorderColor(unpack(backdrop.borderColor))
end
end
function rButtonTemplate:StyleActionButton(button, cfg)
if not button then return end
if button.__styled then return end
local buttonName = button:GetName()
local icon = _G[buttonName.."Icon"]
local flash = _G[buttonName.."Flash"]
local flyoutBorder = _G[buttonName.."FlyoutBorder"]
local flyoutBorderShadow = _G[buttonName.."FlyoutBorderShadow"]
local flyoutArrow = _G[buttonName.."FlyoutArrow"]
local hotkey = _G[buttonName.."HotKey"]
local count = _G[buttonName.."Count"]
local name = _G[buttonName.."Name"]
local border = _G[buttonName.."Border"]
local NewActionTexture = button.NewActionTexture
local cooldown = _G[buttonName.."Cooldown"]
local normalTexture = button:GetNormalTexture()
local pushedTexture = button:GetPushedTexture()
local highlightTexture = button:GetHighlightTexture()
local checkedTexture = button:GetCheckedTexture()
local floatingBG = _G[buttonName.."FloatingBG"]
--hide stuff
if floatingBG then floatingBG:Hide() end
--backdrop
SetupBackdrop(button,cfg.backdrop)
--textures
SetupTexture(icon,cfg.icon,"SetTexture",icon)
SetupTexture(flash,cfg.flash,"SetTexture",flash)
SetupTexture(flyoutBorder,cfg.flyoutBorder,"SetTexture",flyoutBorder)
SetupTexture(flyoutBorderShadow,cfg.flyoutBorderShadow,"SetTexture",flyoutBorderShadow)
SetupTexture(border,cfg.border,"SetTexture",border)
SetupTexture(normalTexture,cfg.normalTexture,"SetNormalTexture",button)
SetupTexture(pushedTexture,cfg.pushedTexture,"SetPushedTexture",button)
SetupTexture(highlightTexture,cfg.highlightTexture,"SetHighlightTexture",button)
SetupTexture(checkedTexture,cfg.checkedTexture,"SetCheckedTexture",button)
--cooldown
SetupCooldown(cooldown,cfg.cooldown)
--hotkey+count+name
SetupFontString(hotkey,cfg.hotkey)
SetupFontString(count,cfg.count)
SetupFontString(name,cfg.name)
button.__styled = true
end
function rButtonTemplate:StyleExtraActionButton(cfg)
local button = ExtraActionButton1
if button.__styled then return end
local buttonName = button:GetName()
local icon = _G[buttonName.."Icon"]
--local flash = _G[buttonName.."Flash"] --wierd the template has two textures of the same name
local hotkey = _G[buttonName.."HotKey"]
local count = _G[buttonName.."Count"]
local buttonstyle = button.style --artwork around the button
local cooldown = _G[buttonName.."Cooldown"]
local normalTexture = button:GetNormalTexture()
local pushedTexture = button:GetPushedTexture()
local highlightTexture = button:GetHighlightTexture()
local checkedTexture = button:GetCheckedTexture()
--backdrop
SetupBackdrop(button,cfg.backdrop)
--textures
SetupTexture(icon,cfg.icon,"SetTexture",icon)
SetupTexture(buttonstyle,cfg.buttonstyle,"SetTexture",buttonstyle)
SetupTexture(normalTexture,cfg.normalTexture,"SetNormalTexture",button)
SetupTexture(pushedTexture,cfg.pushedTexture,"SetPushedTexture",button)
SetupTexture(highlightTexture,cfg.highlightTexture,"SetHighlightTexture",button)
SetupTexture(checkedTexture,cfg.checkedTexture,"SetCheckedTexture",button)
--cooldown
SetupCooldown(cooldown,cfg.cooldown)
--hotkey+count+name
SetupFontString(hotkey,cfg.hotkey)
button.__styled = true
end
function rButtonTemplate:StyleItemButton(button,cfg)
if not button then return end
if button.__styled then return end
local buttonName = button:GetName()
local icon = _G[buttonName.."IconTexture"]
local count = _G[buttonName.."Count"]
local stock = _G[buttonName.."Stock"]
local searchOverlay = _G[buttonName.."SearchOverlay"]
local border = button.IconBorder
local normalTexture = button:GetNormalTexture()
local pushedTexture = button:GetPushedTexture()
local highlightTexture = button:GetHighlightTexture()
local checkedTexture = button:GetCheckedTexture()
--backdrop
SetupBackdrop(button,cfg.backdrop)
--textures
SetupTexture(icon,cfg.icon,"SetTexture",icon)
SetupTexture(searchOverlay,cfg.searchOverlay,"SetTexture",searchOverlay)
SetupTexture(border,cfg.border,"SetTexture",border)
SetupTexture(normalTexture,cfg.normalTexture,"SetNormalTexture",button)
SetupTexture(pushedTexture,cfg.pushedTexture,"SetPushedTexture",button)
SetupTexture(highlightTexture,cfg.highlightTexture,"SetHighlightTexture",button)
SetupTexture(checkedTexture,cfg.checkedTexture,"SetCheckedTexture",button)
--count+stock
SetupFontString(count,cfg.count)
SetupFontString(stock,cfg.stock)
button.__styled = true
end
function rButtonTemplate:StyleAllActionButtons(cfg)
for i = 1, NUM_ACTIONBAR_BUTTONS do
rButtonTemplate:StyleActionButton(_G["ActionButton"..i],cfg)
rButtonTemplate:StyleActionButton(_G["MultiBarBottomLeftButton"..i],cfg)
rButtonTemplate:StyleActionButton(_G["MultiBarBottomRightButton"..i],cfg)
rButtonTemplate:StyleActionButton(_G["MultiBarRightButton"..i],cfg)
rButtonTemplate:StyleActionButton(_G["MultiBarLeftButton"..i],cfg)
end
for i = 1, 6 do
rButtonTemplate:StyleActionButton(_G["OverrideActionBarButton"..i],cfg)
end
--petbar buttons
for i=1, NUM_PET_ACTION_SLOTS do
rButtonTemplate:StyleActionButton(_G["PetActionButton"..i],cfg)
end
--stancebar buttons
for i=1, NUM_STANCE_SLOTS do
rButtonTemplate:StyleActionButton(_G["StanceButton"..i],cfg)
end
--possess buttons
for i=1, NUM_POSSESS_SLOTS do
rButtonTemplate:StyleActionButton(_G["PossessButton"..i],cfg)
end
end
function rButtonTemplate:StyleAuraButton(button, cfg)
if not button then return end
if button.__styled then return end
local buttonName = button:GetName()
local icon = _G[buttonName.."Icon"]
local count = _G[buttonName.."Count"]
local duration = _G[buttonName.."Duration"]
local border = _G[buttonName.."Border"]
local symbol = button.symbol
--backdrop
SetupBackdrop(button,cfg.backdrop)
--textures
SetupTexture(icon,cfg.icon,"SetTexture",icon)
SetupTexture(border,cfg.border,"SetTexture",border)
--create a normal texture on the aura button
if cfg.normalTexture and cfg.normalTexture.file then
button:SetNormalTexture(cfg.normalTexture.file)
local normalTexture = button:GetNormalTexture()
SetupTexture(normalTexture,cfg.normalTexture,"SetNormalTexture",button)
end
--count,duration,symbol
SetupFontString(count,cfg.count)
SetupFontString(duration,cfg.duration)
SetupFontString(symbol,cfg.symbol)
button.__styled = true
end
--style player BuffFrame buff buttons
local buffButtonIndex = 1
function rButtonTemplate:StyleBuffButtons(cfg)
local function UpdateBuffButtons()
if buffButtonIndex > BUFF_MAX_DISPLAY then return end
for i = buffButtonIndex, BUFF_MAX_DISPLAY do
local button = _G["BuffButton"..i]
if not button then break end
rButtonTemplate:StyleAuraButton(button, cfg)
if button.__styled then buffButtonIndex = i+1 end
end
end
hooksecurefunc("BuffFrame_UpdateAllBuffAnchors", UpdateBuffButtons)
end
--style player BuffFrame debuff buttons
function rButtonTemplate:StyleDebuffButtons(cfg)
local function UpdateDebuffButton(buttonName, i)
local button = _G["DebuffButton"..i]
rButtonTemplate:StyleAuraButton(button, cfg)
end
hooksecurefunc("DebuffButton_UpdateAnchors", UpdateDebuffButton)
end
--style player TempEnchant buttons
function rButtonTemplate:StyleTempEnchants(cfg)
rButtonTemplate:StyleAuraButton(TempEnchant1, cfg)
rButtonTemplate:StyleAuraButton(TempEnchant2, cfg)
rButtonTemplate:StyleAuraButton(TempEnchant3, cfg)
end
--style all aura buttons
function rButtonTemplate:StyleAllAuraButtons(cfg)
rButtonTemplate:StyleBuffButtons(cfg)
rButtonTemplate:StyleDebuffButtons(cfg)
rButtonTemplate:StyleTempEnchants(cfg)
end