annotate SkeletonKey/KeyButton.lua @ 52:81a7c71c4483

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