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@6: local kb, print = 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@6: local actionFrames = {} 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@6: ["PLAYER_ENTERING_WORLD"] = {"world","all"}, Nenue@6: ["PET_UI_UPDATE"] = {"pet"}, Nenue@6: } Nenue@6: Nenue@6: do Nenue@6: local tickerQueue = {} Nenue@6: local ticker Nenue@6: local instant = false Nenue@6: hotkey.tick = function() Nenue@6: Nenue@6: if #tickerQueue == 0 then Nenue@6: instant = true Nenue@6: return Nenue@6: else Nenue@6: instant = false Nenue@6: end Nenue@6: local func = tremove(tickerQueue, 1) Nenue@6: if func then Nenue@6: --print('#', #tickerQueue) Nenue@6: func() Nenue@6: end Nenue@6: end Nenue@6: hotkey.wrap = function(f) Nenue@6: if not ticker then Nenue@6: --print('create ticker') Nenue@6: ticker = C_Timer.NewTicker(0, hotkey.tick) Nenue@6: end Nenue@6: if instant then Nenue@6: f() Nenue@6: else Nenue@6: tinsert(tickerQueue, f) Nenue@6: end Nenue@6: end Nenue@6: end 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: hotkey.ActionButton_Update = function(frame) Nenue@6: hotkey.wrap(function() Nenue@6: local actionType, actionID = GetActionInfo(frame.action) Nenue@6: hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, HasAction(frame.action)) Nenue@6: end) Nenue@6: end Nenue@6: Nenue@6: Nenue@6: hotkey.RegisterFrame = function(frame) Nenue@6: --hotkey.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@6: hotkey.world = function() Nenue@6: hotkeyEvents["UPDATE_BINDINGS"] = {"actionbar"} 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: -- Set this after, since we already full-scanned buttons Nenue@6: hooksecurefunc("ActionButton_Update", hotkey.ActionButton_Update) 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@6: if bindings[actionType] then Nenue@6: if actionType == 'macro' then Nenue@6: actionID = GetMacroInfo(actionID) Nenue@6: end 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@6: hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, HasAction(frame.action)) Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: hotkey.actionslot = function(self, event, slot) Nenue@6: --print(event, slot) Nenue@6: --print(GetActionButtonForID(slot)) Nenue@6: hotkey.UpdateSkeletonKeyText(GetActionButtonForID(slot)) Nenue@6: end Nenue@6: Nenue@6: hotkey.player = function() Nenue@6: hotkey.actionbar() Nenue@6: end Nenue@6: Nenue@6: 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: