Files

82 lines
3.4 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Octo Honor: spendable honor currency from Octo's TW_HONOR service (Tortoise HonorMgr
-- SendHonorCurrencyUpdate "S2C_HONOR_RESPONSE;<points>"; ChatHandler answers
-- "C2S_HONOR_REQUEST"). Shown in whichever native honor pane this client loads
-- (vanilla HonorFrame or camelot PVPRankFrame), as Octo's honorframe.lua does: faction
-- PvP icon and the amount grouped by spaces.
local PREFIX = "TW_HONOR"
local points
local function send(payload)
if not C_ChatInfo or type(C_ChatInfo.SendAddonMessage) ~= "function" then return false end
local result = C_ChatInfo.SendAddonMessage(PREFIX, payload, "WHISPER", UnitName("player"))
return result == 0 or result == true
end
local function grouped(value)
local s, n = tostring(value), 0
repeat s, n = s:gsub("^(-?%d+)(%d%d%d)", "%1 %2") until n == 0
return s
end
local displays = {}
local function display(parent, anchor)
if displays[parent] then return displays[parent] end
local holder = CreateFrame("Frame", nil, parent)
holder:SetSize(140, 20)
anchor(holder)
-- Above the rank emblem ring, which otherwise covers the icon.
holder:SetFrameLevel(parent:GetFrameLevel() + 10)
local icon = holder:CreateTexture(nil, "ARTWORK")
icon:SetSize(18, 18)
icon:SetPoint("LEFT")
local text = holder:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
text:SetPoint("LEFT", icon, "RIGHT", 2, 0)
holder:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(HONOR_POINTS or HONOR, 1, 1, 1)
GameTooltip:Show()
end)
holder:SetScript("OnLeave", GameTooltip_Hide)
holder.icon, holder.text = icon, text
displays[parent] = holder
return holder
end
local function refresh()
local faction = UnitFactionGroup("player")
for _, holder in pairs(displays) do
-- Client FDIDs icons/pvpcurrency-honor-alliance|horde (square currency icons).
holder.icon:SetTexture(faction == "Alliance" and 463450 or 463451)
holder.text:SetText(points and grouped(points) or "")
holder:SetShown(points ~= nil)
end
end
local hooked = {}
local function hook(frame, anchor)
if not frame or hooked[frame] then return end
hooked[frame] = true
display(frame, anchor)
frame:HookScript("OnShow", function() send("C2S_HONOR_REQUEST"); refresh() end)
end
local function hookAll()
hook(HonorFrame, function(h) h:SetPoint("TOPRIGHT", HonorFrame, "TOPRIGHT", -44, -76) end)
hook(PVPRankFrame, function(h) h:SetPoint("TOPRIGHT", PVPRankFrame.MainInfoFrame or PVPRankFrame, "BOTTOMRIGHT", -8, -4) end)
end
hookAll()
local events = CreateFrame("Frame")
if C_ChatInfo and C_ChatInfo.RegisterAddonMessagePrefix then C_ChatInfo.RegisterAddonMessagePrefix(PREFIX) end
events:RegisterEvent("CHAT_MSG_ADDON")
events:RegisterEvent("PLAYER_ENTERING_WORLD")
events:RegisterEvent("ADDON_LOADED")
events:SetScript("OnEvent", function(_, event, prefix, message, distribution, sender)
if event ~= "CHAT_MSG_ADDON" then hookAll(); return end
if prefix ~= PREFIX or distribution ~= "GUILD" then return end
if sender and Ambiguate(sender, "none") ~= UnitName("player") then return end
local value = message:match("^S2C_HONOR_RESPONSE;(%d+)$")
if value then points = tonumber(value); refresh() end
end)