Nenue@6: -- KrakTool Nenue@6: -- HotKey.lua Nenue@6: -- Created: 7/22/2016 10:28 PM Nenue@6: -- %file-revision% Nenue@6: -- Module for fixing actionbar hotkey text Nenue@6: Nenue@14: local kb, print, wrap = LibStub("LibKraken").register(KeyBinder, 'HotKey') Nenue@6: local hotkey = {} Nenue@6: local hotkeyText = {} Nenue@6: local blizHotKey = {} Nenue@6: local bindings Nenue@6: Nenue@6: -- frames obtained via post-load hooks, created by addons like Dominos or BarTender4 Nenue@6: local loadedFrames = {} Nenue@6: -- frames divided by update categories Nenue@6: local categoryFrames = {} Nenue@6: -- frames indexed by action slot ID (just the action bar, for... reasons) Nenue@27: local actionSlots = {} Nenue@6: local actionFrames = {} Nenue@27: local actionIndex = {} Nenue@6: Nenue@6: kb.wrap(hotkey) Nenue@6: Nenue@6: --- Used to determine which groups of action buttons need updating Nenue@6: local hotkeyEvents = { Nenue@6: ["UPDATE_BONUS_ACTIONBAR"] = {"bonus"}, Nenue@6: ["UPDATE_VEHICLE_ACTIONBAR"] = {"vehicle"}, Nenue@6: ["UPDATE_OVERRIDE_ACTIONBAR"] = {"override"}, Nenue@6: ["ACTIONBAR_PAGE_CHANGED"] = {"actionbar"}, Nenue@27: ["ACTIONBAR_SLOT_CHANGED"] = {"actionslot"}, Nenue@6: ["PLAYER_ENTERING_WORLD"] = {"world","all"}, Nenue@6: ["PET_UI_UPDATE"] = {"pet"}, Nenue@6: } Nenue@6: Nenue@6: Nenue@6: hotkey.wrapEvent = function(event, ...) Nenue@6: kb:RegisterEvent(event) Nenue@6: hotkeyEvents[event] = {...} Nenue@6: hotkey[event] = hotkey.UpdateFromEvent Nenue@6: end Nenue@6: Nenue@6: hotkey.unwrapEvent = function(event) Nenue@6: if not kb[event] then Nenue@6: kb:UnregisterEvent(event) Nenue@6: end Nenue@6: hotkeyEvents[event] = nil Nenue@6: hotkey[event] = nil Nenue@6: end Nenue@6: Nenue@6: Nenue@6: hotkey.RegisterFrame = function(frame) Nenue@14: --wrap(function() Nenue@6: --print('ActionBarButtonEventsFrame_RegisterFrame(', frame:GetName(), frame.action, frame:IsVisible(), frame:IsShown()) Nenue@6: --end) Nenue@6: blizHotKey[frame] = frame.HotKey Nenue@6: loadedFrames[frame] = true Nenue@6: end Nenue@6: Nenue@6: hotkey.UpdateFromEvent = function(self, event, ...) Nenue@6: if hotkeyEvents[event] then Nenue@6: --print('call batch', event, ...) Nenue@6: for i, func in ipairs(hotkeyEvents[event]) do Nenue@6: Nenue@6: if hotkey[func] then Nenue@6: --print(' ', func) Nenue@6: hotkey[func](self, event, ...) Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: return true Nenue@6: end Nenue@6: Nenue@6: hotkey.variables = function() Nenue@6: bindings = kb.GetBindings() Nenue@6: for event, manifest in pairs(hotkeyEvents) do Nenue@6: kb:RegisterEvent(event) Nenue@6: hotkey[event] = hotkey.UpdateFromEvent Nenue@6: end Nenue@6: hotkey.wrapEvent('UNIT_PET', 'pet') Nenue@6: end Nenue@6: Nenue@6: hotkey.init = function() Nenue@6: hooksecurefunc("ActionBarButtonEventsFrame_RegisterFrame", hotkey.RegisterFrame) Nenue@6: end Nenue@6: Nenue@13: hotkey.ui = function() Nenue@27: --hotkey.player() Nenue@27: --hotkey.pet() Nenue@13: end Nenue@13: Nenue@6: hotkey.world = function() Nenue@27: hotkeyEvents["UPDATE_BINDINGS"] = {"binding"} Nenue@6: hotkey.UPDATE_BINDINGS = hotkey.UpdateFromEvent Nenue@6: kb:RegisterEvent("UPDATE_BINDINGS") Nenue@6: Nenue@6: hotkey.player() Nenue@6: hotkey.pet() Nenue@6: Nenue@6: end Nenue@6: Nenue@6: -- requires all these arguments since non-actionbar buttons don't have all of said methods Nenue@6: hotkey.UpdateSkeletonKeyText = function(frame, actionType, actionID, hasAction) Nenue@13: bindings = kb.GetBindings() Nenue@13: print(frame, actionType, actionID, hasAction) Nenue@27: Nenue@27: local indexKey = tostring(actionType) .. '_' .. tostring(actionID) Nenue@27: local oldKey = actionIndex[frame] Nenue@27: if hasAction and not actionFrames[indexKey] then Nenue@27: actionFrames[indexKey] = frame Nenue@27: actionIndex[frame] = indexKey Nenue@27: print('|cFF00FF00['..indexKey.. '] = '.. tostring(frame)) Nenue@27: end Nenue@27: Nenue@6: if bindings[actionType] then Nenue@6: --print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction) Nenue@6: local binds = bindings[actionType][actionID] Nenue@6: if binds then Nenue@6: if hasAction and not frame.HotKey:IsVisible() then Nenue@6: if not hotkeyText[frame] then Nenue@6: hotkeyText[frame] = frame:CreateFontString('KeyBinderHotKeyText', 'OVERLAY') Nenue@6: hotkeyText[frame]:SetFont(frame.HotKey:GetFont()) Nenue@6: hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor()) Nenue@6: hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT') Nenue@6: end Nenue@6: Nenue@6: hotkeyText[frame]:SetText(kb.BindingString(unpack(binds))) Nenue@6: print('|cFF00FFFFUpdate text for', frame:GetName()) Nenue@6: print(unpack(binds)) Nenue@6: return Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: if hotkeyText[frame] then Nenue@6: hotkeyText[frame]:SetText(nil) Nenue@6: --print('|cFFFF4400cleared text from', frame:GetName()) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: hotkey.actionbar = function() Nenue@6: if ActionBarButtonEventsFrame.frames then Nenue@6: for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do Nenue@6: local actionType, actionID = GetActionInfo(frame.action) Nenue@27: local hasAction = HasAction(frame.action) Nenue@27: actionSlots[frame.action] = frame Nenue@27: hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, hasAction) Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: hotkey.actionslot = function(self, event, slot) Nenue@27: print(actionSlots[slot], event, slot, GetActionInfo(slot)) Nenue@6: --print(GetActionButtonForID(slot)) Nenue@27: local atype, aid = GetActionInfo(slot) Nenue@27: hotkey.UpdateSkeletonKeyText(actionSlots[slot], atype, aid, HasAction(slot)) Nenue@6: end Nenue@6: Nenue@6: hotkey.player = function() Nenue@6: hotkey.actionbar() Nenue@6: end Nenue@6: Nenue@6: Nenue@27: Nenue@6: hotkey.pet = function(self, event, arg1) Nenue@6: if event == 'UNIT_PET' and arg1 == 'player' then Nenue@6: if PetHasActionBar() and UnitIsVisible("pet") then Nenue@6: hotkey.wrapEvent('PET_UI_CLOSE', 'pet') Nenue@6: hotkey.wrapEvent('PET_BAR_UPDATE', 'pet') Nenue@6: else Nenue@6: hotkey.unwrapEvent('PET_UI_CLOSE') Nenue@6: hotkey.unwrapEvent('PET_BAR_UPDATE') Nenue@6: return Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: for i=1, NUM_PET_ACTION_SLOTS, 1 do Nenue@6: local button = _G['PetActionButton'.. i] Nenue@6: --print(button:GetName()) Nenue@6: for k, v in pairs(button) do Nenue@6: --print(' ', k, type(v)) Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: Nenue@27: --- used to pick up changes from user interaction Nenue@27: local changeIndex = 1 Nenue@27: hotkey.binding = function() Nenue@27: print('|cFFFF0088BindingsUpdate') Nenue@27: local changeNum = #kb.ChangedBindings Nenue@27: if changeNum >= changeIndex then Nenue@27: for i = changeIndex, changeNum do Nenue@27: local actionType, actionID, name = unpack(kb.ChangedBindings[i]) Nenue@27: local key = actionType .. '_' .. actionID Nenue@27: if actionFrames[key] then Nenue@27: hotkey.UpdateSkeletonKeyText(actionFrames[key] , actionType, actionID, HasAction(actionFrames[key].action)) Nenue@27: end Nenue@27: Nenue@27: changeIndex = i + 1 Nenue@27: end Nenue@27: Nenue@27: end Nenue@27: end