annotate SkeletonKey/HotKey.lua @ 61:b7be92f62b05

unbreak hotkey startup sequence
author Nenue
date Sun, 28 Aug 2016 10:06:59 -0400
parents d8bb2629fea8
children 04c23ceaf9e0
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@50 7 local _G, wipe, tContains, tinsert = _G, table.wipe, tContains, tinsert
Nenue@61 8
Nenue@61 9 local hotkey = CreateFrame('Frame', 'SkeletonHotKeys', UIParent)
Nenue@61 10 local kb, print, wrap = LibStub("LibKraken").register(KeyBinder, hotkey)
Nenue@6 11 local hotkeyText = {}
Nenue@6 12 local blizHotKey = {}
Nenue@6 13 local bindings
Nenue@6 14
Nenue@6 15 -- frames obtained via post-load hooks, created by addons like Dominos or BarTender4
Nenue@6 16 local loadedFrames = {}
Nenue@6 17 -- frames divided by update categories
Nenue@6 18 local categoryFrames = {}
Nenue@6 19 -- frames indexed by action slot ID (just the action bar, for... reasons)
Nenue@27 20 local actionSlots = {}
Nenue@6 21 local actionFrames = {}
Nenue@27 22 local actionIndex = {}
Nenue@6 23
Nenue@6 24
Nenue@6 25 --- Used to determine which groups of action buttons need updating
Nenue@6 26 local hotkeyEvents = {
Nenue@6 27 ["UPDATE_BONUS_ACTIONBAR"] = {"bonus"},
Nenue@6 28 ["UPDATE_VEHICLE_ACTIONBAR"] = {"vehicle"},
Nenue@6 29 ["UPDATE_OVERRIDE_ACTIONBAR"] = {"override"},
Nenue@6 30 ["ACTIONBAR_PAGE_CHANGED"] = {"actionbar"},
Nenue@27 31 ["ACTIONBAR_SLOT_CHANGED"] = {"actionslot"},
Nenue@6 32 ["PLAYER_ENTERING_WORLD"] = {"world","all"},
Nenue@6 33 ["PET_UI_UPDATE"] = {"pet"},
Nenue@6 34 }
Nenue@6 35
Nenue@6 36
Nenue@6 37 hotkey.wrapEvent = function(event, ...)
Nenue@6 38 kb:RegisterEvent(event)
Nenue@6 39 hotkeyEvents[event] = {...}
Nenue@6 40 hotkey[event] = hotkey.UpdateFromEvent
Nenue@6 41 end
Nenue@6 42
Nenue@6 43 hotkey.unwrapEvent = function(event)
Nenue@6 44 if not kb[event] then
Nenue@6 45 kb:UnregisterEvent(event)
Nenue@6 46 end
Nenue@6 47 hotkeyEvents[event] = nil
Nenue@6 48 hotkey[event] = nil
Nenue@6 49 end
Nenue@6 50
Nenue@6 51
Nenue@6 52 hotkey.RegisterFrame = function(frame)
Nenue@14 53 --wrap(function()
Nenue@61 54 print('ActionBarButtonEventsFrame_RegisterFrame(', frame:GetName(), frame.action, frame:IsVisible(), frame:IsShown())
Nenue@6 55 --end)
Nenue@6 56 blizHotKey[frame] = frame.HotKey
Nenue@6 57 loadedFrames[frame] = true
Nenue@6 58 end
Nenue@6 59
Nenue@6 60 hotkey.UpdateFromEvent = function(self, event, ...)
Nenue@6 61 if hotkeyEvents[event] then
Nenue@6 62 --print('call batch', event, ...)
Nenue@6 63 for i, func in ipairs(hotkeyEvents[event]) do
Nenue@6 64
Nenue@6 65 if hotkey[func] then
Nenue@6 66 --print(' ', func)
Nenue@6 67 hotkey[func](self, event, ...)
Nenue@6 68 end
Nenue@6 69 end
Nenue@6 70 end
Nenue@6 71 return true
Nenue@6 72 end
Nenue@6 73
Nenue@6 74 hotkey.variables = function()
Nenue@61 75 print('variables')
Nenue@6 76 bindings = kb.GetBindings()
Nenue@6 77 for event, manifest in pairs(hotkeyEvents) do
Nenue@6 78 kb:RegisterEvent(event)
Nenue@6 79 hotkey[event] = hotkey.UpdateFromEvent
Nenue@6 80 end
Nenue@6 81 hotkey.wrapEvent('UNIT_PET', 'pet')
Nenue@61 82 hotkey.player()
Nenue@6 83 end
Nenue@6 84
Nenue@54 85
Nenue@6 86 hotkey.init = function()
Nenue@61 87
Nenue@6 88 hooksecurefunc("ActionBarButtonEventsFrame_RegisterFrame", hotkey.RegisterFrame)
Nenue@61 89
Nenue@6 90 end
Nenue@6 91
Nenue@13 92 hotkey.ui = function()
Nenue@61 93 print('ui')
Nenue@27 94 --hotkey.player()
Nenue@27 95 --hotkey.pet()
Nenue@13 96 end
Nenue@13 97
Nenue@61 98
Nenue@6 99 hotkey.world = function()
Nenue@61 100 print('world')
Nenue@27 101 hotkeyEvents["UPDATE_BINDINGS"] = {"binding"}
Nenue@6 102 hotkey.UPDATE_BINDINGS = hotkey.UpdateFromEvent
Nenue@61 103 hotkey:RegisterEvent("UPDATE_BINDINGS")
Nenue@6 104
Nenue@6 105 hotkey.player()
Nenue@6 106 hotkey.pet()
Nenue@6 107
Nenue@6 108 end
Nenue@6 109
Nenue@6 110 -- requires all these arguments since non-actionbar buttons don't have all of said methods
Nenue@50 111 hotkey.UpdateHotKey = function(frame, actionType, actionID, hasAction)
Nenue@13 112 bindings = kb.GetBindings()
Nenue@27 113
Nenue@50 114 local indexKey = kb.FormatActionID(actionType, actionID)
Nenue@50 115 print('|cFF00FFFFUpdate|r', frame, indexKey, hasAction)
Nenue@27 116
Nenue@50 117
Nenue@50 118 if bindings[indexKey] then
Nenue@61 119 print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction)
Nenue@50 120 local binds = bindings[indexKey]
Nenue@57 121 if binds and (not frame.HotKey:IsVisible()) then
Nenue@50 122 if hasAction then
Nenue@50 123 local bindingsText = kb.BindingString(unpack(binds))
Nenue@50 124
Nenue@6 125 if not hotkeyText[frame] then
Nenue@50 126 print('-new hotkey element')
Nenue@50 127 hotkeyText[frame] = frame:CreateFontString(frame:GetName()..'SkeletonKey', 'OVERLAY')
Nenue@6 128 hotkeyText[frame]:SetFont(frame.HotKey:GetFont())
Nenue@6 129 hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor())
Nenue@6 130 hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT')
Nenue@57 131
Nenue@57 132 hooksecurefunc(frame.HotKey, 'SetVertexColor', function(self, r,g,b,a)
Nenue@57 133 hotkeyText[frame]:SetTextColor(r,g,b,a)
Nenue@57 134 end)
Nenue@6 135 end
Nenue@6 136
Nenue@50 137 hotkeyText[frame]:SetText(bindingsText)
Nenue@50 138 hotkeyText[frame]:Show()
Nenue@50 139 print('|cFF00FFFFUpdate text for', frame:GetName(), '|cFFFFFF00'..tostring(bindingsText)..'|r')
Nenue@50 140
Nenue@6 141 return
Nenue@6 142 end
Nenue@6 143 end
Nenue@6 144 end
Nenue@6 145
Nenue@6 146 if hotkeyText[frame] then
Nenue@6 147 hotkeyText[frame]:SetText(nil)
Nenue@6 148 --print('|cFFFF4400cleared text from', frame:GetName())
Nenue@6 149 end
Nenue@6 150 end
Nenue@6 151
Nenue@6 152 hotkey.actionbar = function()
Nenue@50 153 wipe(actionFrames)
Nenue@50 154 -- reset frames list
Nenue@61 155 print('actionbar')
Nenue@6 156 if ActionBarButtonEventsFrame.frames then
Nenue@6 157 for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do
Nenue@61 158
Nenue@50 159 local slot = frame.action
Nenue@50 160 local actionType, actionID = GetActionInfo(slot)
Nenue@50 161 local hasAction = HasAction(slot)
Nenue@50 162 local indexKey = kb.FormatActionID(actionType, actionID)
Nenue@50 163 actionSlots[slot] = frame
Nenue@50 164 actionFrames[indexKey] = actionFrames[indexKey] or {}
Nenue@50 165 if not tContains(actionFrames[indexKey]) then
Nenue@50 166 tinsert(actionFrames[indexKey], frame)
Nenue@50 167 actionIndex[slot] = indexKey
Nenue@50 168 end
Nenue@50 169
Nenue@50 170 hotkey.UpdateHotKey(frame, actionType, actionID, hasAction)
Nenue@6 171 end
Nenue@6 172 end
Nenue@6 173 end
Nenue@6 174
Nenue@6 175 hotkey.actionslot = function(self, event, slot)
Nenue@27 176 print(actionSlots[slot], event, slot, GetActionInfo(slot))
Nenue@6 177 --print(GetActionButtonForID(slot))
Nenue@27 178 local atype, aid = GetActionInfo(slot)
Nenue@50 179 local indexKey = kb.FormatActionID(atype, aid)
Nenue@50 180 local frame = actionSlots[slot]
Nenue@50 181 if frame then
Nenue@50 182 hotkey.UpdateHotKey(frame, atype, aid, HasAction(slot))
Nenue@29 183 end
Nenue@29 184
Nenue@6 185 end
Nenue@6 186
Nenue@6 187 hotkey.player = function()
Nenue@61 188 print('player')
Nenue@6 189 hotkey.actionbar()
Nenue@6 190 end
Nenue@6 191
Nenue@6 192
Nenue@27 193
Nenue@6 194 hotkey.pet = function(self, event, arg1)
Nenue@6 195 if event == 'UNIT_PET' and arg1 == 'player' then
Nenue@6 196 if PetHasActionBar() and UnitIsVisible("pet") then
Nenue@6 197 hotkey.wrapEvent('PET_UI_CLOSE', 'pet')
Nenue@6 198 hotkey.wrapEvent('PET_BAR_UPDATE', 'pet')
Nenue@6 199 else
Nenue@6 200 hotkey.unwrapEvent('PET_UI_CLOSE')
Nenue@6 201 hotkey.unwrapEvent('PET_BAR_UPDATE')
Nenue@6 202 return
Nenue@6 203 end
Nenue@6 204 end
Nenue@6 205
Nenue@6 206 for i=1, NUM_PET_ACTION_SLOTS, 1 do
Nenue@6 207 local button = _G['PetActionButton'.. i]
Nenue@6 208 --print(button:GetName())
Nenue@6 209 for k, v in pairs(button) do
Nenue@6 210 --print(' ', k, type(v))
Nenue@6 211 end
Nenue@6 212 end
Nenue@6 213 end
Nenue@6 214
Nenue@6 215
Nenue@27 216 --- used to pick up changes from user interaction
Nenue@27 217 local changeIndex = 1
Nenue@27 218 hotkey.binding = function()
Nenue@27 219 print('|cFFFF0088BindingsUpdate')
Nenue@27 220 local changeNum = #kb.ChangedBindings
Nenue@27 221 if changeNum >= changeIndex then
Nenue@50 222
Nenue@50 223
Nenue@27 224 for i = changeIndex, changeNum do
Nenue@27 225 local actionType, actionID, name = unpack(kb.ChangedBindings[i])
Nenue@50 226 local actionKey = kb.FormatActionID(actionType, actionID)
Nenue@50 227 local frames = actionFrames[actionKey]
Nenue@50 228 if frames then
Nenue@50 229 for i, frame in ipairs(frames) do
Nenue@50 230 print('|cFFFF0088'..actionKey..'|r', frame)
Nenue@50 231 if frame then
Nenue@50 232 hotkey.UpdateHotKey(frame , actionType, actionID, HasAction(frame.action))
Nenue@50 233 end
Nenue@50 234 end
Nenue@50 235 else
Nenue@50 236 print('no frames picked up, rebuild')
Nenue@50 237 hotkey.actionbar()
Nenue@27 238 end
Nenue@27 239
Nenue@27 240 changeIndex = i + 1
Nenue@27 241 end
Nenue@27 242
Nenue@27 243 end
Nenue@27 244 end