forked from miraage/gladdy
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFrame.lua
355 lines (305 loc) · 11.7 KB
/
Frame.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
355
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:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16})
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"]
normalTex:SetHeight(button:GetHeight())
normalTex:SetWidth(button:GetWidth())
normalTex:SetPoint("CENTER")
button:SetNormalTexture("Interface\\AddOns\\Gladdy\\Images\\Gloss")
icon:SetTexCoord(.1, .9, .1, .9)
icon:SetPoint("TOPLEFT", button, "TOPLEFT", 2, -2)
icon:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -2, 2)
normalTex:SetVertexColor(1, 1, 1, 1)
end
function Gladdy:UpdateFrame()
local teamSize = self.curBracket or 5
local iconSize = self.db.healthBarHeight
local margin = self.db.bottomMargin
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
-- Castbar
margin = margin + self.db.castBarHeight
height = height + self.db.castBarHeight * teamSize
extraBarHeight = extraBarHeight + self.db.castBarHeight
-- 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, self.db.padding + extraBarHeight)
button.secure:SetPoint("BOTTOMLEFT", self.frame, "BOTTOMLEFT", self.db.padding + 2, self.db.padding)
else
button:SetPoint("BOTTOMLEFT", self.buttons["arena" .. (i - 1)], "TOPLEFT", 0, margin)
button.secure:SetPoint("BOTTOMLEFT", self.buttons["arena" .. (i - 1)], "TOPLEFT", 0, margin - extraBarHeight)
end
else
if (i == 1) then
button:SetPoint("TOPLEFT", self.frame, "TOPLEFT", self.db.padding + 2, -self.db.padding)
button.secure:SetPoint("TOPLEFT", self.frame, "TOPLEFT", self.db.padding + 2, -self.db.padding)
else
button:SetPoint("TOPLEFT", self.buttons["arena" .. (i - 1)], "BOTTOMLEFT", 0, -margin)
button.secure:SetPoint("TOPLEFT", self.buttons["arena" .. (i - 1)], "BOTTOMLEFT", 0, -margin)
end
end
-- Cooldown frame
if (self.db.cooldown) then
button.spellCooldownFrame:ClearAllPoints()
if self.db.cooldownPos == "RIGHT" then
button.spellCooldownFrame:SetPoint("TOPLEFT", button,"TOPRIGHT", iconSize+5, 1) -- needs to be properly anchored after trinket
else
button.spellCooldownFrame:SetPoint("TOPRIGHT",button,"TOPLEFT",-5,-1)
end
--button.spellCooldownFrame:SetHeight(self.db.healthBarHeight+extraBarHeight)
button.spellCooldownFrame:SetHeight(self.db.cooldownSize*4)
--button.spellCooldownFrame:SetWidth(self.db.healthBarHeight+extraBarHeight)
button.spellCooldownFrame:SetWidth(self.db.cooldownSize*4)
button.spellCooldownFrame:Show()
-- Update each cooldown icon
for i=1,14 do
local icon = button.spellCooldownFrame["icon"..i]
icon:SetHeight(button.spellCooldownFrame:GetHeight()/2)
icon:SetWidth(button.spellCooldownFrame:GetWidth()/2)
icon:ClearAllPoints()
if(self.db.cooldownPos == "RIGHT") then
if(i==1) then
icon:SetPoint("TOPLEFT",button.spellCooldownFrame)
elseif(i==2) then
icon:SetPoint("TOP",button.spellCooldownFrame["icon"..i-1],"BOTTOM",0,-1)
elseif(i>=3) then
icon:SetPoint("LEFT",button.spellCooldownFrame["icon"..i-2],"RIGHT",1,0)
end
else
if(i==1) then
icon:SetPoint("TOPRIGHT",button.spellCooldownFrame)
elseif(i==2) then
icon:SetPoint("TOP",button.spellCooldownFrame["icon"..i-1],"BOTTOM",0,-1)
elseif(i>=3) then
icon:SetPoint("RIGHT",button.spellCooldownFrame["icon"..i-2],"LEFT",-1,0)
end
end
if (icon.active) then
icon.active = false
icon.cooldown:SetCooldown(GetTime(), 0)
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
end
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)
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