annotate SkeletonKey/HotKey.lua @ 29:bb160c04de88

- update matching patterns used for picking up profession keybinds
author Nenue
date Fri, 05 Aug 2016 12:25:18 -0400
parents 73df13211b22
children 1aba8a6fd4a9
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@14 7 local kb, print, wrap = 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@27 18 local actionSlots = {}
Nenue@6 19 local actionFrames = {}
Nenue@27 20 local actionIndex = {}
Nenue@6 21
Nenue@6 22 kb.wrap(hotkey)
Nenue@6 23
Nenue@6 24 --- Used to determine which groups of action buttons need updating
Nenue@6 25 local hotkeyEvents = {
Nenue@6 26 ["UPDATE_BONUS_ACTIONBAR"] = {"bonus"},
Nenue@6 27 ["UPDATE_VEHICLE_ACTIONBAR"] = {"vehicle"},
Nenue@6 28 ["UPDATE_OVERRIDE_ACTIONBAR"] = {"override"},
Nenue@6 29 ["ACTIONBAR_PAGE_CHANGED"] = {"actionbar"},
Nenue@27 30 ["ACTIONBAR_SLOT_CHANGED"] = {"actionslot"},
Nenue@6 31 ["PLAYER_ENTERING_WORLD"] = {"world","all"},
Nenue@6 32 ["PET_UI_UPDATE"] = {"pet"},
Nenue@6 33 }
Nenue@6 34
Nenue@6 35
Nenue@6 36 hotkey.wrapEvent = function(event, ...)
Nenue@6 37 kb:RegisterEvent(event)
Nenue@6 38 hotkeyEvents[event] = {...}
Nenue@6 39 hotkey[event] = hotkey.UpdateFromEvent
Nenue@6 40 end
Nenue@6 41
Nenue@6 42 hotkey.unwrapEvent = function(event)
Nenue@6 43 if not kb[event] then
Nenue@6 44 kb:UnregisterEvent(event)
Nenue@6 45 end
Nenue@6 46 hotkeyEvents[event] = nil
Nenue@6 47 hotkey[event] = nil
Nenue@6 48 end
Nenue@6 49
Nenue@6 50
Nenue@6 51 hotkey.RegisterFrame = function(frame)
Nenue@14 52 --wrap(function()
Nenue@6 53 --print('ActionBarButtonEventsFrame_RegisterFrame(', frame:GetName(), frame.action, frame:IsVisible(), frame:IsShown())
Nenue@6 54 --end)
Nenue@6 55 blizHotKey[frame] = frame.HotKey
Nenue@6 56 loadedFrames[frame] = true
Nenue@6 57 end
Nenue@6 58
Nenue@6 59 hotkey.UpdateFromEvent = function(self, event, ...)
Nenue@6 60 if hotkeyEvents[event] then
Nenue@6 61 --print('call batch', event, ...)
Nenue@6 62 for i, func in ipairs(hotkeyEvents[event]) do
Nenue@6 63
Nenue@6 64 if hotkey[func] then
Nenue@6 65 --print(' ', func)
Nenue@6 66 hotkey[func](self, event, ...)
Nenue@6 67 end
Nenue@6 68 end
Nenue@6 69 end
Nenue@6 70 return true
Nenue@6 71 end
Nenue@6 72
Nenue@6 73 hotkey.variables = function()
Nenue@6 74 bindings = kb.GetBindings()
Nenue@6 75 for event, manifest in pairs(hotkeyEvents) do
Nenue@6 76 kb:RegisterEvent(event)
Nenue@6 77 hotkey[event] = hotkey.UpdateFromEvent
Nenue@6 78 end
Nenue@6 79 hotkey.wrapEvent('UNIT_PET', 'pet')
Nenue@6 80 end
Nenue@6 81
Nenue@6 82 hotkey.init = function()
Nenue@6 83 hooksecurefunc("ActionBarButtonEventsFrame_RegisterFrame", hotkey.RegisterFrame)
Nenue@6 84 end
Nenue@6 85
Nenue@13 86 hotkey.ui = function()
Nenue@27 87 --hotkey.player()
Nenue@27 88 --hotkey.pet()
Nenue@13 89 end
Nenue@13 90
Nenue@6 91 hotkey.world = function()
Nenue@27 92 hotkeyEvents["UPDATE_BINDINGS"] = {"binding"}
Nenue@6 93 hotkey.UPDATE_BINDINGS = hotkey.UpdateFromEvent
Nenue@6 94 kb:RegisterEvent("UPDATE_BINDINGS")
Nenue@6 95
Nenue@6 96 hotkey.player()
Nenue@6 97 hotkey.pet()
Nenue@6 98
Nenue@6 99 end
Nenue@6 100
Nenue@6 101 -- requires all these arguments since non-actionbar buttons don't have all of said methods
Nenue@6 102 hotkey.UpdateSkeletonKeyText = function(frame, actionType, actionID, hasAction)
Nenue@13 103 bindings = kb.GetBindings()
Nenue@13 104 print(frame, actionType, actionID, hasAction)
Nenue@27 105
Nenue@27 106 local indexKey = tostring(actionType) .. '_' .. tostring(actionID)
Nenue@27 107 local oldKey = actionIndex[frame]
Nenue@27 108 if hasAction and not actionFrames[indexKey] then
Nenue@27 109 actionFrames[indexKey] = frame
Nenue@27 110 actionIndex[frame] = indexKey
Nenue@27 111 print('|cFF00FF00['..indexKey.. '] = '.. tostring(frame))
Nenue@27 112 end
Nenue@27 113
Nenue@6 114 if bindings[actionType] then
Nenue@6 115 --print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction)
Nenue@6 116 local binds = bindings[actionType][actionID]
Nenue@6 117 if binds then
Nenue@6 118 if hasAction and not frame.HotKey:IsVisible() then
Nenue@6 119 if not hotkeyText[frame] then
Nenue@6 120 hotkeyText[frame] = frame:CreateFontString('KeyBinderHotKeyText', 'OVERLAY')
Nenue@6 121 hotkeyText[frame]:SetFont(frame.HotKey:GetFont())
Nenue@6 122 hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor())
Nenue@6 123 hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT')
Nenue@6 124 end
Nenue@6 125
Nenue@6 126 hotkeyText[frame]:SetText(kb.BindingString(unpack(binds)))
Nenue@6 127 print('|cFF00FFFFUpdate text for', frame:GetName())
Nenue@6 128 print(unpack(binds))
Nenue@6 129 return
Nenue@6 130 end
Nenue@6 131 end
Nenue@6 132 end
Nenue@6 133
Nenue@6 134 if hotkeyText[frame] then
Nenue@6 135 hotkeyText[frame]:SetText(nil)
Nenue@6 136 --print('|cFFFF4400cleared text from', frame:GetName())
Nenue@6 137 end
Nenue@6 138 end
Nenue@6 139
Nenue@6 140 hotkey.actionbar = function()
Nenue@6 141 if ActionBarButtonEventsFrame.frames then
Nenue@6 142 for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do
Nenue@6 143 local actionType, actionID = GetActionInfo(frame.action)
Nenue@27 144 local hasAction = HasAction(frame.action)
Nenue@27 145 actionSlots[frame.action] = frame
Nenue@27 146 hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, hasAction)
Nenue@6 147 end
Nenue@6 148 end
Nenue@6 149 end
Nenue@6 150
Nenue@6 151 hotkey.actionslot = function(self, event, slot)
Nenue@27 152 print(actionSlots[slot], event, slot, GetActionInfo(slot))
Nenue@6 153 --print(GetActionButtonForID(slot))
Nenue@27 154 local atype, aid = GetActionInfo(slot)
Nenue@29 155 if actionSlots[slot] then
Nenue@27 156 hotkey.UpdateSkeletonKeyText(actionSlots[slot], atype, aid, HasAction(slot))
Nenue@29 157 end
Nenue@29 158
Nenue@6 159 end
Nenue@6 160
Nenue@6 161 hotkey.player = function()
Nenue@6 162 hotkey.actionbar()
Nenue@6 163 end
Nenue@6 164
Nenue@6 165
Nenue@27 166
Nenue@6 167 hotkey.pet = function(self, event, arg1)
Nenue@6 168 if event == 'UNIT_PET' and arg1 == 'player' then
Nenue@6 169 if PetHasActionBar() and UnitIsVisible("pet") then
Nenue@6 170 hotkey.wrapEvent('PET_UI_CLOSE', 'pet')
Nenue@6 171 hotkey.wrapEvent('PET_BAR_UPDATE', 'pet')
Nenue@6 172 else
Nenue@6 173 hotkey.unwrapEvent('PET_UI_CLOSE')
Nenue@6 174 hotkey.unwrapEvent('PET_BAR_UPDATE')
Nenue@6 175 return
Nenue@6 176 end
Nenue@6 177 end
Nenue@6 178
Nenue@6 179 for i=1, NUM_PET_ACTION_SLOTS, 1 do
Nenue@6 180 local button = _G['PetActionButton'.. i]
Nenue@6 181 --print(button:GetName())
Nenue@6 182 for k, v in pairs(button) do
Nenue@6 183 --print(' ', k, type(v))
Nenue@6 184 end
Nenue@6 185 end
Nenue@6 186 end
Nenue@6 187
Nenue@6 188
Nenue@27 189 --- used to pick up changes from user interaction
Nenue@27 190 local changeIndex = 1
Nenue@27 191 hotkey.binding = function()
Nenue@27 192 print('|cFFFF0088BindingsUpdate')
Nenue@27 193 local changeNum = #kb.ChangedBindings
Nenue@27 194 if changeNum >= changeIndex then
Nenue@27 195 for i = changeIndex, changeNum do
Nenue@27 196 local actionType, actionID, name = unpack(kb.ChangedBindings[i])
Nenue@27 197 local key = actionType .. '_' .. actionID
Nenue@27 198 if actionFrames[key] then
Nenue@27 199 hotkey.UpdateSkeletonKeyText(actionFrames[key] , actionType, actionID, HasAction(actionFrames[key].action))
Nenue@27 200 end
Nenue@27 201
Nenue@27 202 changeIndex = i + 1
Nenue@27 203 end
Nenue@27 204
Nenue@27 205 end
Nenue@27 206 end