Files

438 lines
22 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Octo Spec Profiles: SimpleActionSets editor (owner 2026-11-29: "the window is too small and it didn't let me edit
-- anything"). Full port of the Octo 1.12 SimpleActionSets window as an add-on-owned native-look window:
-- * set dropdown (this character's sets; other characters' sets can be loaded and saved under a new name)
-- * 10 bars x 12 slots, scrollable, per-bar "apply this bar" switch
-- * drag spells / items / macros / equipment sets / action-bar buttons onto a slot; click a slot to pick its
-- action up (drop it on a real bar or on another slot); right-click clears a slot
-- * Save, Save As, New from bars, Load current bars, Clear, Revert, Delete, Apply, Undo apply
-- * options (skip empty bars/slots, equip linked set, auto restore at login + warning, minimap button)
-- * resizable and movable; size and position are remembered.
-- Edits go to a working copy; nothing touches the real action bars until Apply.
local P = OctoSpecProfiles
local win, scroll, content
local rows, cells = {}, {}
local edit = {name = nil, actions = {}, bars = {}, dirty = false, source = nil}
local GAP, LABEL_H, MIN_ICON, MAX_ICON = 3, 22, 26, 44
local function Opt() local _, _, o = P.DB(); return o end
local function Copy(t) local c = {}; for k, v in pairs(t or {}) do if type(v) == "table" then c[k] = Copy(v) else c[k] = v end end; return c end
local function Note(text) if win then win.status:SetText(text or "") end end
local function Button(parent, text, width, tooltip, onClick)
local b = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
b:SetSize(width, 22); b:SetText(text); b:SetScript("OnClick", onClick)
if tooltip then
b:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP"); GameTooltip:SetText(text, 1, 1, 1); GameTooltip:AddLine(tooltip, nil, nil, nil, true); GameTooltip:Show()
end)
b:SetScript("OnLeave", GameTooltip_Hide)
end
return b
end
-------------------------------------------------------------------------------- working copy
local function Load(name, profile, source)
edit.name, edit.source = name, source
edit.actions = Copy(profile and profile.actions)
edit.bars = Copy(profile and profile.bars)
for bar = 1, P.NUM_BARS do if edit.bars[bar] == nil then edit.bars[bar] = true end end
edit.dirty = false
end
local function Changed() edit.dirty = true; P.OnChanged() end
local function SaveAs(default)
P.PromptName("Save this action set as:", default or "", function(text)
if text and text:match("%S") then
text = text:sub(1, 30)
P.Store(text, Copy(edit.actions), Copy(edit.bars))
edit.name, edit.source, edit.dirty = text, nil, false
P.OnChanged()
end
end)
end
local function Save()
if not edit.name or edit.source then SaveAs(edit.name); return end
P.Store(edit.name, Copy(edit.actions), Copy(edit.bars)); edit.dirty = false; P.OnChanged()
end
-------------------------------------------------------------------------------- slots
local function SlotTooltip(cell)
local rec = edit.actions[cell.slot]
GameTooltip:SetOwner(cell, "ANCHOR_RIGHT")
if not rec then GameTooltip:SetText(EMPTY or "Empty", 0.6, 0.6, 0.6)
elseif rec.t == "spell" and GameTooltip.SetSpellByID then GameTooltip:SetSpellByID(rec.id)
elseif rec.t == "item" and GameTooltip.SetItemByID then GameTooltip:SetItemByID(rec.id)
else GameTooltip:SetText((rec.name or rec.t) .. " (" .. rec.t .. ")", 1, 1, 1) end
if rec and not P.Known(rec) then GameTooltip:AddLine("Not available now (spell not known / item not in bags).", 1, 0.3, 0.3, true) end
GameTooltip:AddLine(string.format("%s, slot %d", P.BAR_LABELS[math.ceil(cell.slot / P.BAR_SIZE)], (cell.slot - 1) % P.BAR_SIZE + 1), 0.5, 0.5, 0.5)
GameTooltip:AddLine("Drop an action here. Click: pick up. Right-click: clear.", 0.5, 0.8, 1, true)
GameTooltip:Show()
end
local function DropOnto(cell)
local rec, kind = P.RecordFromCursor()
if not rec then
if kind then Note("|cffff6060" .. kind .. " actions cannot be stored in a set.|r") end
return false
end
local old = edit.actions[cell.slot]
edit.actions[cell.slot] = rec
ClearCursor()
if old then P.PickupRecord(old) end -- swap like an action bar: the replaced action goes on the cursor
Changed()
return true
end
local function PickUp(cell)
local rec = edit.actions[cell.slot]
if not rec then return end
if P.PickupRecord(rec) then edit.actions[cell.slot] = nil; Changed()
else Note("|cffff6060" .. (rec.name or "That action") .. " cannot be picked up (not known / not in bags).|r") end
end
local function NewCell(parent, slot)
local cell = CreateFrame("Button", nil, parent)
cell.slot = slot
cell.bg = cell:CreateTexture(nil, "BACKGROUND"); cell.bg:SetAllPoints(); cell.bg:SetTexture("Interface\\Buttons\\UI-EmptySlot-Disabled")
cell.bg:SetTexCoord(0.2, 0.8, 0.2, 0.8)
cell.icon = cell:CreateTexture(nil, "ARTWORK"); cell.icon:SetPoint("TOPLEFT", 1, -1); cell.icon:SetPoint("BOTTOMRIGHT", -1, 1)
cell.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
cell.border = cell:CreateTexture(nil, "OVERLAY"); cell.border:SetAllPoints(); cell.border:SetColorTexture(0, 0, 0, 0)
cell:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square", "ADD")
cell:RegisterForClicks("LeftButtonUp", "RightButtonUp")
cell:RegisterForDrag("LeftButton")
cell:SetScript("OnEnter", SlotTooltip)
cell:SetScript("OnLeave", GameTooltip_Hide)
cell:SetScript("OnClick", function(self, button)
if button == "RightButton" then
if edit.actions[self.slot] then edit.actions[self.slot] = nil; Changed() end
elseif GetCursorInfo() then DropOnto(self)
else PickUp(self) end
if GameTooltip:IsOwned(self) then SlotTooltip(self) end
end)
cell:SetScript("OnDragStart", PickUp)
cell:SetScript("OnReceiveDrag", DropOnto)
return cell
end
local function BuildRows()
for bar = 1, P.NUM_BARS do
local row = CreateFrame("Frame", nil, content)
row.check = CreateFrame("CheckButton", nil, row, "UICheckButtonTemplate")
row.check:SetSize(22, 22); row.check:SetPoint("TOPLEFT", 0, 0)
row.check:SetScript("OnClick", function(self) edit.bars[bar] = self:GetChecked() and true or false; Changed() end)
row.check:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT"); GameTooltip:SetText(P.BAR_LABELS[bar], 1, 1, 1)
GameTooltip:AddLine("Unchecked bars are left alone when this set is applied.", nil, nil, nil, true); GameTooltip:Show()
end)
row.check:SetScript("OnLeave", GameTooltip_Hide)
row.label = row:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
row.label:SetPoint("LEFT", row.check, "RIGHT", 2, 0); row.label:SetText(bar .. ". " .. P.BAR_LABELS[bar])
row.clear = CreateFrame("Button", nil, row, "UIPanelButtonTemplate")
row.clear:SetSize(60, 18); row.clear:SetText("Clear"); row.clear:SetPoint("TOPRIGHT", 0, -2)
row.clear:SetScript("OnClick", function()
for i = 1, P.BAR_SIZE do edit.actions[(bar - 1) * P.BAR_SIZE + i] = nil end; Changed()
end)
row.take = CreateFrame("Button", nil, row, "UIPanelButtonTemplate")
row.take:SetSize(84, 18); row.take:SetText("From bars"); row.take:SetPoint("RIGHT", row.clear, "LEFT", -4, 0)
row.take:SetScript("OnClick", function()
for i = 1, P.BAR_SIZE do local slot = (bar - 1) * P.BAR_SIZE + i; edit.actions[slot] = P.CaptureSlot(slot) end; Changed()
end)
row.take:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP"); GameTooltip:SetText("Copy this bar from your current action bars", 1, 1, 1); GameTooltip:Show()
end)
row.take:SetScript("OnLeave", GameTooltip_Hide)
for i = 1, P.BAR_SIZE do
local slot = (bar - 1) * P.BAR_SIZE + i
cells[slot] = NewCell(row, slot)
end
rows[bar] = row
end
end
-- Lay the rows out for the current width: icons grow with the window (SAS had fixed 36 px buttons).
local function Layout()
if not win then return end
local width = scroll:GetWidth()
if not width or width <= 0 then return end
local icon = math.floor((width - 8 - (P.BAR_SIZE - 1) * GAP) / P.BAR_SIZE)
icon = math.max(MIN_ICON, math.min(MAX_ICON, icon))
local rowH = LABEL_H + icon + 8
content:SetSize(width, rowH * P.NUM_BARS)
for bar = 1, P.NUM_BARS do
local row = rows[bar]
row:ClearAllPoints(); row:SetPoint("TOPLEFT", 0, -(bar - 1) * rowH); row:SetSize(width, rowH)
for i = 1, P.BAR_SIZE do
local cell = cells[(bar - 1) * P.BAR_SIZE + i]
cell:SetSize(icon, icon); cell:ClearAllPoints()
cell:SetPoint("TOPLEFT", 4 + (i - 1) * (icon + GAP), -LABEL_H)
end
end
end
local function RefreshSlots()
for bar = 1, P.NUM_BARS do
local row = rows[bar]
row.check:SetChecked(edit.bars[bar] ~= false)
row:SetAlpha(edit.bars[bar] == false and 0.55 or 1)
end
for slot, cell in pairs(cells) do
local rec = edit.actions[slot]
cell.icon:SetTexture(rec and P.Icon(rec) or nil)
cell.icon:SetDesaturated(rec ~= nil and not P.Known(rec))
if rec and not P.Known(rec) then cell.icon:SetVertexColor(1, 0.5, 0.5) else cell.icon:SetVertexColor(1, 1, 1) end
end
end
-------------------------------------------------------------------------------- window
local function SetMenu(_, root)
root:CreateTitle("This character")
local names = P.SortedNames()
if #names == 0 then root:CreateButton("|cff808080(no saved sets)|r", function() end) end
for _, name in ipairs(names) do
root:CreateRadio(P.DisplayName(name), function() return edit.name == name and not edit.source end, function()
Load(name, P.Get(name)); P.OnChanged()
end)
end
local others = P.OtherCharacters()
if #others > 0 then
root:CreateDivider()
local sub = root:CreateButton("Other characters")
for _, key in ipairs(others) do
local charMenu = sub:CreateButton(key)
local list = {}
for name in pairs(P.OtherProfiles(key)) do list[#list + 1] = name end
table.sort(list)
for _, name in ipairs(list) do
charMenu:CreateButton(P.DisplayName(name), function()
Load(name, P.OtherProfiles(key)[name], key); edit.dirty = true
Note("Loaded " .. name .. " from " .. key .. ". Save it to keep it on this character.")
P.OnChanged()
end)
end
end
end
end
local function OptionCheck(parent, label, tooltip, key, onSet)
local c = CreateFrame("CheckButton", nil, parent, "UICheckButtonTemplate")
c:SetSize(22, 22)
c.text2 = c:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
c.text2:SetPoint("LEFT", c, "RIGHT", 1, 0); c.text2:SetText(label)
c:SetScript("OnClick", function(self) Opt()[key] = self:GetChecked() and true or false; if onSet then onSet() end end)
c:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP"); 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(Opt()[key]) end
return c
end
local optionChecks = {}
local function Build()
if win then return end
win = CreateFrame("Frame", "OctoActionSetsFrame", UIParent, "ButtonFrameTemplate")
win:SetFrameStrata("HIGH"); win:SetToplevel(true); win:SetClampedToScreen(true)
win:SetMovable(true); win:SetResizable(true); win:EnableMouse(true)
if win.SetResizeBounds then win:SetResizeBounds(560, 430, 1100, 1000) end
win:RegisterForDrag("LeftButton")
win:SetScript("OnDragStart", win.StartMoving)
win:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local o = Opt(); local x, y = self:GetLeft(), self:GetTop()
o.window = {x = x, y = y, w = self:GetWidth(), h = self:GetHeight()}
end)
if ButtonFrameTemplate_HidePortrait then ButtonFrameTemplate_HidePortrait(win) end
if ButtonFrameTemplate_HideButtonBar then ButtonFrameTemplate_HideButtonBar(win) end
if win.SetTitle then win:SetTitle("Action Sets") end
if win.Inset then win.Inset:ClearAllPoints(); win.Inset:SetPoint("TOPLEFT", 10, -112); win.Inset:SetPoint("BOTTOMRIGHT", -8, 82) end
tinsert(UISpecialFrames, "OctoActionSetsFrame")
local o = Opt()
local w = o.window
win:SetSize(w and w.w or 640, w and w.h or 640)
if w and w.x then win:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", w.x, w.y) else win:SetPoint("CENTER") end
win:Hide()
-- set selection + apply row
local setLabel = win:CreateFontString(nil, "ARTWORK", "GameFontNormal")
setLabel:SetPoint("TOPLEFT", 16, -34); setLabel:SetText("Set:")
win.setMenu = CreateFrame("DropdownButton", nil, win, "WowStyle1DropdownTemplate")
win.setMenu:SetWidth(230); win.setMenu:SetPoint("LEFT", setLabel, "RIGHT", 8, 0)
win.setMenu:SetupMenu(SetMenu)
win.apply = Button(win, "Apply", 80, "Put this set on your action bars (unsaved edits are applied too).", function()
if edit.dirty and edit.name and not edit.source then Save() end
if edit.name and not edit.source and P.Get(edit.name) then P.Apply(edit.name)
else Note("|cffff6060Save the set first.|r") end
end)
win.apply:SetPoint("LEFT", win.setMenu, "RIGHT", 8, 0)
win.undo = Button(win, "Undo Apply", 96, "Put your bars back to how they were before the last Apply.", function() P.Undo() end)
win.undo:SetPoint("LEFT", win.apply, "RIGHT", 4, 0)
-- editing row
local bar = CreateFrame("Frame", nil, win); bar:SetSize(10, 22); bar:SetPoint("TOPLEFT", 12, -62)
local defs = {
{"Save", 64, "Save your edits to this set.", Save},
{"Save As...", 84, "Save the edited set under a new name.", function() SaveAs(edit.name and (edit.name .. " copy")) end},
{"New from bars", 110, "Start a new set from your current action bars.", function()
Load(nil, {actions = P.CaptureAll()}); edit.dirty = true; SaveAs("") end},
{"Load bars", 84, "Replace the edited set with your current action bars (not saved until you press Save).", function()
edit.actions = P.CaptureAll(); Changed() end},
{"Clear", 60, "Empty every slot of the edited set.", function() edit.actions = {}; Changed() end},
{"Revert", 64, "Throw away unsaved edits.", function()
if edit.name and not edit.source then Load(edit.name, P.Get(edit.name)) end; P.OnChanged() end},
{DELETE or "Delete", 64, "Delete this set.", function()
if edit.name and not edit.source and P.Get(edit.name) then
local name = edit.name; P.Delete(name); Load(nil, nil); Note("Deleted " .. name .. ".")
P.OnChanged()
end
end},
}
local last
win.edits = {}
for _, d in ipairs(defs) do
local b = Button(bar, d[1], d[2], d[3], d[4])
if last then b:SetPoint("LEFT", last, "RIGHT", 3, 0) else b:SetPoint("LEFT") end
last = b; win.edits[d[1]] = b
end
win.dirtyText = win:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
win.dirtyText:SetPoint("TOPLEFT", 16, -90)
-- bars
scroll = CreateFrame("ScrollFrame", nil, win, "ScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", win.Inset or win, "TOPLEFT", 6, -6)
scroll:SetPoint("BOTTOMRIGHT", win.Inset or win, "BOTTOMRIGHT", -26, 6)
content = CreateFrame("Frame", nil, scroll); content:SetSize(10, 10)
scroll:SetScrollChild(content)
BuildRows()
scroll:SetScript("OnSizeChanged", Layout)
-- options
local optionDefs = {
{"Skip empty bars", "Bars with no actions in the set are not applied.", "emptyBars"},
{"Keep empty slots", "Slots that are empty in the set keep what is on your bar now.", "emptyButtons"},
{"Equip linked set", "Applying a Device spec also equips its linked equipment set.", "equip"},
{"Auto restore at login", "At login, put your bars back to how they were at your last logout (a character played on several computers).", "autoRestore"},
{"Warn on auto restore", "Tell me in chat when auto restore changed something.", "autoRestoreWarn"},
{"Minimap button", "Show the Action Sets button on the minimap.", "minimap", function() if P.UpdateMinimapButton then P.UpdateMinimapButton() end end},
}
for index, d in ipairs(optionDefs) do
local c = OptionCheck(win, d[1], d[2], d[3], d[4])
local col, line = (index - 1) % 3, math.floor((index - 1) / 3)
c:SetPoint("BOTTOMLEFT", 14 + col * 185, 52 - line * 22)
optionChecks[#optionChecks + 1] = c
end
win.status = win:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
win.status:SetPoint("BOTTOMLEFT", 16, 12); win.status:SetPoint("RIGHT", -40, 0); win.status:SetJustifyH("LEFT")
win.device = Button(win, "Device Specs", 110, "Goblin Brainwashing Device specs (names, talents, equipment sets).", function()
if P.ToggleWindow then P.ToggleWindow() end
end)
win.device:SetPoint("BOTTOMRIGHT", -30, 8)
-- resize grip
local grip = CreateFrame("Button", nil, win)
grip:SetSize(16, 16); grip:SetPoint("BOTTOMRIGHT", -4, 4)
grip:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
grip:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
grip:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
grip:SetScript("OnMouseDown", function() win:StartSizing("BOTTOMRIGHT") end)
grip:SetScript("OnMouseUp", function()
win:StopMovingOrSizing()
Opt().window = {x = win:GetLeft(), y = win:GetTop(), w = win:GetWidth(), h = win:GetHeight()}
Layout()
end)
win:SetScript("OnShow", function()
if not edit.name and not edit.source then
local _, char = P.DB()
local name = char.lastApplied and P.Get(char.lastApplied) and char.lastApplied or P.SortedNames()[1]
if name then Load(name, P.Get(name)) end
end
Layout(); P.OnChanged()
end)
end
local function Refresh()
if not win or not win:IsShown() then return end
if edit.name and not edit.source and not P.Get(edit.name) and not edit.dirty then Load(nil, nil) end
win.setMenu:GenerateMenu()
local title = edit.name and P.DisplayName(edit.name) or "(new set)"
if edit.source then title = title .. " (" .. edit.source .. ")" end
win.setMenu:SetText(title)
win.dirtyText:SetText(edit.dirty and "|cffffd100Unsaved changes|r" or "")
local saved = edit.name and not edit.source and P.Get(edit.name) ~= nil
win.apply:SetEnabled(saved or (edit.name ~= nil and not edit.source))
win.undo:SetEnabled(P.CanUndo())
win.edits[DELETE or "Delete"]:SetEnabled(saved)
win.edits["Revert"]:SetEnabled(saved and edit.dirty)
RefreshSlots()
for _, c in ipairs(optionChecks) do c:Refresh() end
end
local previous = P.OnChanged
P.OnChanged = function() if previous then previous() end; pcall(Refresh) end
function P.ToggleSets()
Build()
win:SetShown(not win:IsShown())
end
-------------------------------------------------------------------------------- minimap button (SAS)
local mini
local function PlaceMini()
local angle = math.rad(Opt().minimapAngle or 200)
mini:ClearAllPoints()
mini:SetPoint("CENTER", Minimap, "CENTER", math.cos(angle) * 80, math.sin(angle) * 80)
end
function P.UpdateMinimapButton()
if not Minimap then return end
if not mini then
mini = CreateFrame("Button", "OctoActionSetsMinimapButton", Minimap)
mini:SetSize(31, 31); mini:SetFrameStrata("MEDIUM"); mini:SetFrameLevel(8)
mini.icon = mini:CreateTexture(nil, "BACKGROUND"); mini.icon:SetSize(20, 20); mini.icon:SetPoint("TOPLEFT", 7, -5)
mini.icon:SetTexture("Interface\\Icons\\INV_Gizmo_02")
mini.border = mini:CreateTexture(nil, "OVERLAY"); mini.border:SetSize(53, 53); mini.border:SetPoint("TOPLEFT")
mini.border:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
mini:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
mini:RegisterForClicks("LeftButtonUp", "RightButtonUp")
mini:RegisterForDrag("LeftButton")
mini:SetScript("OnDragStart", function(self)
self:SetScript("OnUpdate", function()
local mx, my = Minimap:GetCenter()
local cx, cy = GetCursorPosition(); local scale = Minimap:GetEffectiveScale()
Opt().minimapAngle = math.deg(math.atan2(cy / scale - my, cx / scale - mx))
PlaceMini()
end)
end)
mini:SetScript("OnDragStop", function(self) self:SetScript("OnUpdate", nil) end)
mini:SetScript("OnClick", function(self, button)
if button == "RightButton" and MenuUtil and MenuUtil.CreateContextMenu then
MenuUtil.CreateContextMenu(self, function(_, root)
root:CreateTitle("Apply action set")
for _, name in ipairs(P.SortedNames()) do root:CreateButton(P.DisplayName(name), function() P.Apply(name) end) end
if P.CanUndo() then root:CreateDivider(); root:CreateButton("Undo last apply", P.Undo) end
end)
else
P.ToggleSets()
end
end)
mini:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT"); GameTooltip:SetText("Action Sets", 1, 1, 1)
GameTooltip:AddLine("Left-click: open the editor. Right-click: apply a set. Drag: move.", nil, nil, nil, true)
GameTooltip:Show()
end)
mini:SetScript("OnLeave", GameTooltip_Hide)
end
PlaceMini()
mini:SetShown(Opt().minimap)
end
local events = CreateFrame("Frame")
events:RegisterEvent("PLAYER_LOGIN")
events:RegisterEvent("BAG_UPDATE_DELAYED")
events:RegisterEvent("SPELLS_CHANGED")
events:SetScript("OnEvent", function(_, event)
if event == "PLAYER_LOGIN" then pcall(P.UpdateMinimapButton)
elseif win and win:IsShown() then pcall(RefreshSlots) end
end)