-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrame.lua
More file actions
462 lines (411 loc) · 20.3 KB
/
Frame.lua
File metadata and controls
462 lines (411 loc) · 20.3 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
local tonumber = tonumber
local pairs = pairs
local CreateFrame = CreateFrame
local UIParent = UIParent
local InCombatLockdown = InCombatLockdown
local Gladdy = LibStub("Gladdy")
local L = Gladdy.L
Gladdy.BUTTON_DEFAULTS = {
name = "",
guid = "",
raceLoc = "",
classLoc = "",
class = "",
health = "",
healthMax = 0,
power = 0,
powerMax = 0,
powerType = 0,
spec = "",
spells = {},
ns = false,
nf = false,
pom = false,
fd = false,
damaged = 0,
click = false,
}
function Gladdy:CreateFrame()
--self.db = self.dbi.profile ??
self.frame = CreateFrame("Frame", "GladdyFrame", UIParent)
self.frame:SetClampedToScreen(true)
self.frame:EnableMouse(true)
self.frame:SetMovable(true)
self.frame:RegisterForDrag("LeftButton")
self.frame:SetScript("OnDragStart", function(f)
if (not InCombatLockdown() and not self.db.locked) then
f:StartMoving()
end
end)
self.frame:SetScript("OnDragStop", function(f)
if (not InCombatLockdown()) then
f:StopMovingOrSizing()
local scale = f:GetEffectiveScale()
self.db.x = f:GetLeft() * scale
self.db.y = (self.db.growUp and f:GetBottom() or f:GetTop()) * scale
end
end)
self.anchor = CreateFrame("Button", "GladdyAnchor", self.frame)
self.anchor:SetHeight(20)
self.anchor:SetBackdrop({ bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16 })
self.anchor:SetBackdropColor(0, 0, 0, 1)
self.anchor:SetClampedToScreen(true)
self.anchor:EnableMouse(true)
self.anchor:SetMovable(true)
self.anchor:RegisterForDrag("LeftButton")
self.anchor:RegisterForClicks("RightButtonUp")
self.anchor:SetScript("OnDragStart", function()
if (not InCombatLockdown() and not self.db.locked) then
self.frame:StartMoving()
end
end)
self.anchor:SetScript("OnDragStop", function()
if (not InCombatLockdown()) then
self.frame:StopMovingOrSizing()
local scale = self.frame:GetEffectiveScale()
self.db.x = self.frame:GetLeft() * scale
self.db.y = (self.db.growUp and self.frame:GetBottom() or self.frame:GetTop()) * scale
end
end)
self.anchor:SetScript("OnClick", function()
if (not InCombatLockdown()) then
self:ShowOptions()
end
end)
self.anchor.text = self.anchor:CreateFontString("GladdyAnchorText", "ARTWORK", "GameFontHighlightSmall")
self.anchor.text:SetText(L["Gladdy - drag to move"])
self.anchor.text:SetPoint("CENTER")
self.anchor.button = CreateFrame("Button", "GladdyAnchorButton", self.anchor, "UIPanelCloseButton")
self.anchor.button:SetWidth(20)
self.anchor.button:SetHeight(20)
self.anchor.button:SetPoint("RIGHT", self.anchor, "RIGHT", 2, 0)
self.anchor.button:SetScript("OnClick", function(_, _, down)
if (not down) then
self.db.locked = true
self:UpdateFrame()
end
end)
if (self.db.locked) then
self.anchor:Hide()
end
self.frame:Hide()
end
local function StyleActionButton(f)
local name = f:GetName()
local button = _G[name]
local icon = _G[name .. "Icon"]
local normalTex = _G[name .. "NormalTexture"]
local cooldown = _G[name .. "Cooldown"]
normalTex:SetHeight(button:GetHeight())
normalTex:SetWidth(button:GetWidth())
normalTex:SetPoint("CENTER")
cooldown:SetAlpha(Gladdy.db.cooldownCooldownAlpha)
button:SetNormalTexture(Gladdy.db.cooldownBorderStyle)
normalTex:SetVertexColor(0,0,0,0)
f.border:SetTexture(Gladdy.db.cooldownBorderStyle)
f.border:SetVertexColor(Gladdy.db.cooldownBorderColor.r, Gladdy.db.cooldownBorderColor.g, Gladdy.db.cooldownBorderColor.b, Gladdy.db.cooldownBorderColor.a)
icon:SetTexCoord(.1, .9, .1, .9)
icon:SetPoint("TOPLEFT", button, "TOPLEFT", 2, -2)
icon:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -2, 2)
end
function Gladdy:UpdateFrame()
if (not self.frame) then
self:CreateFrame()
end
local teamSize = self.curBracket or 0
local iconSize = self.db.healthBarHeight
local margin = 0
local width = self.db.barWidth + self.db.padding * 2 + 5
local height = self.db.healthBarHeight * teamSize + margin * (teamSize - 1) + self.db.padding * 2 + 5
local extraBarWidth = 0
local extraBarHeight = 0
-- Powerbar
iconSize = iconSize + self.db.powerBarHeight
margin = margin + self.db.powerBarHeight
height = height + self.db.powerBarHeight * teamSize
extraBarHeight = extraBarHeight + self.db.powerBarHeight
-- Cooldown
margin = margin + 1 + self.db.highlightBorderSize * 2 + 1 -- + 1 space between health and power bar
height = height + self.db.highlightBorderSize * teamSize
if (self.db.cooldownYPos == "TOP" or self.db.cooldownYPos == "BOTTOM") and self.db.cooldown then
margin = margin + self.db.cooldownSize
height = height + self.db.cooldownSize * teamSize
end
if (self.db.buffsCooldownPos == "TOP" or self.db.buffsCooldownPos == "BOTTOM") and self.db.buffsEnabled then
margin = margin + self.db.buffsIconSize
height = height + self.db.buffsIconSize * teamSize
end
if self.db.buffsCooldownPos == "TOP" and self.db.cooldownYPos == "TOP" and self.db.cooldown and self.db.buffsEnabled then
margin = margin + 1
end
if self.db.buffsCooldownPos == "BOTTOM" and self.db.cooldownYPos == "BOTTOM" and self.db.cooldown and self.db.buffsEnabled then
margin = margin + 1
end
-- Classicon
width = width + iconSize
extraBarWidth = extraBarWidth + iconSize
-- Trinket
width = width + iconSize
self.frame:SetScale(self.db.frameScale)
self.frame:SetWidth(width)
self.frame:SetHeight(height)
--self.frame:SetBackdropColor(self.db.frameColor.r, self.db.frameColor.g, self.db.frameColor.b, self.db.frameColor.a)
self.frame:ClearAllPoints()
if (self.db.x == 0 and self.db.y == 0) then
self.frame:SetPoint("CENTER")
else
local scale = self.frame:GetEffectiveScale()
if (self.db.growUp) then
self.frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", self.db.x / scale, self.db.y / scale)
else
self.frame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", self.db.x / scale, self.db.y / scale)
end
end
self.anchor:SetWidth(width)
self.anchor:ClearAllPoints()
if (self.db.growUp) then
self.anchor:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
else
self.anchor:SetPoint("BOTTOMLEFT", self.frame, "TOPLEFT")
end
if (self.db.locked) then
self.anchor:Hide()
self.anchor:Hide()
else
self.anchor:Show()
end
for i = 1, teamSize do
local button = self.buttons["arena" .. i]
button:SetWidth(self.db.barWidth + extraBarWidth)
button:SetHeight(self.db.healthBarHeight)
button.secure:SetWidth(self.db.barWidth + extraBarWidth)
button.secure:SetHeight(self.db.healthBarHeight + extraBarHeight)
button:ClearAllPoints()
button.secure:ClearAllPoints()
if (self.db.growUp) then
if (i == 1) then
button:SetPoint("BOTTOMLEFT", self.frame, "BOTTOMLEFT", self.db.padding + 2, 0)
button.secure:SetPoint("BOTTOMLEFT", self.frame, "BOTTOMLEFT", self.db.padding + 2, 0)
else
button:SetPoint("BOTTOMLEFT", self.buttons["arena" .. (i - 1)], "TOPLEFT", 0, margin + self.db.bottomMargin)
button.secure:SetPoint("BOTTOMLEFT", self.buttons["arena" .. (i - 1)], "TOPLEFT", 0, margin + self.db.bottomMargin)
end
else
if (i == 1) then
button:SetPoint("TOPLEFT", self.frame, "TOPLEFT", self.db.padding + 2, 0)
button.secure:SetPoint("TOPLEFT", self.frame, "TOPLEFT", self.db.padding + 2, 0)
else
button:SetPoint("TOPLEFT", self.buttons["arena" .. (i - 1)], "BOTTOMLEFT", 0, -margin - self.db.bottomMargin)
button.secure:SetPoint("TOPLEFT", self.buttons["arena" .. (i - 1)], "BOTTOMLEFT", 0, -margin - self.db.bottomMargin)
end
end
-- Cooldown frame
if (self.db.cooldown) then
button.spellCooldownFrame:ClearAllPoints()
local verticalMargin = -(Gladdy.db.powerBarHeight)/2
if self.db.cooldownYPos == "TOP" then
if self.db.cooldownXPos == "RIGHT" then
button.spellCooldownFrame:SetPoint("BOTTOMRIGHT", button.healthBar, "TOPRIGHT", Gladdy.db.cooldownXOffset, self.db.highlightBorderSize + Gladdy.db.cooldownYOffset) -- needs to be properly anchored after trinket
else
button.spellCooldownFrame:SetPoint("BOTTOMLEFT", button.healthBar, "TOPLEFT", Gladdy.db.cooldownXOffset, self.db.highlightBorderSize + Gladdy.db.cooldownYOffset)
end
elseif self.db.cooldownYPos == "BOTTOM" then
if self.db.cooldownXPos == "RIGHT" then
button.spellCooldownFrame:SetPoint("TOPRIGHT", button.powerBar, "BOTTOMRIGHT", Gladdy.db.cooldownXOffset, -self.db.highlightBorderSize + Gladdy.db.cooldownYOffset) -- needs to be properly anchored after trinket
else
button.spellCooldownFrame:SetPoint("TOPLEFT", button.powerBar, "BOTTOMLEFT", Gladdy.db.cooldownXOffset, -self.db.highlightBorderSize + Gladdy.db.cooldownYOffset)
end
elseif self.db.cooldownYPos == "LEFT" then
local horizontalMargin = Gladdy.db.highlightBorderSize + Gladdy.db.padding
if (Gladdy.db.trinketPos == "LEFT" and Gladdy.db.trinketEnabled) then
horizontalMargin = horizontalMargin + (Gladdy.db.trinketSize * Gladdy.db.trinketWidthFactor) + Gladdy.db.padding
if (Gladdy.db.classIconPos == "LEFT") then
horizontalMargin = horizontalMargin + (Gladdy.db.classIconSize * Gladdy.db.classIconWidthFactor) + Gladdy.db.padding
end
elseif (Gladdy.db.classIconPos == "LEFT") then
horizontalMargin = horizontalMargin + (Gladdy.db.classIconSize * Gladdy.db.classIconWidthFactor) + Gladdy.db.padding
if (Gladdy.db.trinketPos == "LEFT" and Gladdy.db.trinketEnabled) then
horizontalMargin = horizontalMargin + (Gladdy.db.trinketSize * Gladdy.db.trinketWidthFactor) + Gladdy.db.padding
end
end
if (Gladdy.db.drCooldownPos == "LEFT" and Gladdy.db.drEnabled) then
verticalMargin = verticalMargin + Gladdy.db.drIconSize/2 + Gladdy.db.padding/2
end
if (Gladdy.db.castBarPos == "LEFT") then
verticalMargin = verticalMargin -
((Gladdy.db.castBarHeight < Gladdy.db.castBarIconSize) and Gladdy.db.castBarIconSize
or Gladdy.db.castBarHeight)/2 + Gladdy.db.padding/2
end
if (Gladdy.db.buffsCooldownPos == "LEFT" and Gladdy.db.buffsEnabled) then
verticalMargin = verticalMargin - (Gladdy.db.buffsIconSize/2 + Gladdy.db.padding/2)
end
button.spellCooldownFrame:SetPoint("RIGHT", button.healthBar, "LEFT", -horizontalMargin + Gladdy.db.cooldownXOffset, Gladdy.db.cooldownYOffset + verticalMargin)
elseif self.db.cooldownYPos == "RIGHT" then
verticalMargin = -(Gladdy.db.powerBarHeight)/2
local horizontalMargin = Gladdy.db.highlightBorderSize + Gladdy.db.padding
if (Gladdy.db.trinketPos == "RIGHT" and Gladdy.db.trinketEnabled) then
horizontalMargin = horizontalMargin + (Gladdy.db.trinketSize * Gladdy.db.trinketWidthFactor) + Gladdy.db.padding
if (Gladdy.db.classIconPos == "RIGHT") then
horizontalMargin = horizontalMargin + (Gladdy.db.classIconSize * Gladdy.db.classIconWidthFactor) + Gladdy.db.padding
end
elseif (Gladdy.db.classIconPos == "RIGHT") then
horizontalMargin = horizontalMargin + (Gladdy.db.classIconSize * Gladdy.db.classIconWidthFactor) + Gladdy.db.padding
if (Gladdy.db.trinketPos == "RIGHT" and Gladdy.db.trinketEnabled) then
horizontalMargin = horizontalMargin + (Gladdy.db.trinketSize * Gladdy.db.trinketWidthFactor) + Gladdy.db.padding
end
end
if (Gladdy.db.drCooldownPos == "RIGHT" and Gladdy.db.drEnabled) then
verticalMargin = verticalMargin + Gladdy.db.drIconSize/2 + Gladdy.db.padding/2
end
if (Gladdy.db.castBarPos == "RIGHT") then
verticalMargin = verticalMargin -
((Gladdy.db.castBarHeight < Gladdy.db.castBarIconSize) and Gladdy.db.castBarIconSize
or Gladdy.db.castBarHeight)/2 + Gladdy.db.padding/2
end
if (Gladdy.db.buffsCooldownPos == "RIGHT" and Gladdy.db.buffsEnabled) then
verticalMargin = verticalMargin - (Gladdy.db.buffsIconSize/2 + Gladdy.db.padding/2)
end
button.spellCooldownFrame:SetPoint("LEFT", button.healthBar, "RIGHT", horizontalMargin + Gladdy.db.cooldownXOffset, Gladdy.db.cooldownYOffset + verticalMargin)
end
button.spellCooldownFrame:SetHeight(self.db.cooldownSize)
button.spellCooldownFrame:SetWidth(1)
button.spellCooldownFrame:Show()
-- Update each cooldown icon
local o = 1
for j = 1, 14 do
local icon = button.spellCooldownFrame["icon" .. j]
icon:SetHeight(self.db.cooldownSize)
icon:SetWidth(self.db.cooldownSize * self.db.cooldownWidthFactor)
icon.cooldownFont:SetFont(Gladdy.LSM:Fetch("font", Gladdy.db.cooldownFont), self.db.cooldownSize / 2 * Gladdy.db.cooldownFontScale, "OUTLINE")
icon.cooldownFont:SetTextColor(Gladdy.db.cooldownFontColor.r, Gladdy.db.cooldownFontColor.g, Gladdy.db.cooldownFontColor.b, Gladdy.db.cooldownFontColor.a)
icon:ClearAllPoints()
if (self.db.cooldownXPos == "RIGHT") then
if (j == 1) then
icon:SetPoint("RIGHT", button.spellCooldownFrame, "RIGHT", 0, 0)
elseif (mod(j-1,Gladdy.db.cooldownMaxIconsPerLine) == 0) then
if (self.db.cooldownYPos == "BOTTOM" or self.db.cooldownYPos == "LEFT" or self.db.cooldownYPos == "RIGHT") then
icon:SetPoint("TOP", button.spellCooldownFrame["icon" .. o], "BOTTOM", 0, -Gladdy.db.cooldownIconPadding)
else
icon:SetPoint("BOTTOM", button.spellCooldownFrame["icon" .. o], "TOP", 0, Gladdy.db.cooldownIconPadding)
end
o = o + tonumber(Gladdy.db.cooldownMaxIconsPerLine)
else
icon:SetPoint("RIGHT", button.spellCooldownFrame["icon" .. j - 1], "LEFT", -Gladdy.db.cooldownIconPadding, 0)
end
end
if (self.db.cooldownXPos == "LEFT") then
if (j == 1) then
icon:SetPoint("LEFT", button.spellCooldownFrame, "LEFT", 0, 0)
elseif (mod(j-1,Gladdy.db.cooldownMaxIconsPerLine) == 0) then
if (self.db.cooldownYPos == "BOTTOM" or self.db.cooldownYPos == "LEFT" or self.db.cooldownYPos == "RIGHT") then
icon:SetPoint("TOP", button.spellCooldownFrame["icon" .. o], "BOTTOM", 0, -Gladdy.db.cooldownIconPadding)
else
icon:SetPoint("BOTTOM", button.spellCooldownFrame["icon" .. o], "TOP", 0, Gladdy.db.cooldownIconPadding)
end
o = o + tonumber(Gladdy.db.cooldownMaxIconsPerLine)
else
icon:SetPoint("LEFT", button.spellCooldownFrame["icon" .. j - 1], "RIGHT", Gladdy.db.cooldownIconPadding, 0)
end
end
if (icon.active) then
icon.active = false
icon.cooldown:SetCooldown(GetTime(), 0)
icon.cooldownFont:SetText("")
icon:SetScript("OnUpdate", nil)
end
icon.spellId = nil
icon:SetAlpha(1)
icon.texture:SetTexture("Interface\\Icons\\Spell_Holy_PainSupression")
StyleActionButton(icon)
if (not self.frame.testing) then
icon:Hide()
else
icon:Show()
end
end
button.spellCooldownFrame:Show()
else
button.spellCooldownFrame:Hide()
end
for k, v in self:IterModules() do
self:Call(v, "UpdateFrame", button.unit)
end
Gladdy:UpdateTestCooldowns(i)
end
Gladdy.modules["PlateCastBar"]:UpdateFrame()
end
function Gladdy:HideFrame()
if (self.frame) then
self.frame:Hide()
end
self:UnregisterAllEvents()
self:CancelAllTimers()
self:UnregisterAllComm()
self:RegisterEvent("PLAYER_ENTERING_WORLD")
end
function Gladdy:ToggleFrame(i)
self:Reset()
if (self.frame and self.frame:IsShown() and i == self.curBracket) then
self:HideFrame()
else
self:UnregisterAllEvents()
self.curBracket = i
if (not self.frame) then
self:CreateFrame()
end
self:Test()
self:UpdateFrame()
self.frame:Show()
end
end
function Gladdy:CreateButton(i)
if (not self.frame) then
self:CreateFrame()
end
local button = CreateFrame("Frame", "GladdyButtonFrame" .. i, self.frame)
button:SetAlpha(0)
-- Trinket presser
local trinketButton = CreateFrame("Button", "GladdyTrinketButton" .. i, button, "SecureActionButtonTemplate")
trinketButton:RegisterForClicks("AnyUp")
trinketButton:SetAttribute("*type*", "macro")
--trinketButton:SetAttribute("macrotext1", string.format("/script Gladdy:TrinketUsed(\"%s\")", "arena" .. i))
-- Is there a way to NOT use a global function?
trinketButton:SetAttribute("macrotext1", string.format("/script Trinket:Used(\"%s\")", "arena" .. i))
-- Cooldown frame
local spellCooldownFrame = CreateFrame("Frame", nil, button)
for x = 1, 14 do
local icon = CreateFrame("CheckButton", "GladdyButton" .. i .. "SpellCooldownFrame" .. x, spellCooldownFrame, "ActionButtonTemplate")
icon:EnableMouse(false)
icon.texture = _G[icon:GetName() .. "Icon"]
icon.cooldown = _G[icon:GetName() .. "Cooldown"]
icon.cooldown:SetReverse(false)
icon.cooldown.noCooldownCount = true --Gladdy.db.trinketDisableOmniCC
icon.cooldownFrame = CreateFrame("Frame", nil, icon)
icon.cooldownFrame:ClearAllPoints()
icon.cooldownFrame:SetPoint("TOPLEFT", icon, "TOPLEFT")
icon.cooldownFrame:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT")
icon.border = icon.cooldownFrame:CreateTexture(nil, "OVERLAY")
icon.border:SetTexture("Interface\\AddOns\\Gladdy\\Images\\Border_rounded_blp")
icon.border:SetAllPoints(icon)
icon.cooldownFont = icon.cooldownFrame:CreateFontString(nil, "OVERLAY")
icon:SetFont(Gladdy.LSM:Fetch("font", Gladdy.db.cooldownFont), self.db.cooldownSize / 2 * Gladdy.db.cooldownFontScale, "OUTLINE")
icon.cooldownFont:SetTextColor(Gladdy.db.cooldownFontColor.r, Gladdy.db.cooldownFontColor.g, Gladdy.db.cooldownFontColor.b, Gladdy.db.cooldownFontColor.a)
icon.cooldownFont:SetAllPoints(icon)
spellCooldownFrame["icon" .. x] = icon
end
local secure = CreateFrame("Button", "GladdyButton" .. i, button, "SecureActionButtonTemplate")
secure:RegisterForClicks("AnyUp")
secure:SetAttribute("*type*", "macro")
button.id = i
button.unit = "arena" .. i
button.secure = secure
button.trinketButton = trinketButton
button.spellCooldownFrame = spellCooldownFrame
for k, v in pairs(self.BUTTON_DEFAULTS) do
button[k] = v
end
self.buttons[button.unit] = button
for k, v in self:IterModules() do
self:Call(v, "CreateFrame", button.unit)
end
end