Mercurial > wow > skeletonkey
changeset 50:1aba8a6fd4a9
- fix kb.bindings content and define a generic function for constructing its keystrings
- handle hotkey text for actions placed in multiple slots
-- hotkey.actionbar generates a cache table for use during binding changes
author | Nenue |
---|---|
date | Fri, 19 Aug 2016 01:12:56 -0400 |
parents | 9a9d7f2a7c07 |
children | d0ee4553061a |
files | SkeletonKey/ActionTemplates.lua SkeletonKey/BindingsFrame.lua SkeletonKey/HotKey.lua SkeletonKey/KeyButton.lua SkeletonKey/SkeletonKey.lua |
diffstat | 5 files changed, 72 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/SkeletonKey/ActionTemplates.lua Thu Aug 18 01:34:22 2016 -0400 +++ b/SkeletonKey/ActionTemplates.lua Fri Aug 19 01:12:56 2016 -0400 @@ -149,12 +149,11 @@ else macro:SetAttribute("*macrotext-"..macroName, macroText) end - - cprint('Loading binding', actionType, actionID) - bindings[actionType] = bindings[actionType] or {} - bindings[actionType][actionID] = bindings[actionType][actionID] or {} - bindings[command] = bindings[actionType][actionID] - return bindings[actionType], actionID + local indexKey = actionType..'_'..actionID + cprint('Loading binding', indexKey) + bindings[indexKey] = bindings[indexKey] or {} + bindings[command] = bindings[indexKey] + return bindings[indexKey], actionID end kb.ApplyBindings = function (profile) @@ -181,10 +180,10 @@ if dummy then cprint('|cFFBBFF00Active:|r', dummy) local macroName, spellName, actionType, actionID = unpack(talentInfo) - bindings[actionType] = bindings[actionType] or {} - bindings[actionType][actionID] = {} + local indexKey = actionType .. '_' .. actionID + bindings[indexKey] = {} func = kb.ApplyTalentBinding - dest = kb.bindings[actionType][actionID] + dest = kb.bindings[indexKey] else cprint('|cFFFF4400Inactive:|r', talentInfo[2]) @@ -442,9 +441,9 @@ end kb.UpdateBindingsCache = function(actionType, actionID, bindings) - kb.bindings[actionType] = kb.bindings[actionType] or {} - kb.bindings[actionType][actionID] = bindings + local indexKey = actionType .. '_' .. actionID + kb.bindings[indexKey] = bindings - print('|cFF00FF00'..actionType..'-'..actionID..'|r = {', table.concat(bindings,', '), '}') + print('|cFF00FF00'..indexKey..'|r = {', table.concat(bindings,', '), '}') tinsert(kb.ChangedBindings, {actionType, actionID}) end \ No newline at end of file
--- a/SkeletonKey/BindingsFrame.lua Thu Aug 18 01:34:22 2016 -0400 +++ b/SkeletonKey/BindingsFrame.lua Fri Aug 19 01:12:56 2016 -0400 @@ -60,28 +60,22 @@ kb.saveTarget.border:SetColorTexture(1,1,1,1) end local KeyButton_OnKeyUp = function(self, key) - kb.UpdateSlot(kb.saveTarget) if key == 'ESCAPE' then kb.DeactivateSlot(kb.saveTarget) kb.ui() return end - if key:match('[RL]SHIFT') or key:match('[RL]ALT') or key:match('[RL]CTRL') then return elseif kb.saveTarget then - if kb.SaveSlot(kb.saveTarget, key) then if not (kb.db.stickyMode or kb.db.hoverInput) then - kb.DeactivateSlot(kb.saveTarget) end kb.ui() end end - - end local KeyButton_OnClick = function(self, click) @@ -96,20 +90,16 @@ kb.db.stickyMode = true KeyBinderStickyMode:SetChecked(true) end - kb.ActivateSlot(self) kb.ui() end - end elseif click == 'RightButton' then kb.ReleaseSlot(self) kb.ui() elseif kb.saveTarget then - if kb.SaveSlot(kb.saveTarget, string.upper(click)) then if not (kb.db.stickyMode or kb.db.hoverInput) then - kb.DeactivateSlot(kb.saveTarget) end kb.ui()
--- a/SkeletonKey/HotKey.lua Thu Aug 18 01:34:22 2016 -0400 +++ b/SkeletonKey/HotKey.lua Fri Aug 19 01:12:56 2016 -0400 @@ -4,6 +4,7 @@ -- %file-revision% -- Module for fixing actionbar hotkey text +local _G, wipe, tContains, tinsert = _G, table.wipe, tContains, tinsert local kb, print, wrap = LibStub("LibKraken").register(KeyBinder, 'HotKey') local hotkey = {} local hotkeyText = {} @@ -99,33 +100,32 @@ end -- requires all these arguments since non-actionbar buttons don't have all of said methods -hotkey.UpdateSkeletonKeyText = function(frame, actionType, actionID, hasAction) +hotkey.UpdateHotKey = function(frame, actionType, actionID, hasAction) bindings = kb.GetBindings() - print(frame, actionType, actionID, hasAction) - local indexKey = tostring(actionType) .. '_' .. tostring(actionID) - local oldKey = actionIndex[frame] - if hasAction and not actionFrames[indexKey] then - actionFrames[indexKey] = frame - actionIndex[frame] = indexKey - print('|cFF00FF00['..indexKey.. '] = '.. tostring(frame)) - end + local indexKey = kb.FormatActionID(actionType, actionID) + print('|cFF00FFFFUpdate|r', frame, indexKey, hasAction) - if bindings[actionType] then + + if bindings[indexKey] then --print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction) - local binds = bindings[actionType][actionID] + local binds = bindings[indexKey] if binds then - if hasAction and not frame.HotKey:IsVisible() then + if hasAction then + local bindingsText = kb.BindingString(unpack(binds)) + if not hotkeyText[frame] then - hotkeyText[frame] = frame:CreateFontString('KeyBinderHotKeyText', 'OVERLAY') + print('-new hotkey element') + hotkeyText[frame] = frame:CreateFontString(frame:GetName()..'SkeletonKey', 'OVERLAY') hotkeyText[frame]:SetFont(frame.HotKey:GetFont()) hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor()) hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT') end - hotkeyText[frame]:SetText(kb.BindingString(unpack(binds))) - print('|cFF00FFFFUpdate text for', frame:GetName()) - print(unpack(binds)) + hotkeyText[frame]:SetText(bindingsText) + hotkeyText[frame]:Show() + print('|cFF00FFFFUpdate text for', frame:GetName(), '|cFFFFFF00'..tostring(bindingsText)..'|r') + return end end @@ -138,12 +138,23 @@ end hotkey.actionbar = function() + wipe(actionFrames) + -- reset frames list + if ActionBarButtonEventsFrame.frames then for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do - local actionType, actionID = GetActionInfo(frame.action) - local hasAction = HasAction(frame.action) - actionSlots[frame.action] = frame - hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, hasAction) + local slot = frame.action + local actionType, actionID = GetActionInfo(slot) + local hasAction = HasAction(slot) + local indexKey = kb.FormatActionID(actionType, actionID) + actionSlots[slot] = frame + actionFrames[indexKey] = actionFrames[indexKey] or {} + if not tContains(actionFrames[indexKey]) then + tinsert(actionFrames[indexKey], frame) + actionIndex[slot] = indexKey + end + + hotkey.UpdateHotKey(frame, actionType, actionID, hasAction) end end end @@ -152,8 +163,10 @@ print(actionSlots[slot], event, slot, GetActionInfo(slot)) --print(GetActionButtonForID(slot)) local atype, aid = GetActionInfo(slot) - if actionSlots[slot] then - hotkey.UpdateSkeletonKeyText(actionSlots[slot], atype, aid, HasAction(slot)) + local indexKey = kb.FormatActionID(atype, aid) + local frame = actionSlots[slot] + if frame then + hotkey.UpdateHotKey(frame, atype, aid, HasAction(slot)) end end @@ -192,11 +205,22 @@ print('|cFFFF0088BindingsUpdate') local changeNum = #kb.ChangedBindings if changeNum >= changeIndex then + + for i = changeIndex, changeNum do local actionType, actionID, name = unpack(kb.ChangedBindings[i]) - local key = actionType .. '_' .. actionID - if actionFrames[key] then - hotkey.UpdateSkeletonKeyText(actionFrames[key] , actionType, actionID, HasAction(actionFrames[key].action)) + local actionKey = kb.FormatActionID(actionType, actionID) + local frames = actionFrames[actionKey] + if frames then + for i, frame in ipairs(frames) do + print('|cFFFF0088'..actionKey..'|r', frame) + if frame then + hotkey.UpdateHotKey(frame , actionType, actionID, HasAction(frame.action)) + end + end + else + print('no frames picked up, rebuild') + hotkey.actionbar() end changeIndex = i + 1
--- a/SkeletonKey/KeyButton.lua Thu Aug 18 01:34:22 2016 -0400 +++ b/SkeletonKey/KeyButton.lua Fri Aug 19 01:12:56 2016 -0400 @@ -220,7 +220,8 @@ if kb.currentProfile.talents[self.actionName] then kb.currentProfile.talents[self.actionName] = nil end - kb.bindings[self.actionType][self.actionID] = nil + + kb.bindings[tostring(self.actionType)..'_'..tostring(self.actionID)] = nil end if kb.currentProfile.bound[self.command] then kb.currentProfile.bound[self.command] = nil
--- a/SkeletonKey/SkeletonKey.lua Thu Aug 18 01:34:22 2016 -0400 +++ b/SkeletonKey/SkeletonKey.lua Fri Aug 19 01:12:56 2016 -0400 @@ -72,11 +72,11 @@ local db -local bindHeader, currentHeader = '', '' -local specID, specGlobalID, specName, specDesc, specTexture, characterHeader = 0, 0, 'SPEC_NAME', 'SPEC_DESCRIPTION', 'Interface\\ICONS\\INV_Misc_QuestionMark', 'PLAYER_NAME' +local _G = _G +local UnitName, SelectedRealmName, InCombatLockdown, UnitClass = UnitName, SelectedRealmName, InCombatLockdown, UnitClass +local tostring, select, tinsert, pairs = tostring, select, tinsert, pairs +local concat, wipe = table.concat, table.wipe local classHeader, className, classID = '', '', 0 -local bindsCommitted = true -local forceButtonUpdate = false --- Control handles local saveButton, restoreButton, clearButton @@ -139,7 +139,7 @@ end if #stack >= 1 then - return table.concat(stack, ',') + return concat(stack, ',') else return nil end @@ -197,11 +197,11 @@ kb.ResetProfile = function(profile, prototype) if profile == kb.currentProfile then - for i, button in pairs(buttons) do + for i, button in pairs(kb.buttons) do kb.ReleaseSlot(button) end end - table.wipe(profile) + wipe(profile) kb.InitProfile(profile, prototype) end @@ -284,13 +284,10 @@ kb.ui() end - - - --- post ADDON_LOADED kb.variables = function() - SkeletonKeyDB = kb.InitProfile(SkeletonKeyDB, {}) - kb.db = SkeletonKeyDB + _G.SkeletonKeyDB = kb.InitProfile(_G.SkeletonKeyDB, {}) + kb.db = _G.SkeletonKeyDB kb.playerName = UnitName('player') kb.playerRealm = SelectedRealmName() kb.profileName = kb.playerRealm .. '_' .. kb.playerName @@ -322,6 +319,7 @@ end -- Volatiles Access +kb.FormatActionID = function(actionType, actionID) return tostring(actionType) .. '_' .. tostring(actionID) end kb.GetBindings = function() return kb.bindings end kb.GetButtons = function() return kb.buttons end kb.GetCharacterProfile = function () return kb.loadedProfiles[BINDING_TYPE_CHARACTER] end