-
Notifications
You must be signed in to change notification settings - Fork 4
/
Options.lua
214 lines (172 loc) · 6.27 KB
/
Options.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
local _, ADDONSELF = ...
local L = ADDONSELF.L
local RegEvent = ADDONSELF.regevent
RegEvent("ADDON_LOADED", function()
if not BuffTimersOptions then
BuffTimersOptions = {}
end
end)
local defs = {}
local function GetConfigOrDefault(key, def)
defs[key] = def
if BuffTimersOptions[key] == nil then
BuffTimersOptions[key] = def
end
return BuffTimersOptions[key]
end
local changedcb = {}
local function RegisterKeyChangedCallback(key, cb)
if not changedcb[key] then
changedcb[key] = {}
end
table.insert(changedcb[key] , cb)
end
ADDONSELF.RegisterKeyChangedCallback = RegisterKeyChangedCallback
local function triggerCallback(key, value)
for _, cb in pairs(changedcb[key] or {}) do
cb(value)
end
end
local function SetConfig(key, value)
BuffTimersOptions[key] = value
triggerCallback(key, value)
end
local f = CreateFrame("Frame", nil, UIParent)
f.name = L["BuffTimers"]
local category, layout = Settings.RegisterCanvasLayoutCategory(f, f.name, f.name)
category.ID = f.name
Settings.RegisterAddOnCategory(category)
do
local t = f:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
t:SetText(L["BuffTimers"])
t:SetPoint("TOPLEFT", f, 15, -15)
end
local function createCheckbox(title, key, def)
local b = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate")
b.text = b:CreateFontString(nil, "OVERLAY", "GameFontNormal")
b.text:SetPoint("LEFT", b, "RIGHT", 0, 1)
b.text:SetText(title)
b.text:SetTextColor(1, 1, 1)
b:SetScript("OnClick", function()
SetConfig(key, b:GetChecked())
end)
RegisterKeyChangedCallback(key, function(v)
b:SetChecked(v)
end)
triggerCallback(key, GetConfigOrDefault(key, def))
return b
end
local sliderTemplate = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC and "UISliderTemplate" or "UISliderTemplateWithLabels"
local function createSlider(key, minValue, maxValue, valueStep, minText, maxText, title, textOnValueChanged, default)
local s = CreateFrame("Slider", f, f, sliderTemplate)
s:SetHeight(14)
s:SetWidth(160)
s:SetMinMaxValues(minValue, maxValue)
s:SetValueStep(valueStep)
if WOW_PROJECT_ID == WOW_PROJECT_CLASSIC then
s.low = f:CreateFontString(key .. "Low_workaround", "OVERLAY")
s.low:SetFont([[Fonts\FRIZQT__.TTF]], 10, "OUTLINE")
s.low:SetPoint("TOPLEFT", s, "BOTTOMLEFT", 0, -5)
s.low:SetText(minText)
s.high = f:CreateFontString(key .. "High_workaround", "OVERLAY")
s.high:SetFont([[Fonts\FRIZQT__.TTF]], 10, "OUTLINE")
s.high:SetPoint("TOPRIGHT", s, "BOTTOMRIGHT", 0, -5)
s.high:SetText(maxText)
end
local l = s:CreateFontString(nil, "OVERLAY", "GameFontNormal")
l:SetFont([[Fonts\FRIZQT__.TTF]], 10, "OUTLINE")
l:SetPoint("RIGHT", s, "LEFT", -20, 1)
l:SetText(title)
l:SetTextColor(1, 1, 1)
s.current = f:CreateFontString(key .. "Current", "OVERLAY")
s.current:SetFont([[Fonts\FRIZQT__.TTF]], 10, "OUTLINE")
s.current:SetPoint("CENTER", s, "RIGHT", 24, 0)
s.current:SetText(default)
s:SetScript("OnValueChanged", function(self, value)
s.current:SetText(textOnValueChanged(value))
SetConfig(key, value)
end)
RegisterKeyChangedCallback(key, function(v)
s:SetValue(v)
end)
triggerCallback(key, GetConfigOrDefault(key, default))
return s, l
end
RegEvent("PLAYER_LOGIN", function()
f.default = function()
for k, v in pairs(defs) do
SetConfig(k, v)
end
end
f.refresh = function()
end
local base = -15
local nextpos = function(offset)
if not offset then
offset = 30
end
base = base - offset
return base
end
do
local key = "time_stamp"
local options = {
["m"] = "minutes (119m)",
["hm"] = "h:mm (1:59h)",
}
local d = CreateFrame("Frame", f, f, "UIDropDownMenuTemplate")
local l = d:CreateFontString(nil, "OVERLAY", "GameFontNormal")
l:SetPoint("RIGHT", d, "LEFT", -20, 1)
l:SetText(L["Time Stamp Format"])
l:SetTextColor(1, 1, 1)
d:SetPoint("TOPLEFT", f, 40 + l:GetStringWidth(), nextpos(45))
d.initialize = function()
for k, option in next, options do
local info = UIDropDownMenu_CreateInfo()
info.text = options[k]
info.value = k
info.checked = k == GetConfigOrDefault(key, "m")
info.func = function(self)
SetConfig(key, self.value)
UIDropDownMenu_SetText(d, options[self.value])
end
UIDropDownMenu_AddButton(info)
end
end
UIDropDownMenu_SetText(d, options[GetConfigOrDefault(key, "m")])
triggerCallback(key, GetConfigOrDefault(key, "m"))
end
do
local b = createCheckbox(L["Show seconds"], "seconds", false)
b:SetPoint("TOPLEFT", f, 15, nextpos())
end
do
local func = function (value) return SecondsToTime(value * 60) end
local s, l = createSlider("seconds_threshold", 1, 120, 1, SecondsToTime(60), SecondsToTime(7200), L["Show seconds below this time"], func, 30)
s:SetPoint("TOPLEFT", f, 40 + l:GetStringWidth(), nextpos(45))
end
do
local b = createCheckbox(L["Show milliseconds below 5 seconds"], "milliseconds", true)
b:SetPoint("TOPLEFT", f, 15, nextpos())
end
do
local b = createCheckbox(L["Always yellow text color"], "yellow_text", false)
b:SetPoint("TOPLEFT", f, 15, nextpos())
end
do
local b = createCheckbox(L["Add more colors to the timer"], "colored_text", false)
b:SetPoint("TOPLEFT", f, 15, nextpos())
end
do
local b = createCheckbox(L["Customize text"], "customize_text", false)
b:SetPoint("TOPLEFT", f, 15, nextpos())
end
do
local s, l = createSlider("vertical_position", -100, 100, 1, "-100", "100", L["Text vertical position"], tostring, -34)
s:SetPoint("TOPLEFT", f, 40 + l:GetStringWidth(), nextpos(45))
end
do
local s, l = createSlider("font_size", 1, 100, 1, "1", "100", L["Text font size"], tostring, 14)
s:SetPoint("TOPLEFT", f, 40 + l:GetStringWidth(), nextpos(45))
end
end)