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