annotate SkeletonKey/KeyButton.lua @ 62:04c23ceaf9e0

- fix taint caused by loading in combat
author Nenue
date Mon, 05 Sep 2016 14:56:38 -0400
parents c416c9e6d212
children 2409fe9b81e1
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 elseif actionType == 'battlepet' then
Nenue@14 147
Nenue@52 148 local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = GetPetInfoByPetID(actionID)
Nenue@14 149 name = customName or petName
Nenue@14 150 icon = petIcon
Nenue@14 151
Nenue@14 152 end
Nenue@15 153 local macroName, macroText, command = kb.RegisterAction(actionType, actionID, name)
Nenue@14 154
Nenue@14 155
Nenue@14 156 local isAssigned, isBound, assignedBy, boundBy = kb.IsCommandBound(self, command)
Nenue@14 157 if isAssigned then
Nenue@14 158 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
Nenue@14 159 popup.slot = self
Nenue@14 160 popup.text = "Currently assigned in |cFFFFFF00"..tostring(kb.configHeaders[assignedBy]).."|r. Are you sure?"
Nenue@14 161 popup.oldProfile = assignedBy
Nenue@14 162 popup.args = {command, name, icon, actionType, actionID, macroName, macroText, pickupID, pickupBook }
Nenue@14 163 kb:SetScript('OnMouseWheel', nil) -- disable scrolling
Nenue@14 164 StaticPopup_Show('SKELETONKEY_CONFIRM_ASSIGN_SLOT')
Nenue@14 165 else
Nenue@14 166 kb.SetSlot(self, command, name, icon, actionType, actionID, macroName, macroText, pickupID, pickupBook)
Nenue@14 167 kb.UpdateSlot(self)
Nenue@14 168 self.active = nil
Nenue@14 169 ClearCursor()
Nenue@14 170 ResetCursor()
Nenue@14 171 end
Nenue@14 172 end
Nenue@14 173 end
Nenue@14 174
Nenue@14 175
Nenue@14 176 do
Nenue@14 177 local PickupAction = {
Nenue@14 178 spell = _G.PickupSpell,
Nenue@55 179 petaction =
Nenue@55 180 function(...)
Nenue@55 181 -- needs to be enclosed to acquire hooksecurefunc effects
Nenue@55 182 _G.PickupSpellBookItem(...)
Nenue@55 183 end,
Nenue@14 184 macro = _G.PickupMacro,
Nenue@14 185 item = _G.PickupItem,
Nenue@14 186 mount = _G.C_MountJournal.Pickup
Nenue@14 187 }
Nenue@14 188 local GetPickupValue = {
Nenue@14 189 spell = function(self) return select(7, GetSpellInfo(self.actionID)) end,
Nenue@14 190 petaction = function(self) return self.pickupSlot, self.pickupBook end,
Nenue@14 191 }
Nenue@14 192 kb.PickupSlot = function(self)
Nenue@15 193 if not (self.command and self.isAvailable) then
Nenue@14 194 return
Nenue@14 195 end
Nenue@14 196 print(self.actionType)
Nenue@14 197 if self.actionType == 'spell' then
Nenue@14 198 -- It can't be picked up if SpellInfo(name) returns void
Nenue@14 199 local dummy = GetSpellInfo(self.actionName)
Nenue@14 200 if not dummy then
Nenue@14 201 return
Nenue@14 202 end
Nenue@14 203 end
Nenue@14 204 if PickupAction[self.actionType] then
Nenue@14 205 if GetPickupValue[self.actionType] then
Nenue@14 206 PickupAction[self.actionType](GetPickupValue[self.actionType](self))
Nenue@14 207 else
Nenue@14 208 PickupAction[self.actionType](self.actionID)
Nenue@14 209 end
Nenue@14 210 kb.ReleaseSlot(self)
Nenue@14 211 kb.UpdateSlot(self)
Nenue@14 212 end
Nenue@14 213 end
Nenue@14 214 end
Nenue@14 215
Nenue@17 216
Nenue@14 217
Nenue@14 218
Nenue@14 219 --- Updates profile assignment and button contents
Nenue@14 220 kb.UpdateSlot = function(self, force)
Nenue@14 221 local slot = self:GetID()
Nenue@14 222
Nenue@14 223 if force then
Nenue@14 224 if kb.currentProfile.buttons[slot] then
Nenue@14 225 kb.SetSlot(self, unpack(kb.currentProfile.buttons[slot]))
Nenue@14 226 else
Nenue@14 227 kb.ReleaseSlot(self)
Nenue@14 228 end
Nenue@14 229 end
Nenue@14 230
Nenue@34 231
Nenue@14 232 if self.command then
Nenue@14 233 print('['..slot..'] =', self.command, GetBindingKey(self.command))
Nenue@14 234
Nenue@15 235 if not self.isAvailable then
Nenue@15 236 self.border:SetColorTexture(1,0,0,1)
Nenue@15 237 self.ignoreTexture:Show()
Nenue@14 238 else
Nenue@15 239 self.ignoreTexture:Hide()
Nenue@15 240
Nenue@15 241 if self.pending then
Nenue@15 242 self.border:SetColorTexture(unpack(BORDER_PENDING))
Nenue@15 243 elseif self.isDynamic then
Nenue@15 244 self.border:SetColorTexture(unpack(BORDER_DYNAMIC))
Nenue@15 245 else
Nenue@15 246 self.border:SetColorTexture(unpack(BORDER_ASSIGNED))
Nenue@15 247 end
Nenue@14 248 end
Nenue@14 249
Nenue@15 250
Nenue@14 251 if self.actionType == 'macro' then
Nenue@14 252 self.macro:Show()
Nenue@14 253 else
Nenue@14 254 self.macro:Hide()
Nenue@14 255 if self.actionType == 'spell' then
Nenue@14 256 local dummy = GetSpellInfo(self.actionName)
Nenue@14 257 if not dummy then
Nenue@14 258 self.icon:SetDesaturated(true)
Nenue@14 259 else
Nenue@14 260 self.icon:SetDesaturated(false)
Nenue@14 261 end
Nenue@14 262
Nenue@14 263 end
Nenue@14 264 end
Nenue@14 265
Nenue@14 266 if self.isDynamic then
Nenue@15 267 print('|cFF00BBFFUpdateSlot|r:', self.isDynamic, self.isAvailable, self.actionID)
Nenue@14 268 end
Nenue@14 269
Nenue@14 270 if self.isDynamic == 'profession' then
Nenue@30 271 if self.profIndex then
Nenue@29 272
Nenue@29 273 local profText = (self.spellNum == 1) and TRADE_SKILLS or (BUTTON_HEADERS[self.profIndex] or GetProfessionInfo(self.profIndex))
Nenue@14 274 print(self.profIndex, 'spnum', type(self.spellNum), (self.spellNum == 1))
Nenue@14 275
Nenue@29 276 self.statusText = '|cFFFFFF00'..tostring(profText)..'|r'
Nenue@14 277 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 278 else
Nenue@29 279
Nenue@30 280 self.statusText = '|cFFFF4400'..PROFESSION_HEADERS[self.professionNum]..'|r'
Nenue@29 281 self.actionName = '(#'..self.professionNum..')'
Nenue@14 282 self.bindingText ='?'
Nenue@14 283 end
Nenue@14 284 elseif self.isDynamic == 'talent' then
Nenue@14 285
Nenue@14 286 self.statusText = '|cFF00FFFF'.. TALENT .. '|r'
Nenue@14 287 if self.isAvailable then
Nenue@14 288 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 289 else
Nenue@19 290 if kb.TalentBindings[self.actionID] then
Nenue@19 291 print(self.actionID, #kb.TalentBindings[self.actionID])
Nenue@19 292 self.bindingText= kb.BindingString(unpack(kb.TalentBindings[self.actionID]))
Nenue@14 293 end
Nenue@14 294
Nenue@14 295 end
Nenue@19 296 elseif self.isDynamic == 'petaction' then
Nenue@21 297 local specialType, specialNum = self.command:match("petaction_([%a%s]+)_(%d)")
Nenue@21 298 if specialType and specialNum then
Nenue@21 299 print('pet skill|cFF00FF00', specialType..'|r', specialNum)
Nenue@21 300 self.statusText = L(specialType..' %%d'):format(specialNum)
Nenue@19 301 else
Nenue@19 302 self.statusText = L('Pet Action')
Nenue@19 303 end
Nenue@15 304 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 305 else
Nenue@14 306 self.statusText = '|cFF00FF00'.. (BUTTON_HEADERS[self.actionType] and BUTTON_HEADERS[self.actionType] or self.actionType) .. '|r'
Nenue@14 307 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 308 end
Nenue@14 309
Nenue@14 310 local locked, layer = kb.IsCommandBound(self)
Nenue@14 311 if locked then
Nenue@14 312 self.icon:SetAlpha(0.5)
Nenue@14 313 else
Nenue@14 314 self.icon:SetAlpha(1)
Nenue@14 315 end
Nenue@14 316
Nenue@17 317
Nenue@14 318 if self.actionType == 'spell' then
Nenue@14 319 self.icon:SetTexture(GetSpellTexture(self.actionID))
Nenue@14 320 end
Nenue@21 321 else
Nenue@34 322 if kb.saveTarget == self then
Nenue@34 323 kb.DeactivateSlot(self)
Nenue@34 324 end
Nenue@34 325
Nenue@21 326 self.ignoreTexture:Hide()
Nenue@14 327 end
Nenue@14 328
Nenue@14 329 if not self.isAvailable then
Nenue@14 330 self.bind:SetTextColor(0.7,0.7,0.7,1)
Nenue@14 331 else
Nenue@14 332 self.bind:SetTextColor(1,1,1,1)
Nenue@14 333 end
Nenue@14 334
Nenue@17 335
Nenue@17 336 if kb.saveTarget and kb.saveTarget ~= self then
Nenue@17 337 self:SetAlpha(0.25)
Nenue@17 338 else
Nenue@17 339
Nenue@17 340 self:SetAlpha(1)
Nenue@17 341 end
Nenue@17 342
Nenue@17 343
Nenue@14 344 self.header:SetText(self.statusText)
Nenue@14 345 self.bind:SetText(self.bindingText)
Nenue@14 346 self.details:SetText(self.actionName)
Nenue@14 347 end
Nenue@14 348
Nenue@14 349 --- Resets button command
Nenue@14 350 kb.ReleaseSlot = function(self)
Nenue@14 351 local slot = self:GetID()
Nenue@14 352
Nenue@14 353
Nenue@14 354 if kb.currentProfile.buttons[slot] then
Nenue@14 355 kb.currentProfile.buttons[slot] = nil
Nenue@14 356 end
Nenue@14 357 if self.command then
Nenue@14 358 kb.currentProfile.commands[self.command] = nil
Nenue@14 359 end
Nenue@14 360 if self.actionType == 'spell' and IsTalentSpell(self.actionName) then
Nenue@14 361 if kb.currentProfile.talents[self.actionID] then
Nenue@14 362 kb.currentProfile.talents[self.actionID] = nil
Nenue@14 363 end
Nenue@14 364 end
Nenue@14 365 local droppedKeys = {}
Nenue@14 366
Nenue@14 367 -- doing removal in second loop to avoid possible iterator shenanigans
Nenue@14 368 for k,v in pairs(kb.currentProfile.bindings) do
Nenue@14 369 if v == self.command then
Nenue@14 370 tinsert(droppedKeys, k)
Nenue@14 371 end
Nenue@14 372 end
Nenue@14 373 if #droppedKeys >=1 then
Nenue@14 374 for i, k in ipairs(droppedKeys) do
Nenue@14 375 kb.currentProfile.bindings[k] = nil
Nenue@14 376 end
Nenue@14 377 end
Nenue@14 378
Nenue@14 379 self.isAvailable = nil
Nenue@14 380 self.isDynamic = nil
Nenue@14 381 self.bindingText = nil
Nenue@14 382 self.statusText = nil
Nenue@14 383 self.command = nil
Nenue@14 384 self.actionType = nil
Nenue@14 385 self.actionID = nil
Nenue@14 386 self.actionName = nil
Nenue@14 387 self.pickupSlot = nil
Nenue@14 388 self.pickupBook = nil
Nenue@14 389 self.macroName = nil
Nenue@14 390 self.profile = nil
Nenue@14 391 self.icon:SetTexture(nil)
Nenue@14 392 self.border:SetColorTexture(unpack(BORDER_UNASSIGNED))
Nenue@14 393 self:EnableKeyboard(false)
Nenue@14 394 self:SetScript('OnKeyDown', nil)
Nenue@15 395 self.ignoreTexture:Hide()
Nenue@14 396 end
Nenue@14 397
Nenue@14 398 kb.SetSlot = function(self, command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook)
Nenue@14 399 local slot = self:GetID()
Nenue@14 400 local isDynamic, isAvailable
Nenue@14 401
Nenue@14 402 print('|cFFFFFF00SetSlot|r:', self:GetID())
Nenue@14 403 if command then
Nenue@14 404
Nenue@14 405 if actionType == 'spell' then
Nenue@14 406 local professionNum, spellNum = command:match("profession_(%d)_(%d)")
Nenue@14 407 if (professionNum and spellNum) then
Nenue@14 408 isDynamic = 'profession'
Nenue@14 409 local cacheInfo = kb.ProfessionCache[professionNum..'_'..spellNum]
Nenue@14 410 if cacheInfo then
Nenue@14 411 isAvailable = true
Nenue@14 412 name = cacheInfo.spellName
Nenue@14 413 icon = cacheInfo.icon
Nenue@14 414 actionID = cacheInfo.spellID
Nenue@14 415 self.profIndex = cacheInfo.profIndex
Nenue@14 416 self.spellOffset = cacheInfo.spellOffset
Nenue@30 417 else
Nenue@30 418 print(professionNum, type(professionNum), PROFESSION_HEADERS[tonumber(professionNum)])
Nenue@30 419 local profID = PROFESSION_HEADERS[tonumber(professionNum)]
Nenue@30 420 if type(profID) == 'number' then
Nenue@30 421 local pname, texture, _, _, numSpells, spellOffset = GetProfessionInfo(profID)
Nenue@30 422 self.profIndex = profID
Nenue@30 423 else
Nenue@30 424 name = profID
Nenue@30 425 end
Nenue@30 426
Nenue@14 427 end
Nenue@14 428 print(' Special slot: |cFF00FFFFProfession|r', professionNum, spellNum, isDynamic, isAvailable)
Nenue@14 429
Nenue@14 430 self.professionNum = tonumber(professionNum)
Nenue@14 431 self.spellNum = tonumber(spellNum)
Nenue@14 432
Nenue@14 433 else
Nenue@14 434 if kb.TalentCache[actionID] then
Nenue@14 435 isDynamic = 'talent'
Nenue@14 436 print(' Special slot: |cFFBBFF00talent|r', name, isAvailable)
Nenue@14 437 end
Nenue@14 438
Nenue@14 439 isAvailable = GetSpellInfo(name)
Nenue@14 440 end
Nenue@15 441 elseif actionType == 'petaction' then
Nenue@15 442 isDynamic = 'petaction'
Nenue@21 443 local specialType, specialNum = command:match(actionType..'_([%a%s]+)_(%d)')
Nenue@21 444
Nenue@21 445 if kb.PetCache.subtext[specialType] and kb.PetCache.subtext[specialType][tonumber(specialNum)] then
Nenue@30 446 print('***dynamic pet skill', specialType, specialNum)
Nenue@21 447 --[[ i, spellName, subText, spellID, texture, specialNum[subText ]]
Nenue@21 448 pickupSlot, name, specialType, actionID, icon, specialNum = unpack(kb.PetCache.subtext[specialType][tonumber(specialNum)])
Nenue@21 449 pickupBook = BOOKTYPE_PET
Nenue@21 450 end
Nenue@21 451
Nenue@22 452 isAvailable = (kb.PetCache.spellslot[name])
Nenue@22 453
Nenue@21 454
Nenue@14 455 elseif actionType == 'macro' then
Nenue@14 456 if not actionID then
Nenue@14 457 actionID = GetMacroIndexByName(name)
Nenue@14 458 end
Nenue@14 459 isAvailable = true
Nenue@14 460 else
Nenue@14 461 --- Journal selections
Nenue@14 462 -- todo: consider using the deep end of blizzard action bar instead
Nenue@14 463 if not actionID then
Nenue@14 464 actionID = command:match("^KeyBinderMacro:(.+)")
Nenue@14 465 end
Nenue@14 466 isAvailable = true
Nenue@14 467 end
Nenue@14 468
Nenue@14 469 if isAvailable then
Nenue@14 470 local oldCommand = command
Nenue@14 471 macroName, macroText, command = kb.RegisterAction(actionType, actionID, name)
Nenue@14 472 if oldCommand ~= command then
Nenue@14 473 print('|cFFFF4400fixing command string', actionType, actionID, name)
Nenue@14 474 kb.currentProfile.bound[oldCommand] = nil
Nenue@14 475 kb.currentProfile.bound[command] = slot
Nenue@14 476 for k,v in pairs(kb.currentProfile.bindings) do
Nenue@14 477 if v == oldCommand then
Nenue@14 478 kb.currentProfile.bindings[k] = command
Nenue@14 479 end
Nenue@14 480 end
Nenue@14 481 end
Nenue@14 482 kb.LoadBinding(command, name, icon, actionType, actionID, macroName, macroText)
Nenue@14 483 end
Nenue@14 484
Nenue@14 485
Nenue@14 486 actionID = actionID or 0
Nenue@14 487 self:EnableKeyboard(true)
Nenue@17 488 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 489 kb.currentProfile.buttons[slot] = {command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook }
Nenue@19 490
Nenue@14 491
Nenue@14 492 -- Clean up conflicting entries for loaded button
Nenue@14 493 local previous = kb.currentProfile.commands[command]
Nenue@14 494 if previous ~= slot and kb.buttons[previous] then
Nenue@14 495 kb.ReleaseSlot(kb.buttons[previous])
Nenue@14 496 end
Nenue@19 497
Nenue@19 498 if not (kb.IsCommandBound(self, command) or kb.currentProfile.bound[command]) then
Nenue@19 499
Nenue@19 500 local binds = {GetBindingKey(command) }
Nenue@19 501 if #binds >= 1 then
Nenue@19 502 kb:print('Recovered key binding for', name)
Nenue@19 503 for i, key in ipairs(binds) do
Nenue@19 504 kb.currentProfile.bindings[key] = command
Nenue@19 505 kb.currentProfile.bound[command] = true
Nenue@19 506 end
Nenue@19 507 end
Nenue@19 508 end
Nenue@19 509
Nenue@19 510
Nenue@14 511 kb.currentProfile.commands[command] = slot
Nenue@19 512
Nenue@14 513 end
Nenue@14 514
Nenue@14 515 self.isAvailable = isAvailable
Nenue@14 516 self.isDynamic = isDynamic
Nenue@14 517
Nenue@15 518 self.pickupSlot = pickupSlot
Nenue@15 519 self.pickupBook = pickupBook
Nenue@14 520 self.macroText = macroText
Nenue@14 521 self.macroName = macroName
Nenue@14 522 self.actionType = actionType
Nenue@14 523 self.actionID = actionID
Nenue@14 524 self.actionName = name
Nenue@14 525 self.command = command
Nenue@14 526 self.icon:SetTexture(icon)
Nenue@14 527 self.profile = kb.db.bindMode
Nenue@14 528 self:RegisterForDrag('LeftButton')
Nenue@14 529 end
Nenue@14 530
Nenue@27 531 kb.GetCommandAction = function(command)
Nenue@27 532 for i, data in ipairs(kb.loadedProfiles) do
Nenue@27 533 if data.commands[command] then
Nenue@27 534 if data.buttons[data.commands[command]] then
Nenue@27 535 local _, _, _, actionType, actionID = unpack(data.buttons[data.commands[command]])
Nenue@27 536 return actionType, actionID
Nenue@27 537 end
Nenue@27 538 end
Nenue@27 539 end
Nenue@27 540 end
Nenue@16 541