annotate classes/ActionButton.lua @ 124:0c5017f6062d

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