annotate KeyButton.lua @ 93:f9df7cd7bfd6 tip

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