176 lines
8.9 KiB
Lua
176 lines
8.9 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Octo StatCompare inside the native character and inspect windows.
|
|
-- The gear totals come from the ported StatCompare scanner (OctoStatCompareScanner.lua), which reads the item
|
|
-- tooltips exactly as the Octo addon does. Character window: each stat row shows its gear part (OctoStatsPane.lua);
|
|
-- bonuses without a stat row are listed under "Other Gear Bonuses". Inspect window: a character-window style Stats pane inside it, comparing their items to yours.
|
|
WoWHybridUI = WoWHybridUI or {}
|
|
local state = WoWHybridUI
|
|
if type(StatScanner_ScanUnit) ~= "function" or not STATCOMPARE_EFFECTS then return end
|
|
|
|
local CATEGORY_NAMES = {ATT = STATCOMPARE_CAT_ATT, MISC = STATCOMPARE_CAT_MISC, BON = STATCOMPARE_CAT_BON,
|
|
SBON = STATCOMPARE_CAT_SBON, RES = STATCOMPARE_CAT_RES, SKILL = STATCOMPARE_CAT_SKILL, OBON = STATCOMPARE_CAT_OBON}
|
|
|
|
local function Scan(unit, linkSource)
|
|
StatScanner_LinkSource = linkSource
|
|
local ok, complete = pcall(StatScanner_ScanUnit, unit)
|
|
StatScanner_LinkSource = nil
|
|
if SCObjectTooltip then SCObjectTooltip:Hide() end
|
|
return ok and StatScanner_bonuses or {}, ok and complete
|
|
end
|
|
|
|
local function Format(effect, value)
|
|
if value == nil then return end
|
|
if effect.format then
|
|
local ok, text = pcall(string.format, effect.format, value)
|
|
if ok then return text end
|
|
end
|
|
return tostring(value)
|
|
end
|
|
|
|
-- Effects in StatCompare's category order, each once.
|
|
local ORDERED = {}
|
|
for _, cat in ipairs(STATCOMPARE_CATEGORIES or {}) do
|
|
for _, effect in ipairs(STATCOMPARE_EFFECTS) do
|
|
if effect.cat == cat and effect.show ~= 0 and effect.name then ORDERED[#ORDERED + 1] = effect end
|
|
end
|
|
end
|
|
|
|
-- Stats pane: one native category with every nonzero gear bonus; the tooltip names the StatCompare group.
|
|
-- Gear totals for the merged Stats pane: bonuses by effect key, plus the formatter and effect definitions.
|
|
state.GearEffects = {}
|
|
for _, effect in ipairs(ORDERED) do state.GearEffects[effect.effect] = effect end
|
|
state.FormatGearEffect = Format
|
|
-- Cached by the equipped-item signature: panel redraws reuse the last complete scan (no tooltip rescans).
|
|
local lastGearSignature, lastGearBonuses
|
|
function state.GetGearBonuses(signature, dirty)
|
|
if signature and signature == lastGearSignature and not dirty then return lastGearBonuses, true end
|
|
lastGearSignature, lastGearBonuses = nil, nil
|
|
local scanned, complete = Scan("player")
|
|
local copy = {}
|
|
for key, value in pairs(scanned) do copy[key] = value end
|
|
if signature and complete then lastGearSignature, lastGearBonuses = signature, copy end
|
|
return copy, complete
|
|
end
|
|
|
|
-- Gear bonuses with no stat row of their own (shown under "Other Gear Bonuses"); `used` = effect keys already
|
|
-- added into a stat row by OctoStatsPane.
|
|
function state.GetGearBonusElements(bonuses, used)
|
|
bonuses = bonuses or Scan("player")
|
|
local out = {}
|
|
for _, effect in ipairs(ORDERED) do
|
|
local value = bonuses[effect.effect]
|
|
value = tonumber(value)
|
|
if value and value ~= 0 and not (used and used[effect.effect]) then
|
|
out[#out + 1] = {isHeader = false, statIndex = #out + 1, labelText = effect.name, valueText = Format(effect, value),
|
|
tooltip = HIGHLIGHT_FONT_COLOR_CODE .. effect.name .. FONT_COLOR_CODE_CLOSE,
|
|
tooltip2 = (CATEGORY_NAMES[effect.cat] or effect.cat) .. ": from equipped items, enchants and set bonuses"}
|
|
end
|
|
end
|
|
if #out == 0 then return out end
|
|
table.insert(out, 1, {isHeader = true, name = used and "Other Gear Bonuses" or "Gear Bonuses"})
|
|
return out
|
|
end
|
|
|
|
-- Inspect: a right-hand Stats pane inside the Inspect window, built from the same native templates as the character
|
|
-- window's Stats pane (CharacterStatsPaneScrollBoxTemplate, category and label row elements). Each row shows the
|
|
-- inspected player's value with the difference to yours; the tooltip has Them / You / Difference.
|
|
local PANE_WIDTH = 233
|
|
local pane, baseWidth, widened
|
|
|
|
local function DiffText(target, mine)
|
|
if type(target) ~= "number" or type(mine) ~= "number" then return end
|
|
local delta = target - mine
|
|
if delta == 0 then return end
|
|
local text = (delta > 0 and "+" or "") .. (math.floor(delta) == delta and tostring(delta) or string.format("%.1f", delta))
|
|
return (delta > 0 and GREEN_FONT_COLOR_CODE or RED_FONT_COLOR_CODE) .. text .. FONT_COLOR_CODE_CLOSE
|
|
end
|
|
|
|
local function BuildPane()
|
|
if pane then return pane end
|
|
pane = CreateFrame("Frame", "WoWHybridInspectStatsPane", InspectFrame, "CharacterStatsPaneScrollBoxTemplate")
|
|
pane.ClassBackground = pane:CreateTexture(nil, "BACKGROUND")
|
|
pane.ClassBackground:SetPoint("TOPLEFT", 0, 5)
|
|
local view = CreateScrollBoxListLinearView(0, 8, 0, 0, 0)
|
|
view:SetElementFactory(function(factory, elementData)
|
|
local template = elementData.isHeader and "CharacterStatFrameCategoryScrollBoxElementTemplate" or "CharacterStatFrameScrollBoxLabelElementTemplate"
|
|
factory(template, function(button, data) button:Init(data) end)
|
|
end)
|
|
ScrollUtil.InitScrollBoxListWithScrollBar(pane.ScrollBox, pane.ScrollBar, view)
|
|
pane:Hide()
|
|
return pane
|
|
end
|
|
|
|
local function SetWidened(on)
|
|
if InCombatLockdown() or widened == on then return end
|
|
baseWidth = baseWidth or InspectFrame:GetWidth()
|
|
InspectFrame:SetWidth(on and baseWidth + PANE_WIDTH or baseWidth)
|
|
widened = on
|
|
if pane then
|
|
pane:ClearAllPoints()
|
|
pane:SetPoint("TOPLEFT", InspectFrame, "TOPLEFT", baseWidth - 4, -62)
|
|
pane:SetPoint("BOTTOMRIGHT", InspectFrame, "BOTTOMRIGHT", -6, 6)
|
|
pane:SetShown(on)
|
|
end
|
|
-- No UpdateUIPanelPositions: from addon code it taints the panel manager's slot state (CharacterFrame errors).
|
|
end
|
|
|
|
local lastSignature
|
|
local function Paint()
|
|
if not InspectFrame or not InspectFrame:IsShown() or InCombatLockdown() then return end
|
|
if InspectPaperDollFrame and not InspectPaperDollFrame:IsShown() then SetWidened(false); return end
|
|
local links = WoWHybridInspectEquipment and WoWHybridInspectEquipment.GetReportedLinks and WoWHybridInspectEquipment.GetReportedLinks()
|
|
if not links then SetWidened(false); lastSignature = nil; return end
|
|
local signature = {}
|
|
for slot = 1, 19 do signature[slot] = links[slot] or "" end
|
|
signature = table.concat(signature, ",")
|
|
BuildPane()
|
|
if signature == lastSignature and widened then return end
|
|
lastSignature = signature
|
|
local target = {}
|
|
for key, value in pairs(Scan("target", function(slot) return links[slot] end)) do target[key] = value end
|
|
local mine = Scan("player")
|
|
local unit = InspectFrame.GetInspectUnit and InspectFrame:GetInspectUnit()
|
|
local _, class = UnitClass(unit or "target")
|
|
if class then pane.ClassBackground:SetAtlas(string.format("UI-Character-Info-%s-BG", class), true) end
|
|
local elements, lastCat, index = {}, nil, 0
|
|
for _, effect in ipairs(ORDERED) do
|
|
local a, b = target[effect.effect], mine[effect.effect]
|
|
if (a and a ~= 0) or (b and b ~= 0) then
|
|
if effect.cat ~= lastCat then
|
|
lastCat, index = effect.cat, 0
|
|
elements[#elements + 1] = {isHeader = true, name = CATEGORY_NAMES[effect.cat] or effect.cat}
|
|
end
|
|
index = index + 1
|
|
local them, you, diff = Format(effect, a) or "-", Format(effect, b) or "-", DiffText(a or 0, b or 0)
|
|
elements[#elements + 1] = {isHeader = false, statIndex = index, labelText = effect.name,
|
|
valueText = diff and (them .. " " .. diff) or them,
|
|
tooltip = HIGHLIGHT_FONT_COLOR_CODE .. effect.name .. FONT_COLOR_CODE_CLOSE,
|
|
tooltip2 = string.format("Them: %s\nYou: %s%s", them, you, diff and ("\nDifference: " .. diff) or "")}
|
|
end
|
|
end
|
|
if #elements == 0 then elements[1] = {isHeader = true, name = "No stats on the reported items"} end
|
|
pane.ScrollBox:SetDataProvider(CreateDataProvider(elements), ScrollBoxConstants.RetainScrollPosition)
|
|
SetWidened(true)
|
|
end
|
|
|
|
local function Install()
|
|
if not WoWHybridInspectEquipment or state.statCompareInspectInstalled or not InspectFrame then return end
|
|
state.statCompareInspectInstalled = true
|
|
local previous = WoWHybridInspectEquipment.OnPainted
|
|
WoWHybridInspectEquipment.OnPainted = function()
|
|
if previous then pcall(previous) end
|
|
Paint()
|
|
end
|
|
InspectFrame:HookScript("OnHide", function() lastSignature = nil; SetWidened(false) end)
|
|
if InspectPaperDollFrame then
|
|
InspectPaperDollFrame:HookScript("OnShow", function() lastSignature = nil; Paint() end)
|
|
InspectPaperDollFrame:HookScript("OnHide", function() SetWidened(false) end)
|
|
end
|
|
end
|
|
|
|
local events = CreateFrame("Frame")
|
|
events:RegisterEvent("ADDON_LOADED")
|
|
events:SetScript("OnEvent", function(_, _, name) if name == "Blizzard_InspectUI" then Install() end end)
|
|
Install()
|