annotate modules/ReAction_PetAction/ReAction_PetAction.lua @ 100:9715174ff220

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