-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathKalecgosFrame.lua
executable file
·273 lines (248 loc) · 6.85 KB
/
KalecgosFrame.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
local Kal = DBM:GetModByName("Kal")
local L = Kal:GetLocalizedStrings()
function Kal:InitializeMenu()
-- self is DBMKalMenu, not Kal
local info1 = UIDropDownMenu_CreateInfo()
info1.text = L.name
info1.notClickable = 1
info1.isTitle = 1
info1.notCheckable = 1
UIDropDownMenu_AddButton(info1, 1)
local info2 = UIDropDownMenu_CreateInfo()
info2.text = L.FrameLock
info2.value = Kal.Options.FrameLocked
info2.func = function() Kal.Options.FrameLocked = not Kal.Options.FrameLocked end
info2.checked = Kal.Options.FrameLocked
info2.keepShownOnClick = 1
UIDropDownMenu_AddButton(info2, 1)
local info3 = UIDropDownMenu_CreateInfo()
info3.text = L.FrameClassColor
info3.value = Kal.Options.FrameClassColor
info3.func = function() Kal.Options.FrameClassColor = not Kal.Options.FrameClassColor Kal:UpdateColors() end
info3.checked = Kal.Options.FrameClassColor
info3.keepShownOnClick = 1
UIDropDownMenu_AddButton(info3, 1)
local info4 = UIDropDownMenu_CreateInfo()
info4.text = L.FrameOrientation
info4.value = Kal.Options.FrameUpwards
info4.func = function() Kal.Options.FrameUpwards = not Kal.Options.FrameUpwards Kal:ChangeFrameOrientation() end
info4.checked = Kal.Options.FrameUpwards
info4.keepShownOnClick = 1
UIDropDownMenu_AddButton(info4, 1)
local info5 = UIDropDownMenu_CreateInfo()
info5.text = L.FrameHide
info5.func = function() _G["DBMKalFrameDrag"]:Hide() end
info5.notCheckable = 1
UIDropDownMenu_AddButton(info5, 1)
local info6 = UIDropDownMenu_CreateInfo()
info6.text = L.FrameClose
info6.func = function() end
info6.notCheckable = 1
UIDropDownMenu_AddButton(info6, 1)
end
local firstEntry = nil
local lastEntry = nil
local frames = {}
local fCounter = 1
local function createBarFrame(name)
local frame
if frames[#frames] then
frame = frames[#frames]
frames[#frames] = nil
frame:Show()
else
frame = CreateFrame("Frame", "DBMKalFrame"..fCounter, _G["DBMKalFrameDrag"], "DBMKalFrameTemplate")
fCounter = fCounter + 1
end
_G[frame:GetName().."BarName"]:SetText(name)
return frame
end
local barMethods = {}
local function createBar(name)
local newEntry = setmetatable({
prev = lastEntry,
next = nil,
data = {
frame = createBarFrame(name),
name = name,
timer = 60
}
},
{
__index = barMethods
})
if lastEntry then
lastEntry.next = newEntry
end
lastEntry = newEntry
firstEntry = firstEntry or newEntry
newEntry.data.frame.entry = newEntry
newEntry:Update(0)
return newEntry
end
function barMethods:Update(elapsed)
local bar = _G[self.data.frame:GetName().."Bar"]
local cooldown = _G[self.data.frame:GetName().."BarCooldown"]
local spark = _G[self.data.frame:GetName().."BarSpark"]
self.data.timer = self.data.timer - elapsed
if self.data.timer <= 0 then
Kal:RemoveEntry(self.data.name)
else
cooldown:SetText(math.floor(self.data.timer))
bar:SetValue(self.data.timer)
spark:ClearAllPoints()
spark:SetPoint("CENTER", bar, "LEFT", ((bar:GetValue() / 60) * bar:GetWidth()), 0)
spark:Show()
end
end
function barMethods:GetNext()
return self.next
end
function barMethods:GetPrev()
return self.prev
end
function barMethods:SetPosition()
self.data.frame:ClearAllPoints()
if self == firstEntry then
if Kal.Options.FrameUpwards then
self.data.frame:SetPoint("BOTTOM", _G["DBMKalFrameDrag"], "TOP", 0, -10)
else
self.data.frame:SetPoint("TOP", _G["DBMKalFrameDrag"], "BOTTOM", 0, 0)
end
else
if Kal.Options.FrameUpwards then
self.data.frame:SetPoint("BOTTOM", self:GetPrev().data.frame, "TOP", 0, -3)
else
self.data.frame:SetPoint("TOP", self:GetPrev().data.frame, "BOTTOM", 0, 3)
end
end
end
function barMethods:GetFrame()
return self.data.frame
end
function barMethods:GetBar()
return _G[self.data.frame:GetName().."Bar"]
end
function barMethods:GetSpark()
return _G[self.data.frame:GetName().."BarSpark"]
end
function Kal:CreateFrame()
_G["DBMKalFrameDragTitle"]:SetText(L.FrameTitle)
if firstEntry then
local entry = firstEntry
while entry do
table.insert(frames, entry.data.frame)
entry.data.frame:Hide()
entry.data = nil
entry = entry:GetNext()
end
firstEntry = nil
lastEntry = nil
end
_G["DBMKalFrameDrag"]:Show()
_G["DBMKalFrameDrag"]:SetPoint(self.Options.PermanentFramePoint or "CENTER", nil, self.Options.PermanentFramePoint or "CENTER", self.Options.PermanentFrameX or 150, self.Options.PermanentFrameY or -50)
end
function Kal:SaveFramePosition()
local point, _, _, x, y = _G["DBMKalFrameDrag"]:GetPoint()
self.Options.PermanentFramePoint = point
self.Options.PermanentFrameX = x
self.Options.PermanentFrameY = y
end
function Kal:DestroyFrame()
_G["DBMKalFrameDrag"]:Hide()
end
function Kal:ChangeFrameOrientation()
if firstEntry then
local entry = firstEntry
while entry do
entry:SetPosition()
entry = entry:GetNext()
end
end
end
function Kal:UpdateColors()
if firstEntry then
local entry = firstEntry
while entry do
if self.Options.FrameClassColor then
local _, _, name = entry.data.name:find("(.+) %(%d%)")
local class
for uId in DBM:GetGroupMembers() do
local name2 = UnitName(uId)
local _, fileName = UnitClass(uId)
if name2 == name then
class = fileName
break
end
end
local r, g, b = 1, 0.7, 0
if self.Options.FrameClassColor then
if RAID_CLASS_COLORS[class or ""] then
r = RAID_CLASS_COLORS[class].r
g = RAID_CLASS_COLORS[class].g
b = RAID_CLASS_COLORS[class].b
end
end
entry:GetBar():SetStatusBarColor(r, g, b)
entry:GetSpark():SetVertexColor(r, g, b)
else
entry:GetBar():SetStatusBarColor(1, 0.7, 0)
entry:GetSpark():SetVertexColor(1, 0.7, 0)
end
entry = entry:GetNext()
end
end
end
function Kal:AddEntry(name, class)
local entry = createBar(name)
local r, g, b = 1, 0.7, 0
if self.Options.FrameClassColor then
if RAID_CLASS_COLORS[class or ""] then
r = RAID_CLASS_COLORS[class].r
g = RAID_CLASS_COLORS[class].g
b = RAID_CLASS_COLORS[class].b
end
end
entry:GetBar():SetStatusBarColor(r, g, b)
entry:GetSpark():SetVertexColor(r, g, b)
entry:SetPosition()
end
function Kal:RemoveEntry(name)
if firstEntry then
local entry = firstEntry
while entry do
if entry.data.name == name then
table.insert(frames, entry.data.frame)
entry.data.frame:Hide()
entry.data = nil
if entry == firstEntry then
local nextEntry = entry:GetNext()
if nextEntry then
nextEntry.prev = nil
firstEntry = nextEntry
else
firstEntry = nil
lastEntry = nil
end
elseif entry == lastEntry then
local prevEntry = entry:GetPrev()
if prevEntry then
prevEntry.next = nil
lastEntry = prevEntry
else
firstEntry = nil
lastEntry = nil
end
else
entry:GetPrev().next = entry:GetNext()
entry:GetNext().prev = entry:GetPrev()
end
if entry:GetNext() then
entry:GetNext():SetPosition()
end
break
end
entry = entry:GetNext()
end
end
end