-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsUI.lua
More file actions
540 lines (457 loc) · 17.4 KB
/
Copy pathSettingsUI.lua
File metadata and controls
540 lines (457 loc) · 17.4 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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
local ADDON_NAME, Addon = ...
local SettingsUI = {}
Addon.SettingsUI = SettingsUI
local panelFrame
local categoryID
local CONTENT_LEFT_INSET = 12
local EDITBOX_LEFT_INSET = 4
local function HasModernSettings()
local settings = Settings
return settings
and settings.RegisterCanvasLayoutCategory
and settings.RegisterAddOnCategory
and settings.OpenToCategory
end
local function IsClassicClient()
return not (WOW_PROJECT_MAINLINE ~= nil and WOW_PROJECT_ID == WOW_PROJECT_MAINLINE)
end
local function NormalizeFontSize(value, fallback)
local numberValue = tonumber(Addon.util.Trim(value))
if not numberValue then
numberValue = tonumber(fallback) or Addon.DEFAULTS.settings.chatFontSize
end
numberValue = math.floor(numberValue + 0.5)
if numberValue < Addon.CHAT_FONT_SIZE_MIN then
return Addon.CHAT_FONT_SIZE_MIN
end
if numberValue > Addon.CHAT_FONT_SIZE_MAX then
return Addon.CHAT_FONT_SIZE_MAX
end
return numberValue
end
local function SetTooltip(widget, title, text)
if not text or text == "" then
return
end
if not widget or type(widget.SetScript) ~= "function" then
return
end
widget:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(title or "CalmChat", 1, 1, 1)
GameTooltip:AddLine(text, nil, nil, nil, true)
GameTooltip:Show()
end)
widget:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
end
local function CreateSectionHeader(parent, text, anchor)
local header = parent:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
header:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -14)
header:SetText(text)
return header
end
local function CreateCheckbox(parent, anchor, label, tooltip, getValue, setValue)
local checkbox = CreateFrame("CheckButton", nil, parent, "UICheckButtonTemplate")
checkbox:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -6)
local text = parent:CreateFontString(nil, "ARTWORK", "GameFontNormal")
text:SetPoint("LEFT", checkbox, "RIGHT", 6, 0)
text:SetText(label)
SetTooltip(checkbox, label, tooltip)
checkbox.Refresh = function()
checkbox:SetChecked(getValue())
end
checkbox:SetScript("OnClick", function(self)
setValue(self:GetChecked() and true or false)
end)
checkbox.ToggleShown = function(show)
if show then
checkbox:Show()
text:Show()
else
checkbox:Hide()
text:Hide()
end
end
checkbox.GetBottomAnchor = function()
return checkbox
end
return checkbox
end
local function CreateEditBox(parent, anchor, label, tooltip, getValue, setValue)
local field = CreateFrame("Frame", nil, parent)
field:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -10)
field:SetSize(320, 44)
local title = field:CreateFontString(nil, "ARTWORK", "GameFontNormal")
title:SetPoint("TOPLEFT", field, "TOPLEFT", 0, 0)
title:SetText(label)
local editBox = CreateFrame("EditBox", nil, field, "InputBoxTemplate")
editBox:SetAutoFocus(false)
editBox:SetSize(260, 22)
editBox:SetPoint("TOPLEFT", title, "BOTTOMLEFT", EDITBOX_LEFT_INSET, -4)
SetTooltip(editBox, label, tooltip)
local function RefreshField()
editBox:SetText(getValue() or "")
editBox:HighlightText(0, 0)
editBox:SetCursorPosition(0)
end
editBox.Refresh = RefreshField
field.Refresh = RefreshField
local function Commit()
setValue(editBox:GetText())
editBox:ClearFocus()
editBox.Refresh()
end
editBox:SetScript("OnEnterPressed", Commit)
editBox:SetScript("OnEditFocusLost", Commit)
editBox:SetScript("OnEscapePressed", function(self)
self:ClearFocus()
self.Refresh()
end)
field.ToggleShown = function(show)
if show then
field:Show()
else
field:Hide()
end
end
field.GetBottomAnchor = function()
return field
end
return field
end
local function CreateDivider(parent, anchor)
local divider = parent:CreateTexture(nil, "ARTWORK")
divider:SetColorTexture(1, 1, 1, 0.15)
divider:SetHeight(1)
divider:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -10)
divider:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -20, 0)
return divider
end
local function EnsureScrollContainer(panel)
local scrollFrame = CreateFrame("ScrollFrame", nil, panel, "UIPanelScrollFrameTemplate")
scrollFrame:SetPoint("TOPLEFT", panel, "TOPLEFT", 16, -16)
scrollFrame:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", -34, 50)
local content = CreateFrame("Frame", nil, scrollFrame)
content:SetSize(1, 1)
scrollFrame:SetScrollChild(content)
panel.scrollFrame = scrollFrame
panel.content = content
end
local function ReflowLayout(panel)
if not panel or not panel.content then
return
end
local controls = panel.controls
local content = panel.content
local showClassic = IsClassicClient()
local showRetailOnly = not showClassic
local currentAnchor = controls.enableRetailServicesTab:GetBottomAnchor()
local contentWidth = panel.scrollFrame and panel.scrollFrame:GetWidth() or 680
if contentWidth < 680 then
contentWidth = 680
else
contentWidth = contentWidth - 20
end
content:SetWidth(contentWidth)
controls.subtitle:SetWidth(math.max(200, contentWidth - CONTENT_LEFT_INSET - 16))
if showClassic then
controls.classicHeader:Show()
else
controls.classicHeader:Hide()
end
controls.enableClassicLFGTab.ToggleShown(showClassic)
controls.autoJoinClassicLFG.ToggleShown(showClassic)
controls.classicLfgName.ToggleShown(showClassic)
controls.classicLayerName.ToggleShown(showClassic)
controls.servicesTabName.ToggleShown(showRetailOnly)
controls.lfgTabName.ToggleShown(showClassic)
if showClassic then
controls.classicHeader:ClearAllPoints()
controls.classicHeader:SetPoint("TOPLEFT", currentAnchor, "BOTTOMLEFT", 0, -14)
controls.enableClassicLFGTab:ClearAllPoints()
controls.enableClassicLFGTab:SetPoint("TOPLEFT", controls.classicHeader, "BOTTOMLEFT", 0, -6)
controls.autoJoinClassicLFG:ClearAllPoints()
controls.autoJoinClassicLFG:SetPoint("TOPLEFT", controls.enableClassicLFGTab, "BOTTOMLEFT", 0, -6)
controls.classicLfgName:ClearAllPoints()
controls.classicLfgName:SetPoint("TOPLEFT", controls.autoJoinClassicLFG, "BOTTOMLEFT", 0, -10)
controls.classicLayerName:ClearAllPoints()
controls.classicLayerName:SetPoint("TOPLEFT", controls.classicLfgName, "BOTTOMLEFT", 0, -10)
currentAnchor = controls.classicLayerName:GetBottomAnchor()
end
controls.tabsHeader:ClearAllPoints()
controls.tabsHeader:SetPoint("TOPLEFT", currentAnchor, "BOTTOMLEFT", 0, -14)
controls.lootTradeTabName:ClearAllPoints()
controls.lootTradeTabName:SetPoint("TOPLEFT", controls.tabsHeader, "BOTTOMLEFT", 0, -10)
currentAnchor = controls.lootTradeTabName:GetBottomAnchor()
if showRetailOnly then
controls.servicesTabName:ClearAllPoints()
controls.servicesTabName:SetPoint("TOPLEFT", currentAnchor, "BOTTOMLEFT", 0, -10)
currentAnchor = controls.servicesTabName:GetBottomAnchor()
end
if showClassic then
controls.lfgTabName:ClearAllPoints()
controls.lfgTabName:SetPoint("TOPLEFT", currentAnchor, "BOTTOMLEFT", 0, -10)
currentAnchor = controls.lfgTabName:GetBottomAnchor()
end
controls.divider:ClearAllPoints()
controls.divider:SetPoint("TOPLEFT", currentAnchor, "BOTTOMLEFT", 0, -12)
controls.divider:SetPoint("TOPRIGHT", content, "TOPRIGHT", -16, 0)
controls.applyButton:ClearAllPoints()
controls.applyButton:SetPoint("TOPLEFT", controls.divider, "BOTTOMLEFT", 0, -10)
controls.resetButton:ClearAllPoints()
controls.resetButton:SetPoint("LEFT", controls.applyButton, "RIGHT", 10, 0)
local contentBottom = controls.applyButton:GetBottom()
local contentTop = controls.title:GetTop()
if not contentBottom or not contentTop then
return
end
local computedHeight = math.ceil((contentTop - contentBottom) + 24)
if computedHeight < 1 then
computedHeight = 1
end
content:SetHeight(computedHeight)
local viewHeight = panel.scrollFrame:GetHeight() or 0
local hasOverflow = computedHeight > (viewHeight + 2)
if panel.scrollFrame.ScrollBar then
panel.scrollFrame.ScrollBar:SetShown(hasOverflow)
end
if hasOverflow then
panel.scrollFrame:ClearAllPoints()
panel.scrollFrame:SetPoint("TOPLEFT", panel, "TOPLEFT", 16, -16)
panel.scrollFrame:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", -34, 50)
else
panel.scrollFrame:ClearAllPoints()
panel.scrollFrame:SetPoint("TOPLEFT", panel, "TOPLEFT", 16, -16)
panel.scrollFrame:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", -16, 50)
panel.scrollFrame:SetVerticalScroll(0)
end
end
local function BuildPanel(panel)
panel.controls = {}
EnsureScrollContainer(panel)
local content = panel.content
local controls = panel.controls
controls.title = content:CreateFontString(nil, "ARTWORK", "GameFontNormalHuge")
controls.title:SetPoint("TOPLEFT", content, "TOPLEFT", CONTENT_LEFT_INSET, 0)
controls.title:SetText("CalmChat")
controls.subtitle = content:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
controls.subtitle:SetPoint("TOPLEFT", controls.title, "BOTTOMLEFT", 0, -6)
controls.subtitle:SetWidth(680 - CONTENT_LEFT_INSET)
controls.subtitle:SetJustifyH("LEFT")
controls.subtitle:SetText("Configure CalmChat defaults. Your current preferences remain the baseline preset.")
local dbGetter = function()
return Addon.GetConfig()
end
controls.applyHeader = CreateSectionHeader(content, "Apply Behavior", controls.subtitle)
controls.setupOnLogin = CreateCheckbox(
content,
controls.applyHeader,
"Run setup after login or reload",
"Automatically applies the selected chat preset shortly after PLAYER_LOGIN.",
function()
return dbGetter().settings.setupOnLogin
end,
function(value)
dbGetter().settings.setupOnLogin = value
end
)
controls.resetBeforeApply = CreateCheckbox(
content,
controls.setupOnLogin,
"Always reset chat windows before apply",
"Keeps full reset behavior before applying CalmChat routing.",
function()
return dbGetter().settings.resetBeforeApply
end,
function(value)
dbGetter().settings.resetBeforeApply = value
end
)
controls.chatFontSize = CreateEditBox(
content,
controls.resetBeforeApply,
"Chat font size",
string.format("Default: %d (range %d-%d)", Addon.DEFAULTS.settings.chatFontSize, Addon.CHAT_FONT_SIZE_MIN, Addon.CHAT_FONT_SIZE_MAX),
function()
return tostring(dbGetter().settings.chatFontSize)
end,
function(value)
local settings = dbGetter().settings
settings.chatFontSize = NormalizeFontSize(value, settings.chatFontSize)
end
)
controls.retailHeader = CreateSectionHeader(content, "Retail Options", controls.chatFontSize)
controls.keepRetailVoiceFrame = CreateCheckbox(
content,
controls.retailHeader,
"Keep Retail voice transcription frame",
"Preserves Blizzard's voice transcription tab when applying layout on Retail.",
function()
return dbGetter().settings.keepRetailVoiceFrame
end,
function(value)
dbGetter().settings.keepRetailVoiceFrame = value
end
)
controls.enableRetailServicesTab = CreateCheckbox(
content,
controls.keepRetailVoiceFrame,
"Enable Retail Services tab",
"Creates a dedicated Services tab and routes the Services channel to it on Retail.",
function()
return dbGetter().settings.enableRetailServicesTab
end,
function(value)
dbGetter().settings.enableRetailServicesTab = value
end
)
controls.classicHeader = CreateSectionHeader(content, "Classic Options", controls.enableRetailServicesTab)
controls.enableClassicLFGTab = CreateCheckbox(
content,
controls.classicHeader,
"Enable Classic LFG tab",
"Creates and routes a dedicated LFG tab on Classic clients.",
function()
return dbGetter().settings.enableClassicLFGTab
end,
function(value)
dbGetter().settings.enableClassicLFGTab = value
end
)
controls.autoJoinClassicLFG = CreateCheckbox(
content,
controls.enableClassicLFGTab,
"Auto-join Classic LFG channels",
"Joins configured LFG channels when applying on enUS Classic clients.",
function()
return dbGetter().tabs.lfg.autoJoin
end,
function(value)
dbGetter().tabs.lfg.autoJoin = value
end
)
controls.classicLfgName = CreateEditBox(
content,
controls.autoJoinClassicLFG,
"Classic LFG channel name",
"Default: LookingForGroup",
function()
return dbGetter().settings.classicChannelNames.lfg
end,
function(value)
dbGetter().settings.classicChannelNames.lfg = Addon.DB.NormalizeText(value, Addon.DEFAULTS.settings.classicChannelNames.lfg)
end
)
controls.classicLayerName = CreateEditBox(
content,
controls.classicLfgName,
"Classic Layer channel name",
"Default: Layer",
function()
return dbGetter().settings.classicChannelNames.layer
end,
function(value)
dbGetter().settings.classicChannelNames.layer = Addon.DB.NormalizeText(value, Addon.DEFAULTS.settings.classicChannelNames.layer)
end
)
controls.tabsHeader = CreateSectionHeader(content, "Tabs and Routing", controls.classicLayerName)
controls.lootTradeTabName = CreateEditBox(
content,
controls.tabsHeader,
"Loot/Trade tab label",
"Default: Loot/Trade",
function()
return dbGetter().tabs.lootTrade.name
end,
function(value)
dbGetter().tabs.lootTrade.name = Addon.DB.NormalizeText(value, Addon.DEFAULTS.tabs.lootTrade.name)
end
)
controls.servicesTabName = CreateEditBox(
content,
controls.lootTradeTabName,
"Services tab label",
"Default: Services",
function()
return dbGetter().tabs.services.name
end,
function(value)
dbGetter().tabs.services.name = Addon.DB.NormalizeText(value, Addon.DEFAULTS.tabs.services.name)
end
)
controls.lfgTabName = CreateEditBox(
content,
controls.servicesTabName,
"LFG tab label",
"Default: LFG",
function()
return dbGetter().tabs.lfg.name
end,
function(value)
dbGetter().tabs.lfg.name = Addon.DB.NormalizeText(value, Addon.DEFAULTS.tabs.lfg.name)
end
)
controls.divider = CreateDivider(content, controls.lfgTabName)
controls.applyButton = CreateFrame("Button", nil, content, "UIPanelButtonTemplate")
controls.applyButton:SetSize(170, 24)
controls.applyButton:SetPoint("TOPLEFT", controls.lfgTabName, "BOTTOMLEFT", 0, -16)
controls.applyButton:SetText("Apply Chat Layout")
controls.applyButton:SetScript("OnClick", function()
Addon.SetupChat()
end)
controls.resetButton = CreateFrame("Button", nil, content, "UIPanelButtonTemplate")
controls.resetButton:SetSize(190, 24)
controls.resetButton:SetPoint("LEFT", controls.applyButton, "RIGHT", 10, 0)
controls.resetButton:SetText("Reset To Calm Defaults")
controls.resetButton:SetScript("OnClick", function()
Addon.ApplyDefaults()
panel.Refresh()
Addon.SetupChat()
end)
panel.Refresh = function()
for _, control in pairs(panel.controls) do
if control and control.Refresh then
control.Refresh()
end
end
ReflowLayout(panel)
end
panel:SetScript("OnShow", panel.Refresh)
end
local function RegisterLegacyOptions(panel)
if type(InterfaceOptions_AddCategory) == "function" then
panel.name = "CalmChat"
InterfaceOptions_AddCategory(panel)
end
end
function SettingsUI.Register()
if panelFrame then
return
end
panelFrame = CreateFrame("Frame", "CalmChatSettingsPanel")
panelFrame.name = "CalmChat"
BuildPanel(panelFrame)
if HasModernSettings() then
local category = Settings.RegisterCanvasLayoutCategory(panelFrame, "CalmChat")
Settings.RegisterAddOnCategory(category)
categoryID = type(category.GetID) == "function" and category:GetID() or category.ID
else
RegisterLegacyOptions(panelFrame)
end
end
function SettingsUI.Open()
SettingsUI.Register()
if categoryID and Settings and Settings.OpenToCategory then
Settings.OpenToCategory(categoryID)
return true
end
if panelFrame and type(InterfaceOptionsFrame_OpenToCategory) == "function" then
InterfaceOptionsFrame_OpenToCategory(panelFrame)
InterfaceOptionsFrame_OpenToCategory(panelFrame)
return true
end
Addon.PrintError("Settings are unavailable on this client.")
return false
end