Mercurial > wow > skeletonkey
diff KeyButton.lua @ 74:9824d524a661
- binding slot mixin:
- store key binding definitions under their slot's data table
- apply action button attributes when a slot is assigned
- obtain correct macro body text when a macro is slotted
- fix algorithm for resolving renamed macro indices
- move spell detail lookup code out of mixin script
- event chains:
- initialize addon from PLAYER_LOGIN
- reload keybinds from PLAYER_SPECIALIZATION_CHANGED, after spec profile is resolved
- refresh interface content from SPELLS_CHANGED
- hotkey text:
- restore communication and detection of key binding updates and reflect them accordingly
- properly respond to dynamic bindings that result from talent updates
author | Nenue |
---|---|
date | Sat, 14 Jan 2017 02:29:33 -0500 |
parents | c48913c5924c |
children | 6623b7f2c1ca |
line wrap: on
line diff
--- a/KeyButton.lua Sat Jan 07 12:52:05 2017 -0500 +++ b/KeyButton.lua Sat Jan 14 02:29:33 2017 -0500 @@ -5,7 +5,7 @@ -- Deals with display and manipulation of binding slots local _, kb = ... -local print = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('SkeletonKey', ...) end or function() end +local print = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('KeyButton', ...) end or function() end local cprint = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('Cfg', ...) end or function() end local L = kb.L local type, tonumber, tostring, tinsert, tremove, ipairs, pairs = type, tonumber, tostring, tinsert, tremove, ipairs, pairs @@ -170,7 +170,7 @@ end - local name, icon, _ + local name, icon, _, macroName, macroText local pickupID, pickupBook if actionType == 'spell' then @@ -178,7 +178,8 @@ name, _, icon = GetSpellInfo(actionID) elseif actionType == 'macro' then - name, icon = GetMacroInfo(actionID) + name, icon, macroText = GetMacroInfo(actionID) + macroName = name elseif actionType == 'petaction' then if CURSOR_SPELLSLOT and CURSOR_BOOKTYPE then @@ -217,7 +218,7 @@ icon = petIcon end - local macroName, macroText, command = kb.RegisterAction(actionType, actionID, name) + local _, macroBody, command = kb.RegisterAction(actionType, actionID, name) local slotInfo = { command = command, actionName = name, @@ -225,7 +226,7 @@ actionType = actionType, actionID = actionID, macroName = macroName, - macroText = macroText, + macroText = macroText or macroBody, spellbookSlot = pickupID, spellbookType = pickupBook, assignedKeys = {GetBindingKey(command)} @@ -242,6 +243,11 @@ StaticPopup_Show('SKELETONKEY_CONFIRM_ASSIGN_SLOT') else kb.currentProfile.buttons[self:GetID()] = slotInfo + if #slotInfo.assignedKeys >= 1 then + kb:print('Obtained following hotkeys:', table.concat(slotInfo.assignedKeys, ', ')) + + end + kb.LoadBinding(slotInfo) self:SetSlot(slotInfo) self:UpdateSlot() self.active = nil @@ -312,8 +318,8 @@ if self.command then - print('|cFFFF4400', self.actionName, #self.assignedKeys, self.assignedKeys) - print(table.concat(self.assignedKeys, ',')) + print('|cFFFF4400', self.actionName, #self.assignedKeys, table.concat(self.assignedKeys, ',')) + print(self.isAvailable) print(self.actionID) self.bindingText= kb.BindingString(unpack(self.assignedKeys)) if not self.isAvailable then @@ -336,13 +342,7 @@ else self.macro:Hide() if self.actionType == 'spell' then - local dummy = GetSpellInfo(self.actionName) - if not dummy then - self.icon:SetDesaturated(true) - else - self.icon:SetDesaturated(false) - end - + self.isAvailable = GetSpellInfo(self.actionName) and true or false end end @@ -378,12 +378,14 @@ end - self.ignoreTexture:SetShown(self.command and not self.isAvailable) - if not self.isAvailable then - self.bind:SetTextColor(0.7,0.7,0.7,1) + self.bind:SetTextColor(.7,.7,.7,1) + self.ignoreTexture:SetShown(self.command and true) + self.icon:SetVertexColor(.5,.5,.5) else + self.ignoreTexture:SetShown(false) self.bind:SetTextColor(1,1,1,1) + self.icon:SetVertexColor(1,1,1) end @@ -459,76 +461,10 @@ end -local spells = {} -local SkeletonKey_GetGenericSpell = function(spellName, spellID, icon) - if not spells[spellID] then - spells[spellID] = {} - spells[spellID].actionType = 'spell' - spells[spellID].actionID = spellID - spells[spellID].actionName = spellName - spells[spellID].iconPath = icon - spells[spellID].statusText = '|cFFBBBBBBSpell|r' - spells[spellID].dynamicType = nil - end - return spells[spellID] +local DoMacroCheck = function(name, macroText, searchID, roughResult) + + return matchID, matchName, matchBody, endOfSearch end - -local tempInfo = {} --- tries to resolve spells from talent overrides/profession book/etc -local dynamicTypes = {['profession'] = 'ProfessionCache', ['talent'] = 'TalentCache', ['petaction'] = 'PetInfoCache'} -local SkeletonKey_GetSpellDetails = function(self) - - local spellName, spellID, command, icon = self.actionName, self.actionID, self.command, self.iconPath - - - print(' In:', spellName, spellID, command) - print(GetSpellInfo(spellName or spellID)) - local internalName, _, internalIcon, _, _, _, _ = GetSpellInfo(spellName or spellID) - local isAvailable = internalName and true - - if internalName and (internalName ~= spellName) then - -- it's a binding for the originating spell, leave it as is - print(' |cFFFF4400spell is an override(', internalName, '~=', spellName,') leave the name info alone') - self.statusText = '|cFFFFFF00Spell|r' - self.isAvailable = true - return - end - - -- let's us match spells replaced by talents - local info = kb.DynamicSpells[internalName or spellName] - if not info then - local dynamicType, dynamicIndex, dynamicSubIndex = command:match("(%a+)_(%S+)_(%S+)") - if kb.DynamicSpells[dynamicType] then - print('|cFFFF4400resolving dynamic type index:', internalName, spellName, command) - dynamicIndex = tonumber(dynamicIndex) - dynamicSubIndex = tonumber(dynamicSubIndex) - local cache = kb.DynamicSpells[dynamicType] - print('type:', dynamicType) - if dynamicIndex and cache[dynamicIndex] then - info = kb.DynamicSpells[dynamicType][dynamicIndex] - print('index:', dynamicIndex) - if dynamicSubIndex and info[dynamicSubIndex] then - info = info[dynamicSubIndex] - print('sub-index:', dynamicSubIndex) - end - isAvailable = true - end - end - if not info then - info = SkeletonKey_GetGenericSpell(spellName, spellID, internalIcon or icon) - end - end - info.isAvailable = isAvailable - - print('|cFF00FF88SpellDetails:|r', info.actionName, info.actionID, info.dynamicType, info.isAvailable) - for k,v in pairs(info) do - --cprint(' ',k,v) - self[k] = v - end - - return info -end - --- Assigns the slot via table copy; any manipulations from this point are temporary and function skb:SetSlot(slotInfo) print('slot info', self:GetID()) @@ -549,7 +485,7 @@ isBound = kb.IsCommandBound(self, self.command) if actionType == 'spell' then - local info = SkeletonKey_GetSpellDetails(self) + local info = kb.ResolveSpellSlot(self) name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook = self.actionName, self.iconPath, self.actionType, self.actionID, self.macroName, self.macroText, self.spellbookSlot, self.spellbookType self.isAvailable = info and info.isAvailable elseif actionType == 'petaction' then @@ -573,35 +509,75 @@ self.isAvailable = (kb.PetCache.spellslot[name]) elseif actionType == 'macro' then if actionID then - -- look for corruption + + -- Update stored information if it mis-matches local nameByID, _, bodyByID = GetMacroInfo(actionID) - local nameByName, _, bodyByName = GetMacroInfo(name) + --print(bodyByID, "\n", macroText) if (nameByID ~= name) or (bodyByID ~= macroText) then - local prevIndex = actionID - actionID = GetMacroIndexByName(name) - local firstName, _, firstBody = GetMacroInfo(actionID) + --kb:print('mismatches for slot', self:GetID(), actionID, ((nameByID ~= name) and 'name' or ''), ((bodyByID ~= macroText) and 'body' or '')) + local matchID, matchName, matchBody, hasMultiple + local roughResult = "" + + local newID = GetMacroIndexByName(name) + local firstName, _, firstBody = GetMacroInfo(newID) if (firstName ~= name) or (firstBody ~= macroText) then + + -- go even deeper - for i = 1, GetNumMacros() do - local searchName, _ , searchBody = GetMacroInfo(i) + local numAccount, numCharacter = GetNumMacros() + local searchID = 1 + while searchID <= (120+numCharacter) do + --kb:print(searchID) + + + local searchName, _ , searchBody = GetMacroInfo(searchID) if (searchName == name) and (searchBody == macroText) then + --kb:print('definitely', matchID, searchName, '\n', searchBody) -- complete match - actionID = i - kb:print('Macro index changed: |cFFFFFF00', actionType, '|r', name, '(was '..tostring(prevIndex)..', now '..tostring(actionID)..')') + matchID = searchID + matchName = searchName + matchBody = searchBody break elseif (searchName == name) or (searchBody == macroText) then -- partial match, continue the search - actionID = i - kb:print('Macro index changed: |cFFFFFF00', actionType, '|r', name, '(was '..tostring(prevIndex)..', now '..tostring(actionID)..')') + + if matchID then + hasMultiple = true + roughResult = roughResult .. "\n" .. tostring(searchID) .. ':'..tostring(searchName) + end + + matchID = searchID + matchName = searchName + matchBody = searchBody + --kb:print('possibly', matchID, matchName, '\n', matchBody) end + + if searchID == numAccount then + searchID = 120 + end + searchID = searchID + 1 end + else + matchID = newID + matchName = firstName + matchBody = firstBody end + --kb:print(matchID, hasMultiple) + if hasMultiple then + kb:print('Macro assignment in slot #'..tostring(self:GetID())..' has multiple possible indexes:\nSaved Info: '..tostring(actionID)..'/'..tostring(name)..'\n|cFFFFFF00', roughResult) + elseif matchID then + 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.') + actionID = matchID + name = matchName + macroName = matchName + macroText = matchBody + end end else actionID = GetMacroIndexByName(name) end - self.statusText = 'Macro' + self.statusText = 'Macro ' .. tostring(actionID) self.isAvailable = true else if not actionID then @@ -692,6 +668,8 @@ self.iconPath = icon self.profile = kb.db.bindMode self:RegisterForDrag('LeftButton') + + return slotInfo end kb.GetCommandAction = function(command)