381 lines
16 KiB
Lua
381 lines
16 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Character-specific additions to the Camelot paper doll and Statistics pane.
|
|
local function Number(value)
|
|
if issecretvalue and issecretvalue(value) then return nil end
|
|
if type(value) == "number" and value == value and math.abs(value) < math.huge then return value end
|
|
end
|
|
|
|
local function Read(fn, ...)
|
|
if type(fn) ~= "function" then return end
|
|
local ok, a, b = pcall(fn, ...)
|
|
if ok then return Number(a), Number(b) end
|
|
end
|
|
|
|
local function SpellPower()
|
|
local minimum, bonuses = nil, {}
|
|
for school = 2, 7 do
|
|
local value = Read(GetSpellBonusDamage, school)
|
|
if value == nil then return end
|
|
bonuses[school] = value
|
|
minimum = minimum and math.min(minimum, value) or value
|
|
end
|
|
return minimum, bonuses
|
|
end
|
|
|
|
local function SpellHit()
|
|
local modifier = Read(GetSpellHitModifier)
|
|
local rating = CR_HIT_SPELL and Read(GetCombatRatingBonus, CR_HIT_SPELL)
|
|
if modifier and rating and modifier + rating ~= 0 then return modifier + rating end
|
|
end
|
|
|
|
local function ManaPerFive()
|
|
local maximum = Enum and Enum.PowerType and Read(UnitPowerMax, "player", Enum.PowerType.Mana)
|
|
if not maximum or maximum <= 0 then return end
|
|
local _, casting = Read(GetManaRegen)
|
|
if casting then return casting * 5 end
|
|
end
|
|
|
|
local function BonusHealing()
|
|
-- The Source profile supplies no scalar healing bonus. A default zero is ambiguous.
|
|
local value = Read(GetSpellBonusHealing)
|
|
if value and value > 0 then return value end
|
|
end
|
|
|
|
local function ReportedSpellCrit()
|
|
-- The Source server keeps spell critical strike chance per school internally.
|
|
local value = Read(GetSpellCritChance)
|
|
if value and value ~= 0 then return value end
|
|
end
|
|
|
|
local rows = {
|
|
{key="HYBRID_SPELLPOWER", label=STAT_SPELLPOWER or "Spell Power", read=SpellPower,
|
|
missing="The client has no complete set of school bonuses yet."},
|
|
{key="HYBRID_SPELLCRIT", label="Spell Crit", read=ReportedSpellCrit, percent=true,
|
|
detail="Spell critical strike chance reported by the client. Server chances can vary by school.",
|
|
missing="The client has no spell critical strike chance available."},
|
|
{key="HYBRID_SPELLHIT", label="Spell Hit", read=SpellHit, percent=true,
|
|
missing="The server does not send a total spell hit bonus. The client has no confirmed value.",
|
|
detail="Hit bonus reported by the client. Other server-side modifiers may apply."},
|
|
{key="HYBRID_SPELLHASTE", label="Spell Haste", read=function() return Read(UnitSpellHaste, "player") end, percent=true,
|
|
missing="The client has no confirmed spell haste value."},
|
|
{key="HYBRID_SPELLHEALING", label="Healing Power", read=BonusHealing,
|
|
missing="The server does not send a total healing power value. The client has no confirmed bonus."},
|
|
{key="HYBRID_SPELLPEN", label=STAT_SPELLPENETRATION or "Spell Pen.", read=function() return Read(GetSpellPenetration) end},
|
|
{key="HYBRID_MANAREGEN", label="Mana/5s casting", read=ManaPerFive,
|
|
detail="Mana regenerated every 5 seconds while casting."},
|
|
}
|
|
|
|
-- A separate child of the right pane keeps addon readers out of native
|
|
-- PaperDollFrame_OnShow -> CharacterStatsPaneScrollBoxMixin:UpdateStats.
|
|
-- Updating the native stat tables even one tick later would taint every
|
|
-- subsequent native refresh, so this panel never writes either table.
|
|
local panel, toggle, scrollChild
|
|
local totals, intervalStart
|
|
local function AddRow(output, group, label, read, options)
|
|
table.insert(output, {group=group,label=label,read=read,options=options or {}})
|
|
end
|
|
|
|
local function VisibleRows()
|
|
local output = {}
|
|
local weaponSkill = WoWHybridUI and WoWHybridUI.weaponSkill
|
|
if weaponSkill and weaponSkill.GetStandaloneRows then
|
|
for _, row in ipairs(weaponSkill.GetStandaloneRows()) do
|
|
AddRow(output, "Weapons", row.label, row.read, {weaponName=row.weaponName})
|
|
end
|
|
end
|
|
local avoidance = WoWHybridUI and WoWHybridUI.characterStats
|
|
if avoidance and avoidance.ReadAvoidanceChance then
|
|
for _, stat in ipairs({"PARRY", "BLOCK"}) do
|
|
local key = stat
|
|
AddRow(output, "Defense", key == "PARRY" and "Parry" or "Block", function()
|
|
local chance = avoidance.ReadAvoidanceChance(key)
|
|
if chance ~= nil then return string.format("%.2f%%", chance) end
|
|
end)
|
|
end
|
|
end
|
|
for _, row in ipairs(rows) do AddRow(output, "Spells", row.label, row.read, {spell=row}) end
|
|
if totals and intervalStart then
|
|
local minutes = math.floor((totals.seconds + math.max(0, GetTime() - intervalStart)) / 60)
|
|
for _, entry in ipairs({
|
|
{"Time (min)", minutes},
|
|
{"Spellcasts", totals.casts},
|
|
{"Quests", totals.quests},
|
|
{"Deaths", totals.deaths},
|
|
}) do
|
|
local value = entry[2]
|
|
AddRow(output, "Recorded on this character", entry[1], function() return tostring(value) end)
|
|
end
|
|
end
|
|
return output
|
|
end
|
|
|
|
local function ReadDisplay(row)
|
|
local ok, value, detail = pcall(row.read)
|
|
if not ok then return nil end
|
|
if issecretvalue then
|
|
if issecretvalue(value) then return nil end
|
|
if issecretvalue(detail) then detail = nil end
|
|
end
|
|
local spell = row.options.spell
|
|
if spell then
|
|
if value == nil then
|
|
if spell.missing then return "Unavailable", spell.missing end
|
|
return nil
|
|
end
|
|
if not Number(value) then return nil end
|
|
local display = spell.percent and string.format("%.1f%%", value)
|
|
or BreakUpLargeNumbers(math.floor(value + 0.5))
|
|
return display, spell.detail, type(detail) == "table" and detail or nil
|
|
end
|
|
if type(value) ~= "string" or value == "" then return nil end
|
|
if type(detail) ~= "string" then detail = nil end
|
|
return value, detail
|
|
end
|
|
|
|
local function ShowRowTooltip(view)
|
|
GameTooltip:SetOwner(view, "ANCHOR_RIGHT")
|
|
GameTooltip:SetText(view.labelText)
|
|
GameTooltip:AddLine(view.fullText, 1, 1, 1, true)
|
|
if view.detail then GameTooltip:AddLine(view.detail, 0.8, 0.8, 0.8, true) end
|
|
if view.schools then
|
|
for school = 2, 7 do
|
|
local value = view.schools[school]
|
|
if Number(value) then
|
|
GameTooltip:AddDoubleLine(_G["DAMAGE_SCHOOL"..school] or tostring(school), BreakUpLargeNumbers(value))
|
|
end
|
|
end
|
|
end
|
|
GameTooltip:Show()
|
|
end
|
|
|
|
local function NewView(y, header)
|
|
local pool = header and panel.headerPool or panel.rowPool
|
|
local frame = table.remove(pool)
|
|
if not frame then
|
|
frame = CreateFrame("Frame", nil, scrollChild)
|
|
local label = frame:CreateFontString(nil, "OVERLAY", header and "GameFontNormal" or "GameFontHighlightSmall")
|
|
label:SetPoint("LEFT", frame, "LEFT", 0, 0)
|
|
label:SetJustifyH("LEFT")
|
|
if label.SetWordWrap then label:SetWordWrap(false) end
|
|
if label.SetMaxLines then label:SetMaxLines(1) end
|
|
frame.Label = label
|
|
if not header then
|
|
local value = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
|
|
value:SetPoint("RIGHT", frame, "RIGHT", 0, 0)
|
|
value:SetWidth(52)
|
|
value:SetJustifyH("RIGHT")
|
|
if value.SetWordWrap then value:SetWordWrap(false) end
|
|
if value.SetMaxLines then value:SetMaxLines(1) end
|
|
frame.Value = value
|
|
label:SetPoint("RIGHT", value, "LEFT", -8, 0)
|
|
frame:EnableMouse(true)
|
|
frame:SetScript("OnEnter", ShowRowTooltip)
|
|
frame:SetScript("OnLeave", function() GameTooltip:Hide() end)
|
|
end
|
|
end
|
|
frame:ClearAllPoints()
|
|
frame:SetPoint("TOPLEFT", scrollChild, "TOPLEFT", 4, -y)
|
|
frame:SetPoint("TOPRIGHT", scrollChild, "TOPRIGHT", -4, -y)
|
|
frame:SetHeight(header and 20 or 16)
|
|
frame:Show()
|
|
return frame
|
|
end
|
|
|
|
local function RefreshOctoPanel()
|
|
if not panel or not panel:IsShown() then return end
|
|
if not scrollChild then return end
|
|
local width = panel.scroll:GetWidth()
|
|
if Number(width) and width > 0 then scrollChild:SetWidth(width) end
|
|
if panel.views then
|
|
for _, view in ipairs(panel.views) do
|
|
view:Hide()
|
|
table.insert(view.Value and panel.rowPool or panel.headerPool, view)
|
|
end
|
|
end
|
|
panel.views = {}
|
|
local y, group = 0, nil
|
|
for _, row in ipairs(VisibleRows()) do
|
|
local value, detail, schools = ReadDisplay(row)
|
|
if value then
|
|
if row.group ~= group then
|
|
group = row.group
|
|
if y > 0 then y = y + 4 end
|
|
local heading = NewView(y, true)
|
|
heading.Label:SetText(group)
|
|
table.insert(panel.views, heading)
|
|
y = y + 20
|
|
end
|
|
local view = NewView(y, false)
|
|
view.Label:SetText(row.label)
|
|
view.Value:SetText(value)
|
|
local weaponSkill = WoWHybridUI and WoWHybridUI.weaponSkill
|
|
if row.options.weaponName and weaponSkill and weaponSkill.FitWeaponName then
|
|
local display = weaponSkill.FitWeaponName(view, value)
|
|
if display ~= value then view.Value:SetText(display) end
|
|
end
|
|
view.labelText, view.fullText, view.detail, view.schools = row.label, value, detail, schools
|
|
table.insert(panel.views, view)
|
|
y = y + 16
|
|
end
|
|
end
|
|
scrollChild:SetHeight(math.max(y + 8, 1))
|
|
end
|
|
|
|
local panelTicker
|
|
local function StopPanelTicker()
|
|
if panelTicker then panelTicker:Cancel(); panelTicker = nil end
|
|
end
|
|
|
|
local function InstallOctoPanel()
|
|
if panel then return true end
|
|
local host = CharacterFrame and CharacterFrame.RightPaneHost
|
|
if not host or not PaperDollFrame then return false end
|
|
-- Parenting to PaperDollFrame gives automatic tab visibility without
|
|
-- installing an addon OnShow/OnHide callback on a native frame.
|
|
toggle = CreateFrame("Button", nil, PaperDollFrame, "UIPanelButtonTemplate")
|
|
toggle:SetSize(88, 20)
|
|
-- Anchor to the bottom of the right pane so it clears the native model /
|
|
-- stat-view tabs at the top of the host.
|
|
toggle:SetPoint("BOTTOMRIGHT", host, "BOTTOMRIGHT", -6, 6)
|
|
toggle:SetText("Octo stats")
|
|
panel = CreateFrame("Frame", nil, PaperDollFrame)
|
|
-- Leave the bottom strip for the toggle; cover the rest of the right pane.
|
|
panel:SetPoint("TOPLEFT", host, "TOPLEFT", 3, -4)
|
|
panel:SetPoint("BOTTOMRIGHT", host, "BOTTOMRIGHT", -3, 31)
|
|
panel:SetFrameLevel(host:GetFrameLevel() + 40)
|
|
panel.rowPool, panel.headerPool = {}, {}
|
|
local background = panel:CreateTexture(nil, "BACKGROUND")
|
|
background:SetAllPoints(panel)
|
|
background:SetColorTexture(0.06, 0.06, 0.08, 1.0)
|
|
local border = panel:CreateTexture(nil, "BORDER")
|
|
border:SetPoint("TOPLEFT", panel, "TOPLEFT", -1, 1)
|
|
border:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", 1, -1)
|
|
border:SetColorTexture(0.25, 0.25, 0.30, 1.0)
|
|
local title = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
|
title:SetPoint("TOPLEFT", panel, "TOPLEFT", 6, -5)
|
|
title:SetText("Octo stats")
|
|
local scroll = CreateFrame("ScrollFrame", nil, panel, "UIPanelScrollFrameTemplate")
|
|
panel.scroll = scroll
|
|
scroll:SetPoint("TOPLEFT", panel, "TOPLEFT", 4, -22)
|
|
scroll:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", -24, 4)
|
|
scrollChild = CreateFrame("Frame", nil, scroll)
|
|
scrollChild:SetWidth(180)
|
|
scrollChild:SetHeight(1)
|
|
scroll:SetScrollChild(scrollChild)
|
|
panel:SetScript("OnShow", function()
|
|
RefreshOctoPanel()
|
|
if not panelTicker and C_Timer and C_Timer.NewTicker then
|
|
panelTicker = C_Timer.NewTicker(60, RefreshOctoPanel)
|
|
end
|
|
end)
|
|
panel:SetScript("OnHide", StopPanelTicker)
|
|
panel:Hide()
|
|
toggle:SetScript("OnClick", function()
|
|
if panel:IsShown() then panel:Hide() else panel:Show() end
|
|
end)
|
|
toggle:Show()
|
|
return true
|
|
end
|
|
|
|
-- SavedVariablesPerCharacter stores only the totals observed by this client.
|
|
local function EndSession()
|
|
if totals then
|
|
totals.seconds = totals.seconds + math.max(0, GetTime() - intervalStart)
|
|
totals, intervalStart = nil, nil
|
|
end
|
|
end
|
|
|
|
local function BeginSession()
|
|
local player = UnitGUID("player")
|
|
if (issecretvalue and issecretvalue(player)) or not player then return end
|
|
if totals and totals == WoWHybridCharacterStatistics and totals.player == player then return end
|
|
EndSession()
|
|
local saved = WoWHybridCharacterStatistics
|
|
if type(saved) ~= "table" or saved.player ~= player then
|
|
saved = {player=player}
|
|
WoWHybridCharacterStatistics = saved
|
|
end
|
|
for _, field in ipairs({"seconds", "casts", "deaths", "quests"}) do
|
|
saved[field] = math.max(0, Number(saved[field]) or 0)
|
|
end
|
|
totals, intervalStart = saved, GetTime()
|
|
end
|
|
|
|
local installedModeTabs
|
|
local function InstallModeTabs()
|
|
local frame = CharacterFrame
|
|
local tabs = frame and frame.ModeTabs
|
|
if not tabs or tabs == installedModeTabs or not tabs.PvPTab or not tabs.CurrencyTab then return end
|
|
|
|
local function UpdateLayout()
|
|
frame:UpdateTabLayout()
|
|
-- Shoulder-button navigation keeps its own list when already open.
|
|
local indicators = frame.TabIndicators
|
|
if indicators and indicators:IsVisible() and indicators.visibleTabs then
|
|
for _, tab in ipairs(indicators.visibleTabs) do
|
|
if tab == tabs.PvPTab or tab == tabs.CurrencyTab then
|
|
indicators:UpdateTabVisibility()
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
local function HideModeTab(button)
|
|
button:Hide()
|
|
UpdateLayout()
|
|
end
|
|
for _, button in ipairs({tabs.PvPTab, tabs.CurrencyTab}) do
|
|
button:HookScript("OnShow", HideModeTab)
|
|
button:Hide()
|
|
end
|
|
installedModeTabs = tabs
|
|
UpdateLayout()
|
|
end
|
|
|
|
-- The separate "Octo stats" box is retired: Octo stats are native Stats-pane categories (OctoStatsPane.lua).
|
|
-- Only the per-character totals recorded here are handed to that pane.
|
|
WoWHybridUI = WoWHybridUI or {}
|
|
function WoWHybridUI.GetRecordedCharacterTotals()
|
|
if not totals or not intervalStart then return end
|
|
local minutes = math.floor((totals.seconds + math.max(0, GetTime() - intervalStart)) / 60)
|
|
return {{"Time (min)", tostring(minutes)}, {"Spellcasts", tostring(totals.casts)},
|
|
{"Quests", tostring(totals.quests)}, {"Deaths", tostring(totals.deaths)}}
|
|
end
|
|
|
|
local function Install()
|
|
InstallModeTabs()
|
|
end
|
|
|
|
local events = CreateFrame("Frame")
|
|
events:RegisterEvent("ADDON_LOADED")
|
|
events:RegisterEvent("PLAYER_ENTERING_WORLD")
|
|
events:RegisterEvent("PLAYER_LEAVING_WORLD")
|
|
events:RegisterEvent("PLAYER_LOGOUT")
|
|
events:RegisterEvent("PLAYER_DEAD")
|
|
events:RegisterEvent("QUEST_TURNED_IN")
|
|
events:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
|
|
events:RegisterEvent("UNIT_STATS")
|
|
events:RegisterEvent("UNIT_AURA")
|
|
events:RegisterEvent("COMBAT_RATING_UPDATE")
|
|
events:RegisterEvent("PLAYER_LEVEL_UP")
|
|
events:RegisterEvent("UNIT_POWER_UPDATE")
|
|
events:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "player")
|
|
events:SetScript("OnEvent", function(_, event, arg)
|
|
if event == "ADDON_LOADED" then
|
|
if arg == "WoWHybridUI" and IsLoggedIn and IsLoggedIn() then BeginSession() end
|
|
Install()
|
|
elseif event == "PLAYER_ENTERING_WORLD" then
|
|
Install()
|
|
BeginSession()
|
|
elseif event == "PLAYER_LOGOUT" or event == "PLAYER_LEAVING_WORLD" then
|
|
EndSession()
|
|
elseif totals then
|
|
if event == "PLAYER_DEAD" then totals.deaths = totals.deaths + 1
|
|
elseif event == "QUEST_TURNED_IN" then totals.quests = totals.quests + 1
|
|
elseif event == "UNIT_SPELLCAST_SUCCEEDED" then totals.casts = totals.casts + 1 end
|
|
end
|
|
RefreshOctoPanel()
|
|
end)
|
|
Install()
|