annotate modules/PetAction.lua @ 116:fb48811a8736

Convert to standard keybindings
author Flick <flickerstreak@gmail.com>
date Fri, 23 Jan 2009 23:44:55 +0000
parents 410d036c43b2
children 6e4a11b9d290
rev   line source
flickerstreak@28 1 --[[
flickerstreak@53 2 ReAction Pet Action button module
flickerstreak@53 3
flickerstreak@53 4 The button module implements standard action button functionality by wrapping Blizzard's
flickerstreak@77 5 PetActionButton frame and associated functions.
flickerstreak@28 6
flickerstreak@28 7 --]]
flickerstreak@28 8
flickerstreak@28 9 -- local imports
flickerstreak@28 10 local ReAction = ReAction
flickerstreak@28 11 local L = ReAction.L
flickerstreak@28 12 local _G = _G
flickerstreak@53 13 local CreateFrame = CreateFrame
flickerstreak@95 14 local format = string.format
flickerstreak@28 15
flickerstreak@80 16 ReAction:UpdateRevision("$Revision$")
flickerstreak@77 17
flickerstreak@93 18 -- libraries
flickerstreak@93 19 local KB = LibStub("LibKeyBound-1.0")
flickerstreak@93 20
flickerstreak@28 21 -- module declaration
flickerstreak@28 22 local moduleID = "PetAction"
flickerstreak@28 23 local module = ReAction:NewModule( moduleID )
flickerstreak@28 24
flickerstreak@77 25 -- Button class declaration
flickerstreak@77 26 local Button = { }
flickerstreak@77 27
flickerstreak@102 28 -- private
flickerstreak@102 29 local function UpdateButtonLock(bar)
flickerstreak@102 30 local f = bar:GetFrame()
flickerstreak@102 31 f:SetAttribute("lockbuttons",bar.config.lockButtons)
flickerstreak@102 32 f:SetAttribute("lockbuttonscombat",bar.config.lockButtonsCombat)
flickerstreak@102 33 f:Execute(
flickerstreak@102 34 [[
flickerstreak@102 35 lockButtons = self:GetAttribute("lockbuttons")
flickerstreak@102 36 lockButtonsCombat = self:GetAttribute("lockbuttonscombat")
flickerstreak@102 37 ]])
flickerstreak@102 38 end
flickerstreak@102 39
flickerstreak@28 40 -- module methods
flickerstreak@28 41 function module:OnInitialize()
flickerstreak@53 42 self.db = ReAction.db:RegisterNamespace( moduleID,
flickerstreak@28 43 {
flickerstreak@28 44 profile = {
flickerstreak@28 45 buttons = { }
flickerstreak@28 46 }
flickerstreak@28 47 }
flickerstreak@28 48 )
flickerstreak@53 49 self.buttons = { }
flickerstreak@63 50
flickerstreak@63 51 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
flickerstreak@63 52
flickerstreak@63 53 ReAction.RegisterCallback(self, "OnCreateBar")
flickerstreak@63 54 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@63 55 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@63 56 ReAction.RegisterCallback(self, "OnEraseBar")
flickerstreak@63 57 ReAction.RegisterCallback(self, "OnRenameBar")
flickerstreak@63 58 ReAction.RegisterCallback(self, "OnConfigModeChanged")
flickerstreak@93 59
flickerstreak@93 60 KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED")
flickerstreak@93 61 KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED")
flickerstreak@93 62 KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED")
flickerstreak@28 63 end
flickerstreak@28 64
flickerstreak@28 65 function module:OnEnable()
flickerstreak@53 66 ReAction:RegisterBarType(L["Pet Action Bar"],
flickerstreak@53 67 {
flickerstreak@53 68 type = moduleID ,
flickerstreak@53 69 defaultButtonSize = 30,
flickerstreak@53 70 defaultBarRows = 1,
flickerstreak@53 71 defaultBarCols = 10,
flickerstreak@53 72 defaultBarSpacing = 8
flickerstreak@53 73 })
flickerstreak@28 74 end
flickerstreak@28 75
flickerstreak@28 76 function module:OnDisable()
flickerstreak@53 77 ReAction:UnregisterBarType(L["Pet Action Bar"])
flickerstreak@28 78 end
flickerstreak@28 79
flickerstreak@63 80 function module:OnCreateBar(event, bar, name)
flickerstreak@53 81 if bar.config.type == moduleID then
flickerstreak@53 82 -- auto show/hide when pet exists
flickerstreak@53 83 bar:GetFrame():SetAttribute("unit","pet")
flickerstreak@90 84 if not ReAction:GetConfigMode() then
flickerstreak@90 85 RegisterUnitWatch(bar:GetFrame())
flickerstreak@90 86 end
flickerstreak@63 87 self:OnRefreshBar(event, bar, name)
flickerstreak@28 88 end
flickerstreak@28 89 end
flickerstreak@28 90
flickerstreak@63 91 function module:OnRefreshBar(event, bar, name)
flickerstreak@53 92 if bar.config.type == moduleID then
flickerstreak@53 93 if self.buttons[bar] == nil then
flickerstreak@53 94 self.buttons[bar] = { }
flickerstreak@53 95 end
flickerstreak@53 96 local btns = self.buttons[bar]
flickerstreak@53 97 local profile = self.db.profile
flickerstreak@63 98 if profile.buttons[name] == nil then
flickerstreak@63 99 profile.buttons[name] = {}
flickerstreak@53 100 end
flickerstreak@63 101 local btnCfg = profile.buttons[name]
flickerstreak@53 102
flickerstreak@53 103 local r, c = bar:GetButtonGrid()
flickerstreak@53 104 local n = r*c
flickerstreak@53 105 for i = 1, n do
flickerstreak@53 106 if btnCfg[i] == nil then
flickerstreak@53 107 btnCfg[i] = {}
flickerstreak@53 108 end
flickerstreak@53 109 if btns[i] == nil then
flickerstreak@94 110 local success, r = pcall(Button.New,Button,bar,i,btnCfg[i])
flickerstreak@94 111 if success and r then
flickerstreak@94 112 btns[i] = r
flickerstreak@94 113 bar:AddButton(i,r)
flickerstreak@94 114 else
flickerstreak@94 115 n = i - 1
flickerstreak@94 116 bar:ClipNButtons(n)
flickerstreak@94 117 break
flickerstreak@94 118 end
flickerstreak@53 119 end
flickerstreak@77 120 btns[i]:Refresh()
flickerstreak@53 121 end
flickerstreak@53 122 for i = n+1, #btns do
flickerstreak@53 123 if btns[i] then
flickerstreak@77 124 bar:RemoveButton(btns[i])
flickerstreak@53 125 btns[i] = btns[i]:Destroy()
flickerstreak@53 126 if btnCfg[i] then
flickerstreak@53 127 btnCfg[i] = nil
flickerstreak@53 128 end
flickerstreak@53 129 end
flickerstreak@53 130 end
flickerstreak@102 131 UpdateButtonLock(bar)
flickerstreak@53 132 end
flickerstreak@53 133 end
flickerstreak@53 134
flickerstreak@63 135 function module:OnDestroyBar(event, bar, name)
flickerstreak@53 136 if self.buttons[bar] then
flickerstreak@53 137 local btns = self.buttons[bar]
flickerstreak@53 138 for _,b in pairs(btns) do
flickerstreak@53 139 if b then
flickerstreak@53 140 b:Destroy()
flickerstreak@53 141 end
flickerstreak@53 142 end
flickerstreak@53 143 self.buttons[bar] = nil
flickerstreak@53 144 end
flickerstreak@53 145 end
flickerstreak@53 146
flickerstreak@63 147 function module:OnEraseBar(event, bar, name)
flickerstreak@63 148 self.db.profile.buttons[name] = nil
flickerstreak@53 149 end
flickerstreak@53 150
flickerstreak@63 151 function module:OnRenameBar(event, bar, oldname, newname)
flickerstreak@53 152 local b = self.db.profile.buttons
flickerstreak@53 153 b[newname], b[oldname] = b[oldname], nil
flickerstreak@53 154 end
flickerstreak@53 155
flickerstreak@53 156
flickerstreak@63 157 function module:OnConfigModeChanged(event, mode)
flickerstreak@77 158 for _, buttons in pairs(self.buttons) do
flickerstreak@77 159 for _, b in pairs(buttons) do
flickerstreak@77 160 b:ShowActionIDLabel(mode)
flickerstreak@77 161 end
flickerstreak@77 162 end
flickerstreak@63 163 for _, bar in ReAction:IterateBars() do
flickerstreak@53 164 if bar and self.buttons[bar] then
flickerstreak@53 165 local f = bar:GetFrame()
flickerstreak@53 166 if mode then
flickerstreak@53 167 UnregisterUnitWatch(f)
flickerstreak@53 168 f:Show()
flickerstreak@53 169 else
flickerstreak@53 170 RegisterUnitWatch(f)
flickerstreak@53 171 end
flickerstreak@53 172 end
flickerstreak@53 173 end
flickerstreak@53 174 end
flickerstreak@53 175
flickerstreak@93 176 function module:LIBKEYBOUND_ENABLED(evt)
flickerstreak@93 177 for _, buttons in pairs(self.buttons) do
flickerstreak@93 178 for _, b in pairs(buttons) do
flickerstreak@93 179 b:SetKeybindMode(true)
flickerstreak@93 180 end
flickerstreak@93 181 end
flickerstreak@93 182 end
flickerstreak@93 183
flickerstreak@93 184 function module:LIBKEYBOUND_DISABLED(evt)
flickerstreak@93 185 for _, buttons in pairs(self.buttons) do
flickerstreak@93 186 for _, b in pairs(buttons) do
flickerstreak@93 187 b:SetKeybindMode(false)
flickerstreak@93 188 end
flickerstreak@93 189 end
flickerstreak@93 190 end
flickerstreak@93 191
flickerstreak@53 192
flickerstreak@60 193 ---- Options ----
flickerstreak@102 194 local Handler = { }
flickerstreak@102 195 local meta = { __index = Handler }
flickerstreak@102 196
flickerstreak@102 197 function Handler:New(bar)
flickerstreak@102 198 return setmetatable(
flickerstreak@102 199 {
flickerstreak@102 200 bar = bar,
flickerstreak@102 201 config = bar.config
flickerstreak@102 202 }, meta)
flickerstreak@102 203 end
flickerstreak@102 204
flickerstreak@102 205 function Handler:GetLockButtons()
flickerstreak@102 206 return LOCK_ACTIONBAR == "1" or self.config.lockButtons
flickerstreak@102 207 end
flickerstreak@102 208
flickerstreak@102 209 function Handler:SetLockButtons(info, value)
flickerstreak@102 210 self.config.lockButtons = value
flickerstreak@102 211 UpdateButtonLock(self.bar)
flickerstreak@102 212 end
flickerstreak@102 213
flickerstreak@102 214 function Handler:LockButtonsDisabled()
flickerstreak@102 215 return LOCK_ACTIONBAR == "1"
flickerstreak@102 216 end
flickerstreak@102 217
flickerstreak@102 218 function Handler:GetLockButtonsCombat()
flickerstreak@102 219 return self.config.lockButtonsCombat
flickerstreak@102 220 end
flickerstreak@102 221
flickerstreak@102 222 function Handler:SetLockButtonsCombat(info, value)
flickerstreak@102 223 self.config.lockButtonsCombat = value
flickerstreak@102 224 UpdateButtonLock(self.bar)
flickerstreak@102 225 end
flickerstreak@102 226
flickerstreak@102 227 function Handler:LockButtonsCombatDisabled()
flickerstreak@102 228 return LOCK_ACTIONBAR == "1" or not self.config.lockButtons
flickerstreak@102 229 end
flickerstreak@102 230
flickerstreak@102 231
flickerstreak@60 232 function module:GetBarOptions(bar)
flickerstreak@91 233 if bar.config.type == moduleID then
flickerstreak@91 234 return {
flickerstreak@91 235 type = "group",
flickerstreak@91 236 name = L["Pet Buttons"],
flickerstreak@102 237 handler = Handler:New(bar),
flickerstreak@91 238 args = {
flickerstreak@102 239 lockButtons = {
flickerstreak@102 240 name = L["Lock Buttons"],
flickerstreak@102 241 desc = L["Prevents picking up/dragging actions.|nNOTE: This setting is overridden by the global setting in Blizzard's Action Buttons tab"],
flickerstreak@102 242 order = 2,
flickerstreak@102 243 type = "toggle",
flickerstreak@102 244 disabled = "LockButtonsDisabled",
flickerstreak@102 245 get = "GetLockButtons",
flickerstreak@102 246 set = "SetLockButtons",
flickerstreak@102 247 },
flickerstreak@102 248 lockOnlyCombat = {
flickerstreak@102 249 name = L["Only in Combat"],
flickerstreak@102 250 desc = L["Only lock the buttons when in combat"],
flickerstreak@102 251 order = 3,
flickerstreak@102 252 type = "toggle",
flickerstreak@102 253 disabled = "LockButtonsCombatDisabled",
flickerstreak@102 254 get = "GetLockButtonsCombat",
flickerstreak@102 255 set = "SetLockButtonsCombat",
flickerstreak@102 256 },
flickerstreak@91 257 }
flickerstreak@60 258 }
flickerstreak@91 259 end
flickerstreak@59 260 end
flickerstreak@59 261
flickerstreak@53 262
flickerstreak@28 263
flickerstreak@77 264 ------ Button class ------
flickerstreak@77 265
flickerstreak@28 266 -- use-count of action IDs
flickerstreak@53 267 local nActionIDs = NUM_PET_ACTION_SLOTS
flickerstreak@28 268 local ActionIDList = setmetatable( {}, {
flickerstreak@28 269 __index = function(self, idx)
flickerstreak@28 270 if idx == nil then
flickerstreak@53 271 for i = 1, nActionIDs do
flickerstreak@28 272 if rawget(self,i) == nil then
flickerstreak@28 273 rawset(self,i,1)
flickerstreak@28 274 return i
flickerstreak@28 275 end
flickerstreak@28 276 end
flickerstreak@53 277 error("ran out of pet action IDs")
flickerstreak@28 278 else
flickerstreak@28 279 local c = rawget(self,idx) or 0
flickerstreak@28 280 rawset(self,idx,c+1)
flickerstreak@28 281 return idx
flickerstreak@28 282 end
flickerstreak@28 283 end,
flickerstreak@28 284 __newindex = function(self,idx,value)
flickerstreak@28 285 if value == nil then
flickerstreak@28 286 value = rawget(self,idx)
flickerstreak@28 287 if value == 1 then
flickerstreak@28 288 value = nil
flickerstreak@28 289 elseif value then
flickerstreak@28 290 value = value - 1
flickerstreak@28 291 end
flickerstreak@28 292 end
flickerstreak@28 293 rawset(self,idx,value)
flickerstreak@28 294 end
flickerstreak@28 295 })
flickerstreak@28 296
flickerstreak@53 297 local frameRecycler = {}
flickerstreak@93 298 local trash = CreateFrame("Frame")
flickerstreak@93 299
flickerstreak@116 300 local function GetActionName(f)
flickerstreak@116 301 local b = f and f._reactionButton
flickerstreak@116 302 if b then
flickerstreak@116 303 return format("%s:%s", b.bar:GetName(), b.idx)
flickerstreak@93 304 end
flickerstreak@116 305 end
flickerstreak@93 306
flickerstreak@116 307 local function GetHotkey(f)
flickerstreak@116 308 return KB:ToShortKey(GetBindingKey(format("CLICK %s:LeftButton",f:GetName())))
flickerstreak@116 309 end
flickerstreak@93 310
flickerstreak@116 311 local function OnEnter( self )
flickerstreak@116 312 if ReAction:GetKeybindMode() then
flickerstreak@116 313 KB:Set(self)
flickerstreak@116 314 elseif self.tooltipName then
flickerstreak@95 315 local uber = GetCVar("UberTooltips")
flickerstreak@95 316 if self.isToken or (uber == "0") then
flickerstreak@95 317 if uber == "0" then
flickerstreak@95 318 GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
flickerstreak@95 319 else
flickerstreak@95 320 GameTooltip_SetDefaultAnchor(GameTooltip, self)
flickerstreak@95 321 end
flickerstreak@116 322 GameTooltip:SetText(self.tooltipName)
flickerstreak@95 323 if self.tooltipSubtext then
flickerstreak@95 324 GameTooltip:AddLine(self.tooltipSubtext, "", 0.5, 0.5, 0.5)
flickerstreak@95 325 end
flickerstreak@95 326 GameTooltip:Show()
flickerstreak@95 327 else
flickerstreak@95 328 GameTooltip_SetDefaultAnchor(GameTooltip, self)
flickerstreak@95 329 GameTooltip:SetPetAction(self:GetID())
flickerstreak@95 330 end
flickerstreak@95 331 end
flickerstreak@116 332 end
flickerstreak@95 333
flickerstreak@116 334 local function OnLeave()
flickerstreak@116 335 GameTooltip:Hide()
flickerstreak@93 336 end
flickerstreak@93 337
flickerstreak@90 338 local meta = { __index = Button }
flickerstreak@28 339
flickerstreak@77 340 function Button:New( bar, idx, config )
flickerstreak@77 341 -- create new self
flickerstreak@90 342 self = setmetatable(
flickerstreak@90 343 {
flickerstreak@90 344 bar = bar,
flickerstreak@90 345 idx = idx,
flickerstreak@90 346 config = config,
flickerstreak@90 347 }, meta )
flickerstreak@28 348
flickerstreak@85 349 local name = config.name or ("ReAction_%s_%s_%d"):format(bar:GetName(),moduleID,idx)
flickerstreak@53 350 config.name = name
flickerstreak@77 351 self.name = name
flickerstreak@28 352 config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured
flickerstreak@116 353
flickerstreak@53 354 -- have to recycle frames with the same name:
flickerstreak@53 355 -- otherwise you either get references to old textures because named CreateFrame()
flickerstreak@90 356 -- doesn't overwrite existing globals. Can't set them to nil in the global table,
flickerstreak@90 357 -- as it causes taint.
flickerstreak@90 358 local parent = bar:GetFrame()
flickerstreak@53 359 local f = frameRecycler[name]
flickerstreak@53 360 if f then
flickerstreak@77 361 f:SetParent(parent)
flickerstreak@53 362 else
flickerstreak@77 363 f = CreateFrame("CheckButton", name, parent, "PetActionButtonTemplate")
flickerstreak@93 364 -- ditch the old hotkey text because it's tied in ActionButton_Update() to the
flickerstreak@93 365 -- standard binding. We use override bindings.
flickerstreak@93 366 local hotkey = _G[name.."HotKey"]
flickerstreak@93 367 hotkey:SetParent(trash)
flickerstreak@93 368 hotkey = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmallGray")
flickerstreak@93 369 hotkey:SetWidth(36)
flickerstreak@93 370 hotkey:SetHeight(18)
flickerstreak@93 371 hotkey:SetJustifyH("RIGHT")
flickerstreak@93 372 hotkey:SetJustifyV("TOP")
flickerstreak@93 373 hotkey:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2)
flickerstreak@93 374 f.hotkey = hotkey
flickerstreak@93 375 f:HookScript("OnDragStart", function() self:Update() end)
flickerstreak@93 376 f:HookScript("OnReceiveDrag", function() self:Update() end)
flickerstreak@95 377 f:SetScript("OnEnter", OnEnter)
flickerstreak@95 378 f:SetScript("OnLeave", OnLeave)
flickerstreak@53 379 end
flickerstreak@53 380 if config.actionID then
flickerstreak@53 381 f:SetID(config.actionID) -- PetActionButtonTemplate isn't a proper SecureActionButton
flickerstreak@53 382 end
flickerstreak@53 383 f:SetFrameStrata("MEDIUM")
flickerstreak@93 384 self.frame = f
flickerstreak@93 385 self.icon = _G[("%sIcon"):format(name)]
flickerstreak@93 386 self.acTex = _G[("%sAutoCastable"):format(name)]
flickerstreak@93 387 self.acModel = _G[("%sShine"):format(name)]
flickerstreak@53 388 self.cooldown = _G[("%sCooldown"):format(name)]
flickerstreak@93 389 self.hotkey = f.hotkey
flickerstreak@93 390 self.border = _G[("%sBorder"):format(name)]
flickerstreak@53 391
flickerstreak@116 392 f._reactionButton = self
flickerstreak@53 393
flickerstreak@116 394 f:RegisterEvent("PLAYER_CONTROL_LOST")
flickerstreak@116 395 f:RegisterEvent("PLAYER_CONTROL_GAINED")
flickerstreak@116 396 f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED")
flickerstreak@116 397 f:RegisterEvent("UNIT_PET")
flickerstreak@116 398 f:RegisterEvent("UNIT_FLAGS")
flickerstreak@116 399 f:RegisterEvent("UNIT_AURA")
flickerstreak@116 400 f:RegisterEvent("PET_BAR_UPDATE")
flickerstreak@116 401 f:RegisterEvent("PET_BAR_UPDATE_COOLDOWN")
flickerstreak@53 402
flickerstreak@53 403 f:SetScript("OnEvent",
flickerstreak@53 404 function(event,arg1)
flickerstreak@53 405 if event =="PET_BAR_UPDATE_COOLDOWN" then
flickerstreak@53 406 self:UpdateCooldown()
flickerstreak@53 407 elseif event == "UPDATE_BINDINGS" then
flickerstreak@53 408 self:UpdateHotkey()
flickerstreak@53 409 else
flickerstreak@53 410 self:Update()
flickerstreak@53 411 end
flickerstreak@53 412 end)
flickerstreak@28 413
flickerstreak@102 414 -- install drag wrappers to lock buttons
flickerstreak@102 415 bar:GetFrame():WrapScript(f, "OnDragStart",
flickerstreak@102 416 -- OnDragStart(self, button, kind, value, ...)
flickerstreak@102 417 [[
flickerstreak@102 418 if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then
flickerstreak@102 419 return "clear"
flickerstreak@102 420 end
flickerstreak@102 421 ]])
flickerstreak@102 422
flickerstreak@108 423 -- attach to skinner
flickerstreak@108 424 bar:SkinButton(self,
flickerstreak@108 425 {
flickerstreak@108 426 HotKey = self.hotkey,
flickerstreak@108 427 }
flickerstreak@108 428 )
flickerstreak@108 429
flickerstreak@77 430 self:Refresh()
flickerstreak@116 431 self:UpdateHotkey()
flickerstreak@93 432 self:SetKeybindMode(ReAction:GetKeybindMode())
flickerstreak@93 433
flickerstreak@77 434 return self
flickerstreak@28 435 end
flickerstreak@28 436
flickerstreak@28 437 function Button:Destroy()
flickerstreak@28 438 local f = self.frame
flickerstreak@28 439 f:UnregisterAllEvents()
flickerstreak@28 440 f:Hide()
flickerstreak@28 441 f:SetParent(UIParent)
flickerstreak@28 442 f:ClearAllPoints()
flickerstreak@28 443 if self.name then
flickerstreak@53 444 frameRecycler[self.name] = f
flickerstreak@28 445 _G[self.name] = nil
flickerstreak@28 446 end
flickerstreak@53 447 if self.config.actionID then
flickerstreak@53 448 ActionIDList[self.config.actionID] = nil
flickerstreak@53 449 end
flickerstreak@116 450 f._reactionButton = nil
flickerstreak@28 451 self.frame = nil
flickerstreak@28 452 self.config = nil
flickerstreak@28 453 self.bar = nil
flickerstreak@28 454 end
flickerstreak@28 455
flickerstreak@77 456 function Button:Refresh()
flickerstreak@77 457 self.bar:PlaceButton(self, 30, 30)
flickerstreak@53 458 self:Update()
flickerstreak@53 459 self:UpdateHotkey()
flickerstreak@94 460 self.frame:Show()
flickerstreak@53 461 end
flickerstreak@53 462
flickerstreak@53 463 function Button:GetFrame()
flickerstreak@53 464 return self.frame
flickerstreak@53 465 end
flickerstreak@53 466
flickerstreak@53 467 function Button:GetName()
flickerstreak@53 468 return self.name
flickerstreak@53 469 end
flickerstreak@53 470
flickerstreak@88 471 function Button:GetConfig()
flickerstreak@88 472 return self.config
flickerstreak@88 473 end
flickerstreak@88 474
flickerstreak@53 475 function Button:GetActionID()
flickerstreak@53 476 return self.config.actionID
flickerstreak@53 477 end
flickerstreak@53 478
flickerstreak@53 479 function Button:Update()
flickerstreak@53 480 local id = self.frame:GetID()
flickerstreak@116 481 local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id)
flickerstreak@53 482 local f = self.frame
flickerstreak@53 483
flickerstreak@53 484 if isToken then
flickerstreak@116 485 self.icon:SetTexture(_G[texture])
flickerstreak@116 486 f.tooltipName = _G[name]
flickerstreak@53 487 else
flickerstreak@116 488 self.icon:SetTexture(texture)
flickerstreak@116 489 f.tooltipName = name
flickerstreak@53 490 end
flickerstreak@53 491
flickerstreak@116 492 f.isToken = isToken
flickerstreak@116 493 f.tooltipSubtext = subtext
flickerstreak@116 494 f:SetChecked( isActive and 1 or 0)
flickerstreak@53 495
flickerstreak@53 496 if autoCastAllowed then
flickerstreak@116 497 self.acTex:Show()
flickerstreak@53 498 else
flickerstreak@116 499 self.acTex:Hide()
flickerstreak@53 500 end
flickerstreak@53 501
flickerstreak@53 502 if autoCastEnabled then
flickerstreak@91 503 AutoCastShine_AutoCastStart(self.acModel)
flickerstreak@53 504 else
flickerstreak@91 505 AutoCastShine_AutoCastStop(self.acModel)
flickerstreak@53 506 end
flickerstreak@53 507
flickerstreak@53 508 if texture then
flickerstreak@91 509 if GetPetActionSlotUsable(id) then
flickerstreak@53 510 SetDesaturation(self.icon,nil)
flickerstreak@53 511 else
flickerstreak@53 512 SetDesaturation(self.icon,1)
flickerstreak@53 513 end
flickerstreak@116 514 self.icon:Show()
flickerstreak@116 515 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
flickerstreak@53 516 else
flickerstreak@116 517 self.icon:Hide()
flickerstreak@116 518 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot")
flickerstreak@53 519 end
flickerstreak@53 520
flickerstreak@53 521 self:UpdateCooldown()
flickerstreak@53 522 end
flickerstreak@53 523
flickerstreak@53 524 function Button:UpdateCooldown()
flickerstreak@116 525 local start, duration, enable = GetPetActionCooldown(self.frame:GetID())
flickerstreak@116 526 CooldownFrame_SetTimer(self.cooldown, start, duration, enable)
flickerstreak@53 527 end
flickerstreak@53 528
flickerstreak@53 529 function Button:UpdateHotkey()
flickerstreak@116 530 self.hotkey:SetText(GetHotkey(self.frame) or "")
flickerstreak@53 531 end
flickerstreak@28 532
flickerstreak@77 533 function Button:ShowActionIDLabel(show)
flickerstreak@77 534 if show then
flickerstreak@77 535 -- store the action ID label in the frame due to frame recycling
flickerstreak@77 536 if not self.actionIDLabel and self:GetActionID() then
flickerstreak@77 537 local label = self.frame:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
flickerstreak@77 538 label:SetAllPoints()
flickerstreak@77 539 label:SetJustifyH("CENTER")
flickerstreak@77 540 label:SetShadowColor(0,0,0,1)
flickerstreak@77 541 label:SetShadowOffset(2,-2)
flickerstreak@77 542 label:SetText(tostring(self:GetActionID()))
flickerstreak@77 543 self.actionIDLabel = label
flickerstreak@28 544 end
flickerstreak@77 545 self.actionIDLabel:Show()
flickerstreak@77 546 elseif self.actionIDLabel then
flickerstreak@77 547 self.actionIDLabel:Hide()
flickerstreak@28 548 end
flickerstreak@77 549 end
flickerstreak@93 550
flickerstreak@93 551
flickerstreak@93 552 function Button:SetKeybindMode(mode)
flickerstreak@93 553 if mode then
flickerstreak@116 554 local f = self.frame
flickerstreak@116 555 f.GetActionName = GetActionName
flickerstreak@116 556 f.GetHotkey = GetHotkey
flickerstreak@93 557 self.border:SetVertexColor(KB:GetColorKeyBoundMode())
flickerstreak@93 558 self.border:Show()
flickerstreak@93 559 else
flickerstreak@93 560 self.border:Hide()
flickerstreak@93 561 end
flickerstreak@93 562 end
flickerstreak@93 563