-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcolors.lua
More file actions
441 lines (369 loc) · 10.8 KB
/
colors.lua
File metadata and controls
441 lines (369 loc) · 10.8 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
local Recount = _G.Recount
local revision = tonumber(string.sub("$Revision: 1441 $", 12, -3))
if Recount.Version < revision then
Recount.Version = revision
end
local pairs = pairs
local string = string
local table = table
local type = type
local GetScreenWidth = GetScreenWidth
local PlaySound = PlaySound
local ColorPickerFrame = ColorPickerFrame
local OpacitySliderFrame = OpacitySliderFrame
local RAID_CLASS_COLORS = RAID_CLASS_COLORS
local WOW_RETAIL = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
local WOW_PANDA_CLASSIC = WOW_PROJECT_ID == WOW_PROJECT_MISTS_CLASSIC
local WOW_VANILLA_CLASSIC = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
local Colors = {}
Recount.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 PreviousColor = {}
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 = WOW_RETAIL and ColorPickerFrame.Content.ColorPicker:GetColorAlpha() or 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 = WOW_RETAIL and ColorPickerFrame.Content.ColorPicker:GetColorAlpha() or 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()
if WOW_RETAIL then
ColorPickerFrame.opacity = PreviousColor.a
ColorPickerFrame.Content.ColorPicker:SetColorAlpha(ColorPickerFrame.opacity)
end
Colors:SetColor(Cur_Branch, Cur_Name, PreviousColor)
end
function Colors:GetColor(Branch, Name)
if Branch == "Class" then
if not Recount.db.profile.Colors[Branch][Name] then
local classcol
if CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[Name] then
classcol = CUSTOM_CLASS_COLORS[Name]
else
classcol = RAID_CLASS_COLORS[Name]
end
classcol.a = 1
return classcol
end
elseif Branch == "Realtime" then
if not Recount.db.profile.Colors[Branch][Name] then
if string.find(Name,"Top$") then
return {r = 1.0, g = 0.0, b = 0.0, a = 1.0}
else
return {r = 0.2, g = 0.0, b = 0.0, a = 0.4}
end
end
end
if Recount.db.profile.Colors[Branch][Name] and not Recount.db.profile.Colors[Branch][Name].a then
Recount.db.profile.Colors[Branch][Name].a = 1
end
return Recount.db.profile.Colors[Branch][Name]
end
local LastSet
function Colors:SetColor(Branch, Name, c)
if type(Recount.db.profile.Colors[Branch][Name]) ~= "table" then
Recount.db.profile.Colors[Branch][Name] = {}
end
Recount.db.profile.Colors[Branch][Name].r = c.r
Recount.db.profile.Colors[Branch][Name].g = c.g
Recount.db.profile.Colors[Branch][Name].b = c.b
--[[if c.a and Branch ~= "Class" then
Recount.db.profile.Colors[Branch][Name].a = c.a
elseif c.a and Branch == "Class" then
Recount.db.profile.Colors[Branch][Name].a = nil
end]]
Recount.db.profile.Colors[Branch][Name].a = c.a
Colors:UpdateColor(Branch, Name)
end
function Colors:UpdateAllColors()
local c
for k1, Branch in pairs(ItemsToUpdate) do
for k2, Name in pairs(Branch) do
c = Recount.db.profile.Colors[k1][k2]
if c then
Colors:SetColor(k1, k2, c)
end
end
end
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.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
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(856)
local c = Colors:GetColor(Branch, Name)
PreviousColor.r, PreviousColor.g, PreviousColor.b, PreviousColor.a = c.r, c.g, c.b, c.a
if WOW_RETAIL then
ColorPickerFrame.Content.ColorSwatchOriginal:SetColorTexture(c.r, c.g, c.b)
ColorPickerFrame.Content.ColorPicker:SetColorRGB(c.r, c.g, c.b)
else
ColorPickerFrame:SetColorRGB(c.r, c.g, c.b)
end
if c.a then
ColorPickerFrame.hasOpacity = true
if WOW_RETAIL then
ColorPickerFrame.opacity = c.a
ColorPickerFrame.Content.ColorPicker:SetColorAlpha(c.a)
else
ColorPickerFrame.opacity = 1.0 - c.a
end
ColorPickerFrame.opacityFunc = Opacity_Change -- Elsia: Was Color_Change
else
ColorPickerFrame.hasOpacity = false
ColorPickerFrame.opacityFunc = nil
end
if WOW_RETAIL or WOW_VANILLA_CLASSIC then
ColorPickerFrame.swatchFunc = Color_Change
else
ColorPickerFrame.func = Color_Change
end
--ColorPickerFrame.previousValues = c
ColorPickerFrame.cancelFunc = Color_Cancel
ColorPickerFrame:ClearAllPoints()
if Attach then
local leftPos = Attach:GetLeft() -- Elsia: Side code adapted from Mirror
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()
if WOW_PANDA_CLASSIC then
ColorPickerFrame.swatchFunc = ColorPickerFrame.func
end
end
--[[function Colors:Debug()
for k1, Branch in pairs(ItemsToUpdate) do
for k2, Name in pairs(Branch) do
Recount:Print(getn(Name).." "..k1.." "..k2)
local Items = ItemsToUpdate[k1][k2]
for k, v in pairs(TypeToUpdate[k1][k2]) do
if v == TYPE_TEXTURE then
Recount:Print("Texture:" .. getn(Items[k]))
elseif v == TYPE_BORDER then
Recount:Print("Border:" .. getn(Items[k]))
elseif v == TYPE_BACKGROUND then
Recount:Print("Background:" .. getn(Items[k]))
elseif v == TYPE_FUNC then
Recount:Print("Func:" .. getn(Items[k]))
elseif v == TYPE_FONT then
Recount:Print("Font:" .. getn(Items[k]))
end
end
end
end
end]]