475 lines
25 KiB
Lua
475 lines
25 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Octo BetterCharacterStats inside the native Camelot Stats pane.
|
|
-- The stat values come from the ported BCS engine (OctoStatsEngine.lua / OctoStatsValues.lua). They are shown as
|
|
-- ordinary native categories and rows (CharacterStatFrameCategory/Label element templates), not in a separate box.
|
|
-- Native General, Attributes and Resistances stay as they are. The native Weapons, Modifiers and Defense categories
|
|
-- are replaced by the BCS categories, which read Turtle's real item, talent and aura bonuses.
|
|
WoWHybridUI = WoWHybridUI or {}
|
|
local state = WoWHybridUI
|
|
if not BCS or not BCS.L then return end
|
|
local L = BCS.L
|
|
|
|
-- Tooltip line recorder: the BCS OnEnter handlers write here instead of the real GameTooltip.
|
|
local recorder = BCS.TipRecorder or {}
|
|
recorder.lines = {}
|
|
function recorder:Reset() self.title, self.lines = nil, {} end
|
|
function recorder:SetOwner() end
|
|
function recorder:ClearLines() self.lines = {} end
|
|
function recorder:IsOwned() return false end
|
|
function recorder:Show() end
|
|
function recorder:SetText(text) if text then self.title = tostring(text) end end
|
|
function recorder:AddLine(text)
|
|
if text and text ~= "\n" then self.lines[#self.lines + 1] = tostring(text) end
|
|
end
|
|
function recorder:AddDoubleLine(left, right)
|
|
if left then self.lines[#self.lines + 1] = tostring(left) .. " " .. HIGHLIGHT_FONT_COLOR_CODE .. tostring(right or "") .. FONT_COLOR_CODE_CLOSE end
|
|
end
|
|
|
|
-- A stand-in for the 1.12 stat frame the BCS functions write to.
|
|
local function NewRow()
|
|
local row = {scripts = {}}
|
|
row.Label = {SetText = function(_, text) row.label = text end}
|
|
row.StatText = {SetText = function(_, text) row.value = text end}
|
|
function row:SetScript(name, fn) self.scripts[name] = fn end
|
|
function row:GetScript(name) return self.scripts[name] end
|
|
return row
|
|
end
|
|
|
|
local function Clean(text)
|
|
if type(text) ~= "string" then text = text ~= nil and tostring(text) or nil end
|
|
if not text then return end
|
|
return (text:gsub("%s*:%s*$", ""))
|
|
end
|
|
|
|
local function Evaluate(method, ...)
|
|
local fn = BCS[method]
|
|
if type(fn) ~= "function" then return end
|
|
local row = NewRow()
|
|
local ok, err = pcall(fn, BCS, row, ...)
|
|
if not ok or row.value == nil or row.label == nil then
|
|
state.octoStatsErrors = state.octoStatsErrors or {}
|
|
state.octoStatsErrors[method] = ok and "no value" or tostring(err)
|
|
return
|
|
end
|
|
local tooltip, tooltip2 = row.tooltip, row.tooltipSubtext
|
|
local onEnter = row.scripts.OnEnter
|
|
if onEnter then
|
|
recorder:Reset()
|
|
if BCS:RunWithThis(row, onEnter) and (recorder.title or #recorder.lines > 0) then
|
|
tooltip = recorder.title or tooltip
|
|
tooltip2 = table.concat(recorder.lines, "\n")
|
|
end
|
|
end
|
|
if row.tooltipExtra then tooltip2 = (tooltip2 and tooltip2 .. "\n" or "") .. row.tooltipExtra end
|
|
return {isHeader = false, labelText = Clean(row.label), valueText = tostring(row.value),
|
|
tooltip = tooltip and (HIGHLIGHT_FONT_COLOR_CODE .. tooltip .. FONT_COLOR_CODE_CLOSE) or nil, tooltip2 = tooltip2}
|
|
end
|
|
|
|
-- Gear part of each stat (one combined BCS + StatCompare view): which StatCompare gear effects feed a row.
|
|
local SCHOOL_DMG = {Arcane = "ARCANEDMG", Fire = "FIREDMG", Frost = "FROSTDMG", Holy = "HOLYDMG", Nature = "NATUREDMG", Shadow = "SHADOWDMG"}
|
|
local function GearKeys(method, arg)
|
|
if method == "SetAttackPower" then return {"ATTACKPOWER"}
|
|
elseif method == "SetRangedAttackPower" then return {"ATTACKPOWER", "RANGEDATTACKPOWER"}
|
|
elseif method == "SetHitRating" then
|
|
return arg == "SPELL" and {"SPELLTOHIT"} or arg == "RANGED" and {"TOHIT", "RANGEDHIT"} or {"TOHIT"}
|
|
elseif method == "SetMeleeCritChance" then return {"CRIT"}
|
|
elseif method == "SetRangedCritChance" then return {"CRIT", "RANGEDCRIT"}
|
|
elseif method == "SetSpellPower" then return arg and SCHOOL_DMG[arg] and {"DMG", SCHOOL_DMG[arg]} or {"DMG"}
|
|
elseif method == "SetSpellCritChance" then return {"SPELLCRIT"}
|
|
elseif method == "SetHealing" then return {"HEAL"}
|
|
elseif method == "SetManaRegen" then return {"MANAREG"}
|
|
elseif method == "SetSpellHaste" or method == "SetAttackSpeed" then return {"HASTE"}
|
|
elseif method == "SetArmor" then return {"ARMOR", "ENARMOR"}
|
|
elseif method == "SetDefense" then return {"DEFENSE"}
|
|
elseif method == "SetDodge" and arg == 0 then return {"DODGE"}
|
|
elseif method == "SetParry" and arg == 0 then return {"PARRY"}
|
|
elseif method == "SetBlock" and arg == 0 then return {"TOBLOCK"}
|
|
end
|
|
end
|
|
-- Native Attributes / Resistance rows by their stat token.
|
|
local NATIVE_KEYS = {STRENGTH = {"STR"}, AGILITY = {"AGI"}, STAMINA = {"STA"}, INTELLECT = {"INT"}, SPIRIT = {"SPI"},
|
|
ARMOR = {"ARMOR", "ENARMOR"}}
|
|
local function NativeGearKeys(token)
|
|
if type(token) ~= "string" then return end
|
|
token = token:upper()
|
|
if NATIVE_KEYS[token] then return NATIVE_KEYS[token] end
|
|
for school in pairs(SCHOOL_DMG) do
|
|
if token:find(school:upper(), 1, true) and token:find("RESIST", 1, true) then return {school:upper() .. "RES", "ALLRES"} end
|
|
end
|
|
end
|
|
|
|
-- Gear total for a row from the StatCompare scan (marks the effects used); 0 when the gear adds nothing.
|
|
local function GearPart(keys, used)
|
|
local gear, sum = state.statsGear, 0
|
|
if not keys then return 0 end
|
|
for _, key in ipairs(keys) do
|
|
local value = gear and tonumber(gear[key]) -- the scanner keeps a single item's bonus as its matched text ("3")
|
|
if value then sum = sum + value end
|
|
if used then used[key] = true end
|
|
end
|
|
return sum
|
|
end
|
|
|
|
local function PlainNumber(text)
|
|
if type(text) ~= "string" then return end
|
|
local plain = text:gsub("|c%x%x%x%x%x%x%x%x", ""):gsub("|r", "")
|
|
return tonumber(plain:match("^%s*(-?[%d%.]+)")), plain:find("%%") ~= nil
|
|
end
|
|
|
|
local function Fmt(value, percent, sign)
|
|
local text
|
|
if percent then text = string.format("%.2f%%", value)
|
|
elseif math.floor(value) == value then text = tostring(value)
|
|
else text = string.format("%.1f", value) end
|
|
return (sign and value > 0 and "+" or "") .. text
|
|
end
|
|
|
|
-- Total as before with the whole bonus in green, "150 (+50)"; tooltip "Base 100 Gear +30 Talents +5 Buffs +15".
|
|
-- parts are disjoint sources, each measured inside the same total, so nothing is counted twice.
|
|
local function AddParts(element, parts)
|
|
local value = element.valueText
|
|
local total, percent = PlainNumber(value)
|
|
local bonus, shown = 0, {}
|
|
for _, part in ipairs(parts) do
|
|
if part[2] and math.abs(part[2]) > 0.004 then bonus = bonus + part[2]; shown[#shown + 1] = part end
|
|
end
|
|
if #shown == 0 then return element end
|
|
element.valueText = (value or "") .. " " .. GREEN_FONT_COLOR_CODE .. "(" .. Fmt(bonus, percent, true) .. ")" .. FONT_COLOR_CODE_CLOSE
|
|
local line = ""
|
|
if total and total - bonus >= -0.004 then line = "Base " .. Fmt(total - bonus, percent) end
|
|
for _, part in ipairs(shown) do
|
|
line = line .. (line ~= "" and " " or "") .. part[1] .. " " .. GREEN_FONT_COLOR_CODE .. Fmt(part[2], percent, true) .. FONT_COLOR_CODE_CLOSE
|
|
end
|
|
element.tooltip2 = element.tooltip2 and (line .. "\n" .. element.tooltip2) or line
|
|
return element
|
|
end
|
|
|
|
-- A BCS row's number with one source (gear / talents / auras cache) left out.
|
|
local ZERO = setmetatable({}, {__index = function() return 0 end, __newindex = function() end})
|
|
local function ValueWithout(method, arg, source)
|
|
local cache, fn = BCS.Cache, BCS[method]
|
|
if not cache or type(fn) ~= "function" then return end
|
|
local saved = cache[source]
|
|
cache[source] = ZERO
|
|
local row = {scripts = {}}
|
|
row.Label = {SetText = function() end}
|
|
row.StatText = {SetText = function(_, text) row.value = text end}
|
|
function row:SetScript() end
|
|
local ok = pcall(fn, BCS, row, arg)
|
|
cache[source] = saved
|
|
if ok then return (PlainNumber(row.value)) end
|
|
end
|
|
|
|
-- Server-side bonus of attack power (vanilla posBuff covers gear and buffs alike); nil in combat / when secret.
|
|
local function ServerBonus(method)
|
|
if InCombatLockdown() then return end
|
|
local query = method == "SetAttackPower" and UnitAttackPower or method == "SetRangedAttackPower" and UnitRangedAttackPower
|
|
if not query then return end
|
|
local ok, _, pos, neg = pcall(query, "player")
|
|
if not ok or type(pos) ~= "number" or (issecretvalue and issecretvalue(pos)) then return end
|
|
return pos + (type(neg) == "number" and neg or 0)
|
|
end
|
|
|
|
local function RowParts(element, method, arg, used)
|
|
local total = PlainNumber(element.valueText)
|
|
local parts = {}
|
|
if total then
|
|
for _, source in ipairs({{"Gear", "gear"}, {"Talents", "talents"}, {"Buffs", "auras"}}) do
|
|
local without = ValueWithout(method, arg, source[2])
|
|
parts[#parts + 1] = {source[1], without and total - without or 0}
|
|
end
|
|
end
|
|
-- Rows the BCS caches do not feed (crit, attack power, armor, defense, avoidance come from the server):
|
|
-- gear from the StatCompare scan; buffs = server bonus minus that gear.
|
|
local gear = GearPart(GearKeys(method, arg), used)
|
|
if (not parts[1] or math.abs(parts[1][2]) <= 0.004) and gear ~= 0 then
|
|
parts[1] = {"Gear", gear}
|
|
local server = ServerBonus(method)
|
|
if server and server > gear and (not parts[3] or math.abs(parts[3][2]) <= 0.004) then parts[3] = {"Buffs", server - gear} end
|
|
end
|
|
return AddParts(element, parts)
|
|
end
|
|
|
|
-- Buff amounts read from the player's own buff tooltips (potions, elixirs, Fortitude, Mark of the Wild ...), once per
|
|
-- rebuild, out of combat only. Used only while the server sends no stat bonus (UnitStat posBuff 0), so a buff is never
|
|
-- counted twice.
|
|
local STAT_WORDS = {strength = "STR", agility = "AGI", stamina = "STA", intellect = "INT", spirit = "SPI", armor = "ARMOR"}
|
|
local function ScanBuffStats()
|
|
local out = {}
|
|
if InCombatLockdown() or not (C_UnitAuras and C_TooltipInfo and C_TooltipInfo.GetUnitBuffByAuraInstanceID) then return out end
|
|
for index = 1, 40 do
|
|
local ok, aura = pcall(C_UnitAuras.GetAuraDataByIndex, "player", index, "HELPFUL")
|
|
if not ok or not aura then break end
|
|
local okTip, tip = pcall(C_TooltipInfo.GetUnitBuffByAuraInstanceID, "player", aura.auraInstanceID)
|
|
for _, line in ipairs(okTip and tip and tip.lines or {}) do
|
|
local text = type(line.leftText) == "string" and not (issecretvalue and issecretvalue(line.leftText)) and line.leftText:lower()
|
|
if text then
|
|
local all = text:match("all attributes by (%d+)") or text:match("all stats by (%d+)")
|
|
if all then for _, key in ipairs({"STR", "AGI", "STA", "INT", "SPI"}) do out[key] = (out[key] or 0) + tonumber(all) end end
|
|
for word, amount in text:gmatch("(%a+) by (%d+)") do
|
|
if STAT_WORDS[word] and not (word == "armor" and text:find("armor by %d+%%")) then
|
|
out[STAT_WORDS[word]] = (out[STAT_WORDS[word]] or 0) + tonumber(amount)
|
|
end
|
|
end
|
|
for word, amount in text:gmatch("(%a+) increased by (%d+)") do
|
|
if STAT_WORDS[word] then out[STAT_WORDS[word]] = (out[STAT_WORDS[word]] or 0) + tonumber(amount) end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return out
|
|
end
|
|
|
|
-- Native attributes: UnitStat posBuff is everything above base (gear + buffs, potions included).
|
|
local STAT_INDEX = {STRENGTH = 1, AGILITY = 2, STAMINA = 3, INTELLECT = 4, SPIRIT = 5}
|
|
local function NativeParts(element, token, keys)
|
|
local gear = GearPart(keys)
|
|
local parts = {{"Gear", gear}}
|
|
local index = type(token) == "string" and STAT_INDEX[token:upper()]
|
|
if index and not InCombatLockdown() then
|
|
local ok, _, _, pos, neg = pcall(UnitStat, "player", index)
|
|
if ok and type(pos) == "number" and not (issecretvalue and issecretvalue(pos)) then
|
|
local bonus = pos + (type(neg) == "number" and neg or 0)
|
|
if bonus > gear then parts[2] = {"Buffs", bonus - gear} end
|
|
if bonus == 0 and keys and state.statsBuffs then
|
|
local buff = 0
|
|
for _, key in ipairs(keys) do buff = buff + (state.statsBuffs[key] or 0) end
|
|
if buff > 0 then parts[2] = {"Buffs", buff} end
|
|
end
|
|
end
|
|
end
|
|
return AddParts(element, parts)
|
|
end
|
|
|
|
local function UsesMana()
|
|
local _, class = UnitClass("player")
|
|
return class ~= "WARRIOR" and class ~= "ROGUE"
|
|
end
|
|
local function HasRanged() return GetInventoryItemLink("player", 18) ~= nil end
|
|
|
|
-- Same category contents as BCS UpdatePaperdollStats; Base Stats is covered by the native Attributes category.
|
|
local CATEGORIES = {
|
|
{key = "PLAYERSTAT_MELEE_COMBAT", rows = {{"SetWeaponSkill"}, {"SetDamage"}, {"SetAttackSpeed"}, {"SetAttackPower"}, {"SetHitRating", "MELEE"}, {"SetMeleeCritChance"}}},
|
|
{key = "PLAYERSTAT_MELEE_BOSS", rows = {{"SetBossMissChance"}, {"SetBossDodgeChance"}, {"SetBossGlanceReduction"}, {"SetBossCritCap"}, {"SetEffectiveBossCrit"}}},
|
|
{key = "PLAYERSTAT_RANGED_COMBAT", show = HasRanged, rows = {{"SetRangedWeaponSkill"}, {"SetRangedDamage"}, {"SetRangedAttackSpeed"}, {"SetRangedAttackPower"}, {"SetHitRating", "RANGED"}, {"SetRangedCritChance"}}},
|
|
{key = "PLAYERSTAT_SPELL_COMBAT", show = UsesMana, rows = {{"SetSpellPower"}, {"SetHitRating", "SPELL"}, {"SetSpellCritChance"}, {"SetHealing"}, {"SetManaRegen"}, {"SetSpellHaste"}}},
|
|
{key = "PLAYERSTAT_SPELL_SCHOOLS", show = UsesMana, rows = {{"SetSpellPower", "Arcane"}, {"SetSpellPower", "Fire"}, {"SetSpellPower", "Frost"}, {"SetSpellPower", "Holy"}, {"SetSpellPower", "Nature"}, {"SetSpellPower", "Shadow"}}},
|
|
{key = "PLAYERSTAT_DEFENSES", rows = {{"SetArmor"}, {"SetDefense"}, {"SetDodge", 0}, {"SetParry", 0}, {"SetBlock", 0}, {"SetTotalAvoidance", 0}}},
|
|
{key = "PLAYERSTAT_DEFENSES_BOSS", rows = {{"SetDodge", 3}, {"SetParry", 3}, {"SetBlock", 3}, {"SetTotalAvoidance", 3}}},
|
|
}
|
|
|
|
-- Equipped items whose data is not loaded yet show partial tooltips (no stats, no Equip: lines). Ask for them and
|
|
-- stay dirty until every one is cached; GET_ITEM_INFO_RECEIVED then rebuilds the pane.
|
|
local function EquippedGearSignature()
|
|
local links, ready = {}, true
|
|
for slot = 1, 19 do
|
|
local id = GetInventoryItemID("player", slot)
|
|
local link = GetInventoryItemLink("player", slot)
|
|
links[slot] = link or ""
|
|
if id and not C_Item.IsItemDataCachedByID(id) then
|
|
ready = false
|
|
C_Item.RequestLoadItemDataByID(id)
|
|
elseif (id and not link) or (link and not id) then
|
|
ready = false
|
|
end
|
|
end
|
|
if ready then return table.concat(links, "\n") end
|
|
end
|
|
|
|
local gearTooltipsPending = false
|
|
local function OctoElements(gearSignature, dirty)
|
|
BCS.needScanGear, BCS.needScanTalents, BCS.needScanAuras, BCS.needScanSkills = dirty, dirty, true, dirty
|
|
pcall(BCS.RunScans, BCS)
|
|
state.octoStatsDirty = gearSignature == nil
|
|
local out, used = {}, {}
|
|
-- Native attribute / resistance rows get their gear part at draw time: count those effects as used here.
|
|
for _, keys in pairs(NATIVE_KEYS) do for _, key in ipairs(keys) do used[key] = true end end
|
|
for school in pairs(SCHOOL_DMG) do used[school:upper() .. "RES"] = true end
|
|
used.ALLRES = true
|
|
for _, category in ipairs(CATEGORIES) do
|
|
if not category.show or category.show() then
|
|
local rows = {}
|
|
for _, spec in ipairs(category.rows) do
|
|
local element = Evaluate(spec[1], spec[2])
|
|
if element then rows[#rows + 1] = RowParts(element, spec[1], spec[2], used) end
|
|
end
|
|
if #rows > 0 then
|
|
out[#out + 1] = {isHeader = true, name = L[category.key] or category.key}
|
|
for index, element in ipairs(rows) do element.statIndex = index; out[#out + 1] = element end
|
|
end
|
|
end
|
|
end
|
|
if state.GetGearBonusElements then
|
|
local ok, gear = pcall(state.GetGearBonusElements, state.statsGear, used)
|
|
if ok and type(gear) == "table" then for _, element in ipairs(gear) do out[#out + 1] = element end end
|
|
end
|
|
local recorded = state.GetRecordedCharacterTotals and state.GetRecordedCharacterTotals()
|
|
if recorded and #recorded > 0 then
|
|
out[#out + 1] = {isHeader = true, name = "This Character"}
|
|
for index, entry in ipairs(recorded) do
|
|
out[#out + 1] = {isHeader = false, statIndex = index, labelText = entry[1], valueText = entry[2]}
|
|
end
|
|
end
|
|
return out
|
|
end
|
|
|
|
local KEEP_BEFORE = {[STAT_CATEGORY_GENERAL or "General"] = true, [STAT_CATEGORY_PRIMARY_ATTRIBUTES or "Attributes"] = true}
|
|
local KEEP_AFTER = {[STAT_CATEGORY_RESISTANCE or "Resistance"] = true}
|
|
|
|
-- Taint rule (70334 secret values): never hand addon tables to Blizzard's stats ScrollBox. Its OnShow layout reads
|
|
-- the provider in secure code, and an addon-built provider taints CharacterFrame:OnShow (TextStatusBar compares secret
|
|
-- health values -> Lua error). The native list is only READ here; the combined list is drawn by an own ScrollBox built
|
|
-- from the same native templates, laid over the native one (which is faded to alpha 0 and covered for mouse input).
|
|
local overlay
|
|
|
|
local function Initializer(button, elementData) button:Init(elementData) end
|
|
|
|
-- Native rows are never re-run here: their updateFunc compares secret stat values (UnitStat posBuff), which errors
|
|
-- under addon taint (live 2026-11-22, Vanilla/PaperDollFrameStats.lua:5). The overlay row shows what Blizzard's own
|
|
-- (secure) row already drew; widget setters accept secret text, so nothing is read or compared.
|
|
local nativeOf = setmetatable({}, {__mode = "k"})
|
|
local function NativeInitializer(button, copy)
|
|
button:Init(copy)
|
|
local element, pane = nativeOf[copy], CharacterStatsPaneScrollBox
|
|
local box = pane and pane.ScrollBox
|
|
local ok, frame = pcall(function() return element and box and box:FindFrame(element) end)
|
|
if not ok or not frame then
|
|
-- Native row scrolled out of Blizzard's (hidden) list: compute it only while stats are not secret (no combat).
|
|
if element and not InCombatLockdown() then
|
|
local plain = {}
|
|
for key, value in pairs(element) do plain[key] = value end
|
|
plain.statIndex = copy.statIndex
|
|
pcall(button.Init, button, plain)
|
|
end
|
|
return
|
|
end
|
|
if frame.Label and button.Label then button.Label:SetText(frame.Label:GetText()) end
|
|
if frame.Value and button.Value then button.Value:SetText(frame.Value:GetText()) end
|
|
button.tooltip, button.tooltip2, button.tooltip3 = frame.tooltip, frame.tooltip2, frame.tooltip3
|
|
-- Gear part, out of combat only (stat text is a secret value in combat: never read or concatenated then).
|
|
local keys = NativeGearKeys(element.name)
|
|
if keys and not InCombatLockdown() and button.Value then
|
|
local ok2, value = pcall(frame.Value.GetText, frame.Value)
|
|
if ok2 and type(value) == "string" and not (issecretvalue and issecretvalue(value)) then
|
|
local decorated = NativeParts({valueText = value}, element.name, keys)
|
|
if decorated.tooltip2 then
|
|
button.Value:SetText(decorated.valueText)
|
|
local extra = decorated.tooltip2
|
|
if type(button.tooltip2) == "string" and not (issecretvalue and issecretvalue(button.tooltip2)) then
|
|
extra = extra .. "\n" .. button.tooltip2
|
|
button.tooltip2 = extra
|
|
elseif button.tooltip2 == nil then
|
|
button.tooltip2 = extra
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local function CreateOverlay(pane)
|
|
overlay = CreateFrame("Frame", nil, pane, "CharacterStatsPaneScrollBoxTemplate")
|
|
overlay:SetAllPoints(pane)
|
|
overlay:SetFrameLevel(pane:GetFrameLevel() + 20)
|
|
overlay:EnableMouse(true)
|
|
if overlay.Border then overlay.Border:Hide() end
|
|
local view = CreateScrollBoxListLinearView(0, 8, 0, 0, 0)
|
|
view:SetElementFactory(function(factory, elementData)
|
|
local init = nativeOf[elementData] and NativeInitializer or Initializer
|
|
if elementData.isHeader then
|
|
factory("CharacterStatFrameCategoryScrollBoxElementTemplate", Initializer)
|
|
elseif elementData.texture or elementData.atlas then
|
|
factory("CharacterStatFrameScrollBoxIconElementTemplate", init)
|
|
else
|
|
factory("CharacterStatFrameScrollBoxLabelElementTemplate", init)
|
|
end
|
|
end)
|
|
ScrollUtil.InitScrollBoxListWithScrollBar(overlay.ScrollBox, overlay.ScrollBar, view)
|
|
-- Frame alpha is not a Lua value: fading the native list does not taint it.
|
|
if pane.ScrollBox then pane.ScrollBox:SetAlpha(0) end
|
|
if pane.ScrollBar then pane.ScrollBar:SetAlpha(0) end
|
|
end
|
|
|
|
local function Rebuild(pane)
|
|
if pane:GetUnit() ~= "player" then return end
|
|
local provider = pane.ScrollBox and pane.ScrollBox:GetDataProvider()
|
|
if not provider then return end
|
|
-- One gear scan per rebuild: every row (native, BCS, resistances) adds its gear part from it.
|
|
local dirty = state.octoStatsDirty ~= false
|
|
local gearSignature = EquippedGearSignature()
|
|
local okGear, gear, complete = false, nil, nil
|
|
if state.GetGearBonuses then okGear, gear, complete = pcall(state.GetGearBonuses, gearSignature, dirty) end
|
|
state.statsGear = okGear and type(gear) == "table" and gear or nil
|
|
gearTooltipsPending = okGear and complete == false
|
|
local okBuffs, buffs = pcall(ScanBuffStats)
|
|
state.statsBuffs = okBuffs and buffs or nil
|
|
local before, after, bucket = {}, {}, nil
|
|
for _, element in provider:Enumerate() do
|
|
if element.isHeader then
|
|
bucket = KEEP_BEFORE[element.name] and before or KEEP_AFTER[element.name] and after or nil
|
|
end
|
|
if bucket then
|
|
-- Copy: the overlay never keeps references to Blizzard's element tables.
|
|
local copy = {}
|
|
for key, value in pairs(element) do copy[key] = value end
|
|
if not copy.isHeader and copy.name then
|
|
-- Drop the stat name so the template never calls Blizzard's updateFunc from addon code.
|
|
copy.name, copy.unit, copy.id, copy.hideAt = nil, nil, nil, nil
|
|
nativeOf[copy] = element
|
|
end
|
|
-- Resistance rows carry their value directly (atlas UI-Character-Info-Resistance-<School>).
|
|
local school = type(copy.atlas) == "string" and copy.atlas:match("Resistance%-(%a+)$")
|
|
if school and SCHOOL_DMG[school] and not InCombatLockdown() and type(copy.valueText) == "string" and
|
|
not (issecretvalue and issecretvalue(copy.valueText)) then
|
|
pcall(NativeParts, copy, nil, {school:upper() .. "RES", "ALLRES"})
|
|
end
|
|
if not element.shouldRemove then bucket[#bucket + 1] = copy end
|
|
end
|
|
end
|
|
local ok, octo = pcall(OctoElements, gearSignature, dirty)
|
|
if not ok then octo = {} end
|
|
local combined = {}
|
|
for _, list in ipairs({before, octo, after}) do for _, element in ipairs(list) do combined[#combined + 1] = element end end
|
|
if not overlay then CreateOverlay(pane) end
|
|
overlay.ScrollBox:SetDataProvider(CreateDataProvider(combined), ScrollBoxConstants.RetainScrollPosition)
|
|
end
|
|
|
|
local function Install()
|
|
if state.octoStatsInstalled then return true end
|
|
local pane = CharacterStatsPaneScrollBox
|
|
if not pane or type(pane.UpdateStats) ~= "function" then return false end
|
|
hooksecurefunc(pane, "UpdateStats", function(self) pcall(Rebuild, self) end)
|
|
state.octoStatsInstalled = true
|
|
return true
|
|
end
|
|
|
|
local events = CreateFrame("Frame")
|
|
for _, event in ipairs({"ADDON_LOADED", "PLAYER_ENTERING_WORLD", "PLAYER_EQUIPMENT_CHANGED", "UNIT_INVENTORY_CHANGED",
|
|
"CHARACTER_POINTS_CHANGED", "SKILL_LINES_CHANGED", "PLAYER_TALENT_UPDATE", "GET_ITEM_INFO_RECEIVED",
|
|
"PLAYER_LEVEL_UP", "UPDATE_INVENTORY_DURABILITY"}) do
|
|
pcall(events.RegisterEvent, events, event)
|
|
end
|
|
local refreshQueued = false
|
|
local function QueueRefresh()
|
|
if refreshQueued then return end
|
|
refreshQueued = true
|
|
C_Timer.After(0.3, function()
|
|
refreshQueued = false
|
|
local pane = CharacterStatsPaneScrollBox
|
|
if (state.octoStatsDirty or gearTooltipsPending) and pane and pane:IsVisible() then pcall(Rebuild, pane) end
|
|
end)
|
|
end
|
|
events:SetScript("OnEvent", function(_, event)
|
|
if event == "GET_ITEM_INFO_RECEIVED" then
|
|
-- Only while a scan is still waiting for item data; other addons' item loads are not our business.
|
|
if state.octoStatsDirty or gearTooltipsPending then QueueRefresh() end
|
|
return
|
|
end
|
|
if event ~= "ADDON_LOADED" then
|
|
state.octoStatsDirty = true
|
|
if event == "PLAYER_LEVEL_UP" or event == "UPDATE_INVENTORY_DURABILITY" then QueueRefresh() end
|
|
end
|
|
Install()
|
|
end)
|
|
Install()
|