annotate SkeletonKey/KeySlot.lua @ 16:cdd387d39137

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