annotate ActionButton.lua @ 300:a682fac2aa98

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