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