flickerstreak@175
|
1 local addonName, addonTable = ...
|
flickerstreak@175
|
2 local ReAction = addonTable.ReAction
|
flickerstreak@122
|
3 local L = ReAction.L
|
flickerstreak@122
|
4 local _G = _G
|
flickerstreak@122
|
5 local CreateFrame = CreateFrame
|
flickerstreak@122
|
6 local format = string.format
|
flickerstreak@122
|
7 local IsUsableAction = IsUsableAction
|
flickerstreak@122
|
8 local IsEquippedAction = IsEquippedAction
|
flickerstreak@122
|
9 local IsConsumableAction = IsConsumableAction
|
flickerstreak@122
|
10 local IsStackableAction = IsStackableAction
|
flickerstreak@122
|
11 local GetActionText = GetActionText
|
flickerstreak@122
|
12 local GetCVar = GetCVar
|
flickerstreak@122
|
13 local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor
|
flickerstreak@122
|
14 local IsCurrentAction = IsCurrentAction
|
flickerstreak@122
|
15 local IsAutoRepeatAction = IsAutoRepeatAction
|
flickerstreak@122
|
16 local IsUsableAction = IsUsableAction
|
flickerstreak@122
|
17 local IsAttackAction = IsAttackAction
|
flickerstreak@122
|
18 local CooldownFrame_SetTimer = CooldownFrame_SetTimer
|
flickerstreak@122
|
19 local GetActionCooldown = GetActionCooldown
|
flickerstreak@122
|
20 local GetActionTexture = GetActionTexture
|
flickerstreak@122
|
21 local ATTACK_BUTTON_FLASH_TIME = ATTACK_BUTTON_FLASH_TIME
|
flickerstreak@122
|
22 local TOOLTIP_UPDATE_TIME = TOOLTIP_UPDATE_TIME
|
flickerstreak@122
|
23 local IsActionInRange = IsActionInRange
|
flickerstreak@122
|
24 local InCombatLockdown = InCombatLockdown
|
flickerstreak@122
|
25 local HasAction = HasAction
|
flickerstreak@122
|
26
|
flickerstreak@122
|
27 --
|
flickerstreak@122
|
28 -- Secure snippets
|
flickerstreak@122
|
29 -- These are run within the context of the bar's sandbox, as the
|
flickerstreak@122
|
30 -- buttons themselves do not have their own sandbox.
|
flickerstreak@122
|
31 --
|
flickerstreak@122
|
32 local _onstate_mc = -- function(self, stateid, newstate)
|
flickerstreak@122
|
33 [[
|
flickerstreak@122
|
34 local oldMcVehicleState = mcVehicleState
|
flickerstreak@122
|
35 mcVehicleState = newstate
|
flickerstreak@122
|
36 control:ChildUpdate()
|
flickerstreak@122
|
37 if oldMcVehicleState == "vehicle" or mcVehicleState == "vehicle" then
|
flickerstreak@122
|
38 control:ChildUpdate("vehicle")
|
flickerstreak@122
|
39 end
|
flickerstreak@122
|
40 ]]
|
flickerstreak@122
|
41
|
flickerstreak@122
|
42 local _childupdate = -- function(self, snippetid, message)
|
flickerstreak@122
|
43 [[
|
flickerstreak@122
|
44 local action = nil
|
flickerstreak@122
|
45 if (doVehicle and mcVehicleState == "vehicle") or
|
flickerstreak@122
|
46 (doMindControl and mcVehicleState == "mc") then
|
flickerstreak@122
|
47 local idx = self:GetAttribute("bar-idx")
|
flickerstreak@145
|
48 local maxN = (doVehicle and mcVehicleState == "vehicle") and 7 or 12
|
flickerstreak@145
|
49 if idx and idx <= maxN then
|
flickerstreak@122
|
50 action = 120 + idx
|
flickerstreak@122
|
51 else
|
flickerstreak@122
|
52 action = 0
|
flickerstreak@122
|
53 end
|
flickerstreak@155
|
54 elseif state and settings[state] and settings[state].page then
|
flickerstreak@155
|
55 action = self:GetAttribute("action-"..settings[state].page)
|
flickerstreak@138
|
56 end
|
flickerstreak@138
|
57 if action == nil then
|
flickerstreak@122
|
58 action = self:GetAttribute("default-action")
|
flickerstreak@122
|
59 end
|
flickerstreak@122
|
60
|
flickerstreak@122
|
61 self:SetAttribute("action",action)
|
flickerstreak@122
|
62
|
flickerstreak@128
|
63 if not self:GetAttribute("showgrid") then
|
flickerstreak@128
|
64 local tempShow = self:GetAttribute("showgrid-temp")
|
flickerstreak@128
|
65 local evtShow = self:GetAttribute("showgrid-event")
|
flickerstreak@128
|
66 if tempShow then tempShow = (tempShow > 0) end
|
flickerstreak@128
|
67 if evtShow then evtShow = (evtShow > 0) end
|
flickerstreak@128
|
68
|
flickerstreak@170
|
69 if tempShow or evtShow or HasAction(action) then
|
flickerstreak@128
|
70 self:Show()
|
flickerstreak@128
|
71 else
|
flickerstreak@128
|
72 self:Hide()
|
flickerstreak@128
|
73 end
|
flickerstreak@122
|
74 end
|
flickerstreak@122
|
75 ]]
|
flickerstreak@122
|
76
|
flickerstreak@122
|
77 local _childupdate_vehicleExit = -- function(self, snippetid, message)
|
flickerstreak@122
|
78 [[
|
flickerstreak@122
|
79 local show = (mcVehicleState == "vehicle")
|
flickerstreak@124
|
80 if show and doVehicle then
|
flickerstreak@122
|
81 self:SetAttribute("type","macro")
|
flickerstreak@122
|
82 self:Show()
|
flickerstreak@122
|
83 else
|
flickerstreak@122
|
84 self:SetAttribute("type","action")
|
flickerstreak@122
|
85 end
|
flickerstreak@122
|
86 control:CallMethod("ShowVehicleExit",show)
|
flickerstreak@122
|
87 ]]
|
flickerstreak@122
|
88
|
flickerstreak@122
|
89 local _childupdate_showgrid = -- function(self, snippetid, message)
|
flickerstreak@122
|
90 [[
|
flickerstreak@128
|
91 self:SetAttribute("showgrid-event",message)
|
flickerstreak@128
|
92 if not self:GetAttribute("showgrid") then
|
flickerstreak@128
|
93 local count = message + (self:GetAttribute("showgrid-temp") or 0)
|
flickerstreak@128
|
94 if count <= 0 then
|
flickerstreak@128
|
95 local action = self:GetAttribute("action")
|
flickerstreak@170
|
96 if HasAction(action) then
|
flickerstreak@128
|
97 self:Show()
|
flickerstreak@128
|
98 else
|
flickerstreak@128
|
99 self:Hide()
|
flickerstreak@128
|
100 end
|
flickerstreak@128
|
101 else
|
flickerstreak@122
|
102 self:Show()
|
flickerstreak@122
|
103 end
|
flickerstreak@122
|
104 end
|
flickerstreak@122
|
105 ]]
|
flickerstreak@122
|
106
|
flickerstreak@122
|
107 local _onDragStart = -- function(self, button, kind, value, ...)
|
flickerstreak@122
|
108 [[
|
flickerstreak@122
|
109 if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then
|
flickerstreak@122
|
110 return kind, value, ...
|
flickerstreak@122
|
111 else
|
flickerstreak@122
|
112 return "action", self:GetAttribute("action")
|
flickerstreak@122
|
113 end
|
flickerstreak@122
|
114 ]]
|
flickerstreak@122
|
115
|
flickerstreak@122
|
116 local _onReceiveDrag = -- function(self, button, kind, value, ...)
|
flickerstreak@122
|
117 [[
|
flickerstreak@129
|
118 if kind ~= "spell" and kind ~= "item" and kind ~= "macro" then
|
flickerstreak@129
|
119 return kind, value, ...
|
flickerstreak@170
|
120 else
|
flickerstreak@170
|
121 return "action", self:GetAttribute("action")
|
flickerstreak@122
|
122 end
|
flickerstreak@122
|
123 ]]
|
flickerstreak@122
|
124
|
flickerstreak@122
|
125 --
|
flickerstreak@122
|
126 -- private
|
flickerstreak@122
|
127 --
|
flickerstreak@122
|
128 local eventList = {
|
flickerstreak@122
|
129 "PLAYER_ENTERING_WORLD",
|
flickerstreak@122
|
130 "ACTIONBAR_PAGE_CHANGED",
|
flickerstreak@122
|
131 "ACTIONBAR_SLOT_CHANGED",
|
flickerstreak@122
|
132 "UPDATE_BINDINGS",
|
flickerstreak@122
|
133 "ACTIONBAR_UPDATE_STATE",
|
flickerstreak@122
|
134 "ACTIONBAR_UPDATE_USABLE",
|
flickerstreak@122
|
135 "ACTIONBAR_UPDATE_COOLDOWN",
|
flickerstreak@165
|
136 "UNIT_INVENTORY_CHANGED",
|
flickerstreak@165
|
137 "LEARNED_SPELL_IN_TAB",
|
flickerstreak@122
|
138 "UPDATE_INVENTORY_ALERTS",
|
flickerstreak@122
|
139 "PLAYER_TARGET_CHANGED",
|
flickerstreak@122
|
140 "TRADE_SKILL_SHOW",
|
flickerstreak@122
|
141 "TRADE_SKILL_CLOSE",
|
flickerstreak@122
|
142 "PLAYER_ENTER_COMBAT",
|
flickerstreak@122
|
143 "PLAYER_LEAVE_COMBAT",
|
flickerstreak@122
|
144 "START_AUTOREPEAT_SPELL",
|
flickerstreak@122
|
145 "STOP_AUTOREPEAT_SPELL",
|
flickerstreak@122
|
146 "UNIT_ENTERED_VEHICLE",
|
flickerstreak@122
|
147 "UNIT_EXITED_VEHICLE",
|
flickerstreak@122
|
148 "COMPANION_UPDATE",
|
flickerstreak@122
|
149 }
|
flickerstreak@122
|
150
|
flickerstreak@122
|
151 --
|
flickerstreak@122
|
152 -- Action Button class
|
flickerstreak@122
|
153 --
|
flickerstreak@122
|
154 local Super = ReAction.Button
|
flickerstreak@122
|
155 local Action = setmetatable( { }, { __index = Super } )
|
flickerstreak@122
|
156 ReAction.Button.Action = Action
|
flickerstreak@122
|
157
|
flickerstreak@128
|
158 function Action:New( idx, barConfig, bar, idHint )
|
flickerstreak@123
|
159 local name = format("ReAction_%s_Action_%d",bar:GetName(),idx)
|
flickerstreak@123
|
160
|
flickerstreak@129
|
161 self = Super.New(self, name, barConfig.buttons[idx], bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" )
|
flickerstreak@129
|
162 self.barConfig = barConfig
|
flickerstreak@122
|
163
|
flickerstreak@122
|
164 local f = self:GetFrame()
|
flickerstreak@122
|
165 local barFrame = bar:GetFrame()
|
flickerstreak@128
|
166 local config = self:GetConfig()
|
flickerstreak@122
|
167
|
flickerstreak@122
|
168 self.rangeTimer = TOOLTIP_UPDATE_TIME
|
flickerstreak@122
|
169
|
flickerstreak@122
|
170 -- set up the base action ID
|
flickerstreak@122
|
171 self:SetActionIDPool("action",120)
|
flickerstreak@122
|
172 config.actionID = self:AcquireActionID(config.actionID, idHint)
|
flickerstreak@122
|
173 self.nPages = 1
|
flickerstreak@122
|
174
|
flickerstreak@122
|
175 -- attribute setup
|
flickerstreak@122
|
176 f:SetAttribute("type","action")
|
flickerstreak@122
|
177 f:SetAttribute("checkselfcast", true)
|
flickerstreak@122
|
178 f:SetAttribute("checkfocuscast", true)
|
flickerstreak@122
|
179 f:SetAttribute("action", config.actionID)
|
flickerstreak@122
|
180 f:SetAttribute("default-action", config.actionID)
|
flickerstreak@128
|
181 f:SetAttribute("bar-idx",idx)
|
flickerstreak@122
|
182 f:SetAttribute("showgrid-temp",0)
|
flickerstreak@128
|
183 f:SetAttribute("showgrid-event",0)
|
flickerstreak@128
|
184 f:SetAttribute("showgrid",not self:GetBarConfig().hideEmpty)
|
flickerstreak@128
|
185
|
flickerstreak@122
|
186 -- non secure scripts
|
flickerstreak@122
|
187 f:SetScript("OnEvent", function(frame, ...) self:OnEvent(...) end)
|
flickerstreak@122
|
188 f:SetScript("OnEnter", function(frame) self:OnEnter() end)
|
flickerstreak@122
|
189 f:SetScript("OnLeave", function(frame) self:OnLeave() end)
|
flickerstreak@122
|
190 f:SetScript("OnAttributeChanged", function(frame, attr, value) self:OnAttributeChanged(attr, value) end)
|
flickerstreak@122
|
191 f:SetScript("PostClick", function(frame, ...) self:PostClick(...) end)
|
flickerstreak@122
|
192 f:SetScript("OnUpdate", function(frame, elapsed) self:OnUpdate(elapsed) end)
|
flickerstreak@122
|
193 f:SetScript("OnDragStart", function(frame) self:OnDragStart() end)
|
flickerstreak@123
|
194 f:SetScript("OnReceiveDrag", function(frame) self:OnReceiveDrag() end)
|
flickerstreak@122
|
195
|
flickerstreak@122
|
196 -- event registration
|
flickerstreak@124
|
197 f:EnableMouse(true)
|
flickerstreak@122
|
198 f:RegisterForDrag("LeftButton", "RightButton")
|
flickerstreak@122
|
199 f:RegisterForClicks("AnyUp")
|
flickerstreak@122
|
200 for _, evt in pairs(eventList) do
|
flickerstreak@122
|
201 f:RegisterEvent(evt)
|
flickerstreak@122
|
202 end
|
flickerstreak@122
|
203
|
flickerstreak@138
|
204 -- secure handlers
|
flickerstreak@138
|
205 f:SetAttribute("_childupdate", _childupdate)
|
flickerstreak@138
|
206 f:SetAttribute("_childupdate-showgrid",_childupdate_showgrid)
|
flickerstreak@138
|
207 barFrame:WrapScript(f, "OnDragStart", _onDragStart)
|
flickerstreak@138
|
208 barFrame:WrapScript(f, "OnReceiveDrag", _onReceiveDrag)
|
flickerstreak@123
|
209
|
flickerstreak@140
|
210 -- attach to skinner
|
flickerstreak@140
|
211 bar:SkinButton(self)
|
flickerstreak@140
|
212
|
flickerstreak@140
|
213 -- initial display
|
flickerstreak@140
|
214 if ReAction:GetConfigMode() then
|
flickerstreak@140
|
215 self:ShowGridTemp(true)
|
flickerstreak@140
|
216 end
|
flickerstreak@140
|
217
|
flickerstreak@140
|
218 self:Refresh()
|
flickerstreak@140
|
219
|
flickerstreak@123
|
220 return self
|
flickerstreak@122
|
221 end
|
flickerstreak@122
|
222
|
flickerstreak@122
|
223 function Action:Destroy()
|
flickerstreak@122
|
224 local f = self:GetFrame()
|
flickerstreak@128
|
225 local c = self:GetConfig()
|
flickerstreak@122
|
226
|
flickerstreak@132
|
227 f:SetAttribute("_childupdate-vehicle",nil)
|
flickerstreak@145
|
228 f:SetAttribute("action",c.actionID) -- so that Super.Destroy releases the right one
|
flickerstreak@122
|
229
|
flickerstreak@139
|
230 if c.pageactions and #c.pageactions > 1 then
|
flickerstreak@139
|
231 for i = 2, #c.pageactions do
|
flickerstreak@132
|
232 self:ReleaseActionID(c.pageactions[i])
|
flickerstreak@122
|
233 self:ReleaseActionID(id)
|
flickerstreak@122
|
234 end
|
flickerstreak@122
|
235 end
|
flickerstreak@122
|
236
|
flickerstreak@128
|
237 Super.Destroy(self)
|
flickerstreak@122
|
238 end
|
flickerstreak@122
|
239
|
flickerstreak@129
|
240 function Action:GetBarConfig()
|
flickerstreak@129
|
241 -- this is the per-bar Action module config structure,
|
flickerstreak@129
|
242 -- not the config structure of the bar itself
|
flickerstreak@129
|
243 return self.barConfig
|
flickerstreak@129
|
244 end
|
flickerstreak@129
|
245
|
flickerstreak@122
|
246 function Action:Refresh()
|
flickerstreak@129
|
247 Super.Refresh(self)
|
flickerstreak@122
|
248 self:RefreshPages()
|
flickerstreak@124
|
249 self:InstallVehicle()
|
flickerstreak@128
|
250 self:ShowGrid(not self:GetBarConfig().hideEmpty)
|
flickerstreak@122
|
251 self:UpdateAction()
|
flickerstreak@122
|
252 end
|
flickerstreak@122
|
253
|
flickerstreak@124
|
254 function Action:InstallVehicle()
|
flickerstreak@145
|
255 local f = self:GetFrame()
|
flickerstreak@128
|
256 if self.idx == 7 and self:GetBarConfig().vehicle then
|
flickerstreak@159
|
257 if not self.vehicleInstalled then
|
flickerstreak@159
|
258 self.vehicleInstalled = true
|
flickerstreak@159
|
259 -- install vehicle-exit button on 7th button (only)
|
flickerstreak@159
|
260 f:SetAttribute("_childupdate-vehicle", _childupdate_vehicleExit)
|
flickerstreak@159
|
261 f:SetAttribute("macrotext","/run VehicleExit()")
|
flickerstreak@159
|
262 self:GetBar():GetFrame().ShowVehicleExit = function(bar,show)
|
flickerstreak@159
|
263 self:ShowVehicleExit(show)
|
flickerstreak@159
|
264 end
|
flickerstreak@124
|
265 end
|
flickerstreak@159
|
266 -- setscale blows away tex coords
|
flickerstreak@159
|
267 self:UpdateIcon()
|
flickerstreak@159
|
268 elseif self.vehicleInstalled then
|
flickerstreak@159
|
269 self.vehicleInstalled = false
|
flickerstreak@145
|
270 f:SetAttribute("_childupdate-vehicle",nil)
|
flickerstreak@145
|
271 f:SetAttribute("macrotext",nil)
|
flickerstreak@128
|
272 end
|
flickerstreak@128
|
273 end
|
flickerstreak@128
|
274
|
flickerstreak@128
|
275 function Action:ShowGrid( show )
|
flickerstreak@128
|
276 if not InCombatLockdown() then
|
flickerstreak@128
|
277 self.frame:SetAttribute("showgrid", show)
|
flickerstreak@128
|
278 self:UpdateShowGrid()
|
flickerstreak@128
|
279 end
|
flickerstreak@128
|
280 end
|
flickerstreak@128
|
281
|
flickerstreak@128
|
282 function Action:ShowGridTemp( show )
|
flickerstreak@128
|
283 -- This function only modifies the show-grid when out
|
flickerstreak@128
|
284 -- of combat, and is ignored by the secure handler. Use
|
flickerstreak@128
|
285 -- it for configuration modes.
|
flickerstreak@128
|
286 if not InCombatLockdown() then
|
flickerstreak@128
|
287 local count = self.showGridTempCount or 0
|
flickerstreak@128
|
288 if show then
|
flickerstreak@128
|
289 count = count + 1
|
flickerstreak@128
|
290 else
|
flickerstreak@128
|
291 count = count - 1
|
flickerstreak@128
|
292 end
|
flickerstreak@128
|
293 if count < 0 then count = 0 end
|
flickerstreak@128
|
294 self.showGridTempCount = count
|
flickerstreak@128
|
295 self:GetFrame():SetAttribute("showgrid-temp",count)
|
flickerstreak@128
|
296 self:UpdateShowGrid()
|
flickerstreak@124
|
297 end
|
flickerstreak@124
|
298 end
|
flickerstreak@124
|
299
|
flickerstreak@122
|
300 function Action:UpdateAll()
|
flickerstreak@122
|
301 self:UpdateActionIDLabel(ReAction:GetConfigMode())
|
flickerstreak@122
|
302 self:UpdateHotkey()
|
flickerstreak@122
|
303 self:UpdateShowGrid()
|
flickerstreak@122
|
304 self:UpdateIcon()
|
flickerstreak@122
|
305 self:UpdateBorder()
|
flickerstreak@122
|
306 self:UpdateMacroText()
|
flickerstreak@122
|
307 self:UpdateCount()
|
flickerstreak@122
|
308 self:UpdateTooltip()
|
flickerstreak@122
|
309 self:UpdateCheckedState()
|
flickerstreak@122
|
310 self:UpdateUsable()
|
flickerstreak@122
|
311 self:UpdateCooldown()
|
flickerstreak@122
|
312 self:UpdateFlash()
|
flickerstreak@122
|
313 end
|
flickerstreak@122
|
314
|
flickerstreak@122
|
315 function Action:UpdateAction()
|
flickerstreak@122
|
316 local action = self:GetActionID()
|
flickerstreak@122
|
317 if action ~= self.actionID then
|
flickerstreak@122
|
318 self.actionID = action
|
flickerstreak@122
|
319 self:UpdateAll()
|
flickerstreak@122
|
320 end
|
flickerstreak@122
|
321 end
|
flickerstreak@122
|
322
|
flickerstreak@122
|
323 function Action:UpdateShowGrid()
|
flickerstreak@170
|
324 if not InCombatLockdown() then
|
flickerstreak@128
|
325 local f = self:GetFrame()
|
flickerstreak@128
|
326 local count = (f:GetAttribute("showgrid-event") or 0) +
|
flickerstreak@128
|
327 (self.showGridTempCount or 0) +
|
flickerstreak@128
|
328 (f:GetAttribute("showgrid") and 1 or 0)
|
flickerstreak@128
|
329
|
flickerstreak@128
|
330 if count <= 0 and not HasAction(self.actionID) then
|
flickerstreak@128
|
331 if f:IsShown() then
|
flickerstreak@128
|
332 f:Hide()
|
flickerstreak@128
|
333 end
|
flickerstreak@128
|
334 elseif not f:IsShown() then
|
flickerstreak@122
|
335 f:Show()
|
flickerstreak@122
|
336 end
|
flickerstreak@122
|
337 end
|
flickerstreak@122
|
338 end
|
flickerstreak@122
|
339
|
flickerstreak@122
|
340 function Action:UpdateIcon()
|
flickerstreak@161
|
341 local texture, tLeft, tRight, tTop, tBottom = self:GetIconTexture()
|
flickerstreak@122
|
342 local icon = self.frames.icon
|
flickerstreak@122
|
343 local hotkey = self.frames.hotkey
|
flickerstreak@122
|
344 local f = self:GetFrame()
|
flickerstreak@145
|
345
|
flickerstreak@145
|
346 if self.vehicleExitMode then
|
flickerstreak@145
|
347 texture = "Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up"
|
flickerstreak@145
|
348 icon:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375)
|
flickerstreak@159
|
349 icon:SetVertexColor(1,1,1)
|
flickerstreak@145
|
350 else
|
flickerstreak@145
|
351 icon:SetTexCoord(0,1,0,1)
|
flickerstreak@145
|
352 end
|
flickerstreak@145
|
353
|
flickerstreak@122
|
354 if texture then
|
flickerstreak@122
|
355 icon:SetTexture(texture)
|
flickerstreak@161
|
356 if tLeft then
|
flickerstreak@161
|
357 icon:SetTexCoord(tLeft,tRight,tTop,tBottom)
|
flickerstreak@161
|
358 end
|
flickerstreak@122
|
359 icon:Show()
|
flickerstreak@122
|
360 self.rangeTimer = -1
|
flickerstreak@122
|
361 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
|
flickerstreak@122
|
362 else
|
flickerstreak@122
|
363 icon:Hide()
|
flickerstreak@122
|
364 self.frames.cooldown:Hide()
|
flickerstreak@122
|
365 self.rangeTimer = nil
|
flickerstreak@159
|
366 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot")
|
flickerstreak@122
|
367 end
|
flickerstreak@122
|
368 end
|
flickerstreak@122
|
369
|
flickerstreak@161
|
370 function Action:GetIconTexture()
|
flickerstreak@161
|
371 return GetActionTexture(self.actionID)
|
flickerstreak@161
|
372 end
|
flickerstreak@161
|
373
|
flickerstreak@122
|
374 function Action:UpdateBorder()
|
flickerstreak@122
|
375 local action = self.actionID
|
flickerstreak@122
|
376 if ReAction:GetKeybindMode() then
|
flickerstreak@122
|
377 self:UpdateKeybindModeDisplay(true)
|
flickerstreak@122
|
378 elseif IsEquippedAction(action) then
|
flickerstreak@122
|
379 self.frames.border:SetVertexColor(0, 1.0, 0, 0.35)
|
flickerstreak@122
|
380 self.frames.border:Show()
|
flickerstreak@122
|
381 else
|
flickerstreak@122
|
382 self.frames.border:Hide()
|
flickerstreak@122
|
383 end
|
flickerstreak@122
|
384 end
|
flickerstreak@122
|
385
|
flickerstreak@122
|
386 function Action:UpdateMacroText()
|
flickerstreak@122
|
387 local action = self.actionID
|
flickerstreak@122
|
388 if not IsConsumableAction(action) and not IsStackableAction(action) then
|
flickerstreak@122
|
389 self.frames.name:SetText(GetActionText(action))
|
flickerstreak@122
|
390 else
|
flickerstreak@122
|
391 self.frames.name:SetText("")
|
flickerstreak@122
|
392 end
|
flickerstreak@122
|
393 end
|
flickerstreak@122
|
394
|
flickerstreak@122
|
395 function Action:UpdateCount()
|
flickerstreak@122
|
396 local action = self.actionID
|
flickerstreak@122
|
397 if IsConsumableAction(action) or IsStackableAction(action) then
|
flickerstreak@122
|
398 self.frames.count:SetText(GetActionCount(action))
|
flickerstreak@122
|
399 else
|
flickerstreak@122
|
400 self.frames.count:SetText("")
|
flickerstreak@122
|
401 end
|
flickerstreak@122
|
402 end
|
flickerstreak@122
|
403
|
flickerstreak@122
|
404 function Action:UpdateTooltip()
|
flickerstreak@122
|
405 local f = self:GetFrame()
|
flickerstreak@122
|
406 if GameTooltip:GetOwner() == f then
|
flickerstreak@122
|
407 self:SetTooltip()
|
flickerstreak@122
|
408 end
|
flickerstreak@122
|
409 end
|
flickerstreak@122
|
410
|
flickerstreak@122
|
411 function Action:SetTooltip()
|
flickerstreak@122
|
412 local f = self:GetFrame()
|
flickerstreak@122
|
413 if GetCVar("UberTooltips") == "1" then
|
flickerstreak@122
|
414 GameTooltip_SetDefaultAnchor(GameTooltip, f)
|
flickerstreak@122
|
415 else
|
flickerstreak@165
|
416 GameTooltip:SetOwner(f,"ANCHOR_RIGHT")
|
flickerstreak@122
|
417 end
|
flickerstreak@122
|
418 GameTooltip:SetAction(self.actionID)
|
flickerstreak@122
|
419 end
|
flickerstreak@122
|
420
|
flickerstreak@122
|
421 function Action:UpdateCheckedState()
|
flickerstreak@122
|
422 local action = self.actionID
|
flickerstreak@122
|
423 if IsCurrentAction(action) or IsAutoRepeatAction(action) then
|
flickerstreak@122
|
424 self:GetFrame():SetChecked(1)
|
flickerstreak@122
|
425 else
|
flickerstreak@122
|
426 self:GetFrame():SetChecked(0)
|
flickerstreak@122
|
427 end
|
flickerstreak@122
|
428 end
|
flickerstreak@122
|
429
|
flickerstreak@122
|
430 function Action:UpdateUsable()
|
flickerstreak@161
|
431 local isUsable, notEnoughMana = self:GetUsable()
|
flickerstreak@161
|
432 local noRange = self:GetInRange()
|
flickerstreak@159
|
433
|
flickerstreak@159
|
434 isUsable = self.vehicleExitMode or (isUsable and not noRange)
|
flickerstreak@159
|
435
|
flickerstreak@159
|
436 if isUsable then
|
flickerstreak@159
|
437 if self.usableStatus ~= "usable" then
|
flickerstreak@159
|
438 self.frames.icon:SetVertexColor(1.0, 1.0, 1.0)
|
flickerstreak@159
|
439 self.frames.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
|
flickerstreak@159
|
440 self.usableStatus = "usable"
|
flickerstreak@159
|
441 end
|
flickerstreak@159
|
442 elseif noRange then
|
flickerstreak@159
|
443 if self.usableStatus ~= "norange" then
|
flickerstreak@159
|
444 self.frames.icon:SetVertexColor(1.0,0.1,0.1)
|
flickerstreak@159
|
445 self.frames.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
|
flickerstreak@159
|
446 self.usableStatus = "norange"
|
flickerstreak@159
|
447 end
|
flickerstreak@122
|
448 elseif notEnoughMana then
|
flickerstreak@159
|
449 if self.usableStatus ~= "oom" then
|
flickerstreak@159
|
450 self.frames.icon:SetVertexColor(0.5, 0.5, 1.0)
|
flickerstreak@159
|
451 self.frames.normalTexture:SetVertexColor(0.5, 0.5, 1.0)
|
flickerstreak@159
|
452 self.usableStatus = "oom"
|
flickerstreak@159
|
453 end
|
flickerstreak@122
|
454 else
|
flickerstreak@159
|
455 if self.usableStatus ~= "unusable" then
|
flickerstreak@159
|
456 self.frames.icon:SetVertexColor(0.4, 0.4, 0.4)
|
flickerstreak@159
|
457 self.frames.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
|
flickerstreak@159
|
458 self.usableStatus = "unusable"
|
flickerstreak@159
|
459 end
|
flickerstreak@122
|
460 end
|
flickerstreak@122
|
461 end
|
flickerstreak@122
|
462
|
flickerstreak@161
|
463 function Action:GetUsable()
|
flickerstreak@161
|
464 return IsUsableAction(self.actionID)
|
flickerstreak@161
|
465 end
|
flickerstreak@161
|
466
|
flickerstreak@161
|
467 function Action:GetInRange()
|
flickerstreak@161
|
468 return IsActionInRange(self.actionID) == 0
|
flickerstreak@161
|
469 end
|
flickerstreak@161
|
470
|
flickerstreak@122
|
471 function Action:UpdateCooldown()
|
flickerstreak@161
|
472 CooldownFrame_SetTimer(self.frames.cooldown, self:GetCooldown())
|
flickerstreak@161
|
473 end
|
flickerstreak@161
|
474
|
flickerstreak@161
|
475 function Action:GetCooldown()
|
flickerstreak@161
|
476 return GetActionCooldown(self.actionID)
|
flickerstreak@122
|
477 end
|
flickerstreak@122
|
478
|
flickerstreak@122
|
479 function Action:UpdateFlash()
|
flickerstreak@122
|
480 local action = self.actionID
|
flickerstreak@122
|
481 self:SetFlash( (IsAttackAction(action) and IsCurrentAction(action)) or IsAutoRepeatAction(action) )
|
flickerstreak@122
|
482 end
|
flickerstreak@122
|
483
|
flickerstreak@122
|
484 function Action:SetFlash(flash)
|
flickerstreak@122
|
485 if self.flashing ~= flash then
|
flickerstreak@122
|
486 self.flashing = flash
|
flickerstreak@122
|
487 self.flashtime = 0
|
flickerstreak@122
|
488 if not flash then
|
flickerstreak@122
|
489 self.frames.flash:Hide()
|
flickerstreak@122
|
490 end
|
flickerstreak@122
|
491 self:UpdateCheckedState()
|
flickerstreak@122
|
492 end
|
flickerstreak@122
|
493 end
|
flickerstreak@122
|
494
|
flickerstreak@122
|
495 function Action:RunFlash(elapsed)
|
flickerstreak@122
|
496 if self.flashing then
|
flickerstreak@122
|
497 local flashtime = self.flashtime - elapsed
|
flickerstreak@122
|
498 self.flashtime = flashtime
|
flickerstreak@122
|
499 if flashtime <= 0 then
|
flickerstreak@122
|
500 local overtime = -flashtime
|
flickerstreak@122
|
501 if overtime >= ATTACK_BUTTON_FLASH_TIME then
|
flickerstreak@122
|
502 overtime = 0
|
flickerstreak@122
|
503 end
|
flickerstreak@122
|
504 flashtime = ATTACK_BUTTON_FLASH_TIME - overtime
|
flickerstreak@122
|
505 local flash = self.frames.flash
|
flickerstreak@122
|
506 if flash:IsShown() then
|
flickerstreak@122
|
507 flash:Hide()
|
flickerstreak@122
|
508 else
|
flickerstreak@122
|
509 flash:Show()
|
flickerstreak@122
|
510 end
|
flickerstreak@122
|
511 end
|
flickerstreak@122
|
512 end
|
flickerstreak@122
|
513 end
|
flickerstreak@122
|
514
|
flickerstreak@122
|
515 function Action:RunRangeFinder(elapsed)
|
flickerstreak@122
|
516 local rangeTimer = self.rangeTimer
|
flickerstreak@122
|
517 if rangeTimer then
|
flickerstreak@122
|
518 rangeTimer = rangeTimer - elapsed
|
flickerstreak@122
|
519 self.rangeTimer = rangeTimer
|
flickerstreak@122
|
520 if rangeTimer <= 0 then
|
flickerstreak@159
|
521 self:UpdateUsable()
|
flickerstreak@123
|
522 self.rangeTimer = TOOLTIP_UPDATE_TIME
|
flickerstreak@122
|
523 end
|
flickerstreak@122
|
524 end
|
flickerstreak@122
|
525 end
|
flickerstreak@122
|
526
|
flickerstreak@122
|
527 function Action:GetActionID(page)
|
flickerstreak@122
|
528 if page == nil then
|
flickerstreak@122
|
529 -- get the effective ID
|
flickerstreak@122
|
530 return self:GetFrame():GetAttribute("action")
|
flickerstreak@122
|
531 else
|
flickerstreak@122
|
532 if page == 1 then
|
flickerstreak@122
|
533 return self.config.actionID
|
flickerstreak@122
|
534 else
|
flickerstreak@122
|
535 return self.config.pageactions and self.config.pageactions[page] or self.config.actionID
|
flickerstreak@122
|
536 end
|
flickerstreak@122
|
537 end
|
flickerstreak@122
|
538 end
|
flickerstreak@122
|
539
|
flickerstreak@122
|
540 function Action:SetActionID( id, page )
|
flickerstreak@122
|
541 id = tonumber(id)
|
flickerstreak@122
|
542 page = tonumber(page)
|
flickerstreak@122
|
543 if id == nil or id < 1 or id > 120 then
|
flickerstreak@129
|
544 ReAction:UserError(L["Action ID range is 1-120"])
|
flickerstreak@129
|
545 return
|
flickerstreak@122
|
546 end
|
flickerstreak@122
|
547 if page and page ~= 1 then
|
flickerstreak@122
|
548 if not self.config.pageactions then
|
flickerstreak@122
|
549 self.config.pageactions = { }
|
flickerstreak@122
|
550 end
|
flickerstreak@122
|
551 self:ReleaseActionID(self.config.pageactions[page])
|
flickerstreak@122
|
552 self.config.pageactions[page] = id
|
flickerstreak@122
|
553 self:AcquireActionID(self.config.pageactions[page])
|
flickerstreak@122
|
554 self.frame:SetAttribute("action-page"..page,id)
|
flickerstreak@122
|
555 else
|
flickerstreak@122
|
556 self:ReleaseActionID(self.config.actionID)
|
flickerstreak@122
|
557 self.config.actionID = id
|
flickerstreak@122
|
558 self:AcquireActionID(self.config.actionID)
|
flickerstreak@122
|
559 self.frame:SetAttribute("action",id)
|
flickerstreak@122
|
560 self.frame:SetAttribute("default-action",id)
|
flickerstreak@122
|
561 if self.config.pageactions then
|
flickerstreak@122
|
562 self.config.pageactions[1] = id
|
flickerstreak@122
|
563 self.frame:SetAttribute("action-page1",id)
|
flickerstreak@122
|
564 end
|
flickerstreak@122
|
565 end
|
flickerstreak@122
|
566 end
|
flickerstreak@122
|
567
|
flickerstreak@122
|
568 function Action:RefreshPages( force )
|
flickerstreak@128
|
569 local nPages = self:GetBarConfig().nPages
|
flickerstreak@122
|
570 if nPages and (nPages ~= self.nPages or force) then
|
flickerstreak@122
|
571 local f = self:GetFrame()
|
flickerstreak@122
|
572 local c = self.config.pageactions
|
flickerstreak@122
|
573 if nPages > 1 and not c then
|
flickerstreak@122
|
574 c = { }
|
flickerstreak@122
|
575 self.config.pageactions = c
|
flickerstreak@122
|
576 end
|
flickerstreak@122
|
577 for i = 1, nPages do
|
flickerstreak@122
|
578 if i > 1 then
|
flickerstreak@122
|
579 c[i] = self:AcquireActionID(c[i], self.config.actionID + (i-1)*self.bar:GetNumButtons())
|
flickerstreak@122
|
580 else
|
flickerstreak@122
|
581 c[i] = self.config.actionID -- page 1 is the same as the base actionID
|
flickerstreak@122
|
582 end
|
flickerstreak@129
|
583 f:SetAttribute("action-page"..i,c[i])
|
flickerstreak@122
|
584 end
|
flickerstreak@122
|
585 for i = nPages+1, #c do
|
flickerstreak@122
|
586 self:ReleaseActionID(c[i])
|
flickerstreak@122
|
587 c[i] = nil
|
flickerstreak@129
|
588 f:SetAttribute("action-page"..i,nil)
|
flickerstreak@122
|
589 end
|
flickerstreak@122
|
590 self.nPages = nPages
|
flickerstreak@122
|
591 end
|
flickerstreak@122
|
592 end
|
flickerstreak@122
|
593
|
flickerstreak@128
|
594 function Action.SetupBarHeader( bar, config ) -- call this as a static method
|
flickerstreak@122
|
595 local f = bar:GetFrame()
|
flickerstreak@128
|
596 f:SetAttribute("mindcontrol",config.mindcontrol)
|
flickerstreak@128
|
597 f:SetAttribute("vehicle",config.vehicle)
|
flickerstreak@122
|
598 f:Execute(
|
flickerstreak@122
|
599 [[
|
flickerstreak@122
|
600 doMindControl = self:GetAttribute("mindcontrol")
|
flickerstreak@122
|
601 doVehicle = self:GetAttribute("vehicle")
|
flickerstreak@122
|
602 control:ChildUpdate()
|
flickerstreak@122
|
603 ]])
|
flickerstreak@122
|
604
|
flickerstreak@122
|
605 f:SetAttribute("_onstate-mc", _onstate_mc)
|
flickerstreak@165
|
606 RegisterStateDriver(f, "mc", "[vehicleui] vehicle; [bonusbar:5] mc; none")
|
flickerstreak@122
|
607
|
flickerstreak@128
|
608 f:SetAttribute("lockbuttons",config.lockButtons)
|
flickerstreak@128
|
609 f:SetAttribute("lockbuttonscombat",config.lockButtonsCombat)
|
flickerstreak@122
|
610 f:Execute(
|
flickerstreak@122
|
611 [[
|
flickerstreak@122
|
612 lockButtons = self:GetAttribute("lockbuttons")
|
flickerstreak@122
|
613 lockButtonsCombat = self:GetAttribute("lockbuttonscombat")
|
flickerstreak@122
|
614 ]])
|
flickerstreak@122
|
615 end
|
flickerstreak@122
|
616
|
flickerstreak@122
|
617
|
flickerstreak@123
|
618 function Action.SetButtonLock( bar, lock, lockCombat ) -- call this as a static method
|
flickerstreak@123
|
619 local f = bar:GetFrame()
|
flickerstreak@123
|
620 f:SetAttribute("lockbuttons",lock)
|
flickerstreak@123
|
621 f:SetAttribute("lockbuttonscombat",lockCombat)
|
flickerstreak@123
|
622 f:Execute(
|
flickerstreak@123
|
623 [[
|
flickerstreak@123
|
624 lockButtons = self:GetAttribute("lockbuttons")
|
flickerstreak@123
|
625 lockButtonsCombat = self:GetAttribute("lockbuttonscombat")
|
flickerstreak@123
|
626 ]])
|
flickerstreak@123
|
627 end
|
flickerstreak@123
|
628
|
flickerstreak@123
|
629
|
flickerstreak@122
|
630 function Action:ShowVehicleExit(show)
|
flickerstreak@145
|
631 self.vehicleExitMode = show and self:GetBarConfig().vehicle
|
flickerstreak@145
|
632 self:UpdateIcon()
|
flickerstreak@122
|
633 end
|
flickerstreak@122
|
634
|
flickerstreak@122
|
635 function Action:OnEnter( )
|
flickerstreak@122
|
636 self:SetTooltip()
|
flickerstreak@122
|
637 end
|
flickerstreak@122
|
638
|
flickerstreak@122
|
639 function Action:OnLeave( )
|
flickerstreak@122
|
640 GameTooltip:Hide()
|
flickerstreak@122
|
641 end
|
flickerstreak@122
|
642
|
flickerstreak@122
|
643 function Action:OnAttributeChanged( attr, value )
|
flickerstreak@161
|
644 if attr ~= "statehidden" then
|
flickerstreak@161
|
645 self:UpdateAction()
|
flickerstreak@161
|
646 end
|
flickerstreak@122
|
647 end
|
flickerstreak@122
|
648
|
flickerstreak@122
|
649 function Action:PostClick( )
|
flickerstreak@122
|
650 self:UpdateCheckedState()
|
flickerstreak@122
|
651 end
|
flickerstreak@122
|
652
|
flickerstreak@122
|
653 function Action:OnUpdate( elapsed )
|
flickerstreak@122
|
654 self:RunFlash(elapsed)
|
flickerstreak@122
|
655 self:RunRangeFinder(elapsed)
|
flickerstreak@122
|
656 end
|
flickerstreak@122
|
657
|
flickerstreak@122
|
658 function Action:OnDragStart()
|
flickerstreak@122
|
659 self:UpdateCheckedState()
|
flickerstreak@122
|
660 self:UpdateFlash()
|
flickerstreak@122
|
661 end
|
flickerstreak@122
|
662
|
flickerstreak@122
|
663 function Action:OnReceiveDrag()
|
flickerstreak@122
|
664 self:UpdateCheckedState()
|
flickerstreak@122
|
665 self:UpdateFlash()
|
flickerstreak@122
|
666 end
|
flickerstreak@122
|
667
|
flickerstreak@122
|
668 function Action:OnEvent(event, ...)
|
flickerstreak@122
|
669 if self[event] then
|
flickerstreak@122
|
670 self[event](self, event, ...)
|
flickerstreak@122
|
671 end
|
flickerstreak@122
|
672 end
|
flickerstreak@122
|
673
|
flickerstreak@122
|
674 function Action:ACTIONBAR_SLOT_CHANGED(event, action)
|
flickerstreak@122
|
675 if action == 0 or action == self.actionID then
|
flickerstreak@128
|
676 self:UpdateAll()
|
flickerstreak@122
|
677 end
|
flickerstreak@122
|
678 end
|
flickerstreak@122
|
679
|
flickerstreak@122
|
680 function Action:PLAYER_ENTERING_WORLD()
|
flickerstreak@122
|
681 self:UpdateAction()
|
flickerstreak@122
|
682 end
|
flickerstreak@122
|
683
|
flickerstreak@122
|
684 function Action:ACTIONBAR_PAGE_CHANGED()
|
flickerstreak@122
|
685 self:UpdateAction()
|
flickerstreak@122
|
686 end
|
flickerstreak@122
|
687
|
flickerstreak@122
|
688 function Action:UPDATE_BONUS_ACTIONBAR()
|
flickerstreak@122
|
689 self:UpdateAction()
|
flickerstreak@122
|
690 end
|
flickerstreak@122
|
691
|
flickerstreak@122
|
692 function Action:UPDATE_BINDINGS()
|
flickerstreak@122
|
693 self:UpdateHotkey()
|
flickerstreak@122
|
694 end
|
flickerstreak@122
|
695
|
flickerstreak@122
|
696 function Action:PLAYER_TARGET_CHANGED()
|
flickerstreak@122
|
697 self.rangeTimer = -1
|
flickerstreak@122
|
698 end
|
flickerstreak@122
|
699
|
flickerstreak@122
|
700 function Action:ACTIONBAR_UPDATE_STATE()
|
flickerstreak@122
|
701 self:UpdateCheckedState()
|
flickerstreak@122
|
702 end
|
flickerstreak@124
|
703
|
flickerstreak@124
|
704 function Action:TRADE_SKILL_SHOW()
|
flickerstreak@124
|
705 self:UpdateCheckedState()
|
flickerstreak@124
|
706 end
|
flickerstreak@124
|
707 Action.TRADE_SKILL_CLOSE = Action.TRADE_SKILL_CLOSE
|
flickerstreak@122
|
708
|
flickerstreak@122
|
709 function Action:UNIT_ENTERED_VEHICLE(event,unit)
|
flickerstreak@122
|
710 if unit == "player" then
|
flickerstreak@122
|
711 self:UpdateCheckedState()
|
flickerstreak@122
|
712 end
|
flickerstreak@122
|
713 end
|
flickerstreak@122
|
714 Action.UNIT_EXITED_VEHICLE = Action.UNIT_ENTERED_VEHICLE
|
flickerstreak@122
|
715
|
flickerstreak@122
|
716 function Action:COMPANION_UPDATE(event,unit)
|
flickerstreak@122
|
717 if unit == "mount" then
|
flickerstreak@122
|
718 self:UpdateCheckedState()
|
flickerstreak@122
|
719 end
|
flickerstreak@122
|
720 end
|
flickerstreak@122
|
721
|
flickerstreak@122
|
722 function Action:ACTIONBAR_UPDATE_USABLE()
|
flickerstreak@122
|
723 self:UpdateUsable()
|
flickerstreak@122
|
724 end
|
flickerstreak@122
|
725
|
flickerstreak@122
|
726 function Action:ACTIONBAR_UPDATE_COOLDOWN()
|
flickerstreak@122
|
727 self:UpdateCooldown()
|
flickerstreak@122
|
728 end
|
flickerstreak@122
|
729
|
flickerstreak@122
|
730 function Action:PLAYER_ENTER_COMBAT()
|
flickerstreak@122
|
731 if IsAttackAction(self.actionID) then
|
flickerstreak@122
|
732 self:SetFlash(true)
|
flickerstreak@122
|
733 end
|
flickerstreak@122
|
734 end
|
flickerstreak@122
|
735
|
flickerstreak@122
|
736 function Action:PLAYER_LEAVE_COMBAT()
|
flickerstreak@122
|
737 if IsAttackAction(self.actionID) then
|
flickerstreak@122
|
738 self:SetFlash(false)
|
flickerstreak@122
|
739 end
|
flickerstreak@122
|
740 end
|
flickerstreak@122
|
741
|
flickerstreak@122
|
742 function Action:START_AUTOREPEAT_SPELL()
|
flickerstreak@122
|
743 if IsAutoRepeatAction(self.actionID) then
|
flickerstreak@122
|
744 self:SetFlash(true)
|
flickerstreak@122
|
745 end
|
flickerstreak@122
|
746 end
|
flickerstreak@122
|
747
|
flickerstreak@122
|
748 function Action:STOP_AUTOREPEAT_SPELL()
|
flickerstreak@122
|
749 if not IsAttackAction(self.actionID) then
|
flickerstreak@122
|
750 self:SetFlash(false)
|
flickerstreak@122
|
751 end
|
flickerstreak@122
|
752 end
|
flickerstreak@122
|
753
|
flickerstreak@165
|
754 function Action:UNIT_INVENTORY_CHANGED(unit)
|
flickerstreak@165
|
755 if unit == "player" then
|
flickerstreak@165
|
756 self:UpdateTooltip()
|
flickerstreak@165
|
757 end
|
flickerstreak@165
|
758 end
|
flickerstreak@165
|
759
|
flickerstreak@165
|
760 function Action:LEARNED_SPELL_IN_TAB()
|
flickerstreak@165
|
761 self:UpdateTooltip()
|
flickerstreak@165
|
762 end
|