-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
542 lines (477 loc) · 18.7 KB
/
Core.lua
File metadata and controls
542 lines (477 loc) · 18.7 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
local addonName, ns = ...
ns.addonName = addonName
ns.FRAME_WIDTH = 940
ns.FRAME_HEIGHT = 700
ns.SLOT_SIZE = 52
ns.SLOT_SPACING = 5
ns.STATS_WIDTH = 290
ns.LEFT_SLOTS = {
{ id = 1, name = "HeadSlot", label = HEADSLOT or "Head" },
{ id = 2, name = "NeckSlot", label = NECKSLOT or "Neck" },
{ id = 3, name = "ShoulderSlot", label = SHOULDERSLOT or "Shoulders" },
{ id = 15, name = "BackSlot", label = BACKSLOT or "Back" },
{ id = 5, name = "ChestSlot", label = CHESTSLOT or "Chest" },
{ id = 4, name = "ShirtSlot", label = SHIRTSLOT or "Shirt" },
{ id = 19, name = "TabardSlot", label = TABARDSLOT or "Tabard" },
{ id = 9, name = "WristSlot", label = WRISTSLOT or "Wrists" },
}
ns.RIGHT_SLOTS = {
{ id = 10, name = "HandsSlot", label = HANDSSLOT or "Hands" },
{ id = 6, name = "WaistSlot", label = WAISTSLOT or "Waist" },
{ id = 7, name = "LegsSlot", label = LEGSSLOT or "Legs" },
{ id = 8, name = "FeetSlot", label = FEETSLOT or "Feet" },
{ id = 11, name = "Finger0Slot", label = FINGER0SLOT or "Ring 1" },
{ id = 12, name = "Finger1Slot", label = FINGER1SLOT or "Ring 2" },
{ id = 13, name = "Trinket0Slot", label = TRINKET0SLOT or "Trinket 1" },
{ id = 14, name = "Trinket1Slot", label = TRINKET1SLOT or "Trinket 2" },
}
ns.BOTTOM_SLOTS = {
{ id = 16, name = "MainHandSlot", label = MAINHANDSLOT or "Main Hand" },
{ id = 17, name = "SecondaryHandSlot", label = SECONDARYHANDSLOT or "Off Hand" },
}
-- Fallback texture file IDs for when GetInventorySlotInfo
-- no longer returns a texture in modern WoW clients
ns.EMPTY_SLOT_TEXTURES = {
[1] = 136516,
[2] = 136519,
[3] = 136526,
[4] = 136525,
[5] = 136512,
[6] = 136529,
[7] = 136517,
[8] = 136513,
[9] = 136530,
[10] = 136515,
[11] = 136514,
[12] = 136514,
[13] = 136528,
[14] = 136528,
[15] = 136512,
[16] = 136518,
[17] = 136524,
[19] = 136527,
}
--- Apply user-configured scale to all MCU frames.
function ns:ApplyFrameScale()
if not ns.db or not ns.db.global then return end
local charScale = (ns.db.global.characterScale or 100) / 100
local inspScale = (ns.db.global.inspectScale or 100) / 100
if ModernCharacterUIFrame then
ModernCharacterUIFrame:SetScale(charScale)
end
if MCUInspectFrame then
MCUInspectFrame:SetScale(inspScale)
end
-- Dressing room uses FitToScreen on top of the user scale
if MCUDressingRoomFrame and MCUDressingRoomFrame.FitToScreen then
MCUDressingRoomFrame:FitToScreen()
end
end
--- Apply user-configured font size to all equipment slot overlay text.
function ns:ApplySlotFontSize()
if not ns.db or not ns.db.global then return end
local fontSize = ns.db.global.slotFontSize or 10
local upgradeFontSize = max(fontSize - 1, 8)
local style = ns.db.global.slotOverlayStyle or "none"
local fontFlags = (style == "thick_outline") and "OUTLINE, THICKOUTLINE" or "OUTLINE"
local function ApplyToButton(btn)
if btn.ilvlText then
btn.ilvlText:SetFont(STANDARD_TEXT_FONT, fontSize, fontFlags)
end
if btn.upgradeText then
btn.upgradeText:SetFont(STANDARD_TEXT_FONT, upgradeFontSize, fontFlags)
end
if btn.overlays then
if btn.overlays.shadowIlvl then
btn.overlays.shadowIlvl:SetFont(STANDARD_TEXT_FONT, fontSize, fontFlags)
end
if btn.overlays.shadowUpgrade then
btn.overlays.shadowUpgrade:SetFont(STANDARD_TEXT_FONT, upgradeFontSize, fontFlags)
end
end
end
if ns.slotButtons then
for _, btn in pairs(ns.slotButtons) do ApplyToButton(btn) end
end
if MCUInspectFrame and MCUInspectFrame.slotButtons then
for _, btn in pairs(MCUInspectFrame.slotButtons) do ApplyToButton(btn) end
end
end
--- Apply the selected overlay readability style to all slot buttons.
function ns:ApplySlotOverlayStyle()
if not ns.db or not ns.db.global then return end
local style = ns.db.global.slotOverlayStyle or "none"
local function ApplyToButton(btn)
if not btn.overlays then return end
local o = btn.overlays
o.darken:SetShown(style == "darken")
o.gradBot:SetShown(style == "gradient")
o.gradTop:SetShown(style == "gradient")
-- gradTL and cornerTL are managed per-slot based on enchant visibility
o.cornerBR:SetShown(style == "corners")
o.cornerTR:SetShown(style == "corners")
-- Drop shadow: sync text with ilvl/upgrade values on each refresh
local showShadow = (style == "shadow")
o.shadowIlvl:SetShown(showShadow)
o.shadowUpgrade:SetShown(showShadow and btn.upgradeText and btn.upgradeText:IsShown())
if showShadow then
o.shadowIlvl:SetText(btn.ilvlText and btn.ilvlText:GetText() or "")
o.shadowUpgrade:SetText(btn.upgradeText and btn.upgradeText:GetText() or "")
end
end
if ns.slotButtons then
for _, btn in pairs(ns.slotButtons) do ApplyToButton(btn) end
end
if MCUInspectFrame and MCUInspectFrame.slotButtons then
for _, btn in pairs(MCUInspectFrame.slotButtons) do ApplyToButton(btn) end
end
end
function ns:ApplyStatsFontSize()
if not ns.db or not ns.db.global then return end
local fontSize = ns.db.global.statsFontSize or 12
local headerFontSize = ns.db.global.statsHeaderFontSize or 13
if ns.statFontStrings then
for _, pair in ipairs(ns.statFontStrings) do
if pair.label then pair.label:SetFont(STANDARD_TEXT_FONT, fontSize, "") end
if pair.value then pair.value:SetFont(STANDARD_TEXT_FONT, fontSize, "") end
end
end
if ns.statHeaderFontStrings then
for _, fs in ipairs(ns.statHeaderFontStrings) do
fs:SetFont(STANDARD_TEXT_FONT, headerFontSize, "")
end
end
end
function ns:ApplyRepFontSize()
if not ns.db or not ns.db.global then return end
local fontSize = ns.db.global.repFontSize or 16
local barFontSize = max(fontSize - 1, 8)
if ns.repEntries then
for _, entry in ipairs(ns.repEntries) do
if entry.barText then entry.barText:SetFont(STANDARD_TEXT_FONT, barFontSize, "OUTLINE") end
if entry.standing then entry.standing:SetFont(STANDARD_TEXT_FONT, barFontSize, "OUTLINE") end
end
end
if ns.UpdateReputation then ns:UpdateReputation() end
end
function ns:ApplyCurrencyFontSize()
if not ns.db or not ns.db.global then return end
local fontSize = ns.db.global.currencyFontSize or 16
if ns.currEntries then
for _, entry in ipairs(ns.currEntries) do
if entry.qty then entry.qty:SetFont(STANDARD_TEXT_FONT, fontSize, "") end
if entry.detail then entry.detail:SetFont(STANDARD_TEXT_FONT, max(fontSize - 1, 8), "") end
end
end
if ns.UpdateCurrency then ns:UpdateCurrency() end
end
function ns:ApplyIconStyle()
if not ns.db or not ns.db.global then return end
local rounded = ns.db.global.roundedIcons
local function Apply(btn)
if not btn or not btn.icon then return end
local icon = btn.icon
if rounded then
if not btn._mcuIconMask and btn.CreateMaskTexture then
local mask = btn:CreateMaskTexture()
mask:SetAllPoints(icon)
mask:SetTexture("Interface\\COMMON\\common-iconmask", "CLAMPTOBLACKADDITIVE", "CLAMPTOBLACKADDITIVE")
icon:AddMaskTexture(mask)
btn._mcuIconMask = mask
end
icon:SetTexCoord(0, 1, 0, 1)
-- Hide square borders, show rounded border overlay
if btn.borderTextures then
for _, t in ipairs(btn.borderTextures) do t:Hide() end
end
if btn._mcuRoundedBorder then
btn._mcuRoundedBorder:Hide()
end
if btn.ilvlText then
btn.ilvlText:ClearAllPoints()
btn.ilvlText:SetPoint("BOTTOMRIGHT", -6, 5)
end
if btn.upgradeText then
btn.upgradeText:ClearAllPoints()
btn.upgradeText:SetPoint("TOPRIGHT", -5, -6)
end
if btn.enchantWarning then
btn.enchantWarning:ClearAllPoints()
btn.enchantWarning:SetPoint("TOPLEFT", 5, -5)
end
else
if btn._mcuIconMask then
icon:RemoveMaskTexture(btn._mcuIconMask)
btn._mcuIconMask = nil
end
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
-- Restore overlay positions for square mode
if btn.ilvlText then
btn.ilvlText:ClearAllPoints()
btn.ilvlText:SetPoint("BOTTOMRIGHT", -3, 3)
end
if btn.upgradeText then
btn.upgradeText:ClearAllPoints()
btn.upgradeText:SetPoint("TOPRIGHT", -2, -4)
end
if btn.enchantWarning then
btn.enchantWarning:ClearAllPoints()
btn.enchantWarning:SetPoint("TOPLEFT", 2, -2)
end
-- Restore square borders, hide rounded border
if btn.borderTextures then
for _, t in ipairs(btn.borderTextures) do t:Show() end
end
if btn._mcuRoundedBorder then
btn._mcuRoundedBorder:Hide()
end
end
end
if ns.slotButtons then
for _, btn in pairs(ns.slotButtons) do Apply(btn) end
end
if MCUInspectFrame and MCUInspectFrame.slotButtons then
for _, btn in pairs(MCUInspectFrame.slotButtons) do Apply(btn) end
end
end
--- Try the two-return form of GetInventorySlotInfo first; fall back to the
--- pre-baked file-ID table above.
function ns:GetEmptySlotTexture(slotID, slotName)
local id, texture = GetInventorySlotInfo(slotName)
if texture and texture ~= 0 then
return texture
end
return self.EMPTY_SLOT_TEXTURES[slotID] or 136516
end
function ns:FormatPercent(value)
return format("%.2f%%", value or 0)
end
function ns:FormatStat(value)
if not value then return "0" end
return BreakUpLargeNumbers(floor(value))
end
--- Return r, g, b for an item quality (0-8). Falls back to white.
function ns:GetQualityColor(quality)
if quality then
local r, g, b = GetItemQualityColor(quality)
return r, g, b
end
return 1, 1, 1
end
--- Returns true when the player is in a PvP context where PvP item levels apply.
function ns:IsInPvPZone()
if C_PvP then
if C_PvP.IsPVPMap and C_PvP.IsPVPMap() then return true end
if C_PvP.IsWarModeActive and C_PvP.IsWarModeActive() then return true end
end
if IsActiveBattlefieldArena and IsActiveBattlefieldArena() then return true end
return false
end
--- Get the PvP item level for an equipped slot by scanning tooltip data.
--- Returns the PvP ilvl number, or nil if the item has no PvP ilvl.
function ns:GetPvPItemLevel(slotID)
if not C_TooltipInfo or not C_TooltipInfo.GetInventoryItem then return nil end
local data = C_TooltipInfo.GetInventoryItem("player", slotID)
if not data or not data.lines then return nil end
for _, line in ipairs(data.lines) do
local text = line.leftText
if text then
-- Match the localized "PvP Item Level %d" string if available
if PVP_ITEM_LEVEL_TOOLTIP then
local pattern = PVP_ITEM_LEVEL_TOOLTIP:gsub("%%d", "(%%d+)")
local pvpIlvl = text:match(pattern)
if pvpIlvl then return tonumber(pvpIlvl) end
end
-- Fallback: match English "PvP Item Level 123"
local pvpIlvl = text:match("PvP Item Level (%d+)")
if pvpIlvl then return tonumber(pvpIlvl) end
end
end
return nil
end
--- Create a filter/gear button and its dropdown panel.
--- Returns filterBtn, dropdown, and helper functions.
--- addRadio(label, isChecked, onClick)
--- addCheckbox(label, isChecked, onClick)
--- addAction(label, onClick)
--- addDivider()
--- refreshAll() -- call after options change to update checks
local filterDropdownCount = 0
function ns:CreateFilterDropdown(parent, anchorFrame)
filterDropdownCount = filterDropdownCount + 1
local ddName = "ModernCharacterUIFilterDD" .. filterDropdownCount
local filterBtn = CreateFrame("Button", nil, parent)
filterBtn:SetSize(28, 28)
filterBtn:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -6, -2)
local fbNormal = filterBtn:CreateTexture(nil, "ARTWORK")
fbNormal:SetAllPoints()
fbNormal:SetAtlas("common-button-square-gray-up")
filterBtn:SetNormalTexture(fbNormal)
local fbHL = filterBtn:CreateTexture(nil, "HIGHLIGHT")
fbHL:SetAllPoints()
fbHL:SetAtlas("common-button-square-gray-up")
fbHL:SetAlpha(0.4)
filterBtn:SetHighlightTexture(fbHL)
local fbPushed = filterBtn:CreateTexture(nil, "ARTWORK")
fbPushed:SetAllPoints()
fbPushed:SetAtlas("common-button-square-gray-down")
filterBtn:SetPushedTexture(fbPushed)
local fbIcon = filterBtn:CreateTexture(nil, "OVERLAY")
fbIcon:SetSize(16, 16)
fbIcon:SetPoint("CENTER")
fbIcon:SetTexture("Interface\\Buttons\\UI-OptionsButton")
filterBtn.icon = fbIcon
local dropdown = CreateFrame("Frame", ddName, UIParent, "BackdropTemplate")
dropdown:SetWidth(240)
dropdown:SetFrameStrata("DIALOG")
dropdown:SetFrameLevel(200)
dropdown:SetClampedToScreen(true)
dropdown:Hide()
dropdown:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
dropdown:SetBackdropColor(0.06, 0.06, 0.08, 0.97)
dropdown:SetBackdropBorderColor(0.35, 0.35, 0.35, 0.9)
tinsert(UISpecialFrames, ddName)
if ns.frame then
ns.frame:HookScript("OnHide", function()
dropdown:Hide()
end)
end
local options = {}
local yOffset = -8
local refreshAll -- forward declaration so closures below can reference it
local function AddOption(opt)
options[#options + 1] = opt
end
local function RebuildLayout()
yOffset = -8
for _, opt in ipairs(options) do
if opt.frame then
opt.frame:ClearAllPoints()
opt.frame:SetPoint("TOPLEFT", dropdown, "TOPLEFT", 8, yOffset)
opt.frame:SetPoint("TOPRIGHT", dropdown, "TOPRIGHT", -8, yOffset)
yOffset = yOffset - opt.height
end
end
dropdown:SetHeight(math.abs(yOffset) + 8)
end
local function addRadio(label, isCheckedFn, onClick)
local row = CreateFrame("Button", nil, dropdown)
row:SetHeight(20)
local check = row:CreateTexture(nil, "ARTWORK")
check:SetSize(12, 12)
check:SetPoint("LEFT", 2, 0)
check:SetAtlas("common-icon-checkmark")
row.check = check
local text = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
text:SetPoint("LEFT", 18, 0)
text:SetPoint("RIGHT", -4, 0)
text:SetJustifyH("LEFT")
text:SetText(label)
row.text = text
local hl = row:CreateTexture(nil, "HIGHLIGHT")
hl:SetAllPoints()
hl:SetColorTexture(1, 1, 1, 0.08)
row:SetScript("OnClick", function()
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
onClick()
refreshAll()
end)
AddOption({ frame = row, height = 20, refresh = function()
row.check:SetShown(isCheckedFn())
end })
end
local function addCheckbox(label, isCheckedFn, onClick)
local row = CreateFrame("Button", nil, dropdown)
row:SetHeight(20)
local check = row:CreateTexture(nil, "ARTWORK")
check:SetSize(12, 12)
check:SetPoint("LEFT", 2, 0)
row.check = check
local text = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
text:SetPoint("LEFT", 18, 0)
text:SetPoint("RIGHT", -4, 0)
text:SetJustifyH("LEFT")
text:SetText(label)
row.text = text
local hl = row:CreateTexture(nil, "HIGHLIGHT")
hl:SetAllPoints()
hl:SetColorTexture(1, 1, 1, 0.08)
row.isChecked = false
row:SetScript("OnClick", function(self)
self.isChecked = not self.isChecked
PlaySound(self.isChecked and SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
or SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF)
onClick(self.isChecked)
refreshAll()
end)
AddOption({ frame = row, height = 20, refresh = function()
row.isChecked = isCheckedFn()
if row.isChecked then
check:SetAtlas("common-icon-checkmark")
check:Show()
else
check:Hide()
end
end })
end
local function addAction(label, onClick)
local row = CreateFrame("Button", nil, dropdown)
row:SetHeight(20)
local text = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
text:SetPoint("LEFT", 18, 0)
text:SetPoint("RIGHT", -4, 0)
text:SetJustifyH("LEFT")
text:SetText(label)
local hl = row:CreateTexture(nil, "HIGHLIGHT")
hl:SetAllPoints()
hl:SetColorTexture(1, 1, 1, 0.08)
row:SetScript("OnClick", function()
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
onClick()
dropdown:Hide()
end)
AddOption({ frame = row, height = 20 })
end
local function addDivider()
local row = CreateFrame("Frame", nil, dropdown)
row:SetHeight(10)
local line = row:CreateTexture(nil, "ARTWORK")
line:SetHeight(1)
line:SetPoint("LEFT", 4, 0)
line:SetPoint("RIGHT", -4, 0)
line:SetPoint("CENTER")
line:SetColorTexture(0.4, 0.4, 0.4, 0.4)
AddOption({ frame = row, height = 10 })
end
function refreshAll()
for _, opt in ipairs(options) do
if opt.refresh then opt.refresh() end
end
end
parent:HookScript("OnHide", function()
dropdown:Hide()
end)
filterBtn:SetScript("OnClick", function(self)
if dropdown:IsShown() then
dropdown:Hide()
else
refreshAll()
RebuildLayout()
dropdown:ClearAllPoints()
dropdown:SetPoint("TOPRIGHT", self, "BOTTOMRIGHT", 0, -2)
dropdown:Show()
end
end)
return filterBtn, dropdown, {
addRadio = addRadio,
addCheckbox = addCheckbox,
addAction = addAction,
addDivider = addDivider,
refresh = refreshAll,
}
end