-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClick-To-Cast-Tooltip-Settings.lua
275 lines (231 loc) · 10.3 KB
/
Click-To-Cast-Tooltip-Settings.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
local addonName, addonTable = ...
-- These are the default settings for new installs of the addon.
local defaults = {
buttonColor = "ffff0000",
actionColor = "ff00ff00",
dividerColor = "ffffffff",
showHeader = false,
showFooter = false,
showTooltip = true,
showNewLineTop = false,
showNewLineBottom = false
}
function setDefaultSettings(tbl, defaults, force)
if (force) then
for key, value in next, defaults do
if (type(tbl[key]) == "table") then
setDefaultSettings(tbl[key], defaults[key], force)
else
print("Setting default value for key: " .. key)
ClickToCastTooltipDB[key] = value
end
end
else
for key, value in next, defaults do
if (type(tbl[key]) == "table") then
setDefaultSettings(tbl[key], defaults[key])
elseif tbl[key] == nil then
-- print("Setting default value for key: " .. key)
DEFAULT_CHAT_FRAME:AddMessage("Setting default value for key: " .. key)
ClickToCastTooltipDB[key] = value
end
end
end
end
ClickToCastTooltipDB = ClickToCastTooltipDB or CopyTable(defaults)
do
-- Set any values to default if they're currently blank.
setDefaultSettings(ClickToCastTooltipDB, defaults)
if (type(ClickToCastTooltipDB.buttonColor) == "table") then
ClickToCastTooltipDB.buttonColor = defaults.buttonColor
end
if (type(ClickToCastTooltipDB.actionColor) == "table") then
ClickToCastTooltipDB.actionColor = defaults.actionColor
end
if (type(ClickToCastTooltipDB.dividerColor) == "table") then
ClickToCastTooltipDB.dividerColor = defaults.dividerColor
end
end
local function OnSettingsChanged(_, setting, value)
local variable = setting:GetVariable()
ClickToCastTooltipDB[variable] = value
print("Setting changed: " .. setting:GetVariable(), value)
end
local category, layout = Settings.RegisterVerticalLayoutCategory(addonName)
-- Create checkbox which will allow the user to toggle the tooltip on and off.
do
local variable = "showTooltip"
local variableTbl = ClickToCastTooltipDB
local variableKey = "toggle"
local name = "Show tooltip"
local tooltip = "Show the click to cast binding when hovering over a unit frame."
local defaultValue = true
local setting = Settings.RegisterAddOnSetting(category, variable, variableKey, variableTbl, type(defaultValue),
name, defaultValue)
Settings.CreateCheckbox(category, setting, tooltip)
Settings.SetOnValueChangedCallback(variable, OnSettingsChanged)
end
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Dashed Header/Footer"))
-- Create checkbox which will allow the user to toggle the header on the tooltip.
do
local variable = "showHeader"
local variableTbl = ClickToCastTooltipDB
local variableKey = "toggle"
local name = "Show dashed header above the tooltip."
local tooltip = "Show the dashed line header on the tooltip."
local defaultValue = true
local setting = Settings.RegisterAddOnSetting(category, variable, variableKey, variableTbl, type(defaultValue),
name, defaultValue)
Settings.CreateCheckbox(category, setting, tooltip)
Settings.SetOnValueChangedCallback(variable, OnSettingsChanged)
end
-- Create checkbox which will allow the user to toggle the footer on the tooltip.
do
local variable = "showFooter"
local variableTbl = ClickToCastTooltipDB
local variableKey = "toggle"
local name = "Show dashed footer below the tooltip."
local tooltip = "Show the dashed line footer on the tooltip."
local defaultValue = true
local setting = Settings.RegisterAddOnSetting(category, variable, variableKey, variableTbl, type(defaultValue),
name, defaultValue)
Settings.CreateCheckbox(category, setting, tooltip)
Settings.SetOnValueChangedCallback(variable, OnSettingsChanged)
end
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Empty Line Header/Footer"))
-- Create checkbox which will allow the user to toggle the new line at the top of the tooltip.
do
local variable = "showNewLineTop"
local variableTbl = ClickToCastTooltipDB
local variableKey = "toggle"
local name = "Show new line above the tooltip."
local tooltip = "Show a new line at the top of the tooltip."
local defaultValue = false
local setting = Settings.RegisterAddOnSetting(category, variable, variableKey, variableTbl, type(defaultValue),
name, defaultValue)
Settings.CreateCheckbox(category, setting, tooltip)
Settings.SetOnValueChangedCallback(variable, OnSettingsChanged)
end
-- Create checkbox which will allow the user to toggle the new line at the bottom of the tooltip.
do
local variable = "showNewLineBottom"
local variableTbl = ClickToCastTooltipDB
local variableKey = "toggle"
local name = "Show new line below the tooltip."
local tooltip = "Show a new line at the bottom of the tooltip."
local defaultValue = false
local setting = Settings.RegisterAddOnSetting(category, variable, variableKey, variableTbl, type(defaultValue),
name, defaultValue)
Settings.CreateCheckbox(category, setting, tooltip)
Settings.SetOnValueChangedCallback(variable, OnSettingsChanged)
end
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Tooltip Colors"))
-- Create a button which will allow the user to change the color of the click to cast button text.
do
local button = CreateSettingsButtonInitializer("Button Text Color", "Button Text Color", function()
ShowColorPicker("buttonColor", ButtonColorCallback)
end, "Change the color of the button text on the tooltip.", true)
layout:AddInitializer(button)
end
do
local button = CreateSettingsButtonInitializer("Action Text Color", "Action Text Color", function()
ShowColorPicker("actionColor", ActionColorCallback)
end, "Change the color of the action text on the tooltip.", true)
layout:AddInitializer(button)
end
do
local button = CreateSettingsButtonInitializer("Divider Color", "Divider Color", function()
ShowColorPicker("dividerColor", DividerColorCallback)
end, "Change the color of the divider on the tooltip.", true)
layout:AddInitializer(button)
end
do
local button = CreateSettingsButtonInitializer("Reset Colors", "Reset Colors", function()
ClickToCastTooltipDB.buttonColor = defaults.buttonColor
ClickToCastTooltipDB.actionColor = defaults.actionColor
ClickToCastTooltipDB.dividerColor = defaults.dividerColor
end, "Reset the colors to their default values.", true)
layout:AddInitializer(button)
end
Settings.RegisterAddOnCategory(category)
-- -- Shows the color picker with the callback function
function ShowColorPicker(colorToChange, changedCallback)
if (colorToChange == nil) then
throw "Color to change is nil"
elseif (colorToChange == "buttonColor") then
buttonColor = CreateColorFromHexString(ClickToCastTooltipDB.buttonColor)
r, g, b, a = buttonColor.r, buttonColor.g, buttonColor.b, buttonColor.a
elseif (colorToChange == "actionColor") then
actionColor = CreateColorFromHexString(ClickToCastTooltipDB.actionColor)
r, g, b, a = actionColor.r, actionColor.g, actionColor.b, actionColor.a
elseif (colorToChange == "dividerColor") then
dividerColor = CreateColorFromHexString(ClickToCastTooltipDB.dividerColor)
r, g, b, a = dividerColor.r, dividerColor.g, dividerColor.b, dividerColor.a
end
if (ColorPickerFrame.SetupColorPickerAndShow == nil) then
ColorPickerFrame.func = changedCallback
ColorPickerFrame.hasOpacity = (a ~= nil)
ColorPickerFrame.opacityFunc = changedCallback
ColorPickerFrame.opacity = a
ColorPickerFrame.previousValues = {r, g, b, a}
ColorPickerFrame.cancelFunc = changedCallback
ColorPickerFrame.extraInfo = changedCallback
ColorPickerFrame:SetColorRGB(r, g, b)
ColorPickerFrame:Show()
else
local info = {}
info.swatchFunc = changedCallback
info.cancelFunc = ColorPickerCancel
info.hasOpacity = (a ~= nil)
info.previousValues = {r, g, b, a}
info.r, info.g, info.b, info.opacity = r, g, b, a
ColorPickerFrame:SetupColorPickerAndShow(info)
end
end
-- Function to be called when color picker is canceled
function ColorPickerCancel()
-- Do nothing
end
-- Callback function to protect the color picker from no selection being made
function ButtonColorCallback(restore)
local newR, newG, newB, newA
if restore then
-- The user bailed , we extreact the old color from the table created by ShowColorPicker.
newR, newG, newB, newA = unpack(restore)
else
-- Something changed
newA, newR, newG, newB = ColorPickerFrame:GetColorAlpha(), ColorPickerFrame:GetColorRGB()
end
ClickToCastTooltipDB.buttonColor = string.format("%02x%02x%02x%02x", newA * 255, newR * 255, newG * 255, newB * 255)
print("Button color changed to: " .. tostring(ClickToCastTooltipDB.buttonColor))
end
function ActionColorCallback(restore)
local newR, newG, newB, newA
if restore then
-- The user bailed , we extreact the old color from the table created by ShowColorPicker.
newR, newG, newB, newA = unpack(restore)
else
-- Something changed
newA, newR, newG, newB = ColorPickerFrame:GetColorAlpha(), ColorPickerFrame:GetColorRGB()
end
ClickToCastTooltipDB.actionColor = string.format("%02x%02x%02x%02x", newA * 255, newR * 255, newG * 255, newB * 255)
end
function DividerColorCallback(restore)
local newR, newG, newB, newA
if restore then
-- The user bailed , we extreact the old color from the table created by ShowColorPicker.
newR, newG, newB, newA = unpack(restore)
else
-- Something changed
newA, newR, newG, newB = ColorPickerFrame:GetColorAlpha(), ColorPickerFrame:GetColorRGB()
end
ClickToCastTooltipDB.dividerColor =
string.format("%02x%02x%02x%02x", newA * 255, newR * 255, newG * 255, newB * 255)
end
-- Add the supported slash commands
SLASH_CLICKTOCASTTT1 = "/clicktocasttooltip"
SLASH_CLICKTOCASTTT2 = "/ctctt"
-- Handle the slash commands
SlashCmdList["CLICKTOCASTTT"] = function(msg)
Settings.OpenToCategory(category.ID)
end