-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.lua
More file actions
485 lines (390 loc) · 18.9 KB
/
Config.lua
File metadata and controls
485 lines (390 loc) · 18.9 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
-- ChatBar: Configuration and Settings UI
-- Config file
local addonName, ns = ...
-- Create Config object
local Config = {}
ns.Config = Config
-- Local reference to ChatBar
local ChatBar
-- Initialize config (called from ChatBar after ADDON_LOADED)
function Config:Initialize()
ChatBar = ns.ChatBar
self:CreateSettingsPanel()
self:RegisterSlashCommands()
end
-- Create settings panel with scroll
function Config:CreateSettingsPanel()
local L = ns.L
local panel = CreateFrame("Frame", "ChatBarConfigPanel", UIParent)
panel.name = L.ADDON_NAME or "ChatBar"
-- Create scroll frame
local scrollFrame = CreateFrame("ScrollFrame", "ChatBarConfigScroll", panel, "UIPanelScrollFrameTemplate")
scrollFrame:SetPoint("TOPLEFT", 4, -4)
scrollFrame:SetPoint("BOTTOMRIGHT", -27, 4)
-- Create scroll child (content frame)
local content = CreateFrame("Frame", "ChatBarConfigContent", scrollFrame)
content:SetSize(600, 800) -- Will expand as needed
scrollFrame:SetScrollChild(content)
-- Title
local title = content:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 16, -16)
title:SetText(L.SETTINGS_TITLE or "ChatBar Settings")
-- Version
local version = content:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
version:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
version:SetText((L.VERSION or "Version") .. " " .. ChatBar.VERSION)
version:SetTextColor(0.5, 0.5, 0.5)
local yOffset = -80
-- Profile Mode Section
local profileLabel = content:CreateFontString(nil, "ARTWORK", "GameFontNormal")
profileLabel:SetPoint("TOPLEFT", 16, yOffset)
profileLabel:SetText(L.PROFILE_MODE or "Profile Mode:")
local profileAccount = CreateFrame("CheckButton", "ChatBarProfileAccount", content, "UIRadioButtonTemplate")
profileAccount:SetPoint("TOPLEFT", profileLabel, "BOTTOMLEFT", 0, -8)
profileAccount.text = profileAccount:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
profileAccount.text:SetPoint("LEFT", profileAccount, "RIGHT", 0, 0)
profileAccount.text:SetText(L.PROFILE_ACCOUNT or "Account-wide (shared across all characters)")
local profileCharacter = CreateFrame("CheckButton", "ChatBarProfileCharacter", content, "UIRadioButtonTemplate")
profileCharacter:SetPoint("TOPLEFT", profileAccount, "BOTTOMLEFT", 0, -4)
profileCharacter.text = profileCharacter:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
profileCharacter.text:SetPoint("LEFT", profileCharacter, "RIGHT", 0, 0)
profileCharacter.text:SetText(L.PROFILE_CHARACTER or "Per-character settings")
profileAccount:SetScript("OnClick", function(self)
ns.db.profileMode = "account"
profileCharacter:SetChecked(false)
ChatBar:Refresh()
end)
profileCharacter:SetScript("OnClick", function(self)
ns.db.profileMode = "character"
profileAccount:SetChecked(false)
ChatBar:Refresh()
end)
content.profileAccount = profileAccount
content.profileCharacter = profileCharacter
yOffset = yOffset - 80
-- Skin Selection Section
local skinLabel = content:CreateFontString(nil, "ARTWORK", "GameFontNormal")
skinLabel:SetPoint("TOPLEFT", 16, yOffset)
skinLabel:SetText(L.SKIN_SELECTION or "Skin:")
-- Create custom dropdown frame for skin selection
local skinDropdown = CreateFrame("Frame", "ChatBarSkinDropdown", content, "UIDropDownMenuTemplate")
skinDropdown:SetPoint("TOPLEFT", skinLabel, "BOTTOMLEFT", -16, -4)
UIDropDownMenu_SetWidth(skinDropdown, 200)
-- Initialize dropdown with available skins
UIDropDownMenu_Initialize(skinDropdown, function(self, level)
local settings = ChatBar:GetSettings()
local skins = ns.Textures:GetAvailableSkins()
for _, skinInfo in ipairs(skins) do
local info = UIDropDownMenu_CreateInfo()
info.text = skinInfo.name
info.value = skinInfo.id
info.tooltipTitle = skinInfo.name
info.tooltipText = skinInfo.description .. "\n|cff888888by " .. skinInfo.author .. "|r"
info.tooltipOnButton = true
info.func = function(self)
local settings = ChatBar:GetSettings()
settings.skinName = skinInfo.id
UIDropDownMenu_SetSelectedValue(skinDropdown, skinInfo.id)
UIDropDownMenu_SetText(skinDropdown, skinInfo.name)
-- Hot-swap skin
ns.Textures:LoadSkin(skinInfo.id)
-- Apply skin's default fontSize to settings
local newSkin = ns.Textures:GetCurrentSkin()
if newSkin and newSkin.fontSize then
settings.fontSize = newSkin.fontSize
end
ChatBar:RefreshAllButtons()
ChatBar:RefreshBarTextures()
ChatBar:LayoutButtons()
-- Refresh config UI to show new fontSize
if ns.Config and ns.Config.panel then
ns.Config:RefreshPanel(ns.Config.panel)
end
end
info.checked = (settings.skinName == skinInfo.id)
UIDropDownMenu_AddButton(info)
end
end)
content.skinDropdown = skinDropdown
-- Skin description text
local skinDescription = content:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
skinDescription:SetPoint("TOPLEFT", skinDropdown, "BOTTOMLEFT", 20, 0)
skinDescription:SetTextColor(0.6, 0.6, 0.6)
skinDescription:SetWidth(300)
skinDescription:SetJustifyH("LEFT")
content.skinDescription = skinDescription
yOffset = yOffset - 80
-- Orientation Section
local orientationLabel = content:CreateFontString(nil, "ARTWORK", "GameFontNormal")
orientationLabel:SetPoint("TOPLEFT", 16, yOffset)
orientationLabel:SetText(L.ORIENTATION or "Orientation:")
local orientationHorizontal = CreateFrame("CheckButton", "ChatBarOrientationHorizontal", content, "UIRadioButtonTemplate")
orientationHorizontal:SetPoint("TOPLEFT", orientationLabel, "BOTTOMLEFT", 0, -8)
orientationHorizontal.text = orientationHorizontal:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
orientationHorizontal.text:SetPoint("LEFT", orientationHorizontal, "RIGHT", 0, 0)
orientationHorizontal.text:SetText(L.ORIENTATION_HORIZONTAL or "Horizontal")
local orientationVertical = CreateFrame("CheckButton", "ChatBarOrientationVertical", content, "UIRadioButtonTemplate")
orientationVertical:SetPoint("LEFT", orientationHorizontal, "RIGHT", 120, 0)
orientationVertical.text = orientationVertical:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
orientationVertical.text:SetPoint("LEFT", orientationVertical, "RIGHT", 0, 0)
orientationVertical.text:SetText(L.ORIENTATION_VERTICAL or "Vertical")
orientationHorizontal:SetScript("OnClick", function(self)
local settings = ChatBar:GetSettings()
settings.orientation = "horizontal"
orientationVertical:SetChecked(false)
ChatBar:Refresh()
end)
orientationVertical:SetScript("OnClick", function(self)
local settings = ChatBar:GetSettings()
settings.orientation = "vertical"
orientationHorizontal:SetChecked(false)
ChatBar:Refresh()
end)
content.orientationHorizontal = orientationHorizontal
content.orientationVertical = orientationVertical
yOffset = yOffset - 60
-- Two-column layout for sizes
-- Font Size Section (Left column)
local fontSizeLabel = content:CreateFontString(nil, "ARTWORK", "GameFontNormal")
fontSizeLabel:SetPoint("TOPLEFT", 16, yOffset)
fontSizeLabel:SetText("Font Size:")
local fontSizeSlider = CreateFrame("Slider", "ChatBarFontSizeSlider", content, "OptionsSliderTemplate")
fontSizeSlider:SetPoint("TOPLEFT", fontSizeLabel, "BOTTOMLEFT", 4, -20)
fontSizeSlider:SetMinMaxValues(8, 24)
fontSizeSlider:SetValueStep(1)
fontSizeSlider:SetObeyStepOnDrag(true)
fontSizeSlider:SetWidth(120)
-- Set slider labels
_G[fontSizeSlider:GetName() .. "Low"]:SetText("8")
_G[fontSizeSlider:GetName() .. "High"]:SetText("24")
_G[fontSizeSlider:GetName() .. "Text"]:SetText("12")
fontSizeSlider:SetScript("OnValueChanged", function(self, value)
local settings = ChatBar:GetSettings()
settings.fontSize = value
_G[self:GetName() .. "Text"]:SetText(tostring(math.floor(value)))
ChatBar:Refresh()
end)
content.fontSizeSlider = fontSizeSlider
-- Button Size Section (Right column)
local buttonSizeLabel = content:CreateFontString(nil, "ARTWORK", "GameFontNormal")
buttonSizeLabel:SetPoint("TOPLEFT", 300, yOffset)
buttonSizeLabel:SetText("Button Size:")
local buttonSizeSlider = CreateFrame("Slider", "ChatBarButtonSizeSlider", content, "OptionsSliderTemplate")
buttonSizeSlider:SetPoint("TOPLEFT", buttonSizeLabel, "BOTTOMLEFT", 4, -20)
buttonSizeSlider:SetMinMaxValues(10, 32)
buttonSizeSlider:SetValueStep(1)
buttonSizeSlider:SetObeyStepOnDrag(true)
buttonSizeSlider:SetWidth(120)
-- Set slider labels
_G[buttonSizeSlider:GetName() .. "Low"]:SetText("10")
_G[buttonSizeSlider:GetName() .. "High"]:SetText("32")
_G[buttonSizeSlider:GetName() .. "Text"]:SetText("18")
buttonSizeSlider:SetScript("OnValueChanged", function(self, value)
local settings = ChatBar:GetSettings()
settings.buttonSize = value
_G[self:GetName() .. "Text"]:SetText(tostring(math.floor(value)))
ChatBar:Refresh()
end)
content.buttonSizeSlider = buttonSizeSlider
yOffset = yOffset - 80
-- Text Position Section
local textPosLabel = content:CreateFontString(nil, "ARTWORK", "GameFontNormal")
textPosLabel:SetPoint("TOPLEFT", 16, yOffset)
textPosLabel:SetText(L.TEXT_POSITION or "Text Position:")
local textPosInside = CreateFrame("CheckButton", "ChatBarTextPosInside", content, "UIRadioButtonTemplate")
textPosInside:SetPoint("TOPLEFT", textPosLabel, "BOTTOMLEFT", 0, -8)
textPosInside.text = textPosInside:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
textPosInside.text:SetPoint("LEFT", textPosInside, "RIGHT", 0, 0)
textPosInside.text:SetText(L.TEXT_POSITION_INSIDE or "Inside buttons")
local textPosAbove = CreateFrame("CheckButton", "ChatBarTextPosAbove", content, "UIRadioButtonTemplate")
textPosAbove:SetPoint("LEFT", textPosInside, "RIGHT", 120, 0)
textPosAbove.text = textPosAbove:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
textPosAbove.text:SetPoint("LEFT", textPosAbove, "RIGHT", 0, 0)
textPosAbove.text:SetText(L.TEXT_POSITION_ABOVE or "Above buttons")
textPosInside:SetScript("OnClick", function(self)
local settings = ChatBar:GetSettings()
settings.textPosition = "inside"
textPosAbove:SetChecked(false)
ChatBar:Refresh()
end)
textPosAbove:SetScript("OnClick", function(self)
local settings = ChatBar:GetSettings()
settings.textPosition = "above"
textPosInside:SetChecked(false)
ChatBar:Refresh()
end)
content.textPosInside = textPosInside
content.textPosAbove = textPosAbove
yOffset = yOffset - 50
-- Flash Notifications Section
local flashCheckbox = CreateFrame("CheckButton", "ChatBarFlashNotifications", content, "UICheckButtonTemplate")
flashCheckbox:SetPoint("TOPLEFT", 16, yOffset)
flashCheckbox.text = flashCheckbox:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
flashCheckbox.text:SetPoint("LEFT", flashCheckbox, "RIGHT", 0, 0)
flashCheckbox.text:SetText(L.FLASH_NOTIFICATIONS_DESC or "Flash buttons on new messages")
flashCheckbox:SetScript("OnClick", function(self)
local settings = ChatBar:GetSettings()
settings.flashNotifications = self:GetChecked()
end)
content.flashCheckbox = flashCheckbox
yOffset = yOffset - 40
-- Channel Configuration Section
local channelLabel = content:CreateFontString(nil, "ARTWORK", "GameFontNormal")
channelLabel:SetPoint("TOPLEFT", 16, yOffset)
channelLabel:SetText(L.ENABLED_CHANNELS or "Enabled Channels:")
local channelCheckboxes = {}
local checkYOffset = yOffset - 24
local column = 0
local row = 0
-- Create checkboxes for each channel
local channelOrder = {}
for channelType, config in pairs(ns.ChannelInfo) do
table.insert(channelOrder, channelType)
end
table.sort(channelOrder)
for _, channelType in ipairs(channelOrder) do
local info = ns.ChannelInfo[channelType]
local checkbox = CreateFrame("CheckButton", "ChatBarChannel" .. channelType, content, "UICheckButtonTemplate")
local xPos = 20 + (column * 200)
local yPos = checkYOffset - (row * 28)
checkbox:SetPoint("TOPLEFT", xPos, yPos)
checkbox.text = checkbox:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
checkbox.text:SetPoint("LEFT", checkbox, "RIGHT", 0, 0)
checkbox.text:SetText(L[info.labelKey] or info.labelKey)
checkbox.channelType = channelType
checkbox:SetScript("OnClick", function(self)
local settings = ChatBar:GetSettings()
settings.channels[channelType].enabled = self:GetChecked()
ChatBar:UpdateButtons()
end)
channelCheckboxes[channelType] = checkbox
column = column + 1
if column >= 2 then
column = 0
row = row + 1
end
end
content.channelCheckboxes = channelCheckboxes
-- Numbered Channels Section
yOffset = checkYOffset - (row + 1) * 28 - 20
local numberedLabel = content:CreateFontString(nil, "ARTWORK", "GameFontNormal")
numberedLabel:SetPoint("TOPLEFT", 16, yOffset)
numberedLabel:SetText(L.NUMBERED_CHANNELS or "Numbered Channels:")
local numberedEnabled = CreateFrame("CheckButton", "ChatBarNumberedEnabled", content, "UICheckButtonTemplate")
numberedEnabled:SetPoint("TOPLEFT", numberedLabel, "BOTTOMLEFT", 0, -8)
numberedEnabled.text = numberedEnabled:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
numberedEnabled.text:SetPoint("LEFT", numberedEnabled, "RIGHT", 0, 0)
numberedEnabled.text:SetText(L.SHOW_NUMBERED_CHANNELS or "Show numbered channels (General, Trade, LocalDefense, etc.)")
numberedEnabled:SetScript("OnClick", function(self)
local settings = ChatBar:GetSettings()
settings.numberedChannels.enabled = self:GetChecked()
ChatBar:UpdateButtons()
end)
content.numberedEnabled = numberedEnabled
-- Lock Position Section
yOffset = yOffset - 60
local lockLabel = content:CreateFontString(nil, "ARTWORK", "GameFontNormal")
lockLabel:SetPoint("TOPLEFT", 16, yOffset)
lockLabel:SetText("Position:")
local lockPosition = CreateFrame("CheckButton", "ChatBarLockPosition", content, "UICheckButtonTemplate")
lockPosition:SetPoint("TOPLEFT", lockLabel, "BOTTOMLEFT", 0, -8)
lockPosition.text = lockPosition:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
lockPosition.text:SetPoint("LEFT", lockPosition, "RIGHT", 0, 0)
lockPosition.text:SetText("Lock bar position")
lockPosition:SetScript("OnClick", function(self)
local settings = ChatBar:GetSettings()
settings.lockPosition = self:GetChecked()
end)
content.lockPosition = lockPosition
-- Store content reference
panel.content = content
-- Refresh panel callback
panel.refresh = function()
Config:RefreshPanel(panel)
end
-- Auto-refresh on show
panel:SetScript("OnShow", function(self)
if self.refresh then
self.refresh()
end
end)
self.panel = panel
-- Add to interface options using modern Settings API (WoW 12.0.1+)
if Settings and Settings.RegisterCanvasLayoutCategory then
local category = Settings.RegisterCanvasLayoutCategory(panel, panel.name)
Settings.RegisterAddOnCategory(category)
panel.category = category
self.settingsCategory = category
end
return panel
end
-- Refresh panel with current settings
function Config:RefreshPanel(panel)
local content = panel.content
local settings = ChatBar:GetSettings()
-- Profile mode
content.profileAccount:SetChecked(ns.db.profileMode == "account")
content.profileCharacter:SetChecked(ns.db.profileMode == "character")
-- Skin dropdown
if content.skinDropdown then
local skinName = settings.skinName or "Default"
local skin = ns.SkinRegistry and ns.SkinRegistry[skinName]
UIDropDownMenu_SetSelectedValue(content.skinDropdown, skinName)
UIDropDownMenu_SetText(content.skinDropdown, skin and skin.name or skinName)
-- Update description text
if content.skinDescription and skin then
content.skinDescription:SetText(skin.description .. " | by " .. (skin.author or "Unknown"))
end
end
-- Orientation
content.orientationHorizontal:SetChecked(settings.orientation == "horizontal")
content.orientationVertical:SetChecked(settings.orientation == "vertical")
-- Channel checkboxes
for channelType, checkbox in pairs(content.channelCheckboxes) do
if settings.channels[channelType] then
checkbox:SetChecked(settings.channels[channelType].enabled)
end
end
-- Numbered channels
content.numberedEnabled:SetChecked(settings.numberedChannels.enabled)
-- Lock position
content.lockPosition:SetChecked(settings.lockPosition)
-- Font size
if content.fontSizeSlider then
content.fontSizeSlider:SetValue(settings.fontSize or 12)
_G[content.fontSizeSlider:GetName() .. "Text"]:SetText(tostring(math.floor(settings.fontSize or 12)))
end
-- Button size
if content.buttonSizeSlider then
content.buttonSizeSlider:SetValue(settings.buttonSize or 24)
end
-- Text position
if content.textPosInside and content.textPosAbove then
local textPos = settings.textPosition or "inside"
content.textPosInside:SetChecked(textPos == "inside")
content.textPosAbove:SetChecked(textPos == "above")
end
-- Flash notifications
if content.flashCheckbox then
content.flashCheckbox:SetChecked(settings.flashNotifications ~= false)
end
end
-- Open settings panel
function Config:OpenSettings()
if not self.settingsCategory then
local L = ns.L
print(string.format("%s: %s", L.ADDON_NAME, L.MSG_SETTINGS_LOADING))
return
end
if Settings and Settings.OpenToCategory then
Settings.OpenToCategory(self.settingsCategory:GetID())
end
end
-- Register slash commands
function Config:RegisterSlashCommands()
SLASH_CHATBAR1 = "/chatbar"
SLASH_CHATBAR2 = "/cb"
SlashCmdList["CHATBAR"] = function(msg)
ChatBar:HandleSlashCommand(msg)
end
end