-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.lua
299 lines (256 loc) · 8.38 KB
/
core.lua
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
local a, c, v = select(2, ...):unpack()
--=======================================
-- Primary Configuration callback
--=======================================
a:SetScript("OnEvent", a.ConfigCallback)
function a:ConfigCallback()
if (InCombatLockdown()) then
a:RegisterEvent("PLAYER_REGEN_DISABLED")
return
end
a:UnregisterEvent("PLAYER_REGEN_DISABLED")
v.font:SetFont(bdCore.media.font, c.font_size, "OUTLINE")
-- loop through bar callbacks
for k, v in pairs(v.callbacks) do
v()
end
end
local function HideKeybinds(frame)
local hide = frame.hidehotkeys and not IsMouseOverFrame(frame)
for i, button in pairs(frame.buttonList) do
local hotkey = _G[button:GetName().."HotKey"]
if (hotkey) then
if (hide) then
hotkey:Hide()
else
hotkey:Show()
end
end
end
end
--=======================================
-- Create Bars main function
--=======================================
function a:CreateBar(buttonList, cfg)
local frame = CreateFrame("Frame", cfg.frameName, UIParent, "SecureHandlerStateTemplate")
frame:SetPoint(unpack(cfg.frameSpawn))
frame.__blizzardBar = cfg.blizzardBar
frame.buttonList = buttonList
-- hide hotkeys based on mousing over full bar
frame:HookScript("OnEnter", HideKeybinds)
frame:HookScript("OnLeave", HideKeybinds)
-- hook into configuration changes
table.insert(v.callbacks, function() a:LayoutBar(frame, buttonList, cfg) end)
if (cfg.callback) then
table.insert(v.callbacks, cfg.callback)
end
-- Layout the buttons using the config options
a:LayoutBar(frame, buttonList, cfg)
if (cfg.callback) then
cfg:callback(frame)
end
-- Moveable
bdCore:makeMovable(frame)
-- frame:EnableMouse(true)
-- frame:SetMovable(true)
-- frame:SetUserPlaced(true)
-- frame:RegisterForDrag("LeftButton")
-- frame:SetScript("OnDragStart", function() frame:StartMoving() end)
-- frame:SetScript("OnDragStop", function() frame:StopMovingOrSizing() end)
--reparent the Blizzard bar
if cfg.blizzardBar then
cfg.blizzardBar:SetParent(frame)
cfg.blizzardBar:EnableMouse(false)
end
return frame
end
--=======================================
-- Button Layout
--=======================================
function a:LayoutBar(frame, buttonList, cfg)
-- config
frame.limit = c[cfg.cfg.."_buttons"] or 12
frame.scale = c[cfg.cfg.."_scale"] or 1
frame.spacing = (c[cfg.cfg.."_spacing"] or cfg.spacing or 0) + c.border
frame.width = (c[cfg.cfg.."_size"] * frame.scale) * (cfg.widthScale or 1)
frame.height = c[cfg.cfg.."_size"] * frame.scale
frame.rows = c[cfg.cfg.."_rows"] or 1
frame.alpha = c[cfg.cfg.."_alpha"] or 1
frame.enableFader = c[cfg.cfg.."_mouseover"] or false
frame.hidehotkeys = c[cfg.cfg.."_hidehotkeys"] or false
frame.num = #buttonList
frame.cols = math.min(frame.limit, math.floor(frame.num / frame.rows))
-- register visibility driver, on init and on callback
if cfg.frameVisibility then
frame.frameVisibility = cfg.frameVisibility
frame.frameVisibilityFunc = cfg.frameVisibilityFunc
RegisterStateDriver(frame, cfg.frameVisibilityFunc or "visibility", cfg.frameVisibility)
end
-- sizing
local frameWidth = 10 + frame.cols * frame.width + (frame.cols-1) * frame.spacing
local frameHeight = 10 + frame.rows * frame.height + (frame.rows-1) * frame.spacing
frame:SetSize(frameWidth, frameHeight)
frame:SetAlpha(frame.alpha)
-- hotkeys
HideKeybinds(frame)
-- Fader
if (frame.enableFader) then
bdMoveLib:CreateFader(frame, buttonList, alpha)
frame:SetAlpha(0)
end
-- button positioning
local lastRow = nil
local index = 1
local showgrid = tonumber(GetCVar("alwaysShowActionBars"))
for i, button in pairs(buttonList) do
if not frame.__blizzardBar then
button:SetParent(frame)
else
frame.__blizzardBar.size = frame.size
frame.__blizzardBar.alpha = frame.alpha
frame.__blizzardBar.spacing = frame.spacing
end
button:SetSize(frame.width, frame.height)
-- custom skinning callback
if (cfg.buttonSkin) then
cfg.buttonSkin(button)
else
a:SkinButton(button)
end
button:ClearAllPoints()
if (i > frame.limit) then
button:SetPoint("CENTER", v.hidden, "CENTER", 0, 0)
button:Hide()
button:SetAlpha(0)
else
button:SetAlpha(1)
button:Show()
button:SetAttribute("showgrid", showgrid)
if (i == 1) then
button:SetPoint("TOPLEFT", frame, "TOPLEFT", 5, -5)
lastRow = button
elseif (index > frame.cols) then
button:SetPoint("TOPLEFT", lastRow, "BOTTOMLEFT", 0, -frame.spacing)
lastRow = button
index = 1
else
button:SetPoint("LEFT", buttonList[i - 1], "RIGHT", frame.spacing, 0)
end
end
index = index + 1
end
end
--=======================================
-- Skinning
--=======================================
function a:SkinButton(button)
if button.skinned then return end
if (not button.SetNormalTexture) then return end
local name = button:GetName()
local icon = _G[name.."Icon"]
local count = _G[name.."Count"]
local macro = _G[name.."Name"]
local cooldown = _G[name.."Cooldown"]
local flash = _G[name.."Flash"]
local checked = _G[name.."Checked"]
local shine = _G[name.."Shine"]
local hotkey = _G[name.."HotKey"]
local border = _G[name.."Border"]
local normal = _G[name.."NormalTexture"]
local normal2 = _G[name.."NormalTexture2"]
local btnBG = _G[name.."FloatingBG"]
local autocastable = _G[name.."AutoCastable"]
button:SetNormalTexture("")
if ( not flash ) then return end
flash:SetTexture("")
icon:SetTexCoord(.1, .9, .1, .9)
icon:SetDrawLayer("ARTWORK")
-- Text Overrides
hotkey:SetFontObject(v.font)
hotkey:SetJustifyH("Right")
hotkey:SetVertexColor(1, 1, 1)
hotkey:SetTextColor(1, 1, 1)
hotkey.SetTextColor = a.noop
hotkey.SetVertexColor = a.noop
hotkey:ClearAllPoints()
hotkey:SetPoint("TOPRIGHT", button, "TOPRIGHT", 0,-3)
count:SetFontObject(v.font)
count:SetTextColor(0.7,0.7,0.7)
count:SetJustifyH("Center")
count:SetTextColor(1,1,1)
count:ClearAllPoints()
count:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", 0,0)
if (not macro) then return end
macro:SetFontObject(v.font)
macro:SetTextColor(0.7,0.7,0.7)
macro:SetJustifyH("RIGHT")
macro:SetTextColor(1,1,1)
macro:ClearAllPoints()
macro:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", 0,1)
-- Fix cooldown Spiral Positioning
cooldown:GetRegions():SetFontObject(v.font)
cooldown:GetRegions():SetJustifyH("Center")
cooldown:GetRegions():ClearAllPoints()
cooldown:GetRegions():SetAllPoints(cooldown)
cooldown:SetParent(button)
cooldown:ClearAllPoints()
cooldown:SetAllPoints(button)
-- Button Overwrite Textures
button.hover = button:CreateTexture()
button.hover:SetTexture(bdCore.media.flat)
button.hover:SetVertexColor(1, 1, 1, 0.1)
button.hover:SetAllPoints(button)
button:SetHighlightTexture(button.hover)
button.pushed = button:CreateTexture()
button.pushed:SetTexture(bdCore.media.flat)
button.pushed:SetVertexColor(1, 1, 1, 0.2)
button.pushed:SetAllPoints(button)
button:SetPushedTexture(button.pushed)
button.checked = button:CreateTexture()
button.checked:SetTexture(bdCore.media.flat)
button.checked:SetVertexColor(0.2,1,0.2)
button.checked:SetAlpha(0.3)
button.checked.SetAlpha = a.noop
button.checked:SetAllPoints(button)
button:SetCheckedTexture(button.checked)
-- Position these things onto the button
if (shine) then
shine:SetAlpha(0)
shine:Hide()
shine:SetPoint("BOTTOMLEFT", button, "BOTTOMLEFT", 0, 0)
shine:SetPoint("TOPRIGHT", button, "TOPRIGHT", 0, 0)
end
if (checked) then
checked:SetPoint("BOTTOMLEFT", button, "BOTTOMLEFT", 0, 0)
checked:SetPoint("TOPRIGHT", button, "TOPRIGHT", 0, 0)
end
-- Force hide elements we don't want
a:ForceHide(autocastable)
a:ForceHide(normal2)
a:ForceHide(border)
a:ForceHide(btnBG)
bdCore:setBackdrop(button)
button.skinned = true
end
-- Flyout skinning
local function StyleFlyout(self)
if (not self.FlyoutArrow or InCombatLockdown()) then return end
local parent = self:GetParent():GetParent():GetParent()
local size = parent and parent.width or c.bar1_size
local alpha = parent and parent.alpha or 1
local spacing = parent and parent.spacing or 2
for i = 1, NUM_ACTIONBAR_BUTTONS do
local button = _G["SpellFlyoutButton"..i]
if not button then break end
a:SkinButton(button)
button:ClearAllPoints()
button:SetSize(size, size)
if (i == 1) then
button:SetPoint("BOTTOM", SpellFlyout, "BOTTOM", 0, spacing)
else
button:SetPoint("BOTTOM", _G["SpellFlyoutButton"..i-1], "TOP", 0, spacing)
end
end
end
hooksecurefunc("ActionButton_UpdateFlyout", StyleFlyout)
hooksecurefunc("SpellButton_OnClick", StyleFlyout)