-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMainConfig.lua
348 lines (269 loc) · 9.43 KB
/
MainConfig.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
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
-- --------------------
-- TellMeWhen
-- Originally by NephMakes
-- Other contributions by:
-- Sweetmms of Blackrock, Oozebull of Twisting Nether, Oodyboo of Mug'thol,
-- Banjankri of Blackrock, Predeter of Proudmoore, Xenyr of Aszune
-- Currently maintained by
-- Cybeloras of Aerie Peak
-- --------------------
if not TMW then return end
local TMW = TMW
local L = TMW.L
local print = TMW.print
local IE = TMW.IE
local CI = TMW.CI
local tinsert, format
= tinsert, format
local TabGroup = IE:RegisterTabGroup("MAIN", L["MAIN"], 3, function(tabGroup)
IE.Header:SetText("TellMeWhen v" .. TELLMEWHEN_VERSION_FULL)
end)
TabGroup:SetTexts(L["MAIN"], L["TABGROUP_MAIN_DESC"])
local BaseConfig = TMW:NewClass("Main_BaseConfig", "GenericComponent")
BaseConfig.DefaultPanelSet = "profile"
BaseConfig:RegisterConfigPanel_ConstructorFunc(2, "TellMeWhen_Main_General", function(self)
self:SetTitle(L["DOMAIN_PROFILE"] .. ": " .. GENERAL)
self:BuildSimpleCheckSettingFrame({
numPerRow = 1,
function(check)
check:SetTexts(L["UIPANEL_WARNINVALIDS"], L["UIPANEL_WARNINVALIDS_DESC"])
check:SetSetting("WarnInvalids")
end,
})
end)
BaseConfig:RegisterConfigPanel_ConstructorFunc(2, "TellMeWhen_Main_GeneralGlobal", function(self)
self:SetTitle(L["DOMAIN_GLOBAL_NC"] .. ": " .. GENERAL)
self:BuildSimpleCheckSettingFrame({
numPerRow = 1,
function(check)
check:SetTexts(L["UIPANEL_COMBATCONFIG"], L["UIPANEL_COMBATCONFIG_DESC"])
check:SetSetting("AllowCombatConfig")
end,
function(check)
check:SetTexts(L["SHOWGUIDS_OPTION"], L["SHOWGUIDS_OPTION_DESC"])
check:SetSetting("ShowGUIDs")
end,
function(check)
check:SetTexts(L["UIPANEL_ALLOWSCALEIE"], L["UIPANEL_ALLOWSCALEIE_DESC"])
check:SetSetting("ScaleIE")
check:CScriptAdd("SettingTableRequested", function()
return TMW.IE.db.global
end)
check:CScriptAdd("SettingSaved", function()
IE:Load(1)
end)
end,
function(check)
check:SetTexts(L["UIPANEL_SHOWCONFIGWARNING"])
check:SetSetting("ConfigWarning")
check:CScriptAdd("SettingTableRequested", function()
return TMW.IE.db.global
end)
check:CScriptAdd("SettingSaved", function()
-- If someone manually toggles this setting,
-- get rid of the "dont show again" button.
TMW.IE.db.global.ConfigWarningN = -10e6
end)
end,
})
end):SetPanelSet("global")
BaseConfig:RegisterConfigPanel_ConstructorFunc(9, "TellMeWhen_Main_CommSettings", function(self)
self:SetTitle(L["DOMAIN_GLOBAL_NC"] .. ": " .. L["CONFIGPANEL_COMM_HEADER"])
self:BuildSimpleCheckSettingFrame({
numPerRow = 1,
function(check)
check:SetTexts(L["ALLOWCOMM"], L["ALLOWCOMM_DESC"])
check:SetSetting("ReceiveComm")
end,
function(check)
check:SetTexts(L["ALLOWVERSIONWARN"])
check:SetSetting("VersionWarning")
end,
})
end):SetPanelSet("global")
BaseConfig:RegisterConfigPanel_XMLTemplate(30, "TellMeWhen_Main_Media")
BaseConfig:RegisterConfigPanel_XMLTemplate(50, "TellMeWhen_Main_Efficiency"):SetPanelSet("global")
BaseConfig:RegisterConfigPanel_XMLTemplate(1, "TellMeWhen_Main_Profiles")
-- ----------------------
-- CHANGELOG
-- ----------------------
local MainTab = IE:RegisterTab("MAIN", "MAIN", "Main", 1)
MainTab:SetTexts(L["UIPANEL_MAINOPT"], L["ADDONSETTINGS_DESC"])
local HistorySet = TMW.C.HistorySet:New("MAIN")
profileHistories = setmetatable({}, {
__index = function(self, key)
self[key] = {}
return self[key]
end
})
HistorySet:AddBlocker({
profile = {
Groups = true,
NumGroups = true,
Version = true,
Locked = true,
},
global = {
AuraCache = true,
Groups = true,
NumGroups = true,
HelpSettings = true,
}
})
function HistorySet:GetCurrentLocation()
return profileHistories[TMW.db:GetCurrentProfile()]
end
function HistorySet:GetCurrentSettings()
-- Proxy into AceDB settings. Can't give it TMW.db or everything will blow up - even with appropriate blockers.
return {profile = TMW.db.profile, global = TMW.db.global}
end
MainTab:SetHistorySet(HistorySet)
local ChangelogTab = IE:RegisterTab("MAIN", "CHANGELOG", "Changelog", 100)
ChangelogTab:SetTexts(L["CHANGELOG"], L["CHANGELOG_DESC"])
function IE:ShowChangelog(lastVer)
IE.TabGroups.MAIN.CHANGELOG:Click()
IE.Pages.Changelog.Container:Render(lastVer)
end
local function htmlEscape(char)
if char == "&" then
return "&"
elseif char == "<" then
return "<"
elseif char == ">" then
return ">"
end
end
local bulletColors = {
"4FD678",
"2F99FF",
"F62FAD",
}
local function bullets(b, text)
local numDashes = #b
if numDashes <= 0 then
return "><p>" .. text .. "</p><"
end
local color = bulletColors[(numDashes-1) % #bulletColors + 1]
-- This is not a regular space. It is U+2002 - EN SPACE
local dashes = (" "):rep(numDashes) .. "•"
return "><p>|cFF" .. color .. dashes .. " |r" .. text .. "</p><"
end
local CHANGELOGS
function IE:ProcessChangelogData()
if CHANGELOGS then
return CHANGELOGS
end
CHANGELOGS = {}
if not TMW.CHANGELOG then
TMW:Error("There was an error loading TMW's changelog data.")
TMW:Print("There was an error loading TMW's changelog data.")
return CHANGELOGS
end
local log = TMW.CHANGELOG
log = log:gsub("([&<>])", htmlEscape)
log = log:trim(" \t\r\n")
-- Replace 4 equals with h2
log = log:gsub("### (.-)[\r\n]+", "<h2>%1</h2>\n")
-- Replace 3 equals with h1, formatting as a version name
log = log:gsub("## (.-)[\r\n]+", "<h1>TellMeWhen %1</h1>\n")
-- Remove extra space after closing header tags
log = log:gsub("(</h.>)%s*", "%1")
-- Remove extra space before opening header tags.
log = log:gsub("%s*(<h.>)", "%1")
-- Convert newlines to <br/>
log = log:gsub("\r\n", "<br/>")
log = log:gsub("\n", "<br/>")
-- Put a break at the end for the next gsub - it relies on a tag of some kind
-- being at the end of each line.
log = log .. "<br/>"
-- Convert asterisks to colored dashes
log = log:gsub(">([ \t]*%*)%s*(.-)<", bullets)
-- Remove double breaks
log = log:gsub("<br/><br/>", "<br/>")
-- Remove breaks between paragraphs
log = log:gsub("</p><br/><p>", "</p><p>")
-- Add breaks between paragraphs and h2ss
-- Put an empty paragraph in since they are smaller than a full break.
log = log:gsub("</p>%s*<h2>", "</p><p> </p><h2>")
-- Add a "General" header before the first paragraph after an h1
log = log:gsub("</h1>%s*<p>", "</h1><h2>General</h2><p>")
-- Make the phrase "IMPORTANT" be red.
log = log:gsub("IMPORTANT", "|cffff0000IMPORTANT|r")
local subStart, subEnd = 0, 0
repeat
local done
-- Find the start of a version
subStart, endH1 = log:find("<h1>", subEnd)
-- Find the start of the next version
subEnd = log:find("<h1>", endH1)
if not subEnd then
-- We're at the end of the data. Set the length of the data as the end position.
subEnd = #log
done = true
else
-- We want to end just before the start of the next version.
subEnd = subEnd - 1
end
local versionString = log:match("TellMeWhen v([0-9%.]+)", subStart):gsub("%.", "")
local versionNumber = tonumber(versionString) * 100
-- A full version's changelog is between subStart and subEnd. Store it.
CHANGELOGS[versionNumber] = log:sub(subStart, subEnd)
until done
-- Send this out to the garbage collector
TMW.CHANGELOG = nil
return CHANGELOGS
end
TMW:NewClass("Config_Changelog", "Frame"){
lastVer = 0,
OnNewInstance = function(self)
TMW:ConvertContainerToScrollFrame(self, false, 0, 12)
self.ScrollFrame:SetWheelStepAmount(25)
end,
Render = function(self, lastVer)
if not lastVer then lastVer = 0 end
self.lastVer = lastVer
self.RenderAll:SetShown(lastVer > 0)
local texts = {}
local changelogs = IE:ProcessChangelogData()
for version, text in TMW:OrderedPairs(changelogs, nil, nil, true) do
if lastVer >= version then
if lastVer > 0 then
text = text:gsub("</h1>", " (" .. L["CHANGELOG_LAST_VERSION"] .. ")</h1>")
end
tinsert(texts, text)
break
else
tinsert(texts, text)
end
end
-- The intro text, before any actual changelog entries
tinsert(texts, 1, ("<p align='center'>|cff999999Welcome to TellMeWhen v%s!|r</p>"):format(TELLMEWHEN_VERSION_FULL))
local foot = format("<html><body><p align='center'>|cff666666To view changelogs for %s or older, visit TellMeWhen's AddOn page on CurseForge.com|r</p></body></html>", TMW.CHANGELOG_LASTVER or "???")
self.Footer:SetText(foot)
self.Footer.text = foot
local body = format("<html><body>%s</body></html>", table.concat(texts, "<br/>"))
self.HTML:SetText(body)
-- This has to be stored because there is no GetText method.
self.HTML.text = body
self:GetScript("OnSizeChanged")(self)
end,
}
TMW:RegisterCallback("TMW_CONFIG_LOADED", function()
if IE.db.global.LastChangelogVersion > 0 then
if IE.db.global.LastChangelogVersion < TELLMEWHEN_VERSIONNUMBER then
if IE.db.global.LastChangelogVersion < TELLMEWHEN_FORCECHANGELOG -- forced
or TELLMEWHEN_VERSION_MINOR == "" -- upgraded to a release version (e.g. 7.0.0 release)
or floor(IE.db.global.LastChangelogVersion/100) < floor(TELLMEWHEN_VERSIONNUMBER/100) -- upgraded to a new minor version (e.g. 6.2.6 release -> 7.0.0 alpha)
then
-- We have to upvalue this since its about to get set to the current version.l
local version = IE.db.global.LastChangelogVersion
TellMeWhen_ChangelogStandalone.Changelog:Render(version)
TellMeWhen_ChangelogStandalone:Show()
end
IE.db.global.LastChangelogVersion = TELLMEWHEN_VERSIONNUMBER
end
else
IE.db.global.LastChangelogVersion = TELLMEWHEN_VERSIONNUMBER
end
end)
IE:RegisterTab("MAIN", "HELP", "Help", 101):SetTexts(L["HELP"])