annotate SkeletonKey/HotKey.lua @ 13:eeec4a600064

- kb.bindings carries the exact values needed for matching GetActionInfo() outputs
author Nenue
date Thu, 28 Jul 2016 18:20:32 -0400
parents f6d1c192afc6
children 82170735e67c
rev   line source
Nenue@6 1 -- KrakTool
Nenue@6 2 -- HotKey.lua
Nenue@6 3 -- Created: 7/22/2016 10:28 PM
Nenue@6 4 -- %file-revision%
Nenue@6 5 -- Module for fixing actionbar hotkey text
Nenue@6 6
Nenue@6 7 local kb, print = LibStub("LibKraken").register(KeyBinder, 'HotKey')
Nenue@6 8 local hotkey = {}
Nenue@6 9 local hotkeyText = {}
Nenue@6 10 local blizHotKey = {}
Nenue@6 11 local bindings
Nenue@6 12
Nenue@6 13 -- frames obtained via post-load hooks, created by addons like Dominos or BarTender4
Nenue@6 14 local loadedFrames = {}
Nenue@6 15 -- frames divided by update categories
Nenue@6 16 local categoryFrames = {}
Nenue@6 17 -- frames indexed by action slot ID (just the action bar, for... reasons)
Nenue@6 18 local actionFrames = {}
Nenue@6 19
Nenue@6 20 kb.wrap(hotkey)
Nenue@6 21
Nenue@6 22 --- Used to determine which groups of action buttons need updating
Nenue@6 23 local hotkeyEvents = {
Nenue@6 24 ["UPDATE_BONUS_ACTIONBAR"] = {"bonus"},
Nenue@6 25 ["UPDATE_VEHICLE_ACTIONBAR"] = {"vehicle"},
Nenue@6 26 ["UPDATE_OVERRIDE_ACTIONBAR"] = {"override"},
Nenue@6 27 ["ACTIONBAR_PAGE_CHANGED"] = {"actionbar"},
Nenue@6 28 ["PLAYER_ENTERING_WORLD"] = {"world","all"},
Nenue@6 29 ["PET_UI_UPDATE"] = {"pet"},
Nenue@6 30 }
Nenue@6 31
Nenue@6 32 do
Nenue@6 33 local tickerQueue = {}
Nenue@6 34 local ticker
Nenue@6 35 local instant = false
Nenue@6 36 hotkey.tick = function()
Nenue@6 37
Nenue@6 38 if #tickerQueue == 0 then
Nenue@6 39 instant = true
Nenue@6 40 return
Nenue@6 41 else
Nenue@6 42 instant = false
Nenue@6 43 end
Nenue@6 44 local func = tremove(tickerQueue, 1)
Nenue@6 45 if func then
Nenue@6 46 --print('#', #tickerQueue)
Nenue@6 47 func()
Nenue@6 48 end
Nenue@6 49 end
Nenue@6 50 hotkey.wrap = function(f)
Nenue@6 51 if not ticker then
Nenue@6 52 --print('create ticker')
Nenue@6 53 ticker = C_Timer.NewTicker(0, hotkey.tick)
Nenue@6 54 end
Nenue@6 55 if instant then
Nenue@6 56 f()
Nenue@6 57 else
Nenue@6 58 tinsert(tickerQueue, f)
Nenue@6 59 end
Nenue@6 60 end
Nenue@6 61 end
Nenue@6 62
Nenue@6 63 hotkey.wrapEvent = function(event, ...)
Nenue@6 64 kb:RegisterEvent(event)
Nenue@6 65 hotkeyEvents[event] = {...}
Nenue@6 66 hotkey[event] = hotkey.UpdateFromEvent
Nenue@6 67 end
Nenue@6 68
Nenue@6 69 hotkey.unwrapEvent = function(event)
Nenue@6 70 if not kb[event] then
Nenue@6 71 kb:UnregisterEvent(event)
Nenue@6 72 end
Nenue@6 73 hotkeyEvents[event] = nil
Nenue@6 74 hotkey[event] = nil
Nenue@6 75 end
Nenue@6 76
Nenue@6 77 hotkey.ActionButton_Update = function(frame)
Nenue@6 78 hotkey.wrap(function()
Nenue@6 79 local actionType, actionID = GetActionInfo(frame.action)
Nenue@6 80 hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, HasAction(frame.action))
Nenue@6 81 end)
Nenue@6 82 end
Nenue@6 83
Nenue@6 84
Nenue@6 85 hotkey.RegisterFrame = function(frame)
Nenue@6 86 --hotkey.wrap(function()
Nenue@6 87 --print('ActionBarButtonEventsFrame_RegisterFrame(', frame:GetName(), frame.action, frame:IsVisible(), frame:IsShown())
Nenue@6 88 --end)
Nenue@6 89 blizHotKey[frame] = frame.HotKey
Nenue@6 90 loadedFrames[frame] = true
Nenue@6 91 end
Nenue@6 92
Nenue@6 93 hotkey.UpdateFromEvent = function(self, event, ...)
Nenue@6 94 if hotkeyEvents[event] then
Nenue@6 95 --print('call batch', event, ...)
Nenue@6 96 for i, func in ipairs(hotkeyEvents[event]) do
Nenue@6 97
Nenue@6 98 if hotkey[func] then
Nenue@6 99 --print(' ', func)
Nenue@6 100 hotkey[func](self, event, ...)
Nenue@6 101 end
Nenue@6 102 end
Nenue@6 103 end
Nenue@6 104 return true
Nenue@6 105 end
Nenue@6 106
Nenue@6 107 hotkey.variables = function()
Nenue@6 108 bindings = kb.GetBindings()
Nenue@6 109 for event, manifest in pairs(hotkeyEvents) do
Nenue@6 110 kb:RegisterEvent(event)
Nenue@6 111 hotkey[event] = hotkey.UpdateFromEvent
Nenue@6 112 end
Nenue@6 113 hotkey.wrapEvent('UNIT_PET', 'pet')
Nenue@6 114 end
Nenue@6 115
Nenue@6 116 hotkey.init = function()
Nenue@6 117 hooksecurefunc("ActionBarButtonEventsFrame_RegisterFrame", hotkey.RegisterFrame)
Nenue@6 118 end
Nenue@6 119
Nenue@13 120 hotkey.ui = function()
Nenue@13 121 hotkey.player()
Nenue@13 122 hotkey.pet()
Nenue@13 123 end
Nenue@13 124
Nenue@6 125 hotkey.world = function()
Nenue@6 126 hotkeyEvents["UPDATE_BINDINGS"] = {"actionbar"}
Nenue@6 127 hotkey.UPDATE_BINDINGS = hotkey.UpdateFromEvent
Nenue@6 128 kb:RegisterEvent("UPDATE_BINDINGS")
Nenue@6 129
Nenue@6 130 hotkey.player()
Nenue@6 131 hotkey.pet()
Nenue@6 132
Nenue@6 133 -- Set this after, since we already full-scanned buttons
Nenue@6 134 hooksecurefunc("ActionButton_Update", hotkey.ActionButton_Update)
Nenue@6 135 end
Nenue@6 136
Nenue@6 137 -- requires all these arguments since non-actionbar buttons don't have all of said methods
Nenue@6 138 hotkey.UpdateSkeletonKeyText = function(frame, actionType, actionID, hasAction)
Nenue@13 139 bindings = kb.GetBindings()
Nenue@13 140 print(frame, actionType, actionID, hasAction)
Nenue@6 141 if bindings[actionType] then
Nenue@6 142 --print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction)
Nenue@6 143 local binds = bindings[actionType][actionID]
Nenue@6 144 if binds then
Nenue@6 145 if hasAction and not frame.HotKey:IsVisible() then
Nenue@6 146 if not hotkeyText[frame] then
Nenue@6 147 hotkeyText[frame] = frame:CreateFontString('KeyBinderHotKeyText', 'OVERLAY')
Nenue@6 148 hotkeyText[frame]:SetFont(frame.HotKey:GetFont())
Nenue@6 149 hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor())
Nenue@6 150 hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT')
Nenue@6 151 end
Nenue@6 152
Nenue@6 153 hotkeyText[frame]:SetText(kb.BindingString(unpack(binds)))
Nenue@6 154 print('|cFF00FFFFUpdate text for', frame:GetName())
Nenue@6 155 print(unpack(binds))
Nenue@6 156 return
Nenue@6 157 end
Nenue@6 158 end
Nenue@6 159 end
Nenue@6 160
Nenue@6 161 if hotkeyText[frame] then
Nenue@6 162 hotkeyText[frame]:SetText(nil)
Nenue@6 163 --print('|cFFFF4400cleared text from', frame:GetName())
Nenue@6 164 end
Nenue@6 165 end
Nenue@6 166
Nenue@6 167 hotkey.actionbar = function()
Nenue@6 168 if ActionBarButtonEventsFrame.frames then
Nenue@6 169 for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do
Nenue@6 170 local actionType, actionID = GetActionInfo(frame.action)
Nenue@6 171 hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, HasAction(frame.action))
Nenue@6 172 end
Nenue@6 173 end
Nenue@6 174 end
Nenue@6 175
Nenue@6 176 hotkey.actionslot = function(self, event, slot)
Nenue@6 177 --print(event, slot)
Nenue@6 178 --print(GetActionButtonForID(slot))
Nenue@6 179 hotkey.UpdateSkeletonKeyText(GetActionButtonForID(slot))
Nenue@6 180 end
Nenue@6 181
Nenue@6 182 hotkey.player = function()
Nenue@6 183 hotkey.actionbar()
Nenue@6 184 end
Nenue@6 185
Nenue@6 186
Nenue@6 187 hotkey.pet = function(self, event, arg1)
Nenue@6 188 if event == 'UNIT_PET' and arg1 == 'player' then
Nenue@6 189 if PetHasActionBar() and UnitIsVisible("pet") then
Nenue@6 190 hotkey.wrapEvent('PET_UI_CLOSE', 'pet')
Nenue@6 191 hotkey.wrapEvent('PET_BAR_UPDATE', 'pet')
Nenue@6 192 else
Nenue@6 193 hotkey.unwrapEvent('PET_UI_CLOSE')
Nenue@6 194 hotkey.unwrapEvent('PET_BAR_UPDATE')
Nenue@6 195 return
Nenue@6 196 end
Nenue@6 197 end
Nenue@6 198
Nenue@6 199 for i=1, NUM_PET_ACTION_SLOTS, 1 do
Nenue@6 200 local button = _G['PetActionButton'.. i]
Nenue@6 201 --print(button:GetName())
Nenue@6 202 for k, v in pairs(button) do
Nenue@6 203 --print(' ', k, type(v))
Nenue@6 204 end
Nenue@6 205 end
Nenue@6 206 end
Nenue@6 207
Nenue@6 208