This repository was archived by the owner on Apr 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathOptions.lua
More file actions
726 lines (621 loc) · 30.1 KB
/
Copy pathOptions.lua
File metadata and controls
726 lines (621 loc) · 30.1 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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
local _, addon = ...
local L = addon.L
-- Options module: manages all user settings and preferences UI
local Options = {}
addon.Options = Options
-- Initialize saved variables with default values
function Options:InitializeSettings()
local wasReset = addon.ConfigManager.CheckAndResetConfig()
if not QuickTravelDB then
QuickTravelDB = {}
end
local DEFAULT_SETTINGS = {
configVersion = addon.ConfigManager.CURRENT_CONFIG_VERSION, -- (number) Config schema version for upgrades/reset
showLoginMessage = true, -- (boolean) Show login message in chat when addon loads
autoClose = true, -- (boolean) Auto-close addon UI after portal use
favorites = {}, -- (table, array of strings) List of favorite portal instanceKeys
useRandomHearthstoneVariant = true, -- (boolean) Use a random owned Hearthstone variant
selectedHearthstoneVariant = nil, -- (number or nil) Selected Hearthstone variant ItemID (if not random)
categoryOrder = addon.ConfigManager.DEFAULT_CATEGORY_ORDER, -- (table, array) User's preferred order and enable state for portal categories
showLFGTab = true, -- (boolean) Show the QuickTravel button in the Group Finder (LFG)
showUnlearnedSpells = false, -- (boolean) Show spells/portals the player has not learned yet
showSpellTooltips = true, -- (boolean) Show tooltips for spells/portals in the UI
frameHeight = 500, -- (number) default height of the main frame
lockFrameHeight = false, -- (boolean) Lock frame height to prevent resizing
showMinimapIcon = true, -- (boolean) show the minimap icon
minimap = { angle = 200 }, -- (table) persists the icon angle around the minimap
}
-- Apply defaults for missing settings
for key, defaultValue in pairs(DEFAULT_SETTINGS) do
if QuickTravelDB[key] == nil then
QuickTravelDB[key] = defaultValue
end
end
self.db = QuickTravelDB
-- Remove any category entry without a 'key' field
if self.db.categoryOrder then
for i = #self.db.categoryOrder, 1, -1 do
if not self.db.categoryOrder[i].key then
table.remove(self.db.categoryOrder, i)
end
end
end
-- Add missing categories to the order list if they don't exist
local allCategories = addon.ConfigManager.DEFAULT_CATEGORY_ORDER
local foundKeys = {}
for _, cat in ipairs(self.db.categoryOrder or {}) do
foundKeys[cat.key] = true
end
for _, defaultCat in ipairs(allCategories) do
if not foundKeys[defaultCat.key] then
table.insert(self.db.categoryOrder, {
key = defaultCat.key,
enabled = defaultCat.enabled,
order = #self.db.categoryOrder + 1
})
end
end
return QuickTravelDB
end
-- Create a visual separator line between UI sections
function Options:CreateSeparator(parent, previousElement, offsetY)
offsetY = offsetY or -15
local separator = parent:CreateTexture(nil, "ARTWORK")
separator:SetHeight(8)
separator:SetPoint("LEFT", parent, "LEFT", 20, 0)
separator:SetPoint("RIGHT", parent, "RIGHT", -20, 0)
separator:SetPoint("TOP", previousElement, "BOTTOM", 0, offsetY)
separator:SetTexture("Interface\\Common\\UI-TooltipDivider-Transparent")
separator:SetAlpha(0.8)
return separator
end
-- Cache system for owned Hearthstone variant toys to avoid repeated API calls
local variantCache = {
ownedVariants = nil,
lastScan = 0,
cacheTimeout = 60
}
-- Get sorted list of owned Hearthstone variant toys with caching
local function GetOwnedHearthstoneVariants(forceRefresh)
local now = GetTime()
if not forceRefresh and variantCache.ownedVariants and (now - variantCache.lastScan < variantCache.cacheTimeout) then
return variantCache.ownedVariants
end
local owned = {}
local constants = addon.constants
if constants and constants.hearthstoneVariants then
for _, variant in ipairs(constants.hearthstoneVariants) do
if PlayerHasToy(variant.id) then
local name = L[variant.nameKey] or ("Hearthstone " .. variant.id)
table.insert(owned, {id = variant.id, name = name})
end
end
table.sort(owned, function(a, b) return a.name < b.name end)
end
variantCache.ownedVariants = owned
variantCache.lastScan = now
return owned
end
-- Clear the Hearthstone variants cache
local function InvalidateVariantCache()
variantCache.ownedVariants = nil
variantCache.lastScan = 0
end
-- Create the main options UI frame with two tabs: Settings and Categories
function Options:CreateOptionsFrame(mainFrame)
if self.optionsFrame then
return self.optionsFrame
end
-- Main options frame using ButtonFrameTemplate
self.optionsFrame = CreateFrame("Frame", "QuickTravelOptionsFrame", UIParent, "ButtonFrameTemplate")
self.optionsFrame:SetFrameStrata("DIALOG")
self.optionsFrame:SetSize(290, 470)
if mainFrame then
self.optionsFrame:SetPoint("TOPLEFT", mainFrame, "TOPRIGHT", 10, 0)
else
self.optionsFrame:SetPoint("CENTER")
end
self.optionsFrame:EnableMouse(true)
-- Hide unwanted elements from ButtonFrameTemplate
ButtonFrameTemplate_HidePortrait(self.optionsFrame)
ButtonFrameTemplate_HideButtonBar(self.optionsFrame)
self.optionsFrame.Inset:Hide()
-- Set frame title
self.optionsFrame:SetTitle(OPTIONS)
-- Register frame for ESC key handling
table.insert(UISpecialFrames, "QuickTravelOptionsFrame")
-- Create tab system for switching between options and categories
local tab1 = CreateFrame("Button", "QuickTravelOptionsTab1", self.optionsFrame, "PanelTabButtonTemplate")
tab1:SetPoint("TOPLEFT", self.optionsFrame, "BOTTOMLEFT", 15, 2)
tab1:SetText(L["OPTIONS_TAB"])
PanelTemplates_TabResize(tab1, 0)
local tab2 = CreateFrame("Button", "QuickTravelOptionsTab2", self.optionsFrame, "PanelTabButtonTemplate")
tab2:SetPoint("LEFT", tab1, "RIGHT", 3, 0)
tab2:SetText(L["CATEGORIES_TAB"])
PanelTemplates_TabResize(tab2, 0)
self.optionsFrame.tab1 = tab1
self.optionsFrame.tab2 = tab2
self.optionsFrame.currentTab = 1
-- Create content frames for each tab
local optionsContent = CreateFrame("Frame", nil, self.optionsFrame)
optionsContent:SetPoint("TOPLEFT", self.optionsFrame, "TOPLEFT", 10, -40)
optionsContent:SetPoint("BOTTOMRIGHT", self.optionsFrame, "BOTTOMRIGHT", -10, 10)
local categoriesContent = CreateFrame("Frame", nil, self.optionsFrame)
categoriesContent:SetPoint("TOPLEFT", self.optionsFrame, "TOPLEFT", 10, -40)
categoriesContent:SetPoint("BOTTOMRIGHT", self.optionsFrame, "BOTTOMRIGHT", -10, 10)
categoriesContent:Hide()
-- Categories tab: scrollable list for reordering and enabling/disabling categories
local categoriesTitle = categoriesContent:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
categoriesTitle:SetPoint("TOPLEFT", categoriesContent, "TOPLEFT", 8, 0)
categoriesTitle:SetText(L["CATEGORIES_ORDER_HEADER"])
categoriesTitle:SetTextColor(1, 0.82, 0)
local categoriesScrollFrame = CreateFrame("ScrollFrame", nil, categoriesContent, "UIPanelScrollFrameTemplate")
categoriesScrollFrame:SetPoint("TOPLEFT", categoriesContent, "TOPLEFT", 0, -20)
categoriesScrollFrame:SetPoint("BOTTOMRIGHT", categoriesContent, "BOTTOMRIGHT", -25, 0)
local categoriesContentFrame = CreateFrame("Frame", nil, categoriesScrollFrame)
categoriesContentFrame:SetSize(300, 1)
categoriesScrollFrame:SetScrollChild(categoriesContentFrame)
-- Store references for later use
self.optionsFrame.categoriesScrollFrame = categoriesScrollFrame
self.optionsFrame.categoriesContentFrame = categoriesContentFrame
self.optionsFrame.optionsContent = optionsContent
self.optionsFrame.categoriesContent = categoriesContent
self.optionsFrame.numTabs = 2
-- Tab click handlers
tab1:SetScript("OnClick", function() self:ShowTab(1) end)
tab2:SetScript("OnClick", function() self:ShowTab(2) end)
PanelTemplates_SetTab(self.optionsFrame, 1)
-- DISPLAY SECTION: checkboxes for UI display options
local displayHeader = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
displayHeader:SetPoint("TOPLEFT", self.optionsFrame.optionsContent, "TOPLEFT", 10, 0)
displayHeader:SetText(L["DISPLAY_HEADER"])
displayHeader:SetTextColor(1, 0.82, 0)
-- Show login message checkbox
local hideLoginCheckbox = CreateFrame("CheckButton", nil, self.optionsFrame.optionsContent, "InterfaceOptionsCheckButtonTemplate")
hideLoginCheckbox:SetPoint("TOPLEFT", displayHeader, "BOTTOMLEFT", 0, -10)
hideLoginCheckbox:SetSize(22, 22)
local showLoginText = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showLoginText:SetPoint("LEFT", hideLoginCheckbox, "RIGHT", 8, 0)
showLoginText:SetText(L["SHOW_LOGIN_MESSAGE"])
showLoginText:SetTextColor(1, 1, 1)
-- Show spell tooltips checkbox
local showTooltipsCheckbox = CreateFrame("CheckButton", nil, self.optionsFrame.optionsContent, "InterfaceOptionsCheckButtonTemplate")
showTooltipsCheckbox:SetPoint("TOPLEFT", hideLoginCheckbox, "BOTTOMLEFT", 0, -10)
showTooltipsCheckbox:SetSize(22, 22)
local showTooltipsText = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showTooltipsText:SetPoint("LEFT", showTooltipsCheckbox, "RIGHT", 8, 0)
showTooltipsText:SetText(L["SHOW_SPELL_TOOLTIPS"])
showTooltipsText:SetTextColor(1, 1, 1)
-- Show unlearned spells checkbox
local showUnlearnedCheckbox = CreateFrame("CheckButton", nil, self.optionsFrame.optionsContent, "InterfaceOptionsCheckButtonTemplate")
showUnlearnedCheckbox:SetPoint("TOPLEFT", showTooltipsCheckbox, "BOTTOMLEFT", 0, -10)
showUnlearnedCheckbox:SetSize(22, 22)
local showUnlearnedText = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showUnlearnedText:SetPoint("LEFT", showUnlearnedCheckbox, "RIGHT", 8, 0)
showUnlearnedText:SetText(L["SHOW_UNLEARNED_SPELLS"])
showUnlearnedText:SetTextColor(1, 1, 1)
-- Show LFG tab checkbox
local showLFGTabCheckbox = CreateFrame("CheckButton", nil, self.optionsFrame.optionsContent, "InterfaceOptionsCheckButtonTemplate")
showLFGTabCheckbox:SetPoint("TOPLEFT", showUnlearnedCheckbox, "BOTTOMLEFT", 0, -10)
showLFGTabCheckbox:SetSize(22, 22)
local showLFGTabText = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showLFGTabText:SetPoint("LEFT", showLFGTabCheckbox, "RIGHT", 8, 0)
showLFGTabText:SetText(L["SHOW_LFG_TAB"])
showLFGTabText:SetTextColor(1, 1, 1)
-- Show minimap icon checkbox
local showMinimapCheckbox = CreateFrame("CheckButton", nil, self.optionsFrame.optionsContent, "InterfaceOptionsCheckButtonTemplate")
showMinimapCheckbox:SetPoint("TOPLEFT", showLFGTabCheckbox, "BOTTOMLEFT", 0, -10)
showMinimapCheckbox:SetSize(22, 22)
local showMinimapText = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showMinimapText:SetPoint("LEFT", showMinimapCheckbox, "RIGHT", 8, 0)
showMinimapText:SetText(L["SHOW_MINIMAP_ICON"])
showMinimapText:SetTextColor(1, 1, 1)
-- BEHAVIOR SECTION: addon behavior settings
local behaviorHeader = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
behaviorHeader:SetPoint("TOPLEFT", showMinimapCheckbox, "BOTTOMLEFT", 0, -25)
behaviorHeader:SetText(L["BEHAVIOR_HEADER"])
behaviorHeader:SetTextColor(1, 0.82, 0)
-- Auto-close frame after teleport checkbox
local autoCloseCheckbox = CreateFrame("CheckButton", nil, self.optionsFrame.optionsContent, "InterfaceOptionsCheckButtonTemplate")
autoCloseCheckbox:SetPoint("TOPLEFT", behaviorHeader, "BOTTOMLEFT", 0, -10)
autoCloseCheckbox:SetSize(22, 22)
local autoCloseText = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
autoCloseText:SetPoint("LEFT", autoCloseCheckbox, "RIGHT", 8, 0)
autoCloseText:SetText(L["AUTO_CLOSE"])
autoCloseText:SetTextColor(1, 1, 1)
-- Lock frame height checkbox
local lockHeightCheckbox = CreateFrame("CheckButton", nil, self.optionsFrame.optionsContent, "InterfaceOptionsCheckButtonTemplate")
lockHeightCheckbox:SetPoint("TOPLEFT", autoCloseCheckbox, "BOTTOMLEFT", 0, -10)
lockHeightCheckbox:SetSize(22, 22)
local lockHeightText = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
lockHeightText:SetPoint("LEFT", lockHeightCheckbox, "RIGHT", 8, 0)
lockHeightText:SetText(L["LOCK_FRAME_HEIGHT"])
lockHeightText:SetTextColor(1, 1, 1)
-- HEARTHSTONE SECTION: Hearthstone variant selection
local hearthstoneHeader = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
hearthstoneHeader:SetPoint("TOPLEFT", lockHeightCheckbox, "BOTTOMLEFT", 0, -25)
hearthstoneHeader:SetText(L["HEARTHSTONE_HEADER"])
hearthstoneHeader:SetTextColor(1, 0.82, 0)
-- Use random Hearthstone variant checkbox
local randomHearthstoneCheckbox = CreateFrame("CheckButton", nil, self.optionsFrame.optionsContent, "InterfaceOptionsCheckButtonTemplate")
randomHearthstoneCheckbox:SetPoint("TOPLEFT", hearthstoneHeader, "BOTTOMLEFT", 0, -10)
randomHearthstoneCheckbox:SetSize(22, 22)
local randomHearthstoneText = self.optionsFrame.optionsContent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
randomHearthstoneText:SetPoint("LEFT", randomHearthstoneCheckbox, "RIGHT", 8, 0)
randomHearthstoneText:SetText(L["USE_RANDOM_HEARTHSTONE_VARIANT"])
randomHearthstoneText:SetTextColor(1, 1, 1)
-- Dropdown for selecting specific Hearthstone variant
local hearthstoneDropdown = CreateFrame("DropdownButton", "QuickTravelHearthstoneDropdown", self.optionsFrame.optionsContent, "WowStyle1DropdownTemplate")
hearthstoneDropdown:SetPoint("TOPLEFT", randomHearthstoneCheckbox, "BOTTOMLEFT", 0, -10)
hearthstoneDropdown:SetWidth(250)
-- Store references for event handling
self.optionsFrame.hideLoginCheckbox = hideLoginCheckbox
self.optionsFrame.autoCloseCheckbox = autoCloseCheckbox
self.optionsFrame.randomHearthstoneCheckbox = randomHearthstoneCheckbox
self.optionsFrame.hearthstoneDropdown = hearthstoneDropdown
self.optionsFrame.showLFGTabCheckbox = showLFGTabCheckbox
self.optionsFrame.showUnlearnedCheckbox = showUnlearnedCheckbox
self.optionsFrame.showTooltipsCheckbox = showTooltipsCheckbox
self.optionsFrame.randomHearthstoneText = randomHearthstoneText
self.optionsFrame.lockHeightCheckbox = lockHeightCheckbox
self.optionsFrame.showMinimapCheckbox = showMinimapCheckbox
self:LoadOptionsValues()
self:SetupEventHandlers()
self.optionsFrame:Hide()
return self.optionsFrame
end
-- Set up event handlers for all interactive UI elements
function Options:SetupEventHandlers()
local QuickTravel = addon.QuickTravel
local constants = addon.constants
-- Login message toggle
self.optionsFrame.hideLoginCheckbox:SetScript("OnClick", function(checkbox)
self.db.showLoginMessage = checkbox:GetChecked()
print("|cff00ff00QuickTravel|r: " .. (self.db.showLoginMessage and L["MSG_LOGIN_MESSAGE_ENABLED"] or L["MSG_LOGIN_MESSAGE_DISABLED"]))
end)
-- Auto-close toggle
self.optionsFrame.autoCloseCheckbox:SetScript("OnClick", function(checkbox)
self.db.autoClose = checkbox:GetChecked()
end)
-- Lock frame height toggle
self.optionsFrame.lockHeightCheckbox:SetScript("OnClick", function(checkbox)
self.db.lockFrameHeight = checkbox:GetChecked()
if QuickTravel then
QuickTravel:UpdateResizeState()
end
end)
-- Random Hearthstone variant toggle
self.optionsFrame.randomHearthstoneCheckbox:SetScript("OnClick", function(checkbox)
self.db.useRandomHearthstoneVariant = checkbox:GetChecked()
self:UpdateHearthstoneControls()
if constants then
constants.DataManager:InvalidateCache()
end
if QuickTravel then
QuickTravel:PopulatePortalList()
end
end)
-- LFG tab visibility toggle
self.optionsFrame.showLFGTabCheckbox:SetScript("OnClick", function(checkbox)
self.db.showLFGTab = checkbox:GetChecked()
if self.db.showLFGTab then
if QuickTravel then
QuickTravel:CreateLFGButton()
end
else
if QuickTravel and QuickTravel.lfgButton then
QuickTravel.lfgButton:Hide()
QuickTravel.lfgButton:SetParent(nil)
QuickTravel.lfgButton = nil
end
end
end)
-- Minimap icon toggle
self.optionsFrame.showMinimapCheckbox:SetScript("OnClick", function(checkbox)
self.db.showMinimapIcon = checkbox:GetChecked()
if addon.QuickTravel then
addon.QuickTravel:ToggleMinimap(self.db.showMinimapIcon)
end
end)
-- Unlearned spells visibility toggle
self.optionsFrame.showUnlearnedCheckbox:SetScript("OnClick", function(checkbox)
self.db.showUnlearnedSpells = checkbox:GetChecked()
if constants then
constants.DataManager:InvalidateCache()
end
if QuickTravel then
QuickTravel:PopulatePortalList()
end
end)
-- Spell tooltips toggle
self.optionsFrame.showTooltipsCheckbox:SetScript("OnClick", function(checkbox)
self.db.showSpellTooltips = checkbox:GetChecked()
end)
end
-- Load saved settings into UI controls
function Options:LoadOptionsValues()
if not self.optionsFrame then return end
self.optionsFrame.hideLoginCheckbox:SetChecked(self.db.showLoginMessage)
self.optionsFrame.autoCloseCheckbox:SetChecked(self.db.autoClose)
self.optionsFrame.randomHearthstoneCheckbox:SetChecked(self.db.useRandomHearthstoneVariant)
self:SetupHearthstoneDropdown()
self:UpdateHearthstoneControls()
self.optionsFrame.showLFGTabCheckbox:SetChecked(self.db.showLFGTab)
self.optionsFrame.showUnlearnedCheckbox:SetChecked(self.db.showUnlearnedSpells)
self.optionsFrame.showTooltipsCheckbox:SetChecked(self.db.showSpellTooltips)
self.optionsFrame.lockHeightCheckbox:SetChecked(self.db.lockFrameHeight)
self.optionsFrame.showMinimapCheckbox:SetChecked(self.db.showMinimapIcon)
self:SetupCategoriesList()
end
-- Display options window, creating it if necessary
function Options:ShowOptionsFrame(mainFrame)
if not self.optionsFrame then
self:CreateOptionsFrame(mainFrame)
self:LoadOptionsValues()
end
self.optionsFrame:Show()
end
-- Hide options window
function Options:HideOptionsFrame()
if self.optionsFrame then
self.optionsFrame:Hide()
end
end
-- Toggle options window visibility
function Options:ToggleOptionsFrame(mainFrame)
if self.optionsFrame and self.optionsFrame:IsShown() then
self:HideOptionsFrame()
else
self:ShowOptionsFrame(mainFrame)
end
end
-- Populate Hearthstone variant dropdown with owned variants
function Options:SetupHearthstoneDropdown()
local dropdown = self.optionsFrame.hearthstoneDropdown
if not dropdown then return end
local ownedVariants = GetOwnedHearthstoneVariants()
-- Set default selection if none exists
if #ownedVariants > 0 and not self.db.selectedHearthstoneVariant then
self.db.selectedHearthstoneVariant = ownedVariants[1].id
end
-- Callback functions...
local function isSelectedCallback(variantID)
return self.db.selectedHearthstoneVariant == variantID
end
local function onSelectionCallback(variantID)
self.db.selectedHearthstoneVariant = variantID
dropdown:GenerateMenu()
if addon.constants then
addon.constants.DataManager:InvalidateCache()
end
if addon.QuickTravel then
addon.QuickTravel:PopulatePortalList()
end
end
-- Setup dropdown menu (WITHOUT icons)
dropdown:SetupMenu(function(dropdown, rootDescription)
if #ownedVariants == 0 then
local disabledButton = rootDescription:CreateButton(L["NO_HEARTHSTONE_VARIANTS"])
disabledButton:SetEnabled(false)
else
for _, variant in ipairs(ownedVariants) do
rootDescription:CreateRadio(
variant.name,
isSelectedCallback,
onSelectionCallback,
variant.id
)
end
end
end)
dropdown:GenerateMenu()
end
-- Update Hearthstone control states based on category and variant availability
function Options:UpdateHearthstoneControls()
if not self.optionsFrame then return end
-- Check if Hearthstones category is enabled
local hearthstonesEnabled = false
if self.db.categoryOrder then
for _, category in ipairs(self.db.categoryOrder) do
if category.key == addon.ConfigManager.CATEGORY_KEYS.HEARTHSTONES and category.enabled then
hearthstonesEnabled = true
break
end
end
else
hearthstonesEnabled = true
end
local ownedVariants = GetOwnedHearthstoneVariants()
local hasVariants = #ownedVariants > 0
local randomEnabled = hearthstonesEnabled and hasVariants
-- Enable/disable random checkbox based on category and variant availability
self.optionsFrame.randomHearthstoneCheckbox:SetEnabled(randomEnabled)
if randomEnabled then
if self.optionsFrame.randomHearthstoneText then
self.optionsFrame.randomHearthstoneText:SetTextColor(1, 1, 1)
end
else
if self.optionsFrame.randomHearthstoneText then
self.optionsFrame.randomHearthstoneText:SetTextColor(0.5, 0.5, 0.5)
end
end
-- Auto-disable random setting if requirements not met
if not hearthstonesEnabled or not hasVariants then
self.optionsFrame.randomHearthstoneCheckbox:SetChecked(false)
self.db.useRandomHearthstoneVariant = false
end
-- Enable/disable dropdown based on random setting
local dropdownEnabled = hearthstonesEnabled and hasVariants and not self.db.useRandomHearthstoneVariant
self.optionsFrame.hearthstoneDropdown:SetEnabled(dropdownEnabled)
-- Refresh dropdown menu
if dropdownEnabled then
self.optionsFrame.hearthstoneDropdown:GenerateMenu()
end
end
-- Switch between options tabs
function Options:ShowTab(tabID)
self.optionsFrame.currentTab = tabID
if tabID == 1 then
self.optionsFrame.optionsContent:Show()
self.optionsFrame.categoriesContent:Hide()
PanelTemplates_SetTab(self.optionsFrame, 1)
else
self.optionsFrame.optionsContent:Hide()
self.optionsFrame.categoriesContent:Show()
PanelTemplates_SetTab(self.optionsFrame, 2)
end
end
-- Create the categories management list with checkboxes and reorder buttons
function Options:SetupCategoriesList()
if not self.optionsFrame or not self.optionsFrame.categoriesContent then
return
end
-- Clear existing category items
local children = {self.optionsFrame.categoriesContent:GetChildren()}
for _, child in ipairs(children) do
child:Hide()
child:SetParent(nil)
end
-- Ensure category order exists
if not self.db.categoryOrder or #self.db.categoryOrder == 0 then
self.db.categoryOrder = addon.ConfigManager.DEFAULT_CATEGORY_ORDER
end
-- Get localized category names and sort by order
local localizedCategories = addon.ConfigManager.GetLocalizedCategoryOrder(self.db.categoryOrder)
table.sort(localizedCategories, function(a, b) return a.order < b.order end)
local yOffset = -30
-- Create UI elements for each category
for i, category in ipairs(localizedCategories) do
local categoryFrame = CreateFrame("Frame", nil, self.optionsFrame.categoriesContent)
categoryFrame:SetSize(280, 30)
categoryFrame:SetPoint("TOPLEFT", self.optionsFrame.categoriesContent, "TOPLEFT", 10, yOffset)
-- Enable/disable checkbox
local checkbox = CreateFrame("CheckButton", nil, categoryFrame, "InterfaceOptionsCheckButtonTemplate")
checkbox:SetPoint("LEFT", categoryFrame, "LEFT", 0, 0)
checkbox:SetSize(22, 22)
checkbox:SetChecked(category.enabled)
checkbox:SetScript("OnClick", function(cb)
-- Update database when checkbox is toggled
for _, dbCategory in ipairs(self.db.categoryOrder) do
if dbCategory.key == category.key then
dbCategory.enabled = cb:GetChecked()
break
end
end
-- Update visual feedback for this category
self:UpdateCategoryVisualState(categoryFrame, cb:GetChecked())
-- Update Hearthstone controls if this is the Hearthstones category
if category.key == addon.ConfigManager.CATEGORY_KEYS.HEARTHSTONES then
self:UpdateHearthstoneControls()
end
-- Refresh UI
if addon.constants then
addon.constants.DataManager:InvalidateCache()
end
if addon.QuickTravel then
addon.QuickTravel:PopulatePortalList()
end
end)
-- Category name
local nameText = categoryFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
nameText:SetPoint("LEFT", checkbox, "RIGHT", 8, 0)
nameText:SetText(category.name)
-- Move up button
local upButton = CreateFrame("Button", nil, categoryFrame)
upButton:SetSize(24, 24)
upButton:SetPoint("RIGHT", categoryFrame, "RIGHT", -50, 0)
upButton:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollUp-Up")
upButton:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollUp-Down")
upButton:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight")
upButton:SetScript("OnClick", function()
self:MoveCategoryUp(i)
end)
-- Move down button
local downButton = CreateFrame("Button", nil, categoryFrame)
downButton:SetSize(24, 24)
downButton:SetPoint("RIGHT", categoryFrame, "RIGHT", -25, 0)
downButton:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Up")
downButton:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Down")
downButton:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight")
downButton:SetScript("OnClick", function()
self:MoveCategoryDown(i)
end)
-- Disable buttons at list boundaries
if i == 1 then
upButton:SetEnabled(false)
end
if i == #localizedCategories then
downButton:SetEnabled(false)
end
-- Store references for visual updates
categoryFrame.nameText = nameText
categoryFrame.upButton = upButton
categoryFrame.downButton = downButton
categoryFrame.checkbox = checkbox
-- Apply initial visual state
self:UpdateCategoryVisualState(categoryFrame, category.enabled)
yOffset = yOffset - 30
end
end
-- Move category up in display order
function Options:MoveCategoryUp(index)
if index <= 1 or not self.db.categoryOrder then return end
-- Swap categories in database
local temp = self.db.categoryOrder[index]
self.db.categoryOrder[index] = self.db.categoryOrder[index - 1]
self.db.categoryOrder[index - 1] = temp
-- Update order values
self.db.categoryOrder[index].order = index
self.db.categoryOrder[index - 1].order = index - 1
-- Refresh UI
self:SetupCategoriesList()
if addon.constants then
addon.constants.DataManager:InvalidateCache()
end
if addon.QuickTravel then
addon.QuickTravel:PopulatePortalList()
end
end
-- Move category down in display order
function Options:MoveCategoryDown(index)
if not self.db.categoryOrder or index >= #self.db.categoryOrder then return end
-- Swap categories in database
local temp = self.db.categoryOrder[index]
self.db.categoryOrder[index] = self.db.categoryOrder[index + 1]
self.db.categoryOrder[index + 1] = temp
-- Update order values
self.db.categoryOrder[index].order = index
self.db.categoryOrder[index + 1].order = index + 1
-- Refresh UI
self:SetupCategoriesList()
if addon.constants then
addon.constants.DataManager:InvalidateCache()
end
if addon.QuickTravel then
addon.QuickTravel:PopulatePortalList()
end
end
-- Update visual state of a category based on enabled/disabled status
function Options:UpdateCategoryVisualState(categoryFrame, isEnabled)
if not categoryFrame then return end
local nameText = categoryFrame.nameText
local upButton = categoryFrame.upButton
local downButton = categoryFrame.downButton
-- Helper function to update button appearance
local function updateButtonAppearance(button, enabled)
if not button then return end
local normalTexture = button:GetNormalTexture()
if normalTexture then
normalTexture:SetDesaturated(not enabled)
end
button:SetAlpha(enabled and 1.0 or 0.5)
end
-- Update text color
if nameText then
nameText:SetTextColor(isEnabled and 1 or 0.4, isEnabled and 1 or 0.4, isEnabled and 1 or 0.4)
end
-- Update both buttons with the helper function
updateButtonAppearance(upButton, isEnabled)
updateButtonAppearance(downButton, isEnabled)
end
return Options