-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathActionBar.lua
318 lines (265 loc) · 9.29 KB
/
ActionBar.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
--[[
Copyright (c) 2009-2017, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com >
All rights reserved.
]]
local _, Bartender4 = ...
local StateBar = Bartender4.StateBar.prototype
local ActionBar = setmetatable({}, {__index = StateBar})
Bartender4.ActionBar = ActionBar
local LAB10 = LibStub("LibActionButton-1.0")
local tonumber, format, min = tonumber, format, min
-- GLOBALS: UIParent, VehicleExit
--[[===================================================================================
ActionBar Prototype
===================================================================================]]--
local initialPosition
do
-- Sets the Bar to its initial Position in the Center of the Screen
function initialPosition(bar)
local offset = type(bar.id) == "number" and bar.id or 1
bar:ClearSetPoint("CENTER", 0, -250 + (offset-1) * 38)
bar:SavePosition()
end
end
-- Apply the specified config to the bar and refresh all settings
function ActionBar:ApplyConfig(config)
StateBar.ApplyConfig(self, config)
if not self.config.position.x then initialPosition(self) end
self:SetupSmartTarget()
self:UpdateButtons()
self:UpdateButtonConfig()
end
function ActionBar:OnEvent(event, ...)
if event == "PLAYER_TALENT_UPDATE" or event == "PLAYER_SPECIALIZATION_CHANGED" or event == "LEARNED_SPELL_IN_TAB" then
if InCombatLockdown() then
self.updateSmartTargetOnOutOfCombat = true
else
self:SetupSmartTarget()
end
elseif event == "PLAYER_REGEN_ENABLED" then
if self.updateSmartTargetOnOutOfCombat and not InCombatLockdown() then
self.updateSmartTargetOnOutOfCombat = nil
self:SetupSmartTarget()
end
end
StateBar.OnEvent(self, event, ...)
end
function ActionBar:UpdateButtonConfig()
StateBar.UpdateButtonConfig(self)
if not self.buttonConfig then self.buttonConfig = { colors = { range = {}, mana = {} }, hideElements = {} } end
self.buttonConfig.outOfRangeColoring = Bartender4.db.profile.outofrange
self.buttonConfig.tooltip = Bartender4.db.profile.tooltip
self.buttonConfig.colors.range[1], self.buttonConfig.colors.range[2], self.buttonConfig.colors.range[3] = Bartender4.db.profile.colors.range.r, Bartender4.db.profile.colors.range.g, Bartender4.db.profile.colors.range.b
self.buttonConfig.colors.mana[1], self.buttonConfig.colors.mana[2], self.buttonConfig.colors.mana[3] = Bartender4.db.profile.colors.mana.r, Bartender4.db.profile.colors.mana.g, Bartender4.db.profile.colors.mana.b
self.buttonConfig.hideElements.macro = self.config.hidemacrotext and true or false
self.buttonConfig.hideElements.hotkey = self.config.hidehotkey and true or false
self.buttonConfig.hideElements.equipped = self.config.hideequipped and true or false
self.buttonConfig.showGrid = self.config.showgrid
self.buttonConfig.clickOnDown = Bartender4.db.profile.onkeydown
self.buttonConfig.flyoutDirection = self.config.flyoutDirection
if tonumber(self.id) == 1 then
for i, button in self:GetAll() do
self.buttonConfig.keyBoundTarget = format("ACTIONBUTTON%d", i)
button:UpdateConfig(self.buttonConfig)
end
else
self:ForAll("UpdateConfig", self.buttonConfig)
end
self:ForAll("SetAttribute", "smarttarget", self.config.autoassist or self.config.mouseover)
-- self casting
self:UpdateSelfCast()
-- button lock
self:ForAll("SetAttribute", "buttonlock", Bartender4.db.profile.buttonlock)
-- update state
self:ForAll("UpdateState")
end
function ActionBar:UpdateSelfCast()
StateBar.UpdateSelfCast(self)
-- self casting
self:ForAll("SetAttribute", "checkselfcast", Bartender4.db.profile.selfcastmodifier and true or nil)
self:ForAll("SetAttribute", "checkfocuscast", Bartender4.db.profile.focuscastmodifier and true or nil)
self:ForAll("SetAttribute", "*unit2", Bartender4.db.profile.selfcastrightclick and "player" or nil)
end
local UpdateSmartTarget = [[
local state, type, action = ...
self:SetAttribute("targettype", nil)
self:SetAttribute("unit", nil)
if self:GetAttribute("smarttarget") then
if type == "action" then
type, action = GetActionInfo(action)
end
if type == "spell" and action > 0 then
if BT_Spell_Overrides[action] then action = BT_Spell_Overrides[action] end
local id, subtype = FindSpellBookSlotBySpellID(action), "spell"
if id and id > 0 then
if IsHelpfulSpell(id, subtype) == IsHarmfulSpell(id, subtype) then
self:SetAttribute("targettype", 3)
self:SetAttribute("unit", self:GetAttribute("target_all"))
elseif IsHelpfulSpell(id, subtype) then
self:SetAttribute("targettype", 1)
self:SetAttribute("unit", self:GetAttribute("target_help"))
elseif IsHarmfulSpell(id, subtype) then
self:SetAttribute("targettype", 2)
self:SetAttribute("unit", self:GetAttribute("target_harm"))
end
end
end
end
]]
function ActionBar:SetupSmartTarget()
local s = [[
BT_Spell_Overrides = newtable()
BT_Spell_Overrides[16979] = 102401 -- wild charge (bear)
BT_Spell_Overrides[49376] = 102401 -- wild charge (cat)
]]
local i = 1
local subtype, action = GetSpellBookItemInfo(i, "spell")
while subtype do
if subtype == "SPELL" then
local spellId = select(7, GetSpellInfo(i, "spell"))
if spellId and spellId ~= action then
s = s .. "\n" .. ([[ BT_Spell_Overrides[%d] = %d ]]):format(spellId, action)
end
end
i = i + 1
subtype, action = GetSpellBookItemInfo(i, "spell")
end
self:Execute(s)
self:SetAttribute("ChildUpdateSmartTarget", UpdateSmartTarget)
end
function ActionBar:SetupSmartButton(button)
button:SetAttribute("OnStateChanged", [[
if self:GetAttribute("statehidden") then return end
local header = self:GetParent()
header:RunFor(self, header:GetAttribute("ChildUpdateSmartTarget"), ...)
]])
button:SetAttribute("_childupdate-target-help", [[
self:SetAttribute("target_help", message)
if self:GetAttribute("targettype") == 1 then
self:SetAttribute("unit", message)
end
]])
button:SetAttribute("_childupdate-target-harm", [[
self:SetAttribute("target_harm", message)
if self:GetAttribute("targettype") == 2 then
self:SetAttribute("unit", message)
end
]])
button:SetAttribute("_childupdate-target-all", [[
self:SetAttribute("target_all", message)
if self:GetAttribute("targettype") == 3 then
self:SetAttribute("unit", message)
end
]])
end
local customExitButton = {
func = function(button)
VehicleExit()
end,
texture = "Interface\\Icons\\Spell_Shadow_SacrificialShield",
tooltip = LEAVE_VEHICLE,
}
-- Update the number of buttons in our bar, creating new ones if necessary
function ActionBar:UpdateButtons(numbuttons, offset)
if numbuttons then
self.config.buttons = min(numbuttons, 12)
else
numbuttons = min(self.config.buttons, 12)
end
local buttons = self.buttons or {}
local updateStartValue = #buttons + 1
if offset and offset ~= self.config.buttonOffset then
updateStartValue = 1
end
if offset then
self.config.buttonOffset = min(offset, 11)
else
offset = min(self.config.buttonOffset, 11)
end
local updateBindings = (numbuttons > #buttons)
-- create more buttons if needed
for i = updateStartValue, numbuttons do
local absid = (self.id - 1) * 12 + i
if buttons[i] == nil then
buttons[i] = LAB10:CreateButton(absid, format("BT4Button%d", absid), self, nil)
end
local offsetid = (i + offset - 1) % 12 + 1
for k = 1,14 do
buttons[i]:SetState(k, "action", (k - 1) * 12 + offsetid)
end
buttons[i]:SetState(0, "action", (self.id - 1) * 12 + offsetid)
if self.MasqueGroup then
buttons[i]:AddToMasque(self.MasqueGroup)
end
self:SetupSmartButton(buttons[i])
if i == 12 then
buttons[i]:SetState(11, "custom", customExitButton)
buttons[i]:SetState(12, "custom", customExitButton)
end
end
-- show active buttons
for i = 1, numbuttons do
buttons[i]:SetParent(self)
buttons[i]:Show()
buttons[i]:SetAttribute("statehidden", nil)
buttons[i]:UpdateAction()
end
-- hide inactive buttons
for i = (numbuttons + 1), #buttons do
buttons[i]:Hide()
buttons[i]:SetParent(UIParent)
buttons[i]:SetAttribute("statehidden", true)
end
self.numbuttons = numbuttons
self.buttons = buttons
self:UpdateButtonLayout()
self:SetGrid()
if updateBindings and self.id == "1" then
self.module:ReassignBindings()
end
-- need to re-set clickthrough after creating new buttons
self:SetClickThrough()
self:UpdateSelfCast() -- update selfcast and states
end
--[[===================================================================================
ActionBar Config Interface
===================================================================================]]--
-- get the current number of buttons
function ActionBar:GetButtons()
return self.config.buttons
end
-- get the current number of buttons
function ActionBar:GetButtonOffset()
return self.config.buttonOffset
end
-- set the number of buttons and refresh layout
ActionBar.SetButtons = ActionBar.UpdateButtons
function ActionBar:SetButtonOffset(offset)
return self:UpdateButtons(nil, offset)
end
function ActionBar:GetEnabled()
return true
end
function ActionBar:SetEnabled(state)
if not state then
self.module:DisableBar(self.id)
end
end
function ActionBar:GetGrid()
return self.config.showgrid
end
function ActionBar:SetGrid(state)
if state ~= nil then
self.config.showgrid = state
end
self:UpdateButtonConfig()
end
function ActionBar:GetFlyoutDirection()
return self.config.flyoutDirection
end
function ActionBar:SetFlyoutDirection(state)
if state ~= nil then
self.config.flyoutDirection = state
end
self:UpdateButtonConfig()
end