@piekasz/wow-mcp 0.0.0-stage → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE +674 -0
  2. package/NOTICE +37 -0
  3. package/README.md +41 -2
  4. package/addon/WowMcp/AuctionTooltip.lua +106 -0
  5. package/addon/WowMcp/Commands.lua +259 -0
  6. package/addon/WowMcp/Compat.lua +167 -0
  7. package/addon/WowMcp/Core.lua +50 -0
  8. package/addon/WowMcp/Events.lua +62 -0
  9. package/addon/WowMcp/Items.lua +314 -0
  10. package/addon/WowMcp/Maps.lua +66 -0
  11. package/addon/WowMcp/MinimapButton.lua +114 -0
  12. package/addon/WowMcp/Options.lua +208 -0
  13. package/addon/WowMcp/Panel.lua +294 -0
  14. package/addon/WowMcp/QuestDb.lua +303 -0
  15. package/addon/WowMcp/QuestRewards.lua +137 -0
  16. package/addon/WowMcp/Sections/ActionBars.lua +54 -0
  17. package/addon/WowMcp/Sections/Auctions.lua +305 -0
  18. package/addon/WowMcp/Sections/Bank.lua +48 -0
  19. package/addon/WowMcp/Sections/Buyback.lua +47 -0
  20. package/addon/WowMcp/Sections/Character.lua +177 -0
  21. package/addon/WowMcp/Sections/Cooldowns.lua +76 -0
  22. package/addon/WowMcp/Sections/Currencies.lua +47 -0
  23. package/addon/WowMcp/Sections/Deaths.lua +43 -0
  24. package/addon/WowMcp/Sections/Dungeons.lua +117 -0
  25. package/addon/WowMcp/Sections/EquipmentSets.lua +83 -0
  26. package/addon/WowMcp/Sections/FlightPaths.lua +145 -0
  27. package/addon/WowMcp/Sections/Friends.lua +70 -0
  28. package/addon/WowMcp/Sections/Group.lua +101 -0
  29. package/addon/WowMcp/Sections/Guide.lua +317 -0
  30. package/addon/WowMcp/Sections/Guild.lua +131 -0
  31. package/addon/WowMcp/Sections/Inspect.lua +100 -0
  32. package/addon/WowMcp/Sections/Inventory.lua +64 -0
  33. package/addon/WowMcp/Sections/Legacy.lua +375 -0
  34. package/addon/WowMcp/Sections/Loot.lua +170 -0
  35. package/addon/WowMcp/Sections/Macros.lua +26 -0
  36. package/addon/WowMcp/Sections/Mail.lua +70 -0
  37. package/addon/WowMcp/Sections/Note.lua +38 -0
  38. package/addon/WowMcp/Sections/Pet.lua +127 -0
  39. package/addon/WowMcp/Sections/Played.lua +52 -0
  40. package/addon/WowMcp/Sections/Probe.lua +79 -0
  41. package/addon/WowMcp/Sections/Professions.lua +129 -0
  42. package/addon/WowMcp/Sections/Pvp.lua +45 -0
  43. package/addon/WowMcp/Sections/QuestDb.lua +106 -0
  44. package/addon/WowMcp/Sections/QuestGiver.lua +45 -0
  45. package/addon/WowMcp/Sections/Quests.lua +146 -0
  46. package/addon/WowMcp/Sections/Recipes.lua +195 -0
  47. package/addon/WowMcp/Sections/Reputation.lua +56 -0
  48. package/addon/WowMcp/Sections/Spells.lua +87 -0
  49. package/addon/WowMcp/Sections/Stable.lua +90 -0
  50. package/addon/WowMcp/Sections/Talents.lua +137 -0
  51. package/addon/WowMcp/Sections/Trainer.lua +58 -0
  52. package/addon/WowMcp/Sections/Vendor.lua +72 -0
  53. package/addon/WowMcp/Sections/XpGains.lua +258 -0
  54. package/addon/WowMcp/Snapshot.lua +412 -0
  55. package/addon/WowMcp/Store.lua +142 -0
  56. package/addon/WowMcp/TalentGrid.lua +171 -0
  57. package/addon/WowMcp/Timing.lua +61 -0
  58. package/addon/WowMcp/TraitTree.lua +158 -0
  59. package/addon/WowMcp/WowMcp.lua +24 -0
  60. package/addon/WowMcp/WowMcp.toc +72 -0
  61. package/bin/wow-mcp.js +248 -0
  62. package/package.json +41 -4
@@ -0,0 +1,208 @@
1
+ -- SPDX-License-Identifier: GPL-3.0-or-later
2
+ -- Copyright (C) 2026 Piekasz (GitHub: Piekario). Author attribution must be kept: see NOTICE.
3
+
4
+ -- Options page in the game menu (Interface / AddOns). It lists the same switches as the /mcp commands and calls the same
5
+ -- setting functions (Snapshot.setEnabled, MinimapButton.setEnabled, Panel.setCompact, AuctionTooltip.setEnabled,
6
+ -- Played.setTracking), so the page and the commands cannot disagree. It never saves a dump and never does anything in
7
+ -- the game: a checkbox only changes a setting.
8
+ -- Both the modern API (Settings.RegisterCanvasLayoutCategory) and the old one (InterfaceOptions_AddCategory) are
9
+ -- supported. Everything runs in pcall: a client with neither API, or with a different one, simply has no page and /mcp works.
10
+
11
+ local _, ns = ...
12
+ local Snapshot, chat = ns.Snapshot, ns.chat
13
+
14
+ local Options = {}
15
+ ns.Options = Options
16
+
17
+ local PAGE_NAME = "WowMcp"
18
+ local COLUMNS, COLUMN_WIDTH, ROW_HEIGHT = 3, 200, 24
19
+
20
+ local panel -- the frame registered in the options (nil: not registered)
21
+ local category -- category object of the modern API
22
+ local attempted = false
23
+ local populated = false
24
+ local checkboxes = {} -- { box = frame, switch = switch }
25
+
26
+ local function sectionSwitch(name)
27
+ return {
28
+ label = name,
29
+ hint = "Collect the " .. name .. " section in the dump. Unchecked: it disappears from the dump (/mcp off " .. name .. ").",
30
+ get = function() return not Snapshot.isDisabled(name) end,
31
+ set = function(enabled)
32
+ Snapshot.setEnabled(name, enabled)
33
+ ns.Panel.refresh()
34
+ end,
35
+ }
36
+ end
37
+
38
+ -- The switches of the page: the general ones, then one per section that can be disabled. Data only (no frames),
39
+ -- so the list is the same however the page is drawn.
40
+ function Options.generalSwitches()
41
+ return {
42
+ {
43
+ label = "Minimap button",
44
+ hint = "Minimap button; left click shows the panel (/mcp minimap).",
45
+ get = ns.MinimapButton.isEnabled,
46
+ set = function(enabled) ns.MinimapButton.setEnabled(enabled) end,
47
+ },
48
+ {
49
+ label = "Compact panel",
50
+ hint = "One-line panel: dump age and the Save button (/mcp compact).",
51
+ get = ns.Panel.isCompact,
52
+ set = function(enabled) ns.Panel.setCompact(enabled) end,
53
+ },
54
+ {
55
+ label = "Auction house price in the item tooltip",
56
+ hint = "Shows the last known auction house price in item tooltips (/mcp ahtip).",
57
+ get = ns.AuctionTooltip.isEnabled,
58
+ set = function(enabled) ns.AuctionTooltip.setEnabled(enabled) end,
59
+ },
60
+ {
61
+ label = "Request played time after login",
62
+ hint = "Used by the progress statistics (/mcp played).",
63
+ get = ns.Played.isTracking,
64
+ set = function(enabled) ns.Played.setTracking(enabled) end,
65
+ },
66
+ }
67
+ end
68
+
69
+ function Options.sectionSwitches()
70
+ local switches = {}
71
+ for _, name in ipairs(Snapshot.sectionNames()) do
72
+ if Snapshot.canDisable(name) then switches[#switches + 1] = sectionSwitch(name) end
73
+ end
74
+ return switches
75
+ end
76
+
77
+ ---------------------------------------------------------------------------
78
+ -- Drawing
79
+ ---------------------------------------------------------------------------
80
+
81
+ local function addText(parent, template, text, x, y)
82
+ local fontString = parent:CreateFontString(nil, "ARTWORK", template)
83
+ fontString:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
84
+ fontString:SetText(text)
85
+ return fontString
86
+ end
87
+
88
+ local function addCheckbox(parent, switch, x, y)
89
+ local box = CreateFrame("CheckButton", nil, parent, "UICheckButtonTemplate")
90
+ box:SetSize(24, 24)
91
+ box:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
92
+ local label = parent:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
93
+ label:SetPoint("LEFT", box, "RIGHT", 2, 0)
94
+ label:SetText(switch.label)
95
+ box:SetScript("OnClick", function(self)
96
+ pcall(switch.set, self:GetChecked() and true or false)
97
+ end)
98
+ box:SetScript("OnEnter", function(self)
99
+ if not GameTooltip then return end
100
+ GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
101
+ GameTooltip:SetText(switch.hint, 1, 1, 1, 1, true)
102
+ GameTooltip:Show()
103
+ end)
104
+ box:SetScript("OnLeave", function() if GameTooltip then GameTooltip:Hide() end end)
105
+ checkboxes[#checkboxes + 1] = { box = box, switch = switch }
106
+ end
107
+
108
+ -- Draws the checkboxes (once, when the page is first shown).
109
+ local function populate(parent)
110
+ local y = -16
111
+ addText(parent, "GameFontNormalLarge", "WowMcp", 16, y)
112
+ y = y - 28
113
+ addText(parent, "GameFontHighlightSmall",
114
+ "The same switches as the /mcp commands. Nothing here saves or does anything in the game: only the Save button or /mcp reload writes to disk.", 16, y)
115
+ y = y - 30
116
+ for _, switch in ipairs(Options.generalSwitches()) do
117
+ addCheckbox(parent, switch, 16, y)
118
+ y = y - ROW_HEIGHT
119
+ end
120
+ y = y - 12
121
+ addText(parent, "GameFontNormal", "Sections in the dump (unchecked: not collected and removed from the dump)", 16, y)
122
+ y = y - 26
123
+ local switches = Options.sectionSwitches()
124
+ local rows = math.ceil(#switches / COLUMNS)
125
+ for index, switch in ipairs(switches) do
126
+ local column, row = math.floor((index - 1) / rows), (index - 1) % rows
127
+ addCheckbox(parent, switch, 16 + column * COLUMN_WIDTH, y - row * ROW_HEIGHT)
128
+ end
129
+ end
130
+
131
+ -- Sets every checkbox from the current settings (the player may have used /mcp in the meantime).
132
+ local function refreshBoxes()
133
+ for _, entry in ipairs(checkboxes) do
134
+ local ok, value = pcall(entry.switch.get)
135
+ if ok then entry.box:SetChecked(value and true or false) end
136
+ end
137
+ end
138
+
139
+ local function onShow()
140
+ if not populated then
141
+ populated = true
142
+ pcall(populate, panel)
143
+ end
144
+ pcall(refreshBoxes)
145
+ end
146
+
147
+ ---------------------------------------------------------------------------
148
+ -- Registering in the client
149
+ ---------------------------------------------------------------------------
150
+
151
+ local function hasModernApi()
152
+ return type(Settings) == "table" and type(Settings.RegisterCanvasLayoutCategory) == "function"
153
+ and type(Settings.RegisterAddOnCategory) == "function"
154
+ end
155
+
156
+ local function hasLegacyApi()
157
+ return type(InterfaceOptions_AddCategory) == "function"
158
+ end
159
+
160
+ local function createPanel()
161
+ if not (hasModernApi() or hasLegacyApi()) or type(CreateFrame) ~= "function" then return nil end
162
+ local frame = CreateFrame("Frame", "WowMcpOptionsPanel", UIParent)
163
+ frame.name = PAGE_NAME
164
+ frame:SetScript("OnShow", onShow)
165
+ if hasModernApi() then
166
+ category = Settings.RegisterCanvasLayoutCategory(frame, PAGE_NAME)
167
+ Settings.RegisterAddOnCategory(category)
168
+ else
169
+ InterfaceOptions_AddCategory(frame)
170
+ end
171
+ return frame
172
+ end
173
+
174
+ -- Creates and registers the page (once). Returns whether the page exists. Never raises an error.
175
+ function Options.register()
176
+ if panel then return true end
177
+ if attempted then return false end
178
+ attempted = true
179
+ local ok, frame = pcall(createPanel)
180
+ if ok and frame then panel = frame end
181
+ return panel ~= nil
182
+ end
183
+
184
+ local function openModern()
185
+ local id = category.GetID and category:GetID() or category.ID
186
+ Settings.OpenToCategory(id)
187
+ end
188
+
189
+ local function openLegacy()
190
+ -- The first call of the old function only opens the menu in some clients, so it is called twice.
191
+ InterfaceOptionsFrame_OpenToCategory(panel)
192
+ InterfaceOptionsFrame_OpenToCategory(panel)
193
+ end
194
+
195
+ -- /mcp options: opens the page when the client has one.
196
+ function Options.open()
197
+ if not Options.register() then
198
+ chat("This client has no options page for addons. The /mcp commands work: /mcp help")
199
+ return false
200
+ end
201
+ local opener = (category and Settings and Settings.OpenToCategory) and openModern
202
+ or (type(InterfaceOptionsFrame_OpenToCategory) == "function" and openLegacy) or nil
203
+ if not opener or not pcall(opener) then
204
+ chat("Could not open the options page. Open the game menu, Options, AddOns, WowMcp.")
205
+ return false
206
+ end
207
+ return true
208
+ end
@@ -0,0 +1,294 @@
1
+ -- SPDX-License-Identifier: GPL-3.0-or-later
2
+ -- Copyright (C) 2026 Piekasz (GitHub: Piekario). Author attribution must be kept: see NOTICE.
3
+
4
+ -- Panel in game: dump age, free bag slots and a "Save" button
5
+ -- (the same as /mcp reload). Works only on a player click: when a window has given new
6
+ -- data, the panel only highlights "Save" and hints, but never saves by itself.
7
+ -- Hovering shows the list of section errors from the last dump.
8
+
9
+ local _, ns = ...
10
+ local plain, callFirst, Compat = ns.Compat.plain, ns.Compat.callFirst, ns.Compat
11
+ local Store, Snapshot, chat = ns.Store, ns.Snapshot, ns.chat
12
+
13
+ local Panel = {}
14
+ ns.Panel = Panel
15
+
16
+ local REFRESH_SECONDS = 5
17
+ local panel
18
+
19
+ local function formatAgeShort(seconds)
20
+ local minutes = math.floor(seconds / 60)
21
+ if minutes < 1 then return "just now" end
22
+ if minutes < 60 then return minutes .. " min ago" end
23
+ if minutes < 48 * 60 then return math.floor(minutes / 60) .. " h " .. (minutes % 60) .. " min ago" end
24
+ return math.floor(minutes / 1440) .. " days ago"
25
+ end
26
+
27
+ -- Age color: green up to an hour, yellow up to two, then red (the data is already stale).
28
+ local function ageColor(seconds)
29
+ if seconds >= 7200 then return "|cffff5555" end
30
+ if seconds >= 3600 then return "|cffffcc00" end
31
+ return "|cff55ff55"
32
+ end
33
+
34
+ local function ageLine(snapshot)
35
+ if not (snapshot and type(snapshot.dumpedAt) == "number") then
36
+ return "Dump: |cffff5555none|r"
37
+ end
38
+ local seconds = time() - snapshot.dumpedAt
39
+ local line = "Dump: " .. ageColor(seconds) .. formatAgeShort(seconds) .. "|r"
40
+ if Snapshot.isUnsaved() then line = line .. " |cffffcc00(unsaved)|r" end
41
+ return line
42
+ end
43
+
44
+ local function freeBagSlots()
45
+ local free = 0
46
+ for bag = 0, NUM_BAG_SLOTS or 4 do
47
+ local r = callFirst({ "C_Container.GetContainerNumFreeSlots", "GetContainerNumFreeSlots" }, bag)
48
+ if r and type(plain(r[1])) == "number" then free = free + r[1] end
49
+ end
50
+ return free
51
+ end
52
+
53
+ local function infoLine(snapshot)
54
+ local line = "Free slots: " .. freeBagSlots()
55
+ if snapshot and type(snapshot.errors) == "table" and #snapshot.errors > 0 then
56
+ line = line .. " |cffff5555errors: " .. #snapshot.errors .. "|r"
57
+ end
58
+ return line
59
+ end
60
+
61
+ -- Hint shown when a window (trainer, bank, auctions...) has given data that is not on disk yet.
62
+ local function saveHint()
63
+ if #Snapshot.pendingWindowSections() == 0 then return "" end
64
+ return "|cffffcc00New window data: click Save|r"
65
+ end
66
+
67
+ local function panelLines()
68
+ local snapshot = Store.savedCurrentCharacter()
69
+ return ageLine(snapshot), infoLine(snapshot), saveHint()
70
+ end
71
+
72
+ -- Highlighting the button is only a sign for the player; only the player clicks it.
73
+ local function highlightSaveButton(on)
74
+ local button = panel.saveButton
75
+ if not button then return end
76
+ if on then button:LockHighlight() else button:UnlockHighlight() end
77
+ end
78
+
79
+ function Panel.refresh()
80
+ if not panel then return end
81
+ local ok, age, info, hint = pcall(panelLines)
82
+ if ok then
83
+ if Store.settings().compact then
84
+ -- Compact mode: one line (dump age, and an asterisk after new window data).
85
+ panel.ageText:SetText(age .. Compat.pick(hint ~= "", " |cffffcc00*|r", ""))
86
+ panel.infoText:SetText("")
87
+ panel.hintText:SetText("")
88
+ else
89
+ panel.ageText:SetText(age)
90
+ panel.infoText:SetText(info)
91
+ panel.hintText:SetText(hint)
92
+ end
93
+ highlightSaveButton(hint ~= "")
94
+ end
95
+ end
96
+
97
+ -- Panel tooltip: section errors from the last dump (read-only, changes nothing).
98
+ local function showErrorsTooltip(owner)
99
+ if not GameTooltip then return end
100
+ local snapshot = Store.savedCurrentCharacter()
101
+ local errors = snapshot and type(snapshot.errors) == "table" and snapshot.errors or {}
102
+ GameTooltip:SetOwner(owner, "ANCHOR_LEFT")
103
+ if #errors == 0 then
104
+ GameTooltip:SetText("WowMcp: no section errors")
105
+ else
106
+ GameTooltip:SetText("WowMcp: section errors (" .. #errors .. ")")
107
+ for _, err in ipairs(errors) do GameTooltip:AddLine(tostring(err), 1, 0.4, 0.4, true) end
108
+ end
109
+ GameTooltip:Show()
110
+ end
111
+
112
+ local function hideTooltip()
113
+ if GameTooltip then GameTooltip:Hide() end
114
+ end
115
+
116
+ local function saveAndReload(reason)
117
+ pcall(Snapshot.dump, reason)
118
+ ReloadUI()
119
+ end
120
+
121
+ local function placeFrame(f)
122
+ local p = Store.settings().panelPoint
123
+ if type(p) == "table" and type(p[1]) == "string" then
124
+ f:SetPoint(p[1], UIParent, p[2] or p[1], tonumber(p[3]) or 0, tonumber(p[4]) or 0)
125
+ else
126
+ f:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", -230, -220)
127
+ end
128
+ end
129
+
130
+ -- The player can drag the panel with the mouse; the position is kept in settings.
131
+ local function makeDraggable(f)
132
+ f:SetClampedToScreen(true)
133
+ f:EnableMouse(true)
134
+ f:SetMovable(true)
135
+ f:RegisterForDrag("LeftButton")
136
+ f:SetScript("OnDragStart", function(self) self:StartMoving() end)
137
+ f:SetScript("OnDragStop", function(self)
138
+ self:StopMovingOrSizing()
139
+ local point, _, relativePoint, x, y = self:GetPoint()
140
+ if point then Store.settings().panelPoint = { point, relativePoint, x, y } end
141
+ end)
142
+ end
143
+
144
+ local function addBackdrop(f)
145
+ if not f.SetBackdrop then return end
146
+ f:SetBackdrop({
147
+ bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
148
+ edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
149
+ tile = true, tileSize = 16, edgeSize = 12,
150
+ insets = { left = 3, right = 3, top = 3, bottom = 3 },
151
+ })
152
+ f:SetBackdropColor(0, 0, 0, 0.8)
153
+ end
154
+
155
+ local function addTexts(f)
156
+ local title = f:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
157
+ title:SetPoint("TOPLEFT", f, "TOPLEFT", 10, -9)
158
+ title:SetText("WowMcp")
159
+ f.titleText = title
160
+ f.ageText = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
161
+ f.ageText:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -5)
162
+ f.infoText = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
163
+ f.infoText:SetPoint("TOPLEFT", f.ageText, "BOTTOMLEFT", 0, -3)
164
+ f.hintText = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
165
+ f.hintText:SetPoint("TOPLEFT", f.infoText, "BOTTOMLEFT", 0, -3)
166
+ end
167
+
168
+ local function addSaveButton(f)
169
+ local save = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
170
+ save:SetSize(80, 20)
171
+ save:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -8, 8)
172
+ save:SetText("Save")
173
+ save:SetScript("OnClick", function() saveAndReload("panel") end)
174
+ save:SetScript("OnEnter", function(self)
175
+ if GameTooltip then
176
+ GameTooltip:SetOwner(self, "ANCHOR_TOP")
177
+ GameTooltip:SetText("Dump character state and /reload\n(same as /mcp reload)")
178
+ GameTooltip:Show()
179
+ end
180
+ end)
181
+ save:SetScript("OnLeave", hideTooltip)
182
+ f.saveButton = save
183
+ end
184
+
185
+ local function addCloseButton(f)
186
+ local close = CreateFrame("Button", nil, f, "UIPanelCloseButton")
187
+ close:SetSize(22, 22)
188
+ close:SetPoint("TOPRIGHT", f, "TOPRIGHT", -1, -1)
189
+ close:SetScript("OnClick", function()
190
+ f:Hide()
191
+ Store.settings().panelHidden = true
192
+ chat("Panel hidden. /mcp panel shows it again.")
193
+ end)
194
+ f.closeButton = close
195
+ end
196
+
197
+ -- Panel layout: normal (four lines, button in the corner) or compact (one line and a Save button).
198
+ -- Changes only the look; the Save button does the same and still only on a player click.
199
+ local function setVisible(region, visible)
200
+ if visible then region:Show() else region:Hide() end
201
+ end
202
+
203
+ local function applyLayout(f)
204
+ local compact = Store.settings().compact and true or false
205
+ for _, region in ipairs({ f.titleText, f.infoText, f.hintText, f.closeButton }) do
206
+ setVisible(region, not compact)
207
+ end
208
+ f.ageText:ClearAllPoints()
209
+ f.saveButton:ClearAllPoints()
210
+ if compact then
211
+ f:SetSize(230, 28)
212
+ f.ageText:SetPoint("LEFT", f, "LEFT", 8, 0)
213
+ f.saveButton:SetSize(64, 20)
214
+ f.saveButton:SetPoint("RIGHT", f, "RIGHT", -4, 0)
215
+ else
216
+ f:SetSize(190, 100)
217
+ f.ageText:SetPoint("TOPLEFT", f.titleText, "BOTTOMLEFT", 0, -5)
218
+ f.saveButton:SetSize(80, 20)
219
+ f.saveButton:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -8, 8)
220
+ end
221
+ end
222
+
223
+ function Panel.isCompact()
224
+ return Store.settings().compact and true or false
225
+ end
226
+
227
+ -- /mcp compact on|off: remembers the choice and switches the panel (if it already exists).
228
+ function Panel.setCompact(enabled)
229
+ Store.settings().compact = Compat.pick(enabled, true, nil)
230
+ if panel then
231
+ pcall(applyLayout, panel)
232
+ Panel.refresh()
233
+ end
234
+ end
235
+
236
+ -- Refreshes the text every few seconds; only reads the time and counts free slots.
237
+ local function refreshPeriodically(f)
238
+ local elapsed = 0
239
+ f:SetScript("OnUpdate", function(_, delta)
240
+ elapsed = elapsed + (delta or 0)
241
+ if elapsed >= REFRESH_SECONDS then
242
+ elapsed = 0
243
+ Panel.refresh()
244
+ end
245
+ end)
246
+ f:SetScript("OnShow", Panel.refresh)
247
+ end
248
+
249
+ local function addErrorsTooltip(f)
250
+ f:SetScript("OnEnter", showErrorsTooltip)
251
+ f:SetScript("OnLeave", hideTooltip)
252
+ end
253
+
254
+ -- Creates the panel (once); returns the frame, or nil when the client lacks CreateFrame/UIParent.
255
+ function Panel.create()
256
+ if panel then return panel end
257
+ if not (CreateFrame and UIParent) then return nil end
258
+ local f = CreateFrame("Frame", "WowMcpPanel", UIParent, BackdropTemplateMixin and "BackdropTemplate" or nil)
259
+ f:SetSize(190, 100)
260
+ placeFrame(f)
261
+ f:SetFrameStrata("MEDIUM")
262
+ makeDraggable(f)
263
+ addBackdrop(f)
264
+ addTexts(f)
265
+ addSaveButton(f)
266
+ addCloseButton(f)
267
+ if Store.settings().compact then pcall(applyLayout, f) end
268
+ addErrorsTooltip(f)
269
+ refreshPeriodically(f)
270
+ panel = f
271
+ Panel.refresh()
272
+ return f
273
+ end
274
+
275
+ -- New window data refreshes the panel immediately, without waiting for the timer.
276
+ Snapshot.onWindowCaptured(Panel.refresh)
277
+
278
+ function Panel.toggle()
279
+ local ok, f = pcall(Panel.create)
280
+ if not ok or not f then
281
+ chat("Could not create the panel: " .. tostring(f))
282
+ return
283
+ end
284
+ local settings = Store.settings()
285
+ if settings.panelHidden then
286
+ settings.panelHidden = nil
287
+ f:Show()
288
+ chat("Panel visible. You can drag it with the mouse.")
289
+ else
290
+ settings.panelHidden = true
291
+ f:Hide()
292
+ chat("Panel hidden. /mcp panel shows it again.")
293
+ end
294
+ end