Mercurial > wow > skeletonkey
diff SkeletonKey/KeySlot.lua @ 15:32d64e42ec9b
- resolve pet bar actions for binding slots
- detect type of petaction (can be spell, stance, or 'PETACTION')
- keep track of displayed pet ability slots and update them alongside pet cache refreshes
author | Nenue |
---|---|
date | Fri, 29 Jul 2016 03:27:15 -0400 |
parents | 82170735e67c |
children | cdd387d39137 |
line wrap: on
line diff
--- a/SkeletonKey/KeySlot.lua Thu Jul 28 23:58:53 2016 -0400 +++ b/SkeletonKey/KeySlot.lua Fri Jul 29 03:27:15 2016 -0400 @@ -7,8 +7,8 @@ local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot') local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 -local BORDER_UNASSIGNED = {0.2,0.2,0.2,1 } -local BORDER_ASSIGNED = {0.5,0.5,0.5,1 } +local BORDER_UNASSIGNED = {0.2,0.2,0.2,1} +local BORDER_ASSIGNED = {1,1,1,1} local BORDER_DYNAMIC = {1,1,0,1} local BORDER_PENDING = {1,0.5,0,1 } @@ -39,9 +39,30 @@ local isPickup hooksecurefunc("PickupPetAction", function(slot, ...) isPickup = GetCursorInfo() + print(slot, ...) - CURSOR_PETACTION = isPickup and slot + + if kb.PetCache.action[slot] then + if isPickup then + local key = kb.PetCache.action[slot][1] + local spellName = _G[key] or key + if spellName and kb.PetCache.spellslot[spellName] then + print('picked up', spellName, kb.PetCache.spellslot[spellName][1]) + CURSOR_SPELLSLOT = kb.PetCache.spellslot[spellName][1] + CURSOR_BOOKTYPE = BOOKTYPE_PET + end + + else + print('Dropped pet action =', GetPetActionInfo(slot)) + end print('|cFFFF4400PickupPetAction|r', isPickup, CURSOR_PETACTION) + end + + local name, subtext, texture, isToken = GetPetActionInfo(slot) + if name then + kb.PetCache.action[slot] = {name, subtext, texture, isToken} + end + end) end @@ -59,8 +80,7 @@ end - local macroName, macroText - local command, name, icon, _ + local name, icon, _ local pickupID, pickupBook if actionType == 'spell' then @@ -70,17 +90,23 @@ elseif actionType == 'macro' then name, icon = GetMacroInfo(actionID) elseif actionType == 'petaction' then - if not (CURSOR_SPELLSLOT and CURSOR_BOOKTYPE) then + if CURSOR_SPELLSLOT and CURSOR_BOOKTYPE then - ClearCursor() - ResetCursor() + local spellType, spellID = GetSpellBookItemInfo(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE) + local spellName, spellText = GetSpellBookItemName(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE) + if spellType == 'PETACTION' then + actionID = spellText + else + name, _, icon = GetSpellInfo(spellID) + actionID = spellID + end + + pickupID = CURSOR_SPELLSLOT + pickupBook = CURSOR_BOOKTYPE + else + end - local bookType, spellID = GetSpellBookItemInfo(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE) - actionID = spellID - pickupID = CURSOR_SPELLSLOT - pickupBook = CURSOR_BOOKTYPE - name, _, icon = GetSpellInfo(spellID) elseif actionType == 'mount' then if subType == 0 then name, _, icon = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL) @@ -99,7 +125,7 @@ icon = petIcon end - macroName, macroText, command = kb.RegisterAction(actionType, actionID, name) + local macroName, macroText, command = kb.RegisterAction(actionType, actionID, name) local isAssigned, isBound, assignedBy, boundBy = kb.IsCommandBound(self, command) @@ -135,7 +161,7 @@ petaction = function(self) return self.pickupSlot, self.pickupBook end, } kb.PickupSlot = function(self) - if not self.command then + if not (self.command and self.isAvailable) then return end print(self.actionType) @@ -175,14 +201,22 @@ if self.command then print('['..slot..'] =', self.command, GetBindingKey(self.command)) - if self.pending then - self.border:SetColorTexture(unpack(BORDER_PENDING)) - elseif self.isDynamic then - self.border:SetColorTexture(unpack(BORDER_DYNAMIC)) + if not self.isAvailable then + self.border:SetColorTexture(1,0,0,1) + self.ignoreTexture:Show() else - self.border:SetColorTexture(unpack(BORDER_ASSIGNED)) + self.ignoreTexture:Hide() + + if self.pending then + self.border:SetColorTexture(unpack(BORDER_PENDING)) + elseif self.isDynamic then + self.border:SetColorTexture(unpack(BORDER_DYNAMIC)) + else + self.border:SetColorTexture(unpack(BORDER_ASSIGNED)) + end end + if self.actionType == 'macro' then self.macro:Show() else @@ -199,7 +233,7 @@ end if self.isDynamic then - print('|cFFFFBB00UpdateSlot|r: ', self.isDynamic, self.isAvailable, self.actionID) + print('|cFF00BBFFUpdateSlot|r:', self.isDynamic, self.isAvailable, self.actionID) end if self.isDynamic == 'profession' then @@ -226,6 +260,9 @@ end end + elseif self.isDynamic == 'petaction' and self.command:match("special") then + self.statusText = '|cFF00FF00Pet Special|r' + self.bindingText = kb.BindingString(GetBindingKey(self.command)) else self.statusText = '|cFF00FF00'.. (BUTTON_HEADERS[self.actionType] and BUTTON_HEADERS[self.actionType] or self.actionType) .. '|r' self.bindingText = kb.BindingString(GetBindingKey(self.command)) @@ -300,6 +337,7 @@ self.border:SetColorTexture(unpack(BORDER_UNASSIGNED)) self:EnableKeyboard(false) self:SetScript('OnKeyDown', nil) + self.ignoreTexture:Hide() end kb.SetSlot = function(self, command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook) @@ -336,6 +374,15 @@ isAvailable = GetSpellInfo(name) end + elseif actionType == 'petaction' then + isDynamic = 'petaction' + if kb.PetCache.spellslot and kb.PetCache.spellslot[name] then + isAvailable = true + kb.RemoveCacheButton(kb.petFrames, self) + else + print('|cFFFF4400OnCacheUpdate, re-do #', slot) + tinsert(kb.petFrames, self) + end elseif actionType == 'macro' then if not actionID then actionID = GetMacroIndexByName(name) @@ -366,17 +413,10 @@ kb.LoadBinding(command, name, icon, actionType, actionID, macroName, macroText) end - if actionType == 'petaction' then - self.pickupSlot = pickupSlot - self.pickupBook = pickupBook - else - self.pickupSlot = nil - self.pickupBook = nil - end actionID = actionID or 0 self:EnableKeyboard(true) - 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') + 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') kb.currentProfile.buttons[slot] = {command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook} -- Clean up conflicting entries for loaded button @@ -390,6 +430,8 @@ self.isAvailable = isAvailable self.isDynamic = isDynamic + self.pickupSlot = pickupSlot + self.pickupBook = pickupBook self.macroText = macroText self.macroName = macroName self.actionType = actionType