annotate SkeletonKey/KeyButton.lua @ 55:c416c9e6d212

- fixed lua error that occurs when a pet skill picked up from the addon buttons is dropped
author Nenue
date Sun, 21 Aug 2016 03:33:39 -0400
parents 81a7c71c4483
children 04c23ceaf9e0
rev   line source
Nenue@14 1 -- SkeletonKey
Nenue@27 2 -- KeyButton.lua
Nenue@14 3 -- Created: 7/28/2016 11:26 PM
Nenue@14 4 -- %file-revision%
Nenue@52 5 -- Deals with display and manipulation of binding slots
Nenue@14 6
Nenue@14 7 local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot')
Nenue@17 8 local L = kb.L
Nenue@52 9 local type, tonumber, tostring, tinsert, tremove, ipairs, pairs = type, tonumber, tostring, tinsert, tremove, ipairs, pairs
Nenue@52 10 local _G, unpack, select, tostring = _G, unpack, select, tostring
Nenue@52 11 local GetSpellBookItemName, GetSpellBookItemTexture, GetSpellBookItemInfo, GetPetActionInfo = GetSpellBookItemName, GetSpellBookItemTexture, GetSpellBookItemInfo, GetPetActionInfo
Nenue@52 12 local GetSpellInfo, GetMacroInfo, GetItemInfo, GetItemIcon = GetSpellInfo, GetMacroInfo, GetItemInfo, GetItemIcon
Nenue@52 13 local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor
Nenue@52 14 local GetSpellTexture, IsTalentSpell, GetMacroIndexByName, IsAltKeyDown, IsControlKeyDown, IsShiftKeyDown = GetSpellTexture, IsTalentSpell, GetMacroIndexByName, IsAltKeyDown, IsControlKeyDown,IsShiftKeyDown
Nenue@52 15 local GetBindingKey, GetProfessionInfo = GetBindingKey, GetProfessionInfo
Nenue@52 16 local GetMountInfoByID, GetPetInfoByPetID = C_MountJournal.GetMountInfoByID, C_PetJournal.GetPetInfoByPetID
Nenue@52 17
Nenue@17 18 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION, CURSOR_TEXTURE
Nenue@14 19 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
Nenue@15 20 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1}
Nenue@15 21 local BORDER_ASSIGNED = {1,1,1,1}
Nenue@14 22 local BORDER_DYNAMIC = {1,1,0,1}
Nenue@14 23 local BORDER_PENDING = {1,0.5,0,1 }
Nenue@14 24 local BUTTON_HEADERS = {
Nenue@14 25 ['spell'] = SPELLS,
Nenue@14 26 ['macro'] = MACRO,
Nenue@14 27 ['petaction'] = PET,
Nenue@14 28 ['mount'] = MOUNT,
Nenue@14 29 ['battlepet'] = BATTLEPET,
Nenue@14 30
Nenue@14 31
Nenue@14 32 [5] = PROFESSIONS_FIRST_AID,
Nenue@14 33 [7] = PROFESSIONS_COOKING,
Nenue@14 34 [9] = PROFESSIONS_FISHING,
Nenue@14 35 [10] = PROFESSIONS_ARCHAEOLOGY,
Nenue@14 36
Nenue@14 37 }
Nenue@14 38
Nenue@30 39 local PROFESSION_HEADERS = {
Nenue@30 40 [1] = 'Profession 1',
Nenue@30 41 [2] = 'Profession 2',
Nenue@30 42 [3] = 10,
Nenue@30 43 [4] = 7,
Nenue@30 44 [5] = 9,
Nenue@30 45 [6] = 5
Nenue@30 46 }
Nenue@30 47
Nenue@14 48 -- This is needed to identify a spells that aren't reflected by GetCursorInfo()
Nenue@27 49 kb.OnPickupPetAction = function(slot, ...)
Nenue@17 50 local isPickup = GetCursorInfo()
Nenue@17 51 print(slot, ...)
Nenue@17 52 if kb.PetCache.action[slot] then
Nenue@17 53 if isPickup then
Nenue@17 54 local key, _, texture = unpack(kb.PetCache.action[slot])
Nenue@17 55 local spellName = _G[key] or key
Nenue@17 56 if spellName and kb.PetCache.spellslot[spellName] then
Nenue@17 57 CURSOR_SPELLSLOT = kb.PetCache.spellslot[spellName][1]
Nenue@17 58 CURSOR_BOOKTYPE = BOOKTYPE_PET
Nenue@17 59 CURSOR_TEXTURE = _G[texture] or texture
Nenue@17 60 end
Nenue@17 61 else
Nenue@17 62 CURSOR_SPELLSLOT = nil
Nenue@17 63 CURSOR_BOOKTYPE = nil
Nenue@17 64 CURSOR_TEXTURE = nil
Nenue@17 65 end
Nenue@27 66 print('|cFFFF4400PickupPetAction|r', isPickup, CURSOR_PETACTION)
Nenue@17 67 end
Nenue@15 68
Nenue@17 69 local name, subtext, texture, isToken = GetPetActionInfo(slot)
Nenue@17 70 if name then
Nenue@27 71 kb.PetCache.action[slot] = {name, subtext, texture, isToken}
Nenue@17 72 end
Nenue@15 73
Nenue@15 74
Nenue@17 75 print('current cursor info', CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_TEXTURE)
Nenue@15 76
Nenue@27 77 end
Nenue@27 78
Nenue@27 79 kb.OnPickupSpellBookItem = function(slot, bookType)
Nenue@27 80 print('|cFFFF4400PickupSpellBookItem('.. tostring(slot).. ', '..tostring(bookType)..')')
Nenue@27 81 CURSOR_SPELLSLOT = slot
Nenue@27 82 CURSOR_BOOKTYPE = bookType
Nenue@27 83 CURSOR_TEXTURE = GetSpellBookItemTexture(slot, bookType)
Nenue@27 84 print('current cursor info', CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_TEXTURE)
Nenue@27 85 end
Nenue@27 86
Nenue@27 87 kb.CreateHooks = function()
Nenue@27 88 hooksecurefunc("PickupSpellBookItem", kb.OnPickupSpellBookItem)
Nenue@27 89 hooksecurefunc("PickupPetAction", kb.OnPickupPetAction)
Nenue@27 90 end
Nenue@14 91
Nenue@14 92
Nenue@14 93 kb.DropToSlot = function(self)
Nenue@14 94 print(self:GetName(),'|cFF0088FFreceived|r')
Nenue@14 95 local actionType, actionID, subType, subData = GetCursorInfo()
Nenue@14 96 print('GetCursorInfo', GetCursorInfo())
Nenue@14 97 if actionType then
Nenue@14 98
Nenue@14 99 if actionType == 'flyout' then
Nenue@14 100 ClearCursor()
Nenue@14 101 ResetCursor()
Nenue@14 102 return
Nenue@14 103 end
Nenue@14 104
Nenue@14 105
Nenue@15 106 local name, icon, _
Nenue@14 107 local pickupID, pickupBook
Nenue@14 108
Nenue@14 109 if actionType == 'spell' then
Nenue@14 110 actionID = subData
Nenue@14 111 name, _, icon = GetSpellInfo(actionID)
Nenue@14 112
Nenue@14 113 elseif actionType == 'macro' then
Nenue@14 114 name, icon = GetMacroInfo(actionID)
Nenue@14 115 elseif actionType == 'petaction' then
Nenue@15 116 if CURSOR_SPELLSLOT and CURSOR_BOOKTYPE then
Nenue@14 117
Nenue@15 118 local spellType, spellID = GetSpellBookItemInfo(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE)
Nenue@15 119 local spellName, spellText = GetSpellBookItemName(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE)
Nenue@15 120 if spellType == 'PETACTION' then
Nenue@17 121 name = spellName
Nenue@15 122 actionID = spellText
Nenue@17 123 icon = CURSOR_TEXTURE
Nenue@15 124 else
Nenue@15 125 name, _, icon = GetSpellInfo(spellID)
Nenue@15 126 actionID = spellID
Nenue@15 127 end
Nenue@15 128
Nenue@15 129 pickupID = CURSOR_SPELLSLOT
Nenue@15 130 pickupBook = CURSOR_BOOKTYPE
Nenue@15 131 else
Nenue@15 132
Nenue@55 133
Nenue@14 134 end
Nenue@14 135
Nenue@14 136 elseif actionType == 'mount' then
Nenue@14 137 if subType == 0 then
Nenue@14 138 name, _, icon = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL)
Nenue@14 139 actionID = 0
Nenue@14 140 else
Nenue@52 141 name, _, icon = GetMountInfoByID(actionID)
Nenue@14 142 end
Nenue@14 143 elseif actionType == 'item' then
Nenue@14 144 name = GetItemInfo(actionID)
Nenue@14 145 icon = GetItemIcon(actionID)
Nenue@14 146 actionID = name
Nenue@14 147 elseif actionType == 'battlepet' then
Nenue@14 148
Nenue@52 149 local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = GetPetInfoByPetID(actionID)
Nenue@14 150 name = customName or petName
Nenue@14 151 icon = petIcon
Nenue@14 152
Nenue@14 153 end
Nenue@15 154 local macroName, macroText, command = kb.RegisterAction(actionType, actionID, name)
Nenue@14 155
Nenue@14 156
Nenue@14 157 local isAssigned, isBound, assignedBy, boundBy = kb.IsCommandBound(self, command)
Nenue@14 158 if isAssigned then
Nenue@14 159 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
Nenue@14 160 popup.slot = self
Nenue@14 161 popup.text = "Currently assigned in |cFFFFFF00"..tostring(kb.configHeaders[assignedBy]).."|r. Are you sure?"
Nenue@14 162 popup.oldProfile = assignedBy
Nenue@14 163 popup.args = {command, name, icon, actionType, actionID, macroName, macroText, pickupID, pickupBook }
Nenue@14 164 kb:SetScript('OnMouseWheel', nil) -- disable scrolling
Nenue@14 165 StaticPopup_Show('SKELETONKEY_CONFIRM_ASSIGN_SLOT')
Nenue@14 166 else
Nenue@14 167 kb.SetSlot(self, command, name, icon, actionType, actionID, macroName, macroText, pickupID, pickupBook)
Nenue@14 168 kb.UpdateSlot(self)
Nenue@14 169 self.active = nil
Nenue@14 170 ClearCursor()
Nenue@14 171 ResetCursor()
Nenue@14 172 end
Nenue@14 173 end
Nenue@14 174 end
Nenue@14 175
Nenue@14 176
Nenue@14 177 do
Nenue@14 178 local PickupAction = {
Nenue@14 179 spell = _G.PickupSpell,
Nenue@55 180 petaction =
Nenue@55 181 function(...)
Nenue@55 182 -- needs to be enclosed to acquire hooksecurefunc effects
Nenue@55 183 _G.PickupSpellBookItem(...)
Nenue@55 184 end,
Nenue@14 185 macro = _G.PickupMacro,
Nenue@14 186 item = _G.PickupItem,
Nenue@14 187 mount = _G.C_MountJournal.Pickup
Nenue@14 188 }
Nenue@14 189 local GetPickupValue = {
Nenue@14 190 spell = function(self) return select(7, GetSpellInfo(self.actionID)) end,
Nenue@14 191 petaction = function(self) return self.pickupSlot, self.pickupBook end,
Nenue@14 192 }
Nenue@14 193 kb.PickupSlot = function(self)
Nenue@15 194 if not (self.command and self.isAvailable) then
Nenue@14 195 return
Nenue@14 196 end
Nenue@14 197 print(self.actionType)
Nenue@14 198 if self.actionType == 'spell' then
Nenue@14 199 -- It can't be picked up if SpellInfo(name) returns void
Nenue@14 200 local dummy = GetSpellInfo(self.actionName)
Nenue@14 201 if not dummy then
Nenue@14 202 return
Nenue@14 203 end
Nenue@14 204 end
Nenue@14 205 if PickupAction[self.actionType] then
Nenue@14 206 if GetPickupValue[self.actionType] then
Nenue@14 207 PickupAction[self.actionType](GetPickupValue[self.actionType](self))
Nenue@14 208 else
Nenue@14 209 PickupAction[self.actionType](self.actionID)
Nenue@14 210 end
Nenue@14 211 kb.ReleaseSlot(self)
Nenue@14 212 kb.UpdateSlot(self)
Nenue@14 213 end
Nenue@14 214 end
Nenue@14 215 end
Nenue@14 216
Nenue@17 217
Nenue@14 218
Nenue@14 219
Nenue@14 220 --- Updates profile assignment and button contents
Nenue@14 221 kb.UpdateSlot = function(self, force)
Nenue@14 222 local slot = self:GetID()
Nenue@14 223
Nenue@14 224 if force then
Nenue@14 225 if kb.currentProfile.buttons[slot] then
Nenue@14 226 kb.SetSlot(self, unpack(kb.currentProfile.buttons[slot]))
Nenue@14 227 else
Nenue@14 228 kb.ReleaseSlot(self)
Nenue@14 229 end
Nenue@14 230 end
Nenue@14 231
Nenue@34 232
Nenue@14 233 if self.command then
Nenue@14 234 print('['..slot..'] =', self.command, GetBindingKey(self.command))
Nenue@14 235
Nenue@15 236 if not self.isAvailable then
Nenue@15 237 self.border:SetColorTexture(1,0,0,1)
Nenue@15 238 self.ignoreTexture:Show()
Nenue@14 239 else
Nenue@15 240 self.ignoreTexture:Hide()
Nenue@15 241
Nenue@15 242 if self.pending then
Nenue@15 243 self.border:SetColorTexture(unpack(BORDER_PENDING))
Nenue@15 244 elseif self.isDynamic then
Nenue@15 245 self.border:SetColorTexture(unpack(BORDER_DYNAMIC))
Nenue@15 246 else
Nenue@15 247 self.border:SetColorTexture(unpack(BORDER_ASSIGNED))
Nenue@15 248 end
Nenue@14 249 end
Nenue@14 250
Nenue@15 251
Nenue@14 252 if self.actionType == 'macro' then
Nenue@14 253 self.macro:Show()
Nenue@14 254 else
Nenue@14 255 self.macro:Hide()
Nenue@14 256 if self.actionType == 'spell' then
Nenue@14 257 local dummy = GetSpellInfo(self.actionName)
Nenue@14 258 if not dummy then
Nenue@14 259 self.icon:SetDesaturated(true)
Nenue@14 260 else
Nenue@14 261 self.icon:SetDesaturated(false)
Nenue@14 262 end
Nenue@14 263
Nenue@14 264 end
Nenue@14 265 end
Nenue@14 266
Nenue@14 267 if self.isDynamic then
Nenue@15 268 print('|cFF00BBFFUpdateSlot|r:', self.isDynamic, self.isAvailable, self.actionID)
Nenue@14 269 end
Nenue@14 270
Nenue@14 271 if self.isDynamic == 'profession' then
Nenue@30 272 if self.profIndex then
Nenue@29 273
Nenue@29 274 local profText = (self.spellNum == 1) and TRADE_SKILLS or (BUTTON_HEADERS[self.profIndex] or GetProfessionInfo(self.profIndex))
Nenue@14 275 print(self.profIndex, 'spnum', type(self.spellNum), (self.spellNum == 1))
Nenue@14 276
Nenue@29 277 self.statusText = '|cFFFFFF00'..tostring(profText)..'|r'
Nenue@14 278 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 279 else
Nenue@29 280
Nenue@30 281 self.statusText = '|cFFFF4400'..PROFESSION_HEADERS[self.professionNum]..'|r'
Nenue@29 282 self.actionName = '(#'..self.professionNum..')'
Nenue@14 283 self.bindingText ='?'
Nenue@14 284 end
Nenue@14 285 elseif self.isDynamic == 'talent' then
Nenue@14 286
Nenue@14 287 self.statusText = '|cFF00FFFF'.. TALENT .. '|r'
Nenue@14 288 if self.isAvailable then
Nenue@14 289 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 290 else
Nenue@19 291 if kb.TalentBindings[self.actionID] then
Nenue@19 292 print(self.actionID, #kb.TalentBindings[self.actionID])
Nenue@19 293 self.bindingText= kb.BindingString(unpack(kb.TalentBindings[self.actionID]))
Nenue@14 294 end
Nenue@14 295
Nenue@14 296 end
Nenue@19 297 elseif self.isDynamic == 'petaction' then
Nenue@21 298 local specialType, specialNum = self.command:match("petaction_([%a%s]+)_(%d)")
Nenue@21 299 if specialType and specialNum then
Nenue@21 300 print('pet skill|cFF00FF00', specialType..'|r', specialNum)
Nenue@21 301 self.statusText = L(specialType..' %%d'):format(specialNum)
Nenue@19 302 else
Nenue@19 303 self.statusText = L('Pet Action')
Nenue@19 304 end
Nenue@15 305 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 306 else
Nenue@14 307 self.statusText = '|cFF00FF00'.. (BUTTON_HEADERS[self.actionType] and BUTTON_HEADERS[self.actionType] or self.actionType) .. '|r'
Nenue@14 308 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 309 end
Nenue@14 310
Nenue@14 311 local locked, layer = kb.IsCommandBound(self)
Nenue@14 312 if locked then
Nenue@14 313 self.icon:SetAlpha(0.5)
Nenue@14 314 else
Nenue@14 315 self.icon:SetAlpha(1)
Nenue@14 316 end
Nenue@14 317
Nenue@17 318
Nenue@14 319 if self.actionType == 'spell' then
Nenue@14 320 self.icon:SetTexture(GetSpellTexture(self.actionID))
Nenue@14 321 end
Nenue@21 322 else
Nenue@34 323 if kb.saveTarget == self then
Nenue@34 324 kb.DeactivateSlot(self)
Nenue@34 325 end
Nenue@34 326
Nenue@21 327 self.ignoreTexture:Hide()
Nenue@14 328 end
Nenue@14 329
Nenue@14 330 if not self.isAvailable then
Nenue@14 331 self.bind:SetTextColor(0.7,0.7,0.7,1)
Nenue@14 332 else
Nenue@14 333 self.bind:SetTextColor(1,1,1,1)
Nenue@14 334 end
Nenue@14 335
Nenue@17 336
Nenue@17 337 if kb.saveTarget and kb.saveTarget ~= self then
Nenue@17 338 self:SetAlpha(0.25)
Nenue@17 339 else
Nenue@17 340
Nenue@17 341 self:SetAlpha(1)
Nenue@17 342 end
Nenue@17 343
Nenue@17 344
Nenue@14 345 self.header:SetText(self.statusText)
Nenue@14 346 self.bind:SetText(self.bindingText)
Nenue@14 347 self.details:SetText(self.actionName)
Nenue@14 348 end
Nenue@14 349
Nenue@14 350 --- Resets button command
Nenue@14 351 kb.ReleaseSlot = function(self)
Nenue@14 352 local slot = self:GetID()
Nenue@14 353
Nenue@14 354
Nenue@14 355 if kb.currentProfile.buttons[slot] then
Nenue@14 356 kb.currentProfile.buttons[slot] = nil
Nenue@14 357 end
Nenue@14 358 if self.command then
Nenue@14 359 kb.currentProfile.commands[self.command] = nil
Nenue@14 360 end
Nenue@14 361 if self.actionType == 'spell' and IsTalentSpell(self.actionName) then
Nenue@14 362 if kb.currentProfile.talents[self.actionID] then
Nenue@14 363 kb.currentProfile.talents[self.actionID] = nil
Nenue@14 364 end
Nenue@14 365 end
Nenue@14 366 local droppedKeys = {}
Nenue@14 367
Nenue@14 368 -- doing removal in second loop to avoid possible iterator shenanigans
Nenue@14 369 for k,v in pairs(kb.currentProfile.bindings) do
Nenue@14 370 if v == self.command then
Nenue@14 371 tinsert(droppedKeys, k)
Nenue@14 372 end
Nenue@14 373 end
Nenue@14 374 if #droppedKeys >=1 then
Nenue@14 375 for i, k in ipairs(droppedKeys) do
Nenue@14 376 kb.currentProfile.bindings[k] = nil
Nenue@14 377 end
Nenue@14 378 end
Nenue@14 379
Nenue@14 380 self.isAvailable = nil
Nenue@14 381 self.isDynamic = nil
Nenue@14 382 self.bindingText = nil
Nenue@14 383 self.statusText = nil
Nenue@14 384 self.command = nil
Nenue@14 385 self.actionType = nil
Nenue@14 386 self.actionID = nil
Nenue@14 387 self.actionName = nil
Nenue@14 388 self.pickupSlot = nil
Nenue@14 389 self.pickupBook = nil
Nenue@14 390 self.macroName = nil
Nenue@14 391 self.profile = nil
Nenue@14 392 self.icon:SetTexture(nil)
Nenue@14 393 self.border:SetColorTexture(unpack(BORDER_UNASSIGNED))
Nenue@14 394 self:EnableKeyboard(false)
Nenue@14 395 self:SetScript('OnKeyDown', nil)
Nenue@15 396 self.ignoreTexture:Hide()
Nenue@14 397 end
Nenue@14 398
Nenue@14 399 kb.SetSlot = function(self, command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook)
Nenue@14 400 local slot = self:GetID()
Nenue@14 401 local isDynamic, isAvailable
Nenue@14 402
Nenue@14 403 print('|cFFFFFF00SetSlot|r:', self:GetID())
Nenue@14 404 if command then
Nenue@14 405
Nenue@14 406 if actionType == 'spell' then
Nenue@14 407 local professionNum, spellNum = command:match("profession_(%d)_(%d)")
Nenue@14 408 if (professionNum and spellNum) then
Nenue@14 409 isDynamic = 'profession'
Nenue@14 410 local cacheInfo = kb.ProfessionCache[professionNum..'_'..spellNum]
Nenue@14 411 if cacheInfo then
Nenue@14 412 isAvailable = true
Nenue@14 413 name = cacheInfo.spellName
Nenue@14 414 icon = cacheInfo.icon
Nenue@14 415 actionID = cacheInfo.spellID
Nenue@14 416 self.profIndex = cacheInfo.profIndex
Nenue@14 417 self.spellOffset = cacheInfo.spellOffset
Nenue@30 418 else
Nenue@30 419 print(professionNum, type(professionNum), PROFESSION_HEADERS[tonumber(professionNum)])
Nenue@30 420 local profID = PROFESSION_HEADERS[tonumber(professionNum)]
Nenue@30 421 if type(profID) == 'number' then
Nenue@30 422 local pname, texture, _, _, numSpells, spellOffset = GetProfessionInfo(profID)
Nenue@30 423 self.profIndex = profID
Nenue@30 424 else
Nenue@30 425 name = profID
Nenue@30 426 end
Nenue@30 427
Nenue@14 428 end
Nenue@14 429 print(' Special slot: |cFF00FFFFProfession|r', professionNum, spellNum, isDynamic, isAvailable)
Nenue@14 430
Nenue@14 431 self.professionNum = tonumber(professionNum)
Nenue@14 432 self.spellNum = tonumber(spellNum)
Nenue@14 433
Nenue@14 434 else
Nenue@14 435 if kb.TalentCache[actionID] then
Nenue@14 436 isDynamic = 'talent'
Nenue@14 437 print(' Special slot: |cFFBBFF00talent|r', name, isAvailable)
Nenue@14 438 end
Nenue@14 439
Nenue@14 440 isAvailable = GetSpellInfo(name)
Nenue@14 441 end
Nenue@15 442 elseif actionType == 'petaction' then
Nenue@15 443 isDynamic = 'petaction'
Nenue@21 444 local specialType, specialNum = command:match(actionType..'_([%a%s]+)_(%d)')
Nenue@21 445
Nenue@21 446 if kb.PetCache.subtext[specialType] and kb.PetCache.subtext[specialType][tonumber(specialNum)] then
Nenue@30 447 print('***dynamic pet skill', specialType, specialNum)
Nenue@21 448 --[[ i, spellName, subText, spellID, texture, specialNum[subText ]]
Nenue@21 449 pickupSlot, name, specialType, actionID, icon, specialNum = unpack(kb.PetCache.subtext[specialType][tonumber(specialNum)])
Nenue@21 450 pickupBook = BOOKTYPE_PET
Nenue@21 451 end
Nenue@21 452
Nenue@22 453 isAvailable = (kb.PetCache.spellslot[name])
Nenue@22 454
Nenue@21 455
Nenue@14 456 elseif actionType == 'macro' then
Nenue@14 457 if not actionID then
Nenue@14 458 actionID = GetMacroIndexByName(name)
Nenue@14 459 end
Nenue@14 460 isAvailable = true
Nenue@14 461 else
Nenue@14 462 --- Journal selections
Nenue@14 463 -- todo: consider using the deep end of blizzard action bar instead
Nenue@14 464 if not actionID then
Nenue@14 465 actionID = command:match("^KeyBinderMacro:(.+)")
Nenue@14 466 end
Nenue@14 467 isAvailable = true
Nenue@14 468 end
Nenue@14 469
Nenue@14 470 if isAvailable then
Nenue@14 471 local oldCommand = command
Nenue@14 472 macroName, macroText, command = kb.RegisterAction(actionType, actionID, name)
Nenue@14 473 if oldCommand ~= command then
Nenue@14 474 print('|cFFFF4400fixing command string', actionType, actionID, name)
Nenue@14 475 kb.currentProfile.bound[oldCommand] = nil
Nenue@14 476 kb.currentProfile.bound[command] = slot
Nenue@14 477 for k,v in pairs(kb.currentProfile.bindings) do
Nenue@14 478 if v == oldCommand then
Nenue@14 479 kb.currentProfile.bindings[k] = command
Nenue@14 480 end
Nenue@14 481 end
Nenue@14 482 end
Nenue@14 483 kb.LoadBinding(command, name, icon, actionType, actionID, macroName, macroText)
Nenue@14 484 end
Nenue@14 485
Nenue@14 486
Nenue@14 487 actionID = actionID or 0
Nenue@14 488 self:EnableKeyboard(true)
Nenue@17 489 print(' |cFF00FF00kb.currentProfile.buttons['..slot..'] |cFF00FFFF=|r |cFF00FFFF"'.. command.. '"|r |cFF00FF00"'.. name.. '"|r |cFFFFFF00icon:'.. tostring(icon) .. '|r |cFFFF8800"'.. actionType, '"|r |cFFFF0088id:'.. actionID ..'|r |cFF00FF00"'.. macroName .. '"|r')
Nenue@19 490 kb.currentProfile.buttons[slot] = {command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook }
Nenue@19 491
Nenue@14 492
Nenue@14 493 -- Clean up conflicting entries for loaded button
Nenue@14 494 local previous = kb.currentProfile.commands[command]
Nenue@14 495 if previous ~= slot and kb.buttons[previous] then
Nenue@14 496 kb.ReleaseSlot(kb.buttons[previous])
Nenue@14 497 end
Nenue@19 498
Nenue@19 499 if not (kb.IsCommandBound(self, command) or kb.currentProfile.bound[command]) then
Nenue@19 500
Nenue@19 501 local binds = {GetBindingKey(command) }
Nenue@19 502 if #binds >= 1 then
Nenue@19 503 kb:print('Recovered key binding for', name)
Nenue@19 504 for i, key in ipairs(binds) do
Nenue@19 505 kb.currentProfile.bindings[key] = command
Nenue@19 506 kb.currentProfile.bound[command] = true
Nenue@19 507 end
Nenue@19 508 end
Nenue@19 509 end
Nenue@19 510
Nenue@19 511
Nenue@14 512 kb.currentProfile.commands[command] = slot
Nenue@19 513
Nenue@14 514 end
Nenue@14 515
Nenue@14 516 self.isAvailable = isAvailable
Nenue@14 517 self.isDynamic = isDynamic
Nenue@14 518
Nenue@15 519 self.pickupSlot = pickupSlot
Nenue@15 520 self.pickupBook = pickupBook
Nenue@14 521 self.macroText = macroText
Nenue@14 522 self.macroName = macroName
Nenue@14 523 self.actionType = actionType
Nenue@14 524 self.actionID = actionID
Nenue@14 525 self.actionName = name
Nenue@14 526 self.command = command
Nenue@14 527 self.icon:SetTexture(icon)
Nenue@14 528 self.profile = kb.db.bindMode
Nenue@14 529 self:RegisterForDrag('LeftButton')
Nenue@14 530 end
Nenue@14 531
Nenue@27 532 kb.GetCommandAction = function(command)
Nenue@27 533 for i, data in ipairs(kb.loadedProfiles) do
Nenue@27 534 if data.commands[command] then
Nenue@27 535 if data.buttons[data.commands[command]] then
Nenue@27 536 local _, _, _, actionType, actionID = unpack(data.buttons[data.commands[command]])
Nenue@27 537 return actionType, actionID
Nenue@27 538 end
Nenue@27 539 end
Nenue@27 540 end
Nenue@27 541 end
Nenue@16 542