annotate SkeletonKey/KeyButton.lua @ 27:73df13211b22

- actionbar hotkey text properly updates after hotkeys get switched - remove a unused function call
author Nenue
date Tue, 02 Aug 2016 12:33:13 -0400
parents SkeletonKey/KeySlot.lua@f6dd297cb812
children bb160c04de88
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@16 5 -- Code dealing with the slot button innards; they are invoked by frame script and should only chain to Set/Release
Nenue@14 6
Nenue@14 7 local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot')
Nenue@17 8 local L = kb.L
Nenue@17 9 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION, CURSOR_TEXTURE
Nenue@14 10 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
Nenue@15 11 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1}
Nenue@15 12 local BORDER_ASSIGNED = {1,1,1,1}
Nenue@14 13 local BORDER_DYNAMIC = {1,1,0,1}
Nenue@14 14 local BORDER_PENDING = {1,0.5,0,1 }
Nenue@14 15 local BUTTON_HEADERS = {
Nenue@14 16 ['spell'] = SPELLS,
Nenue@14 17 ['macro'] = MACRO,
Nenue@14 18 ['petaction'] = PET,
Nenue@14 19 ['mount'] = MOUNT,
Nenue@14 20 ['battlepet'] = BATTLEPET,
Nenue@14 21
Nenue@14 22
Nenue@14 23 [5] = PROFESSIONS_FIRST_AID,
Nenue@14 24 [7] = PROFESSIONS_COOKING,
Nenue@14 25 [9] = PROFESSIONS_FISHING,
Nenue@14 26 [10] = PROFESSIONS_ARCHAEOLOGY,
Nenue@14 27
Nenue@14 28 }
Nenue@14 29
Nenue@14 30 -- This is needed to identify a spells that aren't reflected by GetCursorInfo()
Nenue@27 31 kb.OnPickupPetAction = function(slot, ...)
Nenue@17 32 local isPickup = GetCursorInfo()
Nenue@17 33 print(slot, ...)
Nenue@17 34 if kb.PetCache.action[slot] then
Nenue@17 35 if isPickup then
Nenue@17 36 local key, _, texture = unpack(kb.PetCache.action[slot])
Nenue@17 37 local spellName = _G[key] or key
Nenue@17 38 if spellName and kb.PetCache.spellslot[spellName] then
Nenue@17 39 CURSOR_SPELLSLOT = kb.PetCache.spellslot[spellName][1]
Nenue@17 40 CURSOR_BOOKTYPE = BOOKTYPE_PET
Nenue@17 41 CURSOR_TEXTURE = _G[texture] or texture
Nenue@17 42 end
Nenue@17 43 else
Nenue@17 44 CURSOR_SPELLSLOT = nil
Nenue@17 45 CURSOR_BOOKTYPE = nil
Nenue@17 46 CURSOR_TEXTURE = nil
Nenue@17 47 end
Nenue@27 48 print('|cFFFF4400PickupPetAction|r', isPickup, CURSOR_PETACTION)
Nenue@17 49 end
Nenue@15 50
Nenue@17 51 local name, subtext, texture, isToken = GetPetActionInfo(slot)
Nenue@17 52 if name then
Nenue@27 53 kb.PetCache.action[slot] = {name, subtext, texture, isToken}
Nenue@17 54 end
Nenue@15 55
Nenue@15 56
Nenue@17 57 print('current cursor info', CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_TEXTURE)
Nenue@15 58
Nenue@27 59 end
Nenue@27 60
Nenue@27 61 kb.OnPickupSpellBookItem = function(slot, bookType)
Nenue@27 62 print('|cFFFF4400PickupSpellBookItem('.. tostring(slot).. ', '..tostring(bookType)..')')
Nenue@27 63 CURSOR_SPELLSLOT = slot
Nenue@27 64 CURSOR_BOOKTYPE = bookType
Nenue@27 65 CURSOR_TEXTURE = GetSpellBookItemTexture(slot, bookType)
Nenue@27 66 print('current cursor info', CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_TEXTURE)
Nenue@27 67 end
Nenue@27 68
Nenue@27 69 kb.CreateHooks = function()
Nenue@27 70 hooksecurefunc("PickupSpellBookItem", kb.OnPickupSpellBookItem)
Nenue@27 71 hooksecurefunc("PickupPetAction", kb.OnPickupPetAction)
Nenue@27 72 end
Nenue@14 73
Nenue@14 74
Nenue@14 75 kb.DropToSlot = function(self)
Nenue@14 76 print(self:GetName(),'|cFF0088FFreceived|r')
Nenue@14 77 local actionType, actionID, subType, subData = GetCursorInfo()
Nenue@14 78 print('GetCursorInfo', GetCursorInfo())
Nenue@14 79 if actionType then
Nenue@14 80
Nenue@14 81 if actionType == 'flyout' then
Nenue@14 82 ClearCursor()
Nenue@14 83 ResetCursor()
Nenue@14 84 return
Nenue@14 85 end
Nenue@14 86
Nenue@14 87
Nenue@15 88 local name, icon, _
Nenue@14 89 local pickupID, pickupBook
Nenue@14 90
Nenue@14 91 if actionType == 'spell' then
Nenue@14 92 actionID = subData
Nenue@14 93 name, _, icon = GetSpellInfo(actionID)
Nenue@14 94
Nenue@14 95 elseif actionType == 'macro' then
Nenue@14 96 name, icon = GetMacroInfo(actionID)
Nenue@14 97 elseif actionType == 'petaction' then
Nenue@15 98 if CURSOR_SPELLSLOT and CURSOR_BOOKTYPE then
Nenue@14 99
Nenue@15 100 local spellType, spellID = GetSpellBookItemInfo(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE)
Nenue@15 101 local spellName, spellText = GetSpellBookItemName(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE)
Nenue@15 102 if spellType == 'PETACTION' then
Nenue@17 103 name = spellName
Nenue@15 104 actionID = spellText
Nenue@17 105 icon = CURSOR_TEXTURE
Nenue@15 106 else
Nenue@15 107 name, _, icon = GetSpellInfo(spellID)
Nenue@15 108 actionID = spellID
Nenue@15 109 end
Nenue@15 110
Nenue@15 111 pickupID = CURSOR_SPELLSLOT
Nenue@15 112 pickupBook = CURSOR_BOOKTYPE
Nenue@15 113 else
Nenue@15 114
Nenue@14 115 end
Nenue@14 116
Nenue@14 117 elseif actionType == 'mount' then
Nenue@14 118 if subType == 0 then
Nenue@14 119 name, _, icon = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL)
Nenue@14 120 actionID = 0
Nenue@14 121 else
Nenue@14 122 name, _, icon = C_MountJournal.GetMountInfoByID(actionID)
Nenue@14 123 end
Nenue@14 124 elseif actionType == 'item' then
Nenue@14 125 name = GetItemInfo(actionID)
Nenue@14 126 icon = GetItemIcon(actionID)
Nenue@14 127 actionID = name
Nenue@14 128 elseif actionType == 'battlepet' then
Nenue@14 129
Nenue@14 130 local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = C_PetJournal.GetPetInfoByPetID(detail);
Nenue@14 131 name = customName or petName
Nenue@14 132 icon = petIcon
Nenue@14 133
Nenue@14 134 end
Nenue@15 135 local macroName, macroText, command = kb.RegisterAction(actionType, actionID, name)
Nenue@14 136
Nenue@14 137
Nenue@14 138 local isAssigned, isBound, assignedBy, boundBy = kb.IsCommandBound(self, command)
Nenue@14 139 if isAssigned then
Nenue@14 140 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
Nenue@14 141 popup.slot = self
Nenue@14 142 popup.text = "Currently assigned in |cFFFFFF00"..tostring(kb.configHeaders[assignedBy]).."|r. Are you sure?"
Nenue@14 143 popup.oldProfile = assignedBy
Nenue@14 144 popup.args = {command, name, icon, actionType, actionID, macroName, macroText, pickupID, pickupBook }
Nenue@14 145 kb:SetScript('OnMouseWheel', nil) -- disable scrolling
Nenue@14 146 StaticPopup_Show('SKELETONKEY_CONFIRM_ASSIGN_SLOT')
Nenue@14 147 else
Nenue@14 148 kb.SetSlot(self, command, name, icon, actionType, actionID, macroName, macroText, pickupID, pickupBook)
Nenue@14 149 kb.UpdateSlot(self)
Nenue@14 150 self.active = nil
Nenue@14 151 ClearCursor()
Nenue@14 152 ResetCursor()
Nenue@14 153 end
Nenue@14 154 end
Nenue@14 155 end
Nenue@14 156
Nenue@14 157
Nenue@14 158 do
Nenue@14 159 local PickupAction = {
Nenue@14 160 spell = _G.PickupSpell,
Nenue@14 161 petaction = _G.PickupSpellBookItem,
Nenue@14 162 macro = _G.PickupMacro,
Nenue@14 163 item = _G.PickupItem,
Nenue@14 164 mount = _G.C_MountJournal.Pickup
Nenue@14 165 }
Nenue@14 166 local GetPickupValue = {
Nenue@14 167 spell = function(self) return select(7, GetSpellInfo(self.actionID)) end,
Nenue@14 168 petaction = function(self) return self.pickupSlot, self.pickupBook end,
Nenue@14 169 }
Nenue@14 170 kb.PickupSlot = function(self)
Nenue@15 171 if not (self.command and self.isAvailable) then
Nenue@14 172 return
Nenue@14 173 end
Nenue@14 174 print(self.actionType)
Nenue@14 175 if self.actionType == 'spell' then
Nenue@14 176 -- It can't be picked up if SpellInfo(name) returns void
Nenue@14 177 local dummy = GetSpellInfo(self.actionName)
Nenue@14 178 if not dummy then
Nenue@14 179 return
Nenue@14 180 end
Nenue@14 181 end
Nenue@14 182 if PickupAction[self.actionType] then
Nenue@14 183 if GetPickupValue[self.actionType] then
Nenue@14 184 PickupAction[self.actionType](GetPickupValue[self.actionType](self))
Nenue@14 185 else
Nenue@14 186 PickupAction[self.actionType](self.actionID)
Nenue@14 187 end
Nenue@14 188 kb.ReleaseSlot(self)
Nenue@14 189 kb.UpdateSlot(self)
Nenue@14 190 end
Nenue@14 191 end
Nenue@14 192 end
Nenue@14 193
Nenue@17 194 kb.UnbindSlot = function(self)
Nenue@17 195
Nenue@17 196 local keys = {GetBindingKey(self.command) }
Nenue@27 197 if #keys >= 1 then
Nenue@27 198 kb.UpdateBindingsCache(self.actionType, self.actionID, {})
Nenue@27 199 end
Nenue@27 200
Nenue@27 201
Nenue@17 202 --print('detected', #keys, 'bindings')
Nenue@17 203 for i, key in pairs(keys) do
Nenue@17 204 --print('clearing', key)
Nenue@17 205 SetBinding(key, nil)
Nenue@17 206 SaveBindings(GetCurrentBindingSet())
Nenue@17 207 if kb.currentProfile.bindings[key] then
Nenue@18 208 --kb:print(L('BINDING_REMOVED', self.actionName, kb.currentHeader))
Nenue@17 209 kb.currentProfile.bindings[key] = nil
Nenue@17 210 end
Nenue@17 211 if kb.currentProfile.talents[self.actionName] then
Nenue@17 212 kb.currentProfile.talents[self.actionName] = nil
Nenue@17 213 end
Nenue@17 214 kb.bindings[self.actionType][self.actionID] = nil
Nenue@17 215 end
Nenue@17 216 if kb.currentProfile.bound[self.command] then
Nenue@17 217 kb.currentProfile.bound[self.command] = nil
Nenue@17 218 --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode]))
Nenue@17 219 end
Nenue@17 220
Nenue@27 221
Nenue@17 222 self.active = false
Nenue@17 223 kb.UpdateSlot(self, true)
Nenue@17 224 end
Nenue@17 225
Nenue@17 226 --- Updates the current KeyBinding for the button's command
Nenue@17 227 kb.SaveSlot = function(self, key)
Nenue@17 228
Nenue@17 229 if not self.command then
Nenue@17 230 return
Nenue@17 231 end
Nenue@17 232 print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key)
Nenue@17 233
Nenue@17 234 local modifier = ''
Nenue@17 235 if IsAltKeyDown() then
Nenue@17 236 modifier = 'ALT-'
Nenue@17 237 end
Nenue@17 238 if IsControlKeyDown() then
Nenue@17 239 modifier = modifier.. 'CTRL-'
Nenue@17 240 end
Nenue@17 241 if IsShiftKeyDown() then
Nenue@17 242 modifier = modifier..'SHIFT-'
Nenue@17 243 end
Nenue@17 244 local binding = modifier..key
Nenue@17 245
Nenue@17 246 if key == 'ESCAPE' then
Nenue@17 247 else
Nenue@19 248 if kb.SystemBindings[binding] then
Nenue@19 249 kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', binding, kb.SystemBindings[binding]))
Nenue@17 250 return
Nenue@17 251 end
Nenue@17 252
Nenue@17 253
Nenue@17 254 if self.command then
Nenue@17 255
Nenue@27 256 local previousCommand = GetBindingAction(binding)
Nenue@27 257 if previousCommand ~= "" and previousCommand ~= self.command then
Nenue@17 258 if kb.SystemBindings[binding] then
Nenue@17 259 -- bounce out if trying to use a protected key
Nenue@17 260 kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, GetBindingAction(binding)))
Nenue@17 261 kb.bindingstext:SetText(nil)
Nenue@19 262 return false
Nenue@17 263 end
Nenue@27 264
Nenue@27 265 local actionType, actionID, name = kb.GetCommandAction(previousCommand)
Nenue@27 266 if actionType then
Nenue@27 267 local keys = {GetBindingKey(previousCommand) }
Nenue@27 268 local i = 1
Nenue@27 269 while keys[i] do
Nenue@27 270 if keys[i] == binding then
Nenue@27 271 table.remove(keys, i)
Nenue@27 272 kb.UpdateBindingsCache(actionType, actionID, keys)
Nenue@27 273 break
Nenue@27 274 end
Nenue@27 275 i = i + 1
Nenue@27 276 end
Nenue@27 277 end
Nenue@27 278 end
Nenue@27 279
Nenue@27 280 local currentHotKeys = {GetBindingKey(self.command)}
Nenue@27 281 local found
Nenue@27 282 for i, key in ipairs(currentHotKeys) do
Nenue@27 283 if key == binding then
Nenue@27 284 found = true
Nenue@27 285 kb:print('hotkey already assigned')
Nenue@27 286 end
Nenue@27 287 end
Nenue@27 288 if not found then
Nenue@27 289 table.insert(currentHotKeys, 1, binding)
Nenue@27 290 kb.UpdateBindingsCache(self.actionType, self.actionID, currentHotKeys)
Nenue@17 291 end
Nenue@17 292
Nenue@17 293 self.binding = binding
Nenue@17 294
Nenue@27 295
Nenue@27 296
Nenue@27 297 SetBinding(binding, self.command)
Nenue@17 298 SaveBindings(GetCurrentBindingSet())
Nenue@17 299
Nenue@27 300
Nenue@27 301
Nenue@17 302 local talentInfo
Nenue@17 303 if self.actionType == 'spell' and kb.TalentCache[self.actionID] then
Nenue@17 304 print('conditional binding (talent = "'..self.actionName..'")')
Nenue@17 305 talentInfo = {self.macroName, self.actionName, self.actionType, self.actionID}
Nenue@17 306 local bindings = {GetBindingKey(self.command) }
Nenue@17 307 for i, key in ipairs(bindings) do
Nenue@17 308 tinsert(talentInfo, key)
Nenue@17 309 end
Nenue@17 310 end
Nenue@17 311
Nenue@17 312 for level, profile in ipairs(kb.orderedProfiles) do
Nenue@17 313 if (level == kb.db.bindMode) then
Nenue@17 314 profile.bound[self.command] = true
Nenue@17 315 if talentInfo then
Nenue@17 316 profile.bindings[self.binding] = nil
Nenue@17 317 else
Nenue@17 318 profile.bindings[self.binding] = self.command
Nenue@17 319 end
Nenue@17 320 profile.talents[self.actionName] = talentInfo
Nenue@17 321 else
Nenue@17 322 profile.bindings[self.binding] = nil
Nenue@17 323 profile.bound[self.command] = nil
Nenue@17 324 kb.currentProfile.talents[self.actionName] = nil
Nenue@17 325 end
Nenue@17 326 if kb.currentProfile.talents[self.actionID] then
Nenue@17 327 kb.currentProfile.talents[self.actionID] = nil
Nenue@17 328 end
Nenue@17 329 end
Nenue@17 330
Nenue@17 331 kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.currentHeader))
Nenue@17 332 end
Nenue@17 333 end
Nenue@17 334 kb.UpdateSlot(self, true)
Nenue@19 335 return true
Nenue@17 336 end
Nenue@14 337
Nenue@14 338
Nenue@14 339 --- Updates profile assignment and button contents
Nenue@14 340 kb.UpdateSlot = function(self, force)
Nenue@14 341 local slot = self:GetID()
Nenue@14 342
Nenue@14 343 if force then
Nenue@14 344 if kb.currentProfile.buttons[slot] then
Nenue@14 345 kb.SetSlot(self, unpack(kb.currentProfile.buttons[slot]))
Nenue@14 346 else
Nenue@14 347 kb.ReleaseSlot(self)
Nenue@14 348 end
Nenue@14 349 end
Nenue@14 350
Nenue@14 351 if self.command then
Nenue@14 352 print('['..slot..'] =', self.command, GetBindingKey(self.command))
Nenue@14 353
Nenue@15 354 if not self.isAvailable then
Nenue@15 355 self.border:SetColorTexture(1,0,0,1)
Nenue@15 356 self.ignoreTexture:Show()
Nenue@14 357 else
Nenue@15 358 self.ignoreTexture:Hide()
Nenue@15 359
Nenue@15 360 if self.pending then
Nenue@15 361 self.border:SetColorTexture(unpack(BORDER_PENDING))
Nenue@15 362 elseif self.isDynamic then
Nenue@15 363 self.border:SetColorTexture(unpack(BORDER_DYNAMIC))
Nenue@15 364 else
Nenue@15 365 self.border:SetColorTexture(unpack(BORDER_ASSIGNED))
Nenue@15 366 end
Nenue@14 367 end
Nenue@14 368
Nenue@15 369
Nenue@14 370 if self.actionType == 'macro' then
Nenue@14 371 self.macro:Show()
Nenue@14 372 else
Nenue@14 373 self.macro:Hide()
Nenue@14 374 if self.actionType == 'spell' then
Nenue@14 375 local dummy = GetSpellInfo(self.actionName)
Nenue@14 376 if not dummy then
Nenue@14 377 self.icon:SetDesaturated(true)
Nenue@14 378 else
Nenue@14 379 self.icon:SetDesaturated(false)
Nenue@14 380 end
Nenue@14 381
Nenue@14 382 end
Nenue@14 383 end
Nenue@14 384
Nenue@14 385 if self.isDynamic then
Nenue@15 386 print('|cFF00BBFFUpdateSlot|r:', self.isDynamic, self.isAvailable, self.actionID)
Nenue@14 387 end
Nenue@14 388
Nenue@14 389 if self.isDynamic == 'profession' then
Nenue@14 390 local profText = (self.spellNum == 1) and TRADE_SKILLS or (BUTTON_HEADERS[self.profIndex] or GetProfessionInfo(self.profIndex))
Nenue@14 391 if self.isAvailable then
Nenue@14 392 print(self.profIndex, 'spnum', type(self.spellNum), (self.spellNum == 1))
Nenue@14 393
Nenue@14 394 self.statusText = '|cFFFFFF00'..profText..'|r'
Nenue@14 395 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 396 else
Nenue@14 397 self.statusText = '|cFFFF4400'..profText..'|r'
Nenue@14 398 self.actionName = '(need to train profession #'..self.profNum..')'
Nenue@14 399 self.bindingText ='?'
Nenue@14 400 end
Nenue@14 401 elseif self.isDynamic == 'talent' then
Nenue@14 402
Nenue@14 403 self.statusText = '|cFF00FFFF'.. TALENT .. '|r'
Nenue@14 404 if self.isAvailable then
Nenue@14 405 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 406 else
Nenue@19 407 if kb.TalentBindings[self.actionID] then
Nenue@19 408 print(self.actionID, #kb.TalentBindings[self.actionID])
Nenue@19 409 self.bindingText= kb.BindingString(unpack(kb.TalentBindings[self.actionID]))
Nenue@14 410 end
Nenue@14 411
Nenue@14 412 end
Nenue@19 413 elseif self.isDynamic == 'petaction' then
Nenue@21 414 local specialType, specialNum = self.command:match("petaction_([%a%s]+)_(%d)")
Nenue@21 415 if specialType and specialNum then
Nenue@21 416 print('pet skill|cFF00FF00', specialType..'|r', specialNum)
Nenue@21 417 self.statusText = L(specialType..' %%d'):format(specialNum)
Nenue@19 418 else
Nenue@19 419 self.statusText = L('Pet Action')
Nenue@19 420 end
Nenue@15 421 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 422 else
Nenue@14 423 self.statusText = '|cFF00FF00'.. (BUTTON_HEADERS[self.actionType] and BUTTON_HEADERS[self.actionType] or self.actionType) .. '|r'
Nenue@14 424 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@14 425 end
Nenue@14 426
Nenue@14 427 local locked, layer = kb.IsCommandBound(self)
Nenue@14 428 if locked then
Nenue@14 429 self.icon:SetAlpha(0.5)
Nenue@14 430 else
Nenue@14 431 self.icon:SetAlpha(1)
Nenue@14 432 end
Nenue@14 433
Nenue@17 434
Nenue@14 435 if self.actionType == 'spell' then
Nenue@14 436 self.icon:SetTexture(GetSpellTexture(self.actionID))
Nenue@14 437 end
Nenue@21 438 else
Nenue@21 439 self.ignoreTexture:Hide()
Nenue@14 440 end
Nenue@14 441
Nenue@14 442 if not self.isAvailable then
Nenue@14 443 self.bind:SetTextColor(0.7,0.7,0.7,1)
Nenue@14 444 else
Nenue@14 445 self.bind:SetTextColor(1,1,1,1)
Nenue@14 446 end
Nenue@14 447
Nenue@17 448
Nenue@17 449 if kb.saveTarget and kb.saveTarget ~= self then
Nenue@17 450 self:SetAlpha(0.25)
Nenue@17 451 else
Nenue@17 452
Nenue@17 453 self:SetAlpha(1)
Nenue@17 454 end
Nenue@17 455
Nenue@17 456
Nenue@14 457 self.header:SetText(self.statusText)
Nenue@14 458 self.bind:SetText(self.bindingText)
Nenue@14 459 self.details:SetText(self.actionName)
Nenue@14 460 end
Nenue@14 461
Nenue@14 462 --- Resets button command
Nenue@14 463 kb.ReleaseSlot = function(self)
Nenue@14 464 local slot = self:GetID()
Nenue@14 465
Nenue@14 466
Nenue@14 467 if kb.currentProfile.buttons[slot] then
Nenue@14 468 kb.currentProfile.buttons[slot] = nil
Nenue@14 469 end
Nenue@14 470 if self.command then
Nenue@14 471 kb.currentProfile.commands[self.command] = nil
Nenue@14 472 end
Nenue@14 473 if self.actionType == 'spell' and IsTalentSpell(self.actionName) then
Nenue@14 474 if kb.currentProfile.talents[self.actionID] then
Nenue@14 475 kb.currentProfile.talents[self.actionID] = nil
Nenue@14 476 end
Nenue@14 477 end
Nenue@14 478 local droppedKeys = {}
Nenue@14 479
Nenue@14 480 -- doing removal in second loop to avoid possible iterator shenanigans
Nenue@14 481 for k,v in pairs(kb.currentProfile.bindings) do
Nenue@14 482 if v == self.command then
Nenue@14 483 tinsert(droppedKeys, k)
Nenue@14 484 end
Nenue@14 485 end
Nenue@14 486 if #droppedKeys >=1 then
Nenue@14 487 for i, k in ipairs(droppedKeys) do
Nenue@14 488 kb.currentProfile.bindings[k] = nil
Nenue@14 489 end
Nenue@14 490 end
Nenue@14 491
Nenue@14 492 self.isAvailable = nil
Nenue@14 493 self.isDynamic = nil
Nenue@14 494 self.bindingText = nil
Nenue@14 495 self.statusText = nil
Nenue@14 496 self.command = nil
Nenue@14 497 self.actionType = nil
Nenue@14 498 self.actionID = nil
Nenue@14 499 self.actionName = nil
Nenue@14 500 self.pickupSlot = nil
Nenue@14 501 self.pickupBook = nil
Nenue@14 502 self.macroName = nil
Nenue@14 503 self.profile = nil
Nenue@14 504 self.icon:SetTexture(nil)
Nenue@14 505 self.border:SetColorTexture(unpack(BORDER_UNASSIGNED))
Nenue@14 506 self:EnableKeyboard(false)
Nenue@14 507 self:SetScript('OnKeyDown', nil)
Nenue@15 508 self.ignoreTexture:Hide()
Nenue@14 509 end
Nenue@14 510
Nenue@14 511 kb.SetSlot = function(self, command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook)
Nenue@14 512 local slot = self:GetID()
Nenue@14 513 local isDynamic, isAvailable
Nenue@14 514
Nenue@14 515 print('|cFFFFFF00SetSlot|r:', self:GetID())
Nenue@14 516 if command then
Nenue@14 517
Nenue@14 518 if actionType == 'spell' then
Nenue@14 519 local professionNum, spellNum = command:match("profession_(%d)_(%d)")
Nenue@14 520 if (professionNum and spellNum) then
Nenue@14 521 isDynamic = 'profession'
Nenue@14 522 local cacheInfo = kb.ProfessionCache[professionNum..'_'..spellNum]
Nenue@14 523 if cacheInfo then
Nenue@14 524 isAvailable = true
Nenue@14 525 name = cacheInfo.spellName
Nenue@14 526 icon = cacheInfo.icon
Nenue@14 527 actionID = cacheInfo.spellID
Nenue@14 528 self.profIndex = cacheInfo.profIndex
Nenue@14 529 self.spellOffset = cacheInfo.spellOffset
Nenue@14 530 end
Nenue@14 531 print(' Special slot: |cFF00FFFFProfession|r', professionNum, spellNum, isDynamic, isAvailable)
Nenue@14 532
Nenue@14 533 self.professionNum = tonumber(professionNum)
Nenue@14 534 self.spellNum = tonumber(spellNum)
Nenue@14 535
Nenue@14 536 else
Nenue@14 537 if kb.TalentCache[actionID] then
Nenue@14 538 isDynamic = 'talent'
Nenue@14 539 print(' Special slot: |cFFBBFF00talent|r', name, isAvailable)
Nenue@14 540 end
Nenue@14 541
Nenue@14 542 isAvailable = GetSpellInfo(name)
Nenue@14 543 end
Nenue@15 544 elseif actionType == 'petaction' then
Nenue@15 545 isDynamic = 'petaction'
Nenue@21 546 local specialType, specialNum = command:match(actionType..'_([%a%s]+)_(%d)')
Nenue@21 547
Nenue@21 548 if kb.PetCache.subtext[specialType] and kb.PetCache.subtext[specialType][tonumber(specialNum)] then
Nenue@21 549 print('***dynamic pet thign', specialType, specialNum)
Nenue@21 550 --[[ i, spellName, subText, spellID, texture, specialNum[subText ]]
Nenue@21 551 pickupSlot, name, specialType, actionID, icon, specialNum = unpack(kb.PetCache.subtext[specialType][tonumber(specialNum)])
Nenue@21 552 pickupBook = BOOKTYPE_PET
Nenue@21 553 end
Nenue@21 554
Nenue@22 555 isAvailable = (kb.PetCache.spellslot[name])
Nenue@22 556
Nenue@21 557
Nenue@14 558 elseif actionType == 'macro' then
Nenue@14 559 if not actionID then
Nenue@14 560 actionID = GetMacroIndexByName(name)
Nenue@14 561 end
Nenue@14 562 isAvailable = true
Nenue@14 563 else
Nenue@14 564 --- Journal selections
Nenue@14 565 -- todo: consider using the deep end of blizzard action bar instead
Nenue@14 566 if not actionID then
Nenue@14 567 actionID = command:match("^KeyBinderMacro:(.+)")
Nenue@14 568 end
Nenue@14 569 isAvailable = true
Nenue@14 570 end
Nenue@14 571
Nenue@14 572 if isAvailable then
Nenue@14 573 local oldCommand = command
Nenue@14 574 macroName, macroText, command = kb.RegisterAction(actionType, actionID, name)
Nenue@14 575 if oldCommand ~= command then
Nenue@14 576 print('|cFFFF4400fixing command string', actionType, actionID, name)
Nenue@14 577 kb.currentProfile.bound[oldCommand] = nil
Nenue@14 578 kb.currentProfile.bound[command] = slot
Nenue@14 579 for k,v in pairs(kb.currentProfile.bindings) do
Nenue@14 580 if v == oldCommand then
Nenue@14 581 kb.currentProfile.bindings[k] = command
Nenue@14 582 end
Nenue@14 583 end
Nenue@14 584 end
Nenue@14 585 kb.LoadBinding(command, name, icon, actionType, actionID, macroName, macroText)
Nenue@14 586 end
Nenue@14 587
Nenue@14 588
Nenue@14 589 actionID = actionID or 0
Nenue@14 590 self:EnableKeyboard(true)
Nenue@17 591 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 592 kb.currentProfile.buttons[slot] = {command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook }
Nenue@19 593
Nenue@14 594
Nenue@14 595 -- Clean up conflicting entries for loaded button
Nenue@14 596 local previous = kb.currentProfile.commands[command]
Nenue@14 597 if previous ~= slot and kb.buttons[previous] then
Nenue@14 598 kb.ReleaseSlot(kb.buttons[previous])
Nenue@14 599 end
Nenue@19 600
Nenue@19 601 if not (kb.IsCommandBound(self, command) or kb.currentProfile.bound[command]) then
Nenue@19 602
Nenue@19 603 local binds = {GetBindingKey(command) }
Nenue@19 604 if #binds >= 1 then
Nenue@19 605 kb:print('Recovered key binding for', name)
Nenue@19 606 for i, key in ipairs(binds) do
Nenue@19 607 kb.currentProfile.bindings[key] = command
Nenue@19 608 kb.currentProfile.bound[command] = true
Nenue@19 609 end
Nenue@19 610 end
Nenue@19 611 end
Nenue@19 612
Nenue@19 613
Nenue@14 614 kb.currentProfile.commands[command] = slot
Nenue@19 615
Nenue@14 616 end
Nenue@14 617
Nenue@14 618 self.isAvailable = isAvailable
Nenue@14 619 self.isDynamic = isDynamic
Nenue@14 620
Nenue@15 621 self.pickupSlot = pickupSlot
Nenue@15 622 self.pickupBook = pickupBook
Nenue@14 623 self.macroText = macroText
Nenue@14 624 self.macroName = macroName
Nenue@14 625 self.actionType = actionType
Nenue@14 626 self.actionID = actionID
Nenue@14 627 self.actionName = name
Nenue@14 628 self.command = command
Nenue@14 629 self.icon:SetTexture(icon)
Nenue@14 630 self.profile = kb.db.bindMode
Nenue@14 631 self:RegisterForDrag('LeftButton')
Nenue@14 632 end
Nenue@14 633
Nenue@27 634 kb.GetCommandAction = function(command)
Nenue@27 635 for i, data in ipairs(kb.loadedProfiles) do
Nenue@27 636 if data.commands[command] then
Nenue@27 637 if data.buttons[data.commands[command]] then
Nenue@27 638 local _, _, _, actionType, actionID = unpack(data.buttons[data.commands[command]])
Nenue@27 639 return actionType, actionID
Nenue@27 640 end
Nenue@27 641 end
Nenue@27 642 end
Nenue@27 643 end
Nenue@16 644
Nenue@14 645
Nenue@14 646 --- Add to blizzard interfaces
Nenue@14 647 StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = {
Nenue@14 648 text = "Confirm moving an assigned command.",
Nenue@14 649 button1 = OKAY,
Nenue@14 650 button2 = CANCEL,
Nenue@14 651 timeout = 0,
Nenue@14 652 whileDead = 1,
Nenue@14 653 showAlert = 1,
Nenue@14 654 OnAccept = kb.AcceptAssignment,
Nenue@14 655 OnCancel = function() kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) end
Nenue@14 656 }