186 lines
9.5 KiB
Lua
186 lines
9.5 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Octo Spec Profiles: Device spec tabs on the native talents page.
|
|
-- WoWHybridUI's TurtleTalents hides the native Primary/Secondary spec tabs (the Turtle server has no spec groups), so
|
|
-- their place above the trees shows one tab per Goblin Brainwashing Device spec, named with GNS. The active spec's tab
|
|
-- shows the live tree. Another spec's tab shows that spec's talents as last recorded while it was active (the server
|
|
-- reports only the a/b/c split for specs that are not active), read-only; Activate there works at the Device.
|
|
local P = OctoSpecProfiles
|
|
local container, overlay, tabs, viewing = nil, nil, {}, nil
|
|
|
|
local function Talents() return GatewayTurtleTalentsOwnedFrame and GatewayTurtleTalentsOwnedFrame() or nil end
|
|
local function Snapshots() local _, char = P.DB(); char.snapshots = char.snapshots or {}; return char.snapshots end
|
|
|
|
-------------------------------------------------------------------------------- recording
|
|
-- The spec whose talents the provider shows right now: the one last saved/activated at the Device, provided the
|
|
-- server's stored split for it (from the Device's lines) still matches; otherwise a unique split match.
|
|
local function RecordingSpec()
|
|
local _, char = P.DB()
|
|
local split = P.TalentSplit()
|
|
local stored = char.deviceTalents or {}
|
|
local a = char.activeSpec
|
|
-- Only a spec whose saved split is known and equals the live split. (Allowing an unknown split let
|
|
-- every talent change after "Save 1st" overwrite spec 1's record, so both tabs showed one tree.)
|
|
if a and split and stored[a] == split then return a end
|
|
local found
|
|
for n = 1, P.DEVICE_SPECS do
|
|
if split and stored[n] == split then if found then return end; found = n end
|
|
end
|
|
return found
|
|
end
|
|
|
|
function P.RecordSnapshot(n)
|
|
local provider = P.TalentProvider()
|
|
if provider and provider.preview then return end
|
|
n = n or RecordingSpec()
|
|
if not provider or not n then return end
|
|
local ranks, total = {}, 0
|
|
for _, tab in ipairs(provider:ClassTabs()) do
|
|
for _, talent in ipairs(provider.talentsByTab[tab.id] or {}) do
|
|
local rank = provider:Rank(talent.id, false)
|
|
if rank > 0 then ranks[talent.id] = rank; total = total + rank end
|
|
end
|
|
end
|
|
Snapshots()[n] = {ranks = ranks, total = total, split = P.TalentSplit(), class = provider.state.class, saved = time()}
|
|
if overlay and overlay:IsShown() then P.RefreshTabs() end
|
|
end
|
|
|
|
-------------------------------------------------------------------------------- read-only view (native tree, provider preview)
|
|
local function BuildOverlay(talents)
|
|
overlay = CreateFrame("Frame", nil, talents)
|
|
overlay.anchor = talents.ClassBackground or talents
|
|
overlay:SetPoint("TOPLEFT", overlay.anchor, "TOPLEFT")
|
|
overlay:SetPoint("BOTTOMRIGHT", overlay.anchor, "BOTTOMRIGHT")
|
|
overlay:SetFrameLevel(talents:GetFrameLevel() + 1500)
|
|
overlay:EnableMouse(true)
|
|
overlay.bg = overlay:CreateTexture(nil, "BACKGROUND"); overlay.bg:SetAllPoints(); overlay.bg:SetColorTexture(0, 0, 0, 0.82)
|
|
overlay.title = overlay:CreateFontString(nil, "ARTWORK", "GameFontNormalHuge")
|
|
overlay.title:SetPoint("TOP", 0, -14)
|
|
overlay.sub = overlay:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
|
|
overlay.sub:SetPoint("TOP", overlay.title, "BOTTOM", 0, -4)
|
|
overlay.message = overlay:CreateFontString(nil, "ARTWORK", "GameFontHighlightLarge")
|
|
overlay.message:SetPoint("CENTER"); overlay.message:SetJustifyH("CENTER")
|
|
overlay.activate = CreateFrame("Button", nil, overlay, "UIPanelButtonTemplate")
|
|
overlay.activate:SetSize(164, 22); overlay.activate:SetText(TALENT_SPEC_ACTIVATE or "Activate")
|
|
overlay.activate:SetPoint("TOPRIGHT", -14, -16)
|
|
overlay.activate:SetScript("OnClick", function() if viewing then P.DeviceChoose("load", viewing) end end)
|
|
overlay:Hide()
|
|
end
|
|
|
|
-------------------------------------------------------------------------------- tabs
|
|
local function SelectView(n)
|
|
local active = P.ActiveSpec()
|
|
viewing = (n and n ~= active) and n or nil
|
|
P.RefreshTabs()
|
|
end
|
|
|
|
function P.RefreshTabs()
|
|
if not container then return end
|
|
local active = P.ActiveSpec()
|
|
local _, char = P.DB()
|
|
local slots = P.DeviceSlots()
|
|
if viewing and viewing > slots then viewing = nil end
|
|
for n, tab in ipairs(tabs) do
|
|
tab:SetShown(n <= slots)
|
|
local label = P.SpecName(n)
|
|
tab:SetText(n == active and ("|cff00ff00" .. label .. "|r") or label)
|
|
PanelTemplates_TabResize(tab, 12)
|
|
if (viewing or active) == n then PanelTemplates_SelectTab(tab) else PanelTemplates_DeselectTab(tab) end
|
|
end
|
|
local provider = P.TalentProvider()
|
|
if viewing then
|
|
local stored = char.deviceTalents and char.deviceTalents[viewing]
|
|
local snap = Snapshots()[viewing]
|
|
local usable = provider and snap and snap.class == provider.state.class
|
|
overlay.title:SetText(P.SpecName(viewing))
|
|
overlay.sub:SetText(stored and string.format("Saved spec %d - talents %s%s - read-only", viewing, stored,
|
|
snap and (", recorded " .. date("%Y-%m-%d %H:%M", snap.saved)) or "") or "Empty slot")
|
|
overlay.activate:SetShown(P.device.open and P.device.options["load" .. viewing] ~= nil)
|
|
-- The saved spec is drawn by the native tree (provider preview); the overlay is only a header
|
|
-- strip, or a full cover with an explanation when nothing was recorded for this spec yet.
|
|
overlay:ClearAllPoints()
|
|
overlay:SetPoint("TOPLEFT", overlay.anchor, "TOPLEFT")
|
|
overlay:SetPoint("TOPRIGHT", overlay.anchor, "TOPRIGHT")
|
|
if usable then
|
|
overlay:SetHeight(56); overlay.bg:SetColorTexture(0, 0, 0, 0.55); overlay.message:Hide()
|
|
if provider then provider:SetPreview(snap.ranks) end
|
|
else
|
|
overlay:SetPoint("BOTTOMRIGHT", overlay.anchor, "BOTTOMRIGHT"); overlay.bg:SetColorTexture(0, 0, 0, 0.82)
|
|
if provider then provider:SetPreview(nil) end
|
|
overlay.message:SetText(stored and string.format("%s\n\nTalents %s on the Device.\nThis spec's individual talents are recorded the next time it is active\n(activate it once at a Goblin Brainwashing Device).",
|
|
P.SpecName(viewing), stored)
|
|
or string.format("%s\n\nNothing saved in this slot yet.\nSpend all talent points, then choose 'Save %s' at a Goblin Brainwashing Device.",
|
|
P.SpecName(viewing), P.ORDINALS[viewing] .. " Specialization."))
|
|
overlay.message:Show()
|
|
end
|
|
overlay:Show()
|
|
else
|
|
if provider and provider.preview then provider:SetPreview(nil) end
|
|
if overlay then overlay:Hide() end
|
|
end
|
|
end
|
|
|
|
local function TabTooltip(self)
|
|
local n = self.spec
|
|
local _, char = P.DB()
|
|
GameTooltip:SetOwner(self, "ANCHOR_TOP")
|
|
GameTooltip:SetText(P.SpecName(n), 1, 1, 1)
|
|
GameTooltip:AddLine(string.format("Goblin Brainwashing Device spec %d - talents %s", n, char.deviceTalents and char.deviceTalents[n] or "?"), 1, 0.82, 0)
|
|
if P.ActiveSpec() == n then GameTooltip:AddLine("Active", 0.1, 1, 0.1) end
|
|
local profile = P.Get(P.DeviceProfileName(n))
|
|
if profile and profile.equipmentSet then GameTooltip:AddLine("Equipment set: " .. profile.equipmentSet, 1, 1, 1) end
|
|
GameTooltip:AddLine("Right-click to rename.", 0.5, 0.5, 0.5)
|
|
GameTooltip:Show()
|
|
end
|
|
|
|
local function Install()
|
|
local talents = Talents()
|
|
if container or not talents then return end
|
|
BuildOverlay(talents)
|
|
container = CreateFrame("Frame", nil, talents)
|
|
container:SetSize(800, 32)
|
|
container:SetPoint("BOTTOMLEFT", talents.BackgroundBorder or talents, "TOPLEFT", 70, -4)
|
|
container:SetFrameLevel(talents:GetFrameLevel() + 1600)
|
|
for n = 1, P.DEVICE_SPECS do
|
|
local tab = CreateFrame("Button", nil, container, "PanelTopTabButtonTemplate")
|
|
tab.spec = n
|
|
tab:SetID(n)
|
|
tab:RegisterForClicks("LeftButtonUp", "RightButtonUp")
|
|
tab:SetScript("OnClick", function(self, button)
|
|
if button == "RightButton" then P.PromptSpecName(n) else SelectView(n) end
|
|
PlaySound(SOUNDKIT.IG_CHARACTER_INFO_TAB)
|
|
end)
|
|
tab:SetScript("OnEnter", TabTooltip); tab:SetScript("OnLeave", GameTooltip_Hide)
|
|
if n == 1 then tab:SetPoint("BOTTOMLEFT") else tab:SetPoint("LEFT", tabs[n - 1], "RIGHT", 4, 0) end
|
|
tabs[n] = tab
|
|
end
|
|
talents:HookScript("OnShow", function() viewing = nil; P.RecordSnapshot(); P.RefreshTabs() end)
|
|
talents:HookScript("OnHide", function()
|
|
viewing = nil; if overlay then overlay:Hide() end
|
|
local provider = P.TalentProvider(); if provider and provider.preview then provider:SetPreview(nil) end
|
|
end)
|
|
P.RefreshTabs()
|
|
end
|
|
|
|
-- Record the active spec's talents whenever the Turtle provider receives a new talent state.
|
|
local hooked
|
|
local function HookProvider()
|
|
local provider = GatewayTurtleTalents
|
|
if hooked or type(provider) ~= "table" or type(provider.listeners) ~= "table" then return end
|
|
hooked = true
|
|
table.insert(provider.listeners, function() if not viewing then P.RecordSnapshot() end; P.RefreshTabs() end)
|
|
end
|
|
|
|
local previous = P.OnChanged
|
|
P.OnChanged = function() if previous then previous() end; pcall(P.RefreshTabs) end
|
|
|
|
local events = CreateFrame("Frame")
|
|
events:RegisterEvent("ADDON_LOADED")
|
|
events:RegisterEvent("PLAYER_LOGIN")
|
|
events:SetScript("OnEvent", function(_, event, name)
|
|
HookProvider()
|
|
if event == "PLAYER_LOGIN" or name == "Blizzard_PlayerSpells" then Install() end
|
|
end)
|
|
HookProvider()
|
|
Install()
|