Mercurial > wow > skeletonkey
diff SkeletonKey/KeySlot.lua @ 17:500f9b2bd9ac
- for RegisterAction, use a function table instead of that if/then rats nest
- consequently pet bar actions work now
- unlocalize bindings data
- activate keyslot input manually instead of on mouse over
- activate checkbox to keep input mode active
- dynamic buttons update in real time for petaction/talent/profession spells
author | Nenue |
---|---|
date | Sat, 30 Jul 2016 00:08:00 -0400 |
parents | cdd387d39137 |
children | 91398d284a99 |
line wrap: on
line diff
--- a/SkeletonKey/KeySlot.lua Fri Jul 29 21:18:15 2016 -0400 +++ b/SkeletonKey/KeySlot.lua Sat Jul 30 00:08:00 2016 -0400 @@ -5,7 +5,8 @@ -- Code dealing with the slot button innards; they are invoked by frame script and should only chain to Set/Release local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot') -local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION +local L = kb.L +local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION, CURSOR_TEXTURE local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1} local BORDER_ASSIGNED = {1,1,1,1} @@ -28,42 +29,44 @@ -- This is needed to identify a spells that aren't reflected by GetCursorInfo() hooksecurefunc("PickupSpellBookItem", function(slot, bookType) - print('|cFFFF4400PickupSpellBookItem(..', tostring(slot),', '..tostring(bookType)..')') + print('|cFFFF4400PickupSpellBookItem('.. tostring(slot).. ', '..tostring(bookType)..')') CURSOR_SPELLSLOT = slot CURSOR_BOOKTYPE = bookType + CURSOR_TEXTURE = GetSpellBookItemTexture(slot, bookType) + print('current cursor info', CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_TEXTURE) end) -do -- Pet actions - local isPickup - hooksecurefunc("PickupPetAction", function(slot, ...) - isPickup = GetCursorInfo() - print(slot, ...) +hooksecurefunc("PickupPetAction", function(slot, ...) + local isPickup = GetCursorInfo() + print(slot, ...) + if kb.PetCache.action[slot] then + if isPickup then + local key, _, texture = unpack(kb.PetCache.action[slot]) + local spellName = _G[key] or key + if spellName and kb.PetCache.spellslot[spellName] then + CURSOR_SPELLSLOT = kb.PetCache.spellslot[spellName][1] + CURSOR_BOOKTYPE = BOOKTYPE_PET + CURSOR_TEXTURE = _G[texture] or texture + end + else + CURSOR_SPELLSLOT = nil + CURSOR_BOOKTYPE = nil + CURSOR_TEXTURE = nil + end + print('|cFFFF4400PickupPetAction|r', isPickup, CURSOR_PETACTION) + end - 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 + local name, subtext, texture, isToken = GetPetActionInfo(slot) + if name then + kb.PetCache.action[slot] = {name, subtext, texture, isToken} + 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 + print('current cursor info', CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_TEXTURE) - end) -end +end) kb.DropToSlot = function(self) @@ -94,7 +97,9 @@ local spellType, spellID = GetSpellBookItemInfo(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE) local spellName, spellText = GetSpellBookItemName(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE) if spellType == 'PETACTION' then + name = spellName actionID = spellText + icon = CURSOR_TEXTURE else name, _, icon = GetSpellInfo(spellID) actionID = spellID @@ -183,6 +188,117 @@ end end +kb.UnbindSlot = function(self) + + local keys = {GetBindingKey(self.command) } + --print('detected', #keys, 'bindings') + for i, key in pairs(keys) do + --print('clearing', key) + SetBinding(key, nil) + SaveBindings(GetCurrentBindingSet()) + if kb.currentProfile.bindings[key] then + kb:print(L('BINDING_REMOVED', self.actionName, kb.currentHeader)) + kb.currentProfile.bindings[key] = nil + end + if kb.currentProfile.talents[self.actionName] then + kb.currentProfile.talents[self.actionName] = nil + end + kb.bindings[self.actionType][self.actionID] = nil + end + if kb.currentProfile.bound[self.command] then + kb.currentProfile.bound[self.command] = nil + --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode])) + end + + self.active = false + kb.UpdateSlot(self, true) +end + +--- Updates the current KeyBinding for the button's command +kb.SaveSlot = function(self, key) + + if not self.command then + return + end + print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key) + + local modifier = '' + if IsAltKeyDown() then + modifier = 'ALT-' + end + if IsControlKeyDown() then + modifier = modifier.. 'CTRL-' + end + if IsShiftKeyDown() then + modifier = modifier..'SHIFT-' + end + local binding = modifier..key + + if key == 'ESCAPE' then + else + if kb.SystemBinds[binding] then + kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', binding, kb.SystemBinds[binding])) + return + end + + + if self.command then + + local previousKeys + local previousAction = GetBindingAction(binding) + local binding1, binding2, new1, new2 + print(type(previousAction), previousAction) + if previousAction ~= "" and previousAction ~= self.command then + if kb.SystemBindings[binding] then + -- bounce out if trying to use a protected key + kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, GetBindingAction(binding))) + kb.bindingstext:SetText(nil) + return + else + kb:print('Discarding keybind for', previousAction) + -- todo: sort out retcon'd talent spells + end + end + + self.binding = binding + + SetBinding(self.binding, self.command) + SaveBindings(GetCurrentBindingSet()) + + local talentInfo + if self.actionType == 'spell' and kb.TalentCache[self.actionID] then + print('conditional binding (talent = "'..self.actionName..'")') + talentInfo = {self.macroName, self.actionName, self.actionType, self.actionID} + local bindings = {GetBindingKey(self.command) } + for i, key in ipairs(bindings) do + tinsert(talentInfo, key) + end + end + + for level, profile in ipairs(kb.orderedProfiles) do + if (level == kb.db.bindMode) then + profile.bound[self.command] = true + if talentInfo then + profile.bindings[self.binding] = nil + else + profile.bindings[self.binding] = self.command + end + profile.talents[self.actionName] = talentInfo + else + profile.bindings[self.binding] = nil + profile.bound[self.command] = nil + kb.currentProfile.talents[self.actionName] = nil + end + if kb.currentProfile.talents[self.actionID] then + kb.currentProfile.talents[self.actionID] = nil + end + end + + kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.currentHeader)) + end + end + kb.UpdateSlot(self, true) +end --- Updates profile assignment and button contents @@ -274,6 +390,7 @@ self.icon:SetAlpha(1) end + if self.actionType == 'spell' then self.icon:SetTexture(GetSpellTexture(self.actionID)) end @@ -285,6 +402,15 @@ self.bind:SetTextColor(1,1,1,1) end + + if kb.saveTarget and kb.saveTarget ~= self then + self:SetAlpha(0.25) + else + + self:SetAlpha(1) + end + + self.header:SetText(self.statusText) self.bind:SetText(self.bindingText) self.details:SetText(self.actionName) @@ -348,7 +474,6 @@ if actionType == 'spell' then local professionNum, spellNum = command:match("profession_(%d)_(%d)") - if (professionNum and spellNum) then isDynamic = 'profession' local cacheInfo = kb.ProfessionCache[professionNum..'_'..spellNum] @@ -375,13 +500,7 @@ 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 + isAvailable = (kb.PetCache.spellslot and kb.PetCache.spellslot[name]) elseif actionType == 'macro' then if not actionID then actionID = GetMacroIndexByName(name) @@ -415,7 +534,7 @@ 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:'.. tostring(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 @@ -443,118 +562,6 @@ end ---- Updates the current KeyBinding for the button's command -kb.SaveSlot = function(self, key) - - if not self.command then - return - end - - if key:match('[RL]SHIFT') or key:match('[RL]ALT') or key:match('[RL]CTRL') then - return - end - print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key) - - local modifier = '' - if IsAltKeyDown() then - modifier = 'ALT-' - end - if IsControlKeyDown() then - modifier = modifier.. 'CTRL-' - end - if IsShiftKeyDown() then - modifier = modifier..'SHIFT-' - end - local binding = modifier..key - - if key == 'ESCAPE' then - local keys = {GetBindingKey(self.command) } - --print('detected', #keys, 'bindings') - for i, key in pairs(keys) do - --print('clearing', key) - SetBinding(key, nil) - SaveBindings(GetCurrentBindingSet()) - if kb.currentProfile.bindings[key] then - kb:print(L('BINDING_REMOVED', self.actionName, kb.configHeaders[db.bindMode])) - kb.currentProfile.bindings[key] = nil - end - if kb.currentProfile.talents[self.actionName] then - kb.currentProfile.talents[self.actionName] = nil - end - bindings[self.actionType][self.actionID] = nil - end - if kb.currentProfile.bound[self.command] then - kb.currentProfile.bound[self.command] = nil - --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode])) - end - - self.active = false - else - if kb.SystemBinds[binding] then - kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, kb.SystemBinds[binding])) - return - end - - - if self.command then - - local previousKeys - local previousAction = GetBindingAction(binding) - local binding1, binding2, new1, new2 - print(type(previousAction), previousAction) - if previousAction ~= "" and previousAction ~= self.command then - if protected[previousAction] then - -- bounce out if trying to use a protected key - kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, GetBindingAction(binding))) - kb.bindingstext:SetText(nil) - return - else - kb:print('Discarding keybind for', previousAction) - -- todo: sort out retcon'd talent spells - end - end - - self.binding = binding - - SetBinding(self.binding, self.command) - SaveBindings(GetCurrentBindingSet()) - - local talentInfo - if self.actionType == 'spell' and kb.TalentCache[self.actionID] then - print('conditional binding (talent = "'..self.actionName..'")') - talentInfo = {self.macroName, self.actionName, self.actionType, self.actionID} - local bindings = {GetBindingKey(self.command) } - for i, key in ipairs(bindings) do - tinsert(talentInfo, key) - end - end - - for level, profile in ipairs(kb.orderedProfiles) do - if (level == db.bindMode) then - profile.bound[self.command] = true - if talentInfo then - profile.bindings[self.binding] = nil - else - profile.bindings[self.binding] = self.command - end - profile.talents[self.actionName] = talentInfo - else - profile.bindings[self.binding] = nil - profile.bound[self.command] = nil - kb.currentProfile.talents[self.actionName] = nil - end - if kb.currentProfile.talents[self.actionID] then - kb.currentProfile.talents[self.actionID] = nil - end - end - - kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.configHeaders[db.bindMode])) - end - end - kb.UpdateSlot(self, true) - KeyBinderSaveButton:Enable() -end - --- Add to blizzard interfaces