Files

185 lines
9.2 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Octo Spec Profiles: panel inside the native talent window (Talents tab of PlayerSpellsFrame).
-- Ported features live inside the native window: a "Device Specs" button at the free bottom-right corner of the
-- talent frame opens an inset panel over the right side of the talent trees. Native templates only.
-- Top: the Goblin Brainwashing Device's 4 server-side specs - GNS name (click to rename), the talent split the
-- server stores (read from the Device's lines), the linked equipment set, Activate / Save (enabled while
-- the Device's gossip is open; they choose the Device's own line).
-- Below: "Action Sets..." opens the SimpleActionSets editor (ActionSets.lua) and the Device options.
local P = OctoSpecProfiles
local panel, toggle, selected
local ICON, GAP = 24, 2
local function Talents() return GatewayTurtleTalentsOwnedFrame and GatewayTurtleTalentsOwnedFrame() or nil end
local function Button(parent, text, width, onClick)
local b = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
b:SetSize(width, 22); b:SetText(text); b:SetScript("OnClick", onClick)
return b
end
local function Check(parent, label, tooltip, get, set)
local c = CreateFrame("CheckButton", nil, parent, "UICheckButtonTemplate")
c:SetSize(24, 24)
c.label = c:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
c.label:SetPoint("LEFT", c, "RIGHT", 2, 0); c.label:SetText(label)
c:SetScript("OnClick", function(self) set(self:GetChecked()) end)
c:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT"); GameTooltip:SetText(label, 1, 1, 1); GameTooltip:AddLine(tooltip, nil, nil, nil, true); GameTooltip:Show()
end)
c:SetScript("OnLeave", GameTooltip_Hide)
c.Refresh = function(self) self:SetChecked(get()) end
return c
end
local function Dropdown(parent, width, setup)
local d = CreateFrame("DropdownButton", nil, parent, "WowStyle1DropdownTemplate")
d:SetWidth(width)
d:SetupMenu(setup)
return d
end
-------------------------------------------------------------------------------- spec rows
local rows = {}
local function EquipmentMenu(name)
return function(_, root)
local profile = P.Get(name)
local current = profile and profile.equipmentSet
root:CreateRadio("No equipment set", function() return current == nil end, function() P.SetEquipment(name, nil) end)
for _, setName in ipairs(P.EquipmentSetNames()) do
root:CreateRadio(setName, function() return current == setName end, function()
if not P.Get(name) then P.Save(name, true) end
P.SetEquipment(name, setName)
end)
end
end
end
local function BuildSpecRow(n)
local row = CreateFrame("Frame", nil, panel)
row:SetSize(400, 42)
row.name = CreateFrame("Button", nil, row)
row.name:SetSize(170, 18); row.name:SetPoint("TOPLEFT", 4, -2)
row.name.text = row.name:CreateFontString(nil, "ARTWORK", "GameFontNormal")
row.name.text:SetAllPoints(); row.name.text:SetJustifyH("LEFT")
row.name:SetScript("OnClick", function() P.PromptSpecName(n) end)
row.name:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT"); GameTooltip:SetText(P.ORDINALS[n] .. " Specialization", 1, 1, 1)
GameTooltip:AddLine("Click to rename (also /gns " .. n .. ").", nil, nil, nil, true); GameTooltip:Show()
end)
row.name:SetScript("OnLeave", GameTooltip_Hide)
row.info = row:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
row.info:SetPoint("TOPLEFT", row.name, "BOTTOMLEFT", 0, -2); row.info:SetJustifyH("LEFT")
row.equip = Dropdown(row, 120, EquipmentMenu(P.DeviceProfileName(n)))
row.equip:SetPoint("TOPLEFT", 176, -2)
row.activate = Button(row, TALENT_SPEC_ACTIVATE or "Activate", 64, function() P.DeviceChoose("load", n) end)
row.activate:SetPoint("TOPRIGHT", -2, 0)
row.save = Button(row, SAVE or "Save", 64, function() P.DeviceChoose("save", n) end)
row.save:SetPoint("TOPRIGHT", row.activate, "BOTTOMRIGHT", 0, -1)
rows[n] = row
return row
end
local function RefreshSpecRow(n)
local row = rows[n]
row:SetAlpha(n <= P.DeviceSlots() and 1 or 0.35)
local _, char = P.DB()
local active = P.ActiveSpec() == n
local name = P.DeviceProfileName(n)
local profile = P.Get(name)
row.name.text:SetText((active and "|cff00ff00" or "") .. n .. ". " .. P.SpecName(n) .. (active and " (active)|r" or ""))
local talents = char.deviceTalents and char.deviceTalents[n]
row.info:SetText(string.format("Talents %s Bars %s", talents or "?", profile and "saved" or "|cff808080not saved|r"))
row.equip:GenerateMenu()
row.equip:SetText(profile and profile.equipmentSet or "No equipment set")
row.activate:SetEnabled(P.device.open and P.device.options["load" .. n] ~= nil and not active)
row.save:SetEnabled(P.device.open and P.device.options["save" .. n] ~= nil)
end
-------------------------------------------------------------------------------- panel
local options = {}
local function Build()
if panel then return end
-- Owner 2026-11-22: a separate, movable window (native ButtonFrameTemplate), not an overlay in the talent frame.
panel = CreateFrame("Frame", "OctoSpecProfilesPanel", UIParent, "ButtonFrameTemplate")
panel:SetSize(450, 390)
panel:SetPoint("CENTER")
panel:SetFrameStrata("HIGH")
panel:SetToplevel(true)
panel:SetClampedToScreen(true)
panel:SetMovable(true)
panel:EnableMouse(true)
panel:RegisterForDrag("LeftButton")
panel:SetScript("OnDragStart", panel.StartMoving)
panel:SetScript("OnDragStop", panel.StopMovingOrSizing)
if ButtonFrameTemplate_HidePortrait then ButtonFrameTemplate_HidePortrait(panel) end
if ButtonFrameTemplate_HideButtonBar then ButtonFrameTemplate_HideButtonBar(panel) end
if panel.SetTitle then panel:SetTitle("Device Specs") end
if panel.Inset then panel.Inset:Hide() end
panel:Hide()
local title = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 14, -32); title:SetText("Goblin Brainwashing Device Specs")
panel.hint = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
panel.hint:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -4); panel.hint:SetWidth(400); panel.hint:SetJustifyH("LEFT")
local last = panel.hint
for n = 1, P.DEVICE_SPECS do
local row = BuildSpecRow(n)
row:SetPoint("TOPLEFT", last, "BOTTOMLEFT", n == 1 and -4 or 0, -6)
last = row
end
-- The action-set editor is its own window (ActionSets.lua, owner 2026-11-29).
local sets = Button(panel, "Action Sets...", 130, function() if P.ToggleSets then P.ToggleSets() end end)
sets:SetPoint("TOPLEFT", last, "BOTTOMLEFT", 4, -12)
local db = function() local _, _, o = P.DB(); return o end
local specs = {
{"Save before switching", "When you activate another spec at the Device, the bars of the spec you leave are saved first.", "autoSave"},
{"Name prompt after Save", "After 'Save Nth Specialization' at the Device, ask for a name (GNS).", "namePrompt"},
{"Equip linked set", "Activating a spec also equips its linked equipment set.", "equip"},
}
for index, spec in ipairs(specs) do
local c = Check(panel, spec[1], spec[2], function() return db()[spec[3]] end, function(v) db()[spec[3]] = v and true or false end)
c:SetPoint("TOPLEFT", sets, "BOTTOMLEFT", -2, -6 - (index - 1) * 22)
options[#options + 1] = c
end
end
local function Refresh()
if not panel or not panel:IsShown() then return end
if selected and not P.Get(selected) then selected = nil end
if not selected then
local active = P.ActiveSpec()
selected = active and P.Get(P.DeviceProfileName(active)) and P.DeviceProfileName(active) or P.SortedNames()[1]
end
panel.hint:SetText(P.device.open and "|cff00ff00At the Device:|r Activate and Save choose its lines for you."
or "Activate and Save work while you talk to a Goblin Brainwashing Device.")
for n = 1, P.DEVICE_SPECS do RefreshSpecRow(n) end
for _, c in ipairs(options) do c:Refresh() end
end
P.OnChanged = function() pcall(Refresh) end
local function Install()
Build()
if not panel.refreshHooked then panel:SetScript("OnShow", Refresh); panel.refreshHooked = true end
local talents = Talents()
if toggle or not talents then return end
toggle = Button(talents, "Device Specs", 130, function() panel:SetShown(not panel:IsShown()) end)
toggle:SetPoint("BOTTOMRIGHT", talents.Background or talents, "BOTTOMRIGHT", -48, 8)
toggle:SetFrameLevel(talents:GetFrameLevel() + 2001)
end
function P.ToggleWindow()
Install()
panel:SetShown(not panel:IsShown())
Refresh()
end
local events = CreateFrame("Frame")
events:RegisterEvent("ADDON_LOADED")
events:RegisterEvent("EQUIPMENT_SETS_CHANGED")
events:SetScript("OnEvent", function(_, event, name)
if event == "ADDON_LOADED" and name == "Blizzard_PlayerSpells" then Install()
elseif event == "EQUIPMENT_SETS_CHANGED" then P.OnChanged() end
end)
Install()