annotate KeyButton.lua @ 80:b9a53385462c

- Fixed Demon Hunter Vengeance bindings, along with other spells that are replaced by specialization variants. - Spells replaced by a specialization now display the replacing name along with the original name in their binding slot.
author Nick@Zahhak
date Tue, 21 Mar 2017 02:23:23 -0400
parents d4c100b0fd01
children 9a206b105ea5
rev   line source
Nenue@70 1 -- SkeletonKey
Nenue@70 2 -- KeyButton.lua
Nenue@70 3 -- Created: 7/28/2016 11:26 PM
Nenue@70 4 -- %file-revision%
Nenue@70 5 -- Deals with display and manipulation of binding slots
Nenue@70 6
Nenue@70 7 local _, kb = ...
Nenue@74 8 local print = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('KeyButton', ...) end or function() end
Nenue@70 9 local cprint = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('Cfg', ...) end or function() end
Nenue@70 10 local L = kb.L
Nenue@70 11 local type, tonumber, tostring, tinsert, tremove, ipairs, pairs = type, tonumber, tostring, tinsert, tremove, ipairs, pairs
Nenue@70 12 local _G, unpack, select, tostring = _G, unpack, select, tostring
Nenue@70 13 local GetSpellBookItemName, GetSpellBookItemTexture, GetSpellBookItemInfo, GetPetActionInfo = GetSpellBookItemName, GetSpellBookItemTexture, GetSpellBookItemInfo, GetPetActionInfo
Nenue@70 14 local GetSpellInfo, GetMacroInfo, GetItemInfo, GetItemIcon = GetSpellInfo, GetMacroInfo, GetItemInfo, GetItemIcon
Nenue@70 15 local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor
Nenue@70 16 local GetSpellTexture, IsTalentSpell, GetMacroIndexByName, IsAltKeyDown, IsControlKeyDown, IsShiftKeyDown = GetSpellTexture, IsTalentSpell, GetMacroIndexByName, IsAltKeyDown, IsControlKeyDown,IsShiftKeyDown
Nenue@70 17 local GetBindingKey, GetProfessionInfo = GetBindingKey, GetProfessionInfo
Nenue@70 18 local GetMountInfoByID, GetPetInfoByPetID = C_MountJournal.GetMountInfoByID, C_PetJournal.GetPetInfoByPetID
Nenue@70 19 local skb = SkeletonKeyButtonMixin
Nenue@70 20 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION, CURSOR_TEXTURE
Nenue@70 21 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
Nenue@70 22 local BORDER_UNASSIGNED = {0.6,0.6,0.6,1}
Nenue@70 23 local BORDER_ASSIGNED = {1,1,1,1}
Nenue@70 24 local BORDER_DYNAMIC = {1,1,0,1}
Nick@80 25 local BORDER_PENDING = {1,0.5,0,1}
Nick@80 26 local BORDER_REPLACED = {0,1,.5,1}
Nenue@70 27 local BUTTON_HEADERS = {
Nenue@70 28 ['spell'] = SPELLS,
Nenue@70 29 ['macro'] = MACRO,
Nenue@70 30 ['petaction'] = PET,
Nenue@70 31 ['mount'] = MOUNT,
Nenue@70 32 ['battlepet'] = BATTLEPET,
Nenue@70 33
Nenue@70 34
Nenue@70 35 [5] = PROFESSIONS_FIRST_AID,
Nenue@70 36 [7] = PROFESSIONS_COOKING,
Nenue@70 37 [9] = PROFESSIONS_FISHING,
Nenue@70 38 [10] = PROFESSIONS_ARCHAEOLOGY,
Nenue@70 39
Nenue@70 40 }
Nenue@70 41
Nenue@70 42 local PROFESSION_HEADERS = {
Nenue@70 43 [1] = 'Profession 1',
Nenue@70 44 [2] = 'Profession 2',
Nenue@70 45 [3] = 10,
Nenue@70 46 [4] = 7,
Nenue@70 47 [5] = 9,
Nenue@70 48 [6] = 5
Nenue@70 49 }
Nenue@70 50
Nenue@70 51
Nenue@70 52 -- This is needed to identify a spells that aren't reflected by GetCursorInfo()
Nenue@70 53 kb.OnPickupPetAction = function(slot, ...)
Nenue@70 54 local isPickup = GetCursorInfo()
Nenue@70 55 print(slot, ...)
Nenue@70 56 if kb.PetCache.action[slot] then
Nenue@70 57 if isPickup then
Nenue@70 58 local key, _, texture = unpack(kb.PetCache.action[slot])
Nenue@70 59 local spellName = _G[key] or key
Nenue@70 60 if spellName and kb.PetCache.spellslot[spellName] then
Nenue@70 61 CURSOR_SPELLSLOT = kb.PetCache.spellslot[spellName][1]
Nenue@70 62 CURSOR_BOOKTYPE = BOOKTYPE_PET
Nenue@70 63 CURSOR_TEXTURE = _G[texture] or texture
Nenue@70 64 end
Nenue@70 65 else
Nenue@70 66 CURSOR_SPELLSLOT = nil
Nenue@70 67 CURSOR_BOOKTYPE = nil
Nenue@70 68 CURSOR_TEXTURE = nil
Nenue@70 69 end
Nenue@70 70 print('|cFFFF4400PickupPetAction|r', isPickup, CURSOR_PETACTION)
Nenue@70 71 end
Nenue@70 72
Nenue@70 73 local name, subtext, texture, isToken = GetPetActionInfo(slot)
Nenue@70 74 if name then
Nenue@70 75 kb.PetCache.action[slot] = {name, subtext, texture, isToken}
Nenue@70 76 end
Nenue@70 77
Nenue@70 78
Nenue@70 79 print('current cursor info', CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_TEXTURE)
Nenue@70 80
Nenue@70 81 end
Nenue@70 82
Nenue@70 83 kb.OnPickupSpellBookItem = function(slot, bookType)
Nenue@70 84 print('|cFFFF4400PickupSpellBookItem('.. tostring(slot).. ', '..tostring(bookType)..')')
Nenue@70 85 CURSOR_SPELLSLOT = slot
Nenue@70 86 CURSOR_BOOKTYPE = bookType
Nenue@70 87 CURSOR_TEXTURE = GetSpellBookItemTexture(slot, bookType)
Nenue@70 88 print('current cursor info', CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_TEXTURE)
Nenue@70 89 end
Nenue@70 90
Nenue@70 91 kb.CreateHooks = function()
Nenue@70 92 hooksecurefunc("PickupSpellBookItem", kb.OnPickupSpellBookItem)
Nenue@70 93 hooksecurefunc("PickupPetAction", kb.OnPickupPetAction)
Nenue@70 94 end
Nenue@70 95
Nenue@70 96
Nenue@70 97
Nenue@70 98 function skb:OnLoad()
Nenue@70 99 self:EnableKeyboard(false)
Nenue@70 100 self:EnableMouse(true)
Nenue@70 101 self:RegisterForDrag('LeftButton')
Nenue@70 102 self:RegisterForClicks('AnyUp')
Nenue@70 103 end
Nenue@70 104
Nenue@70 105 function skb:OnEnter()
Nenue@70 106 if not self.command then
Nenue@70 107 return
Nenue@70 108 end
Nenue@70 109 if self.statusText then
Nenue@70 110 SkeletonKey.statustext:SetText(self.statusText .. ': '..self.actionName)
Nenue@70 111 SkeletonKey.bindingstext:SetText(self.bindingText)
Nenue@70 112 end
Nenue@70 113
Nenue@70 114
Nenue@70 115 if kb.db.hoverInput and kb.saveTarget ~= self then
Nenue@70 116 self:GetParent():ActivateSlot(self)
Nenue@70 117 SkeletonKey:Update()
Nenue@70 118 end
Nenue@70 119 end
Nenue@70 120
Nenue@70 121 function skb:OnLeave()
Nenue@70 122 if kb.db.hoverInput and kb.saveTarget == self then
Nenue@70 123 self:GetParent():DeactivateSlot(self)
Nenue@70 124 SkeletonKey:Update()
Nenue@70 125 end
Nenue@70 126 end
Nenue@70 127
Nenue@70 128 function skb:OnUpdate()
Nenue@70 129 end
Nenue@70 130 function skb:OnClick(click)
Nenue@70 131 print(self:GetName(), 'OnMouseDown', click)
Nenue@70 132 local cursorType = GetCursorInfo()
Nenue@70 133 if click == 'LeftButton' then
Nenue@70 134 if cursorType then
Nenue@70 135 self:DropToSlot()
Nenue@70 136 else
Nenue@76 137 if self.command then
Nenue@70 138 if IsShiftKeyDown() then
Nenue@70 139 kb.db.stickyMode = true
Nenue@70 140 KeyBinderStickyMode:SetChecked(true)
Nenue@70 141 end
Nenue@70 142 self:GetParent():ActivateSlot(self)
Nenue@70 143 end
Nenue@70 144 end
Nenue@70 145 elseif click == 'RightButton' then
Nenue@70 146 self:ReleaseSlot()
Nenue@70 147 else
Nick@80 148 SkeletonKey:ProcessInput(strupper(click))
Nenue@70 149 end
Nenue@70 150 SkeletonKey:Update()
Nenue@70 151 end
Nenue@70 152
Nenue@70 153 function skb:OnDragStart()
Nenue@70 154 self:PickupSlot()
Nenue@70 155 end
Nenue@70 156
Nenue@70 157 function skb:OnReceiveDrag(...)
Nenue@70 158 self:DropToSlot()
Nenue@70 159 end
Nenue@70 160
Nenue@70 161 function skb:DropToSlot ()
Nenue@70 162 print(self:GetName(),'|cFF0088FFreceived|r')
Nenue@70 163 local actionType, actionID, subType, subData = GetCursorInfo()
Nenue@70 164 print('GetCursorInfo', GetCursorInfo())
Nenue@70 165 if actionType then
Nenue@70 166
Nenue@70 167 if actionType == 'flyout' then
Nenue@70 168 ClearCursor()
Nenue@70 169 ResetCursor()
Nenue@70 170 return
Nenue@70 171 end
Nenue@70 172
Nenue@70 173
Nenue@74 174 local name, icon, _, macroName, macroText
Nenue@70 175 local pickupID, pickupBook
Nenue@70 176
Nenue@70 177 if actionType == 'spell' then
Nick@80 178 local realName = GetSpellInfo(subData)
Nick@80 179 name, _, icon, _, _, _, actionID = GetSpellInfo(subData)
Nenue@70 180 elseif actionType == 'macro' then
Nenue@74 181 name, icon, macroText = GetMacroInfo(actionID)
Nenue@74 182 macroName = name
Nenue@70 183 elseif actionType == 'petaction' then
Nenue@70 184 if CURSOR_SPELLSLOT and CURSOR_BOOKTYPE then
Nenue@70 185
Nenue@70 186 local spellType, spellID = GetSpellBookItemInfo(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE)
Nenue@70 187 local spellName, spellText = GetSpellBookItemName(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE)
Nenue@70 188 if spellType == 'PETACTION' then
Nenue@70 189 name = spellName
Nenue@70 190 actionID = spellText
Nenue@70 191 icon = CURSOR_TEXTURE
Nenue@70 192 else
Nenue@70 193 name, _, icon = GetSpellInfo(spellID)
Nenue@70 194 actionID = spellID
Nenue@70 195 end
Nenue@70 196
Nenue@70 197 pickupID = CURSOR_SPELLSLOT
Nenue@70 198 pickupBook = CURSOR_BOOKTYPE
Nenue@70 199 else
Nenue@70 200
Nenue@70 201
Nenue@70 202 end
Nenue@70 203
Nenue@70 204 elseif actionType == 'mount' then
Nenue@70 205 if subType == 0 then
Nenue@70 206 name, _, icon = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL)
Nenue@70 207 actionID = 0
Nenue@70 208 else
Nenue@70 209 name, _, icon = GetMountInfoByID(actionID)
Nenue@70 210 end
Nenue@70 211 elseif actionType == 'item' then
Nenue@70 212 name = GetItemInfo(actionID)
Nenue@70 213 icon = GetItemIcon(actionID)
Nenue@70 214 elseif actionType == 'battlepet' then
Nenue@70 215
Nenue@70 216 local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = GetPetInfoByPetID(actionID)
Nenue@70 217 name = customName or petName
Nenue@70 218 icon = petIcon
Nenue@70 219
Nenue@70 220 end
Nenue@74 221 local _, macroBody, command = kb.RegisterAction(actionType, actionID, name)
Nenue@70 222 local slotInfo = {
Nenue@70 223 command = command,
Nenue@70 224 actionName = name,
Nenue@70 225 iconPath = icon,
Nenue@70 226 actionType = actionType,
Nenue@70 227 actionID = actionID,
Nenue@70 228 macroName = macroName,
Nenue@74 229 macroText = macroText or macroBody,
Nenue@70 230 spellbookSlot = pickupID,
Nenue@70 231 spellbookType = pickupBook,
Nenue@70 232 assignedKeys = {GetBindingKey(command)}
Nenue@70 233 }
Nenue@70 234
Nenue@70 235 local isAssigned, isBound, assignedBy, boundBy = kb.IsCommandBound(self, command)
Nenue@70 236 if isAssigned then
Nenue@70 237 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
Nenue@70 238 popup.slot = self
Nenue@70 239 popup.text = "Currently assigned in |cFFFFFF00"..tostring(kb.configHeaders[assignedBy]).."|r. Are you sure?"
Nenue@70 240 popup.oldProfile = assignedBy
Nenue@70 241 popup.args = {slotInfo}
Nenue@70 242 SkeletonKey:SetScript('OnMouseWheel', nil) -- disable scrolling
Nenue@70 243 StaticPopup_Show('SKELETONKEY_CONFIRM_ASSIGN_SLOT')
Nenue@70 244 else
Nenue@70 245 kb.currentProfile.buttons[self:GetID()] = slotInfo
Nenue@74 246 kb.LoadBinding(slotInfo)
Nenue@70 247 self:SetSlot(slotInfo)
Nenue@70 248 self:UpdateSlot()
Nenue@70 249 self.active = nil
Nenue@70 250 ClearCursor()
Nenue@70 251 ResetCursor()
Nenue@70 252 end
Nenue@70 253 end
Nenue@70 254 end
Nenue@70 255
Nenue@70 256
Nenue@70 257 do
Nenue@70 258 local PickupAction = {
Nenue@70 259 spell = _G.PickupSpell,
Nenue@70 260 petaction =
Nenue@70 261 function(...)
Nenue@70 262 -- needs to be enclosed to acquire hooksecurefunc effects
Nenue@70 263 _G.PickupSpellBookItem(...)
Nenue@70 264 end,
Nenue@70 265 macro = _G.PickupMacro,
Nenue@70 266 item = _G.PickupItem,
Nenue@70 267 mount = _G.C_MountJournal.Pickup
Nenue@70 268 }
Nenue@70 269 local GetPickupValue = {
Nenue@70 270 spell = function(self) return select(7, GetSpellInfo(self.actionID)) end,
Nenue@70 271 petaction = function(self) return self.pickupSlot, self.pickupBook end,
Nenue@70 272 }
Nenue@70 273 function skb:PickupSlot ()
Nenue@70 274 if not (self.command and self.isAvailable) then
Nenue@70 275 return
Nenue@70 276 end
Nenue@70 277 print(self.actionType)
Nenue@70 278 if self.actionType == 'spell' then
Nenue@70 279 -- It can't be picked up if SpellInfo(name) returns void
Nenue@70 280 local dummy = GetSpellInfo(self.actionName)
Nenue@70 281 if not dummy then
Nenue@70 282 return
Nenue@70 283 end
Nenue@70 284 end
Nenue@70 285 if PickupAction[self.actionType] then
Nenue@70 286 if GetPickupValue[self.actionType] then
Nenue@70 287 PickupAction[self.actionType](GetPickupValue[self.actionType](self))
Nenue@70 288 else
Nenue@70 289 PickupAction[self.actionType](self.actionID)
Nenue@70 290 end
Nenue@70 291 self:ReleaseSlot()
Nenue@70 292 self:UpdateSlot()
Nenue@70 293 end
Nenue@70 294 end
Nenue@70 295 end
Nenue@70 296
Nenue@70 297
Nenue@70 298
Nenue@70 299
Nenue@70 300 --- Updates profile assignment and button contents
Nenue@70 301 function skb:UpdateSlot (force)
Nenue@70 302 local slot = self:GetID()
Nenue@70 303
Nenue@70 304 if force then
Nenue@70 305 if kb.currentProfile.buttons[slot] then
Nenue@70 306 print('loading in', slot, kb.db.bindMode)
Nenue@70 307 self:SetSlot(kb.currentProfile.buttons[slot])
Nenue@70 308 else
Nenue@70 309 self:ReleaseSlot()
Nenue@70 310 end
Nenue@70 311 end
Nenue@70 312
Nenue@70 313 local borderType = BORDER_UNASSIGNED
Nick@80 314 local displayName = self.actionName
Nick@80 315 local displayTexture = self.iconPath
Nick@80 316 local altName, altTexture
Nenue@70 317 if self.command then
Nenue@70 318
Nick@80 319 print('|cFFFF4400:', self.actionName, #self.assignedKeys, table.concat(self.assignedKeys, ','))
Nick@80 320 print('|cFF00FF88:', self.isAvailable, self.actionID)
Nick@80 321
Nenue@72 322 self.bindingText= kb.BindingString(unpack(self.assignedKeys))
Nick@80 323
Nenue@70 324 if not self.isAvailable then
Nenue@70 325 borderType = BORDER_DYNAMIC
Nenue@70 326 self.ignoreTexture:Show()
Nenue@70 327 else
Nenue@70 328 self.ignoreTexture:Hide()
Nenue@70 329
Nenue@70 330 if self.pending then
Nenue@70 331 borderType = BORDER_PENDING
Nenue@70 332 elseif self.dynamicType then
Nenue@70 333 borderType = BORDER_DYNAMIC
Nenue@70 334 else
Nenue@70 335 borderType = BORDER_ASSIGNED
Nenue@70 336 end
Nenue@70 337 end
Nenue@70 338
Nenue@70 339 if self.actionType == 'macro' then
Nenue@70 340 self.macro:Show()
Nenue@70 341 else
Nenue@70 342 self.macro:Hide()
Nenue@70 343 if self.actionType == 'spell' then
Nick@80 344 altName, _, altTexture = GetSpellInfo(self.actionName)
Nick@80 345 self.isAvailable = displayName and true or false
Nick@80 346 if altName and (altName ~= self.actionName) then
Nick@80 347 displayName = '|cFFFFFF00'..altName..'|r ('..self.actionName..')'
Nick@80 348 displayTexture = altTexture
Nick@80 349 borderType = BORDER_REPLACED
Nick@80 350 end
Nick@80 351
Nenue@70 352 end
Nenue@70 353 end
Nenue@70 354
Nenue@70 355
Nenue@70 356 if self.dynamicType == 'profession' then
Nenue@70 357 if self.isAvailable then
Nenue@70 358 self.statusText = '|cFFFFFF00Profession|r'
Nenue@70 359 else
Nenue@70 360
Nenue@70 361 self.statusText = '|cFFFF4400'..PROFESSION_HEADERS[self.dynamicIndex]..'|r'
Nenue@70 362 self.actionName = '(#'..self.dynamicIndex..')'
Nenue@70 363 end
Nenue@70 364 elseif self.dynamicType == 'talent' then
Nenue@70 365 self.statusText = '|cFF00FFFF'.. TALENT .. '|r'
Nenue@70 366 end
Nenue@70 367
Nenue@70 368 local locked, layer = kb.IsCommandBound(self)
Nenue@70 369 if locked then
Nenue@70 370 self.icon:SetAlpha(0.5)
Nenue@70 371 else
Nenue@70 372 self.icon:SetAlpha(1)
Nenue@70 373 end
Nenue@70 374
Nenue@70 375
Nenue@70 376 print('|cFF00BBFFUpdateSlot|r:', '['..slot..'] =', self.command, self.bindingText, self.dynamicType, self.isAvailable, self.actionID)
Nenue@70 377
Nenue@70 378 end
Nenue@70 379
Nenue@70 380 if not self.isAvailable then
Nenue@74 381 self.bind:SetTextColor(.7,.7,.7,1)
Nenue@74 382 self.ignoreTexture:SetShown(self.command and true)
Nenue@74 383 self.icon:SetVertexColor(.5,.5,.5)
Nenue@70 384 else
Nenue@74 385 self.ignoreTexture:SetShown(false)
Nenue@70 386 self.bind:SetTextColor(1,1,1,1)
Nenue@74 387 self.icon:SetVertexColor(1,1,1)
Nenue@70 388 end
Nenue@70 389
Nenue@70 390
Nenue@70 391 if kb.saveTarget and kb.saveTarget ~= self then
Nenue@70 392 self:SetAlpha(0.25)
Nenue@70 393 else
Nenue@70 394
Nenue@70 395 self:SetAlpha(1)
Nenue@70 396 end
Nenue@70 397
Nenue@70 398 --self.alert:SetShown(self.command and not self.isBound)
Nenue@70 399
Nick@80 400 self.icon:SetTexture(displayTexture)
Nenue@70 401
Nenue@70 402 self.border:SetColorTexture(unpack(borderType))
Nenue@70 403 self.header:SetText(self.statusText)
Nenue@70 404 self.bind:SetText(self.bindingText)
Nick@80 405 self.details:SetText(displayName)
Nenue@70 406 end
Nenue@70 407
Nenue@70 408 --- Resets button command
Nenue@70 409 function skb:ReleaseSlot ()
Nenue@70 410 local slot = self:GetID()
Nenue@70 411
Nick@80 412 -- keep right click from deleting an assignment during bind mode
Nick@80 413 if kb.saveTarget == self then
Nick@80 414 self:GetParent():DeactivateSlot(self)
Nick@80 415 return
Nick@80 416 end
Nenue@70 417
Nenue@70 418 if kb.currentProfile.buttons[slot] then
Nenue@70 419 kb.currentProfile.buttons[slot] = nil
Nenue@70 420 end
Nenue@70 421 if self.command then
Nenue@70 422 kb.currentProfile.commands[self.command] = nil
Nenue@70 423 end
Nenue@70 424 local talentName = self.actionName
Nenue@70 425 if self.actionType == 'macro' then
Nenue@70 426 talentName = GetMacroSpell(self.actionID)
Nenue@70 427 end
Nenue@76 428
Nenue@70 429 local droppedKeys = {}
Nenue@70 430
Nenue@70 431 -- doing removal in second loop to avoid possible iterator shenanigans
Nenue@70 432 for k,v in pairs(kb.currentProfile.bindings) do
Nenue@70 433 if v == self.command then
Nenue@70 434 tinsert(droppedKeys, k)
Nenue@70 435 end
Nenue@70 436 end
Nenue@70 437 if #droppedKeys >=1 then
Nenue@70 438 for i, k in ipairs(droppedKeys) do
Nenue@70 439 kb.currentProfile.bindings[k] = nil
Nenue@70 440 end
Nenue@70 441 end
Nenue@70 442
Nenue@70 443 self.isAvailable = nil
Nenue@70 444 self.dynamicType = nil
Nenue@70 445 self.bindingText = nil
Nenue@70 446 self.statusText = nil
Nenue@70 447 self.command = nil
Nenue@70 448 self.iconPath = nil
Nenue@70 449 self.actionType = nil
Nenue@70 450 self.actionID = nil
Nenue@70 451 self.actionName = nil
Nenue@70 452 self.pickupSlot = nil
Nenue@70 453 self.pickupBook = nil
Nenue@70 454 self.macroName = nil
Nenue@70 455 self.profile = nil
Nenue@70 456 self.border:SetColorTexture(unpack(BORDER_UNASSIGNED))
Nenue@70 457 self:EnableKeyboard(false)
Nenue@70 458 self:SetScript('OnKeyDown', nil)
Nenue@70 459 self.bindingText = nil
Nenue@70 460 self.icon:SetTexture(nil)
Nenue@70 461 self.ignoreTexture:Hide()
Nenue@70 462
Nenue@70 463 end
Nenue@70 464
Nenue@70 465 --- Assigns the slot via table copy; any manipulations from this point are temporary and
Nenue@70 466 function skb:SetSlot(slotInfo)
Nenue@70 467 print('slot info', self:GetID())
Nenue@70 468
Nenue@70 469 for k,v in pairs(slotInfo) do
Nenue@70 470 print(' -', k, v)
Nenue@70 471 self[k] = v
Nenue@70 472 end
Nenue@70 473 self.dynamicType = slotInfo.dynamicType
Nenue@70 474 local command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook
Nenue@70 475 = self.command, self.actionName, self.iconPath, self.actionType, self.actionID, self.macroName, self.macroText, self.spellbookSlot, self.spellbookType
Nenue@70 476
Nenue@70 477
Nenue@70 478 local slot = self:GetID()
Nenue@70 479 local isBound = false
Nenue@70 480 print('|cFFFFFF00SetSlot|r:', self:GetID())
Nenue@70 481 if self.command then
Nenue@70 482
Nenue@70 483 isBound = kb.IsCommandBound(self, self.command)
Nenue@70 484 if actionType == 'spell' then
Nenue@74 485 local info = kb.ResolveSpellSlot(self)
Nenue@70 486 name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook = self.actionName, self.iconPath, self.actionType, self.actionID, self.macroName, self.macroText, self.spellbookSlot, self.spellbookType
Nenue@71 487 self.isAvailable = info and info.isAvailable
Nenue@70 488 elseif actionType == 'petaction' then
Nenue@70 489 self.dynamicType = 'petaction'
Nenue@70 490 local specialType, specialNum = command:match(actionType..'_([%a%s]+)_(%d)')
Nenue@70 491
Nenue@70 492 if kb.PetCache.subtext[specialType] then
Nenue@70 493
Nenue@70 494 local info = kb.PetCache.subtext[specialType][tonumber(specialNum)]
Nenue@70 495 if info then
Nenue@70 496 print('***dynamic pet skill', specialType, specialNum)
Nenue@70 497 --[[ i, spellName, subText, spellID, texture, specialNum[subText ]]
Nenue@70 498
Nenue@70 499 for k,v in pairs(info) do
Nenue@70 500 self[k] = v
Nenue@70 501 end
Nenue@70 502 end
Nenue@70 503
Nenue@70 504 end
Nenue@70 505 self.statusText = 'Pet Action'
Nenue@70 506 self.isAvailable = (kb.PetCache.spellslot[name])
Nenue@70 507 elseif actionType == 'macro' then
Nenue@70 508 if actionID then
Nenue@74 509
Nenue@74 510 -- Update stored information if it mis-matches
Nenue@70 511 local nameByID, _, bodyByID = GetMacroInfo(actionID)
Nenue@74 512 --print(bodyByID, "\n", macroText)
Nenue@70 513 if (nameByID ~= name) or (bodyByID ~= macroText) then
Nenue@74 514 --kb:print('mismatches for slot', self:GetID(), actionID, ((nameByID ~= name) and 'name' or ''), ((bodyByID ~= macroText) and 'body' or ''))
Nenue@74 515 local matchID, matchName, matchBody, hasMultiple
Nenue@74 516 local roughResult = ""
Nenue@74 517
Nenue@74 518 local newID = GetMacroIndexByName(name)
Nenue@74 519 local firstName, _, firstBody = GetMacroInfo(newID)
Nenue@70 520 if (firstName ~= name) or (firstBody ~= macroText) then
Nenue@74 521
Nenue@74 522
Nenue@70 523 -- go even deeper
Nenue@74 524 local numAccount, numCharacter = GetNumMacros()
Nenue@74 525 local searchID = 1
Nenue@74 526 while searchID <= (120+numCharacter) do
Nenue@74 527 --kb:print(searchID)
Nenue@74 528
Nenue@74 529
Nenue@74 530 local searchName, _ , searchBody = GetMacroInfo(searchID)
Nenue@70 531 if (searchName == name) and (searchBody == macroText) then
Nenue@74 532 --kb:print('definitely', matchID, searchName, '\n', searchBody)
Nenue@70 533 -- complete match
Nenue@74 534 matchID = searchID
Nenue@74 535 matchName = searchName
Nenue@74 536 matchBody = searchBody
Nenue@70 537 break
Nenue@70 538 elseif (searchName == name) or (searchBody == macroText) then
Nenue@70 539 -- partial match, continue the search
Nenue@74 540
Nenue@74 541 if matchID then
Nenue@74 542 hasMultiple = true
Nenue@74 543 roughResult = roughResult .. "\n" .. tostring(searchID) .. ':'..tostring(searchName)
Nenue@74 544 end
Nenue@74 545
Nenue@74 546 matchID = searchID
Nenue@74 547 matchName = searchName
Nenue@74 548 matchBody = searchBody
Nenue@74 549 --kb:print('possibly', matchID, matchName, '\n', matchBody)
Nenue@70 550 end
Nenue@74 551
Nenue@74 552 if searchID == numAccount then
Nenue@74 553 searchID = 120
Nenue@74 554 end
Nenue@74 555 searchID = searchID + 1
Nenue@70 556 end
Nenue@74 557 else
Nenue@74 558 matchID = newID
Nenue@74 559 matchName = firstName
Nenue@74 560 matchBody = firstBody
Nenue@70 561 end
Nenue@72 562
Nenue@74 563 --kb:print(matchID, hasMultiple)
Nenue@74 564 if hasMultiple then
Nenue@74 565 kb:print('Macro assignment in slot #'..tostring(self:GetID())..' has multiple possible indexes:\nSaved Info: '..tostring(actionID)..'/'..tostring(name)..'\n|cFFFFFF00', roughResult)
Nenue@74 566 elseif matchID then
Nenue@74 567 kb:print('Macro for slot #'..tostring(self:GetID())..' ('..tostring(name)..') has probably changed:', ((actionID ~= newID) and (' |cFFFF4400'..tostring(actionID)..'|r to |cFF00FF88' .. newID .. '|r.') or ''), 'We\'re not sure, so you may want to re-do that assignment.')
Nenue@74 568 actionID = matchID
Nenue@74 569 name = matchName
Nenue@74 570 macroName = matchName
Nenue@74 571 macroText = matchBody
Nenue@74 572 end
Nenue@70 573 end
Nenue@70 574 else
Nenue@70 575 actionID = GetMacroIndexByName(name)
Nenue@70 576 end
Nenue@74 577 self.statusText = 'Macro ' .. tostring(actionID)
Nenue@70 578 self.isAvailable = true
Nenue@70 579 else
Nenue@70 580 if not actionID then
Nenue@70 581 actionID = command:match("^KeyBinderMacro:(.+)")
Nenue@70 582 end
Nenue@70 583 self.isAvailable = true
Nenue@70 584 end
Nenue@70 585
Nenue@70 586 if self.isAvailable then
Nenue@72 587 --[[
Nenue@72 588 local checkCommand = command
Nenue@72 589 checkCommand = kb.LoadBinding(self)
Nenue@72 590 if checkCommand and (checkCommand ~= command) then
Nenue@70 591 print('|cFFFF4400fixing command string', actionType, actionID, name)
Nenue@72 592 kb.currentProfile.bound[command] = nil
Nenue@72 593 kb.currentProfile.bound[checkCommand] = slot
Nenue@70 594 for k,v in pairs(kb.currentProfile.bindings) do
Nenue@72 595 if v == command then
Nenue@72 596 kb.currentProfile.bindings[k] = checkCommand
Nenue@70 597 end
Nenue@70 598 end
Nenue@70 599 end
Nenue@72 600 --]]
Nenue@70 601 end
Nenue@70 602
Nenue@70 603
Nenue@70 604 actionID = actionID or 0
Nenue@70 605 self:EnableKeyboard(true)
Nenue@70 606
Nenue@70 607 -- this is done to keep legacy key-values from breaking algorithm assumptions
Nick@80 608 print('assigned', table.concat(slotInfo.assignedKeys,', '))
Nick@80 609
Nick@80 610 if #slotInfo.assignedKeys == 0 then
Nick@80 611 print('updating assigned table to:', GetBindingKey(command))
Nick@80 612 slotInfo.assignedKeys = {GetBindingKey(command) }
Nick@80 613 end
Nick@80 614
Nick@80 615 self.assignedKeys = slotInfo.assignedKeys
Nenue@71 616
Nenue@70 617 local slotInfo = {
Nenue@70 618 command = command,
Nenue@70 619 actionName = name,
Nenue@70 620 iconPath = icon,
Nenue@70 621 actionID = actionID,
Nenue@70 622 actionType = actionType,
Nenue@70 623 macroName = macroName,
Nenue@70 624 macroText = macroText,
Nenue@70 625 spellbookSlot = pickupSlot,
Nenue@70 626 spellbookType = pickupBook,
Nenue@71 627 assignedKeys = slotInfo.assignedKeys,
Nenue@71 628 dynamicType = self.dynamicType,
Nenue@71 629 dynamicID = self.dynamicID,
Nenue@71 630 dynamicIndex = self.dynamicIndex,
Nenue@71 631 dynamicSubIndex = self.dynamicSubIndex
Nenue@70 632 }
Nenue@70 633 kb.currentProfile.buttons[slot] = slotInfo
Nenue@70 634
Nenue@70 635 -- Clean up conflicting entries for loaded button
Nenue@70 636 local previous = kb.currentProfile.commands[command]
Nenue@70 637 if previous ~= slot and kb.buttons[previous] then
Nenue@70 638 kb.ReleaseSlot(kb.buttons[previous])
Nenue@70 639 end
Nenue@70 640
Nenue@70 641 local binds = {GetBindingKey(command) }
Nenue@70 642 if self.isAvailable and (#binds >= 1) then
Nenue@70 643 local found
Nenue@70 644 for i, key in ipairs(binds) do
Nenue@70 645 if not tContains(self.assignedKeys, key) then
Nenue@70 646 tinsert(self.assignedKeys, key)
Nenue@70 647 kb.currentProfile.bindings[key] = command
Nenue@70 648 kb.currentProfile.bound[command] = true
Nenue@70 649 found = true
Nenue@70 650 end
Nenue@70 651 end
Nenue@70 652 if found then
Nenue@70 653 kb:print('Recovered key binding for', name)
Nenue@70 654 end
Nenue@70 655 end
Nenue@70 656
Nenue@70 657 kb.currentProfile.commands[command] = slot
Nenue@70 658 end
Nenue@70 659
Nenue@71 660 --self.assignedKeys = slotInfo.assignedKeys
Nenue@70 661 self.isBound = isBound
Nenue@70 662 self.pickupSlot = pickupSlot
Nenue@70 663 self.pickupBook = pickupBook
Nenue@70 664 self.macroText = macroText
Nenue@70 665 self.macroName = macroName
Nenue@70 666 self.actionType = actionType
Nenue@70 667 self.actionID = actionID
Nenue@70 668 self.actionName = name
Nenue@70 669 self.command = command
Nenue@70 670 self.iconPath = icon
Nenue@70 671 self.profile = kb.db.bindMode
Nenue@70 672 self:RegisterForDrag('LeftButton')
Nenue@74 673
Nenue@74 674 return slotInfo
Nenue@70 675 end
Nenue@70 676
Nenue@70 677 kb.GetCommandAction = function(command)
Nenue@70 678 for i, data in ipairs(kb.loadedProfiles) do
Nenue@70 679 if data.commands[command] then
Nenue@70 680 if data.buttons[data.commands[command]] then
Nenue@70 681 local _, _, _, actionType, actionID = unpack(data.buttons[data.commands[command]])
Nenue@70 682 return actionType, actionID
Nenue@70 683 end
Nenue@70 684 end
Nenue@70 685 end
Nenue@70 686 end
Nenue@70 687