Mercurial > wow > skeletonkey
diff SkeletonKey/HotKey.lua @ 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 | bb160c04de88 |
children | a545933ddf3d |
line wrap: on
line diff
--- 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