-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactionbars.lua
More file actions
109 lines (90 loc) · 3.87 KB
/
Copy pathactionbars.lua
File metadata and controls
109 lines (90 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
local addonName, ns = ...
local LAB = LibStub("LibActionButton-1.0")
local buttonSize = 36
local buttonSpacing = 4
local function CreateBar(name, numButtons, point, x, y, rows)
-- Inherit SecureHandlerStateTemplate to use FrameRefs, WrapScript, and StateDrivers safely
local bar = CreateFrame("Frame", "WoWUIActionBar_" .. name, UIParent, "SecureHandlerStateTemplate")
local cols = math.ceil(numButtons / rows)
bar:SetSize((buttonSize + buttonSpacing) * cols - buttonSpacing, (buttonSize + buttonSpacing) * rows - buttonSpacing)
bar:SetPoint(point, x, y)
bar.buttons = {}
for i = 1, numButtons do
local btn = LAB:CreateButton(i, "WoWUIButton_" .. name .. "_" .. i, bar, nil)
btn:SetSize(buttonSize, buttonSize)
local col = (i - 1) % cols
local row = math.floor((i - 1) / cols)
btn:SetPoint("TOPLEFT", bar, "TOPLEFT", col * (buttonSize + buttonSpacing), -row * (buttonSize + buttonSpacing))
table.insert(bar.buttons, btn)
end
ns.WoWUI:RegisterMovable(bar, "ActionBar_" .. name)
table.insert(ns.WoWUI.actionBars, bar)
return bar
end
local MainBar = CreateBar("Main", 12, "BOTTOM", 0, 50, 1)
local BottomLeftBar = CreateBar("BottomLeft", 12, "BOTTOM", 0, 90, 1)
local BottomRightBar = CreateBar("BottomRight", 12, "BOTTOM", 0, 130, 1)
local RightBar1 = CreateBar("Right1", 12, "RIGHT", -50, 0, 12)
local RightBar2 = CreateBar("Right2", 12, "RIGHT", -10, 0, 12)
-- Setup State Drivers for paging (Stance/Form/Stealth/Vehicle)
local pageDriver = "[vehicleui] 12; [possessbar] 12; [overridebar] 14; [shapeshift] 13; [bar:2] 2; [bar:3] 3; [bar:4] 4; [bar:5] 5; [bar:6] 6; [bonusbar:1] 7; [bonusbar:2] 8; [bonusbar:3] 9; [bonusbar:4] 10; 1"
MainBar:RegisterEvent("PLAYER_LOGIN")
MainBar:SetScript("OnEvent", function(self, event)
if event == "PLAYER_LOGIN" then
-- Apply state driver to the main bar
for i, btn in ipairs(MainBar.buttons) do
btn:SetState(0, "action", i)
for state = 1, 14 do
btn:SetState(state, "action", (state - 1) * 12 + i)
end
end
RegisterStateDriver(MainBar, "page", pageDriver)
MainBar:SetAttribute("_onstate-page", [[
self:ChildUpdate("state", newstate)
]])
-- Setup child updates
for i, btn in ipairs(MainBar.buttons) do
MainBar:SetFrameRef("Button"..i, btn)
btn:SetAttribute("frameref-MainBar", MainBar)
end
-- Add button state script mapping (so they react to ChildUpdate)
for i, btn in ipairs(MainBar.buttons) do
SecureHandlerWrapScript(btn, "OnAttributeChanged", btn, [[
if name == "state-page" then
self:SetAttribute("state", value)
end
]])
end
-- Static Action Bars
local staticOffset = {
[BottomLeftBar] = 6, -- Action Page 6 (BottomLeft)
[BottomRightBar] = 5, -- Action Page 5 (BottomRight)
[RightBar1] = 3, -- Action Page 3 (Right 1)
[RightBar2] = 4, -- Action Page 4 (Right 2)
}
for bar, page in pairs(staticOffset) do
for i, btn in ipairs(bar.buttons) do
btn:SetState(0, "action", (page - 1) * 12 + i)
end
end
-- Hide default Blizzard action bars robustly
local hiddenFrame = CreateFrame("Frame")
hiddenFrame:Hide()
local framesToHide = {
MainMenuBar,
MultiBarBottomLeft,
MultiBarBottomRight,
MultiBarLeft,
MultiBarRight,
StanceBarFrame,
PossessBarFrame,
PetActionBarFrame,
}
for _, frame in ipairs(framesToHide) do
if frame then
frame:SetParent(hiddenFrame)
frame:UnregisterAllEvents()
end
end
end
end)