-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.lua
More file actions
109 lines (95 loc) · 3.14 KB
/
Config.lua
File metadata and controls
109 lines (95 loc) · 3.14 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
local ADDON, NS = ...
-- Ensure DB shape
local function EnsureDB()
MischievousAddonDB = MischievousAddonDB or {}
MischievousAddonDB.specs = MischievousAddonDB.specs or {}
end
-- Build spec list for player's class
local function GetClassSpecs()
local specs = {}
local _, _, classID = UnitClass("player")
if not classID then return specs end
local num = GetNumSpecializationsForClassID(classID)
if not num or num == 0 then return specs end
for i = 1, num do
local specID, name = GetSpecializationInfoForClassID(classID, i)
if specID and name then
table.insert(specs, name)
end
end
table.sort(specs)
return specs
end
-- UI frame
local cfg = CreateFrame("Frame", "MischievousConfigFrame", UIParent, "BasicFrameTemplateWithInset")
cfg:SetSize(360, 260)
cfg:SetPoint("CENTER")
cfg:Hide()
cfg:SetMovable(true)
cfg:EnableMouse(true)
cfg:RegisterForDrag("LeftButton")
cfg:SetScript("OnDragStart", cfg.StartMoving)
cfg:SetScript("OnDragStop", cfg.StopMovingOrSizing)
cfg.title = cfg:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
cfg.title:SetPoint("TOP", 0, -10)
cfg.title:SetText("Mischievous: Spec Setup")
cfg.desc = cfg:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
cfg.desc:SetPoint("TOPLEFT", 16, -38)
cfg.desc:SetJustifyH("LEFT")
cfg.desc:SetText("Choose one or more specs to show in your guild note.\n(Used only if your guild is |cff00ff88Mischievous|r.)")
-- Checkbox container
local boxContainer = CreateFrame("Frame", nil, cfg)
boxContainer:SetPoint("TOPLEFT", 16, -72)
boxContainer:SetSize(328, 140)
local checkboxes = {}
local function RebuildCheckboxes()
EnsureDB()
-- Wipe old
for _, cb in ipairs(checkboxes) do cb:Hide() end
wipe(checkboxes)
local specs = GetClassSpecs()
local y = 0
for i, name in ipairs(specs) do
local cb = CreateFrame("CheckButton", nil, boxContainer, "ChatConfigCheckButtonTemplate")
cb:SetPoint("TOPLEFT", 0, -y)
cb.Text:SetText(name)
cb:SetChecked(MischievousAddonDB.specs[name] == true)
cb:SetScript("OnClick", function(self)
EnsureDB()
MischievousAddonDB.specs[name] = self:GetChecked() or nil
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
end)
table.insert(checkboxes, cb)
y = y + 28
end
end
-- Buttons
cfg.save = CreateFrame("Button", nil, cfg, "UIPanelButtonTemplate")
cfg.save:SetSize(100, 24)
cfg.save:SetPoint("BOTTOMRIGHT", -16, 16)
cfg.save:SetText("Save")
cfg.save:SetScript("OnClick", function()
EnsureDB()
-- Require at least one spec
local any = false
for _, on in pairs(MischievousAddonDB.specs) do if on then any = true break end end
if not any then
UIErrorsFrame:AddMessage("Please select at least one spec.", 1, 0.1, 0.1)
return
end
HideUIPanel(cfg)
C_Timer.After(0.2, function()
if NS and NS._UpdateNoteIfNeeded then NS._UpdateNoteIfNeeded() end
end)
end)
cfg.cancel = CreateFrame("Button", nil, cfg, "UIPanelButtonTemplate")
cfg.cancel:SetSize(100, 24)
cfg.cancel:SetPoint("BOTTOMLEFT", 16, 16)
cfg.cancel:SetText("Cancel")
cfg.cancel:SetScript("OnClick", function() HideUIPanel(cfg) end)
-- Public entry
function NS.ShowConfig()
EnsureDB()
RebuildCheckboxes()
ShowUIPanel(cfg)
end