-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathPlater_Util.lua
139 lines (118 loc) · 4.71 KB
/
Plater_Util.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
local _
local addonName, platerInternal = ...
local detailsFramework = _G.DetailsFramework
function platerInternal.NumberToHex(number)
local hex = string.format("%x", number)
if (#hex == 1) then
hex = "0" .. hex
end
return hex
end
local colorHueCache = {}
for colorName, colorTable in pairs(detailsFramework:GetDefaultColorList()) do
colorHueCache[colorName] = detailsFramework:GetColorHue(unpack(colorTable))
end
local function sortColors(t1, t2)
return colorHueCache[t1[2]] > colorHueCache[t2[2]]
end
local ignoredColors = {
["transparent"] = true,
["black"] = true,
["none"] = true,
}
local colorNoValue = {1, 1, 1, 0.5}
local dropdownStatusBarTexture = platerInternal.Defaults.dropdownStatusBarTexture
local dropdownStatusBarColor = platerInternal.Defaults.dropdownStatusBarColor
function platerInternal.RefreshColorDropdown(frame, dropdown, dbColors, onSelectColorCallback, keyWithValue, enabledIndex, colorIndex)
local currentValue = dropdown[keyWithValue]
if (not currentValue) then
return {}
end
local optionsTableToReturn
if (not frame.cachedColorTable) then
local colorList = {}
local colorsAlreadyAdded = {}
local dropdownOptions = {}
--add, in the top of the list, colors that are already in use
for _, colorTable in pairs(dbColors) do
local bInEnabled
if (enabledIndex) then
bInEnabled = colorTable[enabledIndex]
else
bInEnabled = true
end
local color = colorTable[colorIndex]
if (bInEnabled and not colorsAlreadyAdded[color]) then
colorsAlreadyAdded[color] = true
local r, g, b = detailsFramework:ParseColors(color)
table.insert(colorList, {{r, g, b}, color})
end
end
for index, colorTable in ipairs(colorList) do
local colortable = colorTable[1]
local colorname = colorTable[2]
table.insert(dropdownOptions, {
label = " " .. colorname,
value = colorname,
color = colortable,
onclick = onSelectColorCallback,
statusbar = dropdownStatusBarTexture,
statusbarcolor = dropdownStatusBarColor,
icon = [[Interface\AddOns\Plater\media\star_empty_64]],
iconcolor = {1, 1, 1, .6},
favorite = true,
})
end
--all colors
local allColors = {}
for colorName, colorTable in pairs(detailsFramework:GetDefaultColorList()) do
if (not colorsAlreadyAdded[colorName] and not ignoredColors[colorName]) then
table.insert(allColors, {colorTable, colorName})
end
end
table.sort(allColors, sortColors)
for index, colorTable in ipairs(allColors) do
local colortable = colorTable[1]
local colorname = colorTable[2]
table.insert(dropdownOptions, {
label = colorname,
value = colorname,
color = colortable,
onclick = onSelectColorCallback,
statusbar = dropdownStatusBarTexture,
statusbarcolor = dropdownStatusBarColor,
})
end
table.insert(dropdownOptions, 1, {
label = "no color",
value = platerInternal.RemoveColor,
color = colorNoValue,
statusbar = dropdownStatusBarTexture,
statusbarcolor = dropdownStatusBarColor,
onclick = onSelectColorCallback
})
frame.cachedColorTable = dropdownOptions
optionsTableToReturn = dropdownOptions
else
optionsTableToReturn = frame.cachedColorTable
end
local dropdownColorTableCurrentSelected = dbColors[currentValue]
if (dropdownColorTableCurrentSelected) then
local bColorIsEnabled = dropdownColorTableCurrentSelected[enabledIndex]
local colorNameInUse = dropdownColorTableCurrentSelected[colorIndex]
if (bColorIsEnabled) then
for i = 1, #optionsTableToReturn do
local option = optionsTableToReturn[i]
if (option.value ~= platerInternal.NoColor) then
option.desc = "Hold Shift to change the color of all npcs with the color " .. detailsFramework:AddColorToText(colorNameInUse, colorNameInUse) .. " to " .. detailsFramework:AddColorToText(option.value, option.value) .. "."
end
end
else
for i = 1, #optionsTableToReturn do
local option = optionsTableToReturn[i]
option.desc = nil
end
end
end
return optionsTableToReturn
end