forked from ZMOT7S/Spy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColors.lua
More file actions
364 lines (305 loc) · 8.45 KB
/
Colors.lua
File metadata and controls
364 lines (305 loc) · 8.45 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
local Colors = {}
Spy.Colors = Colors
local ItemsToUpdate = {}
local TypeToUpdate = {}
local ColorMultiplier = {}
local TextureBackgroundsToUpdate = {}
local TYPE_TEXTURE = 1
local TYPE_BORDER = 2
local TYPE_BACKGROUND = 3
local TYPE_FUNC = 4
local TYPE_FONT = 5
local Cur_Branch
local Cur_Name
local TempColor = {}
local function Color_Change()
local r, g, b = ColorPickerFrame:GetColorRGB()
TempColor.r = r
TempColor.g = g
TempColor.b = b
if not ColorPickerFrame.hasOpacity then
TempColor.a = nil
else
TempColor.a = 1.0-OpacitySliderFrame:GetValue()
end
Colors:SetColor(Cur_Branch,Cur_Name, TempColor)
end
local function Opacity_Change()
local r, g, b = ColorPickerFrame:GetColorRGB()
local a = 1.0 - OpacitySliderFrame:GetValue()
TempColor.r = r
TempColor.g = g
TempColor.b = b
TempColor.a = a
Colors:SetColor(Cur_Branch,Cur_Name, TempColor)
end
local function Fake_Change()
end
local function Color_Cancel()
Colors:SetColor(Cur_Branch, Cur_Name, ColorPickerFrame.previousValues)
end
function Colors:GetColor(Branch, Name)
if Branch == "Class" then
if not Spy.db.profile.Colors[Branch][Name] then
local classcol = RAID_CLASS_COLORS[Name]
if classcol ~= nil then
classcol.a = 1
end
return classcol
end
end
if not Spy.db.profile.Colors[Branch][Name].a then
Spy.db.profile.Colors[Branch][Name].a = 1
end
return Spy.db.profile.Colors[Branch][Name]
end
local LastSet
function Colors:SetColor(Branch, Name, c)
if type(Spy.db.profile.Colors[Branch][Name]) ~= "table" then
Spy.db.profile.Colors[Branch][Name] = {}
end
Spy.db.profile.Colors[Branch][Name].r = c.r
Spy.db.profile.Colors[Branch][Name].g = c.g
Spy.db.profile.Colors[Branch][Name].b = c.b
Spy.db.profile.Colors[Branch][Name].a = c.a
Colors:UpdateColor(Branch, Name)
end
function Colors:UpdateColor(Branch, Name)
local c = Colors:GetColor(Branch, Name)
local Items = ItemsToUpdate[Branch][Name]
if LastSet ~= Name then
LastSet = Name
end
for k, v in pairs(TypeToUpdate[Branch][Name]) do
if v == TYPE_TEXTURE then
local Multi = ColorMultiplier[Branch][Name][k]
if c.a then
if Multi then
Items[k]:SetVertexColor(c.r*Multi.r, c.g*Multi.g, c.b*Multi.b, c.a*Multi.a)
else
Items[k]:SetVertexColor(c.r, c.g, c.b, c.a)
end
else
if Multi then
Items[k]:SetVertexColor(c.r*Multi.r, c.g*Multi.g, c.b*Multi.b)
else
Items[k]:SetVertexColor(c.r, c.g, c.b)
end
end
elseif v == TYPE_BORDER then
if c.a then
Items[k]:SetBackdropBorderColor(c.r, c.g, c.b, c.a)
else
Items[k]:SetBackdropBorderColor(c.r, c.g, c.b)
end
elseif v == TYPE_BACKGROUND then
if c.a then
Items[k]:SetBackdropColor(c.r, c.g, c.b, c.a)
else
Items[k]:SetBackdropColor(c.r, c.g, c.b)
end
elseif v == TYPE_FUNC then
Items[k][1](Items[k][2], {c.r, c.g, c.b, c.a})
elseif v == TYPE_FONT then
if c.a then
Items[k]:SetTextColor(c.r, c.g, c.b, c.a)
else
Items[k]:SetTextColor(c.r, c.g, c.b)
end
end
end
end
function Colors:UnregisterItem(Item)
for k1, Branch in pairs(ItemsToUpdate) do
for k2, Name in pairs(Branch) do
for k, v in pairs(Name) do
if v == Item then
Name[k] = nil
TypeToUpdate[k1][k2][k] = nil
ColorMultiplier[k1][k2][k] = nil
end
end
end
end
end
function Colors:RegisterFunction(Branch, Name, Func, Pass)
local c = Colors:GetColor(Branch, Name)
if c.a then
Func(Pass, {c.r, c.g, c.b, c.a})
else
Func(Pass, {c.r, c.g, c.b})
end
if type(ItemsToUpdate[Branch]) ~= "table" then
ItemsToUpdate[Branch] = {}
TypeToUpdate[Branch] = {}
ColorMultiplier[Branch] = {}
end
if type(ItemsToUpdate[Branch][Name]) ~= "table" then
ItemsToUpdate[Branch][Name] = {}
TypeToUpdate[Branch][Name] = {}
ColorMultiplier[Branch][Name] = {}
end
table.insert(ItemsToUpdate[Branch][Name], {Func, Pass})
table.insert(TypeToUpdate[Branch][Name], TYPE_FUNC)
end
function Colors:RegisterTexture(Branch, Name, Texture, Multi)
local c = Colors:GetColor(Branch, Name)
if not Texture.SetVertexColor then
Texture.SetVertexColor = Texture.SetStatusBarColor
end
if c then
if c.a then
if Multi then
Texture:SetVertexColor(c.r*Multi.r, c.g*Multi.g, c.b*Multi.b, c.a*Multi.a)
else
Texture:SetVertexColor(c.r, c.g, c.b, c.a)
end
else
if Multi then
Texture:SetVertexColor(c.r*Multi.r, c.g*Multi.g, c.b*Multi.b)
else
Texture:SetVertexColor(c.r, c.g, c.b)
end
end
end
if type(ItemsToUpdate[Branch]) ~= "table" then
ItemsToUpdate[Branch] = {}
TypeToUpdate[Branch] = {}
ColorMultiplier[Branch] = {}
end
if type(ItemsToUpdate[Branch][Name]) ~= "table" then
ItemsToUpdate[Branch][Name] = {}
TypeToUpdate[Branch][Name] = {}
ColorMultiplier[Branch][Name] = {}
end
local entry = #ItemsToUpdate[Branch][Name]+1
table.insert(ItemsToUpdate[Branch][Name], Texture)
table.insert(TypeToUpdate[Branch][Name], TYPE_TEXTURE)
if Multi then
ColorMultiplier[Branch][Name][entry] = Multi
end
end
function Colors:RegisterBorder(Branch, Name, frame)
local c = Colors:GetColor(Branch, Name)
if c.a then
frame:SetBackdropBorderColor(c.r, c.g, c.b, c.a)
else
frame:SetBackdropBorderColor(c.r, c.g, c.b)
end
if type(ItemsToUpdate[Branch]) ~= "table" then
ItemsToUpdate[Branch] = {}
TypeToUpdate[Branch] = {}
ColorMultiplier[Branch] = {}
end
if type(ItemsToUpdate[Branch][Name]) ~= "table" then
ItemsToUpdate[Branch][Name] = {}
TypeToUpdate[Branch][Name] = {}
ColorMultiplier[Branch][Name] = {}
end
table.insert(ItemsToUpdate[Branch][Name], frame)
table.insert(TypeToUpdate[Branch][Name], TYPE_BORDER)
end
function Colors:RegisterBackground(Branch, Name, frame)
local c = Colors:GetColor(Branch, Name)
if c.a then
frame:SetBackdropColor(c.r, c.g, c.b, c.a)
else
frame:SetBackdropColor(c.r, c.g, c.b)
end
if type(ItemsToUpdate[Branch]) ~= "table" then
ItemsToUpdate[Branch] = {}
TypeToUpdate[Branch] = {}
ColorMultiplier[Branch] = {}
end
if type(ItemsToUpdate[Branch][Name]) ~= "table" then
ItemsToUpdate[Branch][Name] = {}
TypeToUpdate[Branch][Name] = {}
ColorMultiplier[Branch][Name] = {}
end
table.insert(ItemsToUpdate[Branch][Name], frame)
table.insert(TypeToUpdate[Branch][Name], TYPE_BACKGROUND)
end
function Colors:RegisterFont(Branch, Name, frame)
local c = Colors:GetColor(Branch, Name)
if c.a then
frame:SetTextColor(c.r, c.g, c.b, c.a)
else
frame:SetTextColor(c.r, c.g, c.b)
end
if type(ItemsToUpdate[Branch]) ~= "table" then
ItemsToUpdate[Branch] = {}
TypeToUpdate[Branch] = {}
ColorMultiplier[Branch] = {}
end
if type(ItemsToUpdate[Branch][Name]) ~= "table" then
ItemsToUpdate[Branch][Name] = {}
TypeToUpdate[Branch][Name] = {}
ColorMultiplier[Branch][Name] = {}
end
table.insert(ItemsToUpdate[Branch][Name], frame)
table.insert(TypeToUpdate[Branch][Name], TYPE_FONT)
end
function Colors:EditColor(Branch, Name, Attach)
Cur_Branch = Branch
Cur_Name = Name
ColorPickerFrame:Hide()
PlaySound("igMainMenuOptionCheckBoxOn")
local r, g, b = ColorPickerFrame:GetColorRGB()
local c = Colors:GetColor(Branch, Name)
if c.a then
ColorPickerFrame.hasOpacity = true
ColorPickerFrame.opacity = 1.0 - c.a
ColorPickerFrame.opacityFunc = Opacity_Change
else
ColorPickerFrame.hasOpacity = false
ColorPickerFrame.opacityFunc = nil
end
ColorPickerFrame.func = Color_Change
ColorPickerFrame:SetColorRGB(c.r, c.g, c.b)
ColorPickerFrame.previousValues = c
ColorPickerFrame.cancelFunc = Color_Cancel
ColorPickerFrame:ClearAllPoints()
if Attach then
local leftPos = Attach:GetLeft()
local rightPos = Attach:GetRight()
local side
local oside
if not rightPos then
rightPos = 0
end
if not leftPos then
leftPos = 0
end
local rightDist = GetScreenWidth() - rightPos
if leftPos and rightDist < leftPos then
side = "LEFT"
oside = "RIGHT"
else
side = "RIGHT"
oside = "LEFT"
end
ColorPickerFrame:SetPoint(oside, Attach, side, 0, 0)
end
ColorPickerFrame:Show()
end
function Colors:Debug()
for k1, Branch in pairs(ItemsToUpdate) do
for k2, Name in pairs(Branch) do
Spy:Print(getn(Name).." "..k1.." "..k2)
local Items = ItemsToUpdate[k1][k2]
for k, v in pairs(TypeToUpdate[k1][k2]) do
if v == TYPE_TEXTURE then
Spy:Print("Texture:" .. getn(Items[k]))
elseif v == TYPE_BORDER then
Spy:Print("Border:" .. getn(Items[k]))
elseif v == TYPE_BACKGROUND then
Spy:Print("Background:" .. getn(Items[k]))
elseif v == TYPE_FUNC then
Spy:Print("Func:" .. getn(Items[k]))
elseif v == TYPE_FONT then
Spy:Print("Font:" .. getn(Items[k]))
end
end
end
end
end