-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.lua
More file actions
355 lines (301 loc) · 13.3 KB
/
Copy pathui.lua
File metadata and controls
355 lines (301 loc) · 13.3 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
local L = _G.CGH_L or {}
local api = _G.CloakFiberHelper and _G.CloakFiberHelper._api or (_G.CloakGemHelper and _G.CloakGemHelper._api)
-- Minimal UI shim: print help and current config
local function printConfig()
if not api then return end
api.ensureDefaults()
local key = api.getPlayerKey()
local cloaks = api.getAllowedCloakIDs() or {}
local csv = table.concat(cloaks, ", ")
print("[CFH] Allowed cloaks: " .. (csv ~= "" and csv or "(none)"))
-- List specs and their desired fiber tier for each game mode
local gameModes = api.getGameModes()
for i = 1, GetNumSpecializations() do
local specID = GetSpecializationInfo(i)
if specID then
local _, specName = GetSpecializationInfoByID(specID)
local outdoorTier = api.getDesiredTierForSpec(specID, gameModes.OUTDOOR)
local mplusTier = api.getDesiredTierForSpec(specID, gameModes.MYTHICPLUS)
local raidTier = api.getDesiredTierForSpec(specID, gameModes.RAID)
local function getTierText(tier)
if not tier then return (L["SPEC_UNASSIGNED"] or "Unassigned") end
local gemTier = api.getGemTiers()[tier]
return gemTier and (L[gemTier.nameKey] or gemTier.nameKey) or tostring(tier)
end
print(string.format("[CFH] %s: Outdoor=%s, M+=%s, Raid=%s",
specName or "?",
getTierText(outdoorTier),
getTierText(mplusTier),
getTierText(raidTier)))
end
end
print("[CFH] Commands: /cfh scan || /cfh sessiondisable || /cfh sessionenable || /cfh cloaks 235499,12345 || /cfh set <crit||haste||versa||mastery> [specID]")
end
function CloakGemHelper_OpenOptions()
-- Ensure panel exists
if not _G.CFHOptionsPanel then
-- createOptionsPanel is local in this file
if type(createOptionsPanel) == "function" then
createOptionsPanel()
end
end
if Settings and Settings.OpenToCategory then
Settings.OpenToCategory("CloakFiberHelperOptions")
elseif InterfaceOptionsFrame_OpenToCategory and _G.CFHOptionsPanel then
InterfaceOptionsFrame_OpenToCategory(_G.CFHOptionsPanel)
C_Timer.After(0, function()
InterfaceOptionsFrame_OpenToCategory(_G.CFHOptionsPanel)
end)
else
-- Fallback: print current config if no options UI is available
printConfig()
end
end
-- Add a small action button to trigger scan instantly
local f
local function ensureScanButton()
if f then return end
f = CreateFrame("Button", "CGHScanButton", UIParent, "UIPanelButtonTemplate")
f:SetSize(120, 24)
f:SetText(L["SCAN_NOW"] or "Scan now")
f:SetPoint("CENTER")
f:Hide()
f:SetScript("OnClick", function()
if CloakGemHelper and CloakGemHelper.ScanCloak then
CloakGemHelper:ScanCloak(true)
end
end)
end
-- Show hint after login
C_Timer.After(5, function()
ensureScanButton()
print("[CFH] " .. (L["UI_OPEN_HINT"] or "Use /cfh to open settings, /cfh scan to scan"))
end)
-- Options → AddOns panel that lists chat commands
local function createOptionsPanel()
local panel = CreateFrame("Frame", "CFHOptionsPanel", UIParent)
local titleText = L["TITLE"] or "Cloak Fiber Helper"
panel.name = titleText
_G.CFHOptionsPanel = panel
local title = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 16, -16)
title:SetText(titleText)
local intro = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
intro:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -12)
intro:SetJustifyH("LEFT")
intro:SetWidth(700)
intro:SetText(L["OPTIONS_INTRO"] or "This addon checks your cloak's fiber category. The following chat commands are available:")
local header = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
header:SetPoint("TOPLEFT", intro, "BOTTOMLEFT", 0, -12)
header:SetText(L["CHAT_COMMANDS"] or "Chat Commands")
local commands = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
commands:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 0, -8)
commands:SetJustifyH("LEFT")
commands:SetWidth(700)
commands:SetText("/cfh scan\n/cfh sessionenable\n/cfh sessiondisable\n/cfh cloaks 235499,12345\n/cfh set <crit||haste||versa||mastery> [specID]\n/cfh show")
-- Cloak Settings section (above fiber/spec settings)
local cloakSection = CreateFrame("Frame", nil, panel)
cloakSection:SetPoint("TOPLEFT", commands, "BOTTOMLEFT", 0, -16)
cloakSection:SetPoint("RIGHT", panel, "RIGHT", -16, 0)
cloakSection:SetHeight(60) -- will be resized in refresh
local cloakHeader = cloakSection:CreateFontString(nil, "ARTWORK", "GameFontNormal")
cloakHeader:SetPoint("TOPLEFT", cloakSection, "TOPLEFT", 0, 0)
cloakHeader:SetText(L["ALLOWED_CLOAK_IDS"] or "Allowed cloak ItemIDs (comma-separated)")
local cloakInput = CreateFrame("EditBox", nil, cloakSection, "InputBoxTemplate")
cloakInput:SetSize(160, 24)
cloakInput:SetAutoFocus(false)
cloakInput:SetPoint("TOPLEFT", cloakHeader, "BOTTOMLEFT", 0, -6)
cloakInput:SetCursorPosition(0)
cloakInput:SetTextInsets(4, 4, 2, 2)
cloakInput:SetMaxLetters(10)
local addBtn = CreateFrame("Button", nil, cloakSection, "UIPanelButtonTemplate")
addBtn:SetSize(80, 22)
addBtn:SetPoint("LEFT", cloakInput, "RIGHT", 8, 0)
addBtn:SetText(L["ADD"] or "Add")
local listHeader = cloakSection:CreateFontString(nil, "ARTWORK", "GameFontNormal")
listHeader:SetPoint("TOPLEFT", cloakInput, "BOTTOMLEFT", 0, -10)
listHeader:SetText(L["CURRENT_CLOAKS"] or "Current cloaks")
cloakSection._rows = {}
local function setAllowedFromList(idList)
table.sort(idList)
local parts = {}
for _, id in ipairs(idList) do table.insert(parts, tostring(id)) end
if api and api.setAllowedCloakIDs then
api.setAllowedCloakIDs(table.concat(parts, ","))
end
end
local function getAllowedListCopy()
if not api then return {} end
api.ensureDefaults()
local ids = api.getAllowedCloakIDs() or {}
local copy = {}
for i = 1, #ids do copy[i] = ids[i] end
return copy
end
local function refreshCloakList()
local ids = getAllowedListCopy()
table.sort(ids)
local yAnchor = listHeader
local totalHeight = 0
for index, itemID in ipairs(ids) do
local row = cloakSection._rows[index]
if not row then
row = {}
row.name = cloakSection:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
row.remove = CreateFrame("Button", nil, cloakSection, "UIPanelButtonTemplate")
row.remove:SetSize(70, 20)
row.remove:SetText(L["REMOVE"] or "Remove")
cloakSection._rows[index] = row
end
row.name:ClearAllPoints()
row.name:SetPoint("TOPLEFT", yAnchor, "BOTTOMLEFT", 0, -6)
row.name:SetWidth(520)
row.name:SetJustifyH("LEFT")
local name = GetItemInfo(itemID)
if not name and Item and Item.CreateFromItemID then
local obj = Item:CreateFromItemID(itemID)
obj:ContinueOnItemLoad(function()
if panel:IsShown() then refreshCloakList() end
end)
end
row.name:SetText((name or (L["ITEM_UNKNOWN"] or "Item") .. " #" .. tostring(itemID)) .. " (" .. tostring(itemID) .. ")")
row.remove:ClearAllPoints()
row.remove:SetPoint("LEFT", row.name, "RIGHT", 8, 0)
row.remove:SetScript("OnClick", function()
local current = getAllowedListCopy()
local nextList = {}
for _, id in ipairs(current) do if id ~= itemID then table.insert(nextList, id) end end
setAllowedFromList(nextList)
refreshCloakList()
end)
yAnchor = row.name
totalHeight = totalHeight + 26
end
-- Hide extra rows if count shrank
for i = #ids + 1, #cloakSection._rows do
local row = cloakSection._rows[i]
if row then
if row.name then row.name:SetText("") end
if row.remove then row.remove:Hide() end
end
end
-- Re-show remove buttons for visible rows
for i = 1, #ids do
local row = cloakSection._rows[i]
if row and row.remove then row.remove:Show() end
end
cloakSection:SetHeight(46 + totalHeight)
end
addBtn:SetScript("OnClick", function()
local txt = (cloakInput:GetText() or ""):gsub("%s+", "")
local id = tonumber(txt)
if id then
local list = getAllowedListCopy()
local exists = false
for _, v in ipairs(list) do if v == id then exists = true break end end
if not exists then table.insert(list, id) end
setAllowedFromList(list)
cloakInput:SetText("")
refreshCloakList()
else
UIErrorsFrame:AddMessage(L["INVALID_ITEM_ID"] or "Invalid ItemID", 1.0, 0.1, 0.1, 1.0)
end
end)
-- Initial population of the cloak list (will update names asynchronously when item info arrives)
C_Timer.After(0.1, refreshCloakList)
-- Header for per-spec desired fiber selection
local specHeader = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
specHeader:SetPoint("TOPLEFT", cloakSection, "BOTTOMLEFT", 0, -16)
specHeader:SetText(L["DESIRED_FIBER_PER_SPEC"] or "Desired Fiber per Specialization")
-- Build spec table when the panel is shown the first time
panel._builtSpecs = false
local function buildSpecTable()
if panel._builtSpecs then return end
panel._builtSpecs = true
if not api then return end
api.ensureDefaults()
local gemTiers = api.getGemTiers() or {}
local tierChoices = {
{ value = nil, text = "-" },
{ value = 1, text = (L[gemTiers[1] and gemTiers[1].nameKey or "CRIT"] or "Critical Strike") },
{ value = 2, text = (L[gemTiers[2] and gemTiers[2].nameKey or "HASTE"] or "Haste") },
{ value = 3, text = (L[gemTiers[3] and gemTiers[3].nameKey or "VERS"] or "Versatility") },
{ value = 4, text = (L[gemTiers[4] and gemTiers[4].nameKey or "MASTERY"] or "Mastery") },
}
local gameModes = api.getGameModes()
local gameModeNames = api.getGameModeNames()
-- Create table header
local headerY = -12
local colWidth = 120
local rowHeight = 30
local dropdownWidth = colWidth - 10
local startX = 150
-- Column headers - center them over the dropdowns
local outdoorHeader = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
outdoorHeader:SetPoint("TOPLEFT", specHeader, "BOTTOMLEFT", startX + (dropdownWidth / 2), headerY)
outdoorHeader:SetJustifyH("CENTER")
outdoorHeader:SetText(L["OUTDOOR"] or "Outdoor")
local mplusHeader = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
mplusHeader:SetPoint("TOPLEFT", specHeader, "BOTTOMLEFT", startX + colWidth + (dropdownWidth / 2), headerY)
mplusHeader:SetJustifyH("CENTER")
mplusHeader:SetText(L["MYTHICPLUS"] or "M+")
local raidHeader = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
raidHeader:SetPoint("TOPLEFT", specHeader, "BOTTOMLEFT", startX + (colWidth * 2) + (dropdownWidth / 2), headerY)
raidHeader:SetJustifyH("CENTER")
raidHeader:SetText(L["RAID"] or "Raid")
local key = api.getPlayerKey()
local db = _G.CloakFiberHelperDB and _G.CloakFiberHelperDB[key]
-- Create rows for each specialization
for i = 1, (GetNumSpecializations() or 0) do
local specID = GetSpecializationInfo(i)
if specID then
local _, specName = GetSpecializationInfoByID(specID)
local yOffset = headerY - (i * rowHeight)
-- Spec name label
local specLabel = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
specLabel:SetPoint("TOPLEFT", specHeader, "BOTTOMLEFT", 0, yOffset)
specLabel:SetWidth(140)
specLabel:SetJustifyH("LEFT")
specLabel:SetText(specName or ("Spec %d"):format(i))
-- Create dropdowns for each game mode
local dropdowns = {}
local xOffsets = {startX, startX + colWidth, startX + (colWidth * 2)}
for modeIndex, gameMode in ipairs({gameModes.OUTDOOR, gameModes.MYTHICPLUS, gameModes.RAID}) do
local dropdown = CreateFrame("Frame", nil, panel, "UIDropDownMenuTemplate")
dropdown:SetPoint("TOPLEFT", specHeader, "BOTTOMLEFT", xOffsets[modeIndex], yOffset + 5)
UIDropDownMenu_SetWidth(dropdown, dropdownWidth)
UIDropDownMenu_Initialize(dropdown, function(self, level)
for _, choice in ipairs(tierChoices) do
local info = UIDropDownMenu_CreateInfo()
info.text = choice.text
info.value = choice.value
info.func = function()
UIDropDownMenu_SetSelectedValue(dropdown, choice.value)
if api and api.setDesiredTierForSpec then
api.setDesiredTierForSpec(specID, choice.value, gameMode)
end
end
UIDropDownMenu_AddButton(info, level)
end
end)
-- Set current value
local current = api.getDesiredTierForSpec and api.getDesiredTierForSpec(specID, gameMode) or nil
if current then
UIDropDownMenu_SetSelectedValue(dropdown, current)
end
dropdowns[gameMode] = dropdown
end
end
end
end
panel:SetScript("OnShow", buildSpecTable)
if Settings and Settings.RegisterAddOnCategory and Settings.RegisterCanvasLayoutCategory then
local category = Settings.RegisterCanvasLayoutCategory(panel, titleText)
category.ID = "CloakFiberHelperOptions"
Settings.RegisterAddOnCategory(category)
elseif InterfaceOptions_AddCategory then
InterfaceOptions_AddCategory(panel)
end
end
-- Create the panel shortly after load so it appears under Options → AddOns
C_Timer.After(0, createOptionsPanel)