annotate SkeletonKey/HotKey.lua @ 14:82170735e67c

- move co-routine handler to general lib - slightly better handling of pet actions
author Nenue
date Thu, 28 Jul 2016 23:58:53 -0400
parents eeec4a600064
children 73df13211b22
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@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
Nenue@6 33 hotkey.wrapEvent = function(event, ...)
Nenue@6 34 kb:RegisterEvent(event)
Nenue@6 35 hotkeyEvents[event] = {...}
Nenue@6 36 hotkey[event] = hotkey.UpdateFromEvent
Nenue@6 37 end
Nenue@6 38
Nenue@6 39 hotkey.unwrapEvent = function(event)
Nenue@6 40 if not kb[event] then
Nenue@6 41 kb:UnregisterEvent(event)
Nenue@6 42 end
Nenue@6 43 hotkeyEvents[event] = nil
Nenue@6 44 hotkey[event] = nil
Nenue@6 45 end
Nenue@6 46
Nenue@6 47 hotkey.ActionButton_Update = function(frame)
Nenue@14 48 wrap(function()
Nenue@6 49 local actionType, actionID = GetActionInfo(frame.action)
Nenue@6 50 hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, HasAction(frame.action))
Nenue@6 51 end)
Nenue@6 52 end
Nenue@6 53
Nenue@6 54
Nenue@6 55 hotkey.RegisterFrame = function(frame)
Nenue@14 56 --wrap(function()
Nenue@6 57 --print('ActionBarButtonEventsFrame_RegisterFrame(', frame:GetName(), frame.action, frame:IsVisible(), frame:IsShown())
Nenue@6 58 --end)
Nenue@6 59 blizHotKey[frame] = frame.HotKey
Nenue@6 60 loadedFrames[frame] = true
Nenue@6 61 end
Nenue@6 62
Nenue@6 63 hotkey.UpdateFromEvent = function(self, event, ...)
Nenue@6 64 if hotkeyEvents[event] then
Nenue@6 65 --print('call batch', event, ...)
Nenue@6 66 for i, func in ipairs(hotkeyEvents[event]) do
Nenue@6 67
Nenue@6 68 if hotkey[func] then
Nenue@6 69 --print(' ', func)
Nenue@6 70 hotkey[func](self, event, ...)
Nenue@6 71 end
Nenue@6 72 end
Nenue@6 73 end
Nenue@6 74 return true
Nenue@6 75 end
Nenue@6 76
Nenue@6 77 hotkey.variables = function()
Nenue@6 78 bindings = kb.GetBindings()
Nenue@6 79 for event, manifest in pairs(hotkeyEvents) do
Nenue@6 80 kb:RegisterEvent(event)
Nenue@6 81 hotkey[event] = hotkey.UpdateFromEvent
Nenue@6 82 end
Nenue@6 83 hotkey.wrapEvent('UNIT_PET', 'pet')
Nenue@6 84 end
Nenue@6 85
Nenue@6 86 hotkey.init = function()
Nenue@6 87 hooksecurefunc("ActionBarButtonEventsFrame_RegisterFrame", hotkey.RegisterFrame)
Nenue@6 88 end
Nenue@6 89
Nenue@13 90 hotkey.ui = function()
Nenue@13 91 hotkey.player()
Nenue@13 92 hotkey.pet()
Nenue@13 93 end
Nenue@13 94
Nenue@6 95 hotkey.world = function()
Nenue@6 96 hotkeyEvents["UPDATE_BINDINGS"] = {"actionbar"}
Nenue@6 97 hotkey.UPDATE_BINDINGS = hotkey.UpdateFromEvent
Nenue@6 98 kb:RegisterEvent("UPDATE_BINDINGS")
Nenue@6 99
Nenue@6 100 hotkey.player()
Nenue@6 101 hotkey.pet()
Nenue@6 102
Nenue@6 103 -- Set this after, since we already full-scanned buttons
Nenue@6 104 hooksecurefunc("ActionButton_Update", hotkey.ActionButton_Update)
Nenue@6 105 end
Nenue@6 106
Nenue@6 107 -- requires all these arguments since non-actionbar buttons don't have all of said methods
Nenue@6 108 hotkey.UpdateSkeletonKeyText = function(frame, actionType, actionID, hasAction)
Nenue@13 109 bindings = kb.GetBindings()
Nenue@13 110 print(frame, actionType, actionID, hasAction)
Nenue@6 111 if bindings[actionType] then
Nenue@6 112 --print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction)
Nenue@6 113 local binds = bindings[actionType][actionID]
Nenue@6 114 if binds then
Nenue@6 115 if hasAction and not frame.HotKey:IsVisible() then
Nenue@6 116 if not hotkeyText[frame] then
Nenue@6 117 hotkeyText[frame] = frame:CreateFontString('KeyBinderHotKeyText', 'OVERLAY')
Nenue@6 118 hotkeyText[frame]:SetFont(frame.HotKey:GetFont())
Nenue@6 119 hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor())
Nenue@6 120 hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT')
Nenue@6 121 end
Nenue@6 122
Nenue@6 123 hotkeyText[frame]:SetText(kb.BindingString(unpack(binds)))
Nenue@6 124 print('|cFF00FFFFUpdate text for', frame:GetName())
Nenue@6 125 print(unpack(binds))
Nenue@6 126 return
Nenue@6 127 end
Nenue@6 128 end
Nenue@6 129 end
Nenue@6 130
Nenue@6 131 if hotkeyText[frame] then
Nenue@6 132 hotkeyText[frame]:SetText(nil)
Nenue@6 133 --print('|cFFFF4400cleared text from', frame:GetName())
Nenue@6 134 end
Nenue@6 135 end
Nenue@6 136
Nenue@6 137 hotkey.actionbar = function()
Nenue@6 138 if ActionBarButtonEventsFrame.frames then
Nenue@6 139 for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do
Nenue@6 140 local actionType, actionID = GetActionInfo(frame.action)
Nenue@6 141 hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, HasAction(frame.action))
Nenue@6 142 end
Nenue@6 143 end
Nenue@6 144 end
Nenue@6 145
Nenue@6 146 hotkey.actionslot = function(self, event, slot)
Nenue@6 147 --print(event, slot)
Nenue@6 148 --print(GetActionButtonForID(slot))
Nenue@6 149 hotkey.UpdateSkeletonKeyText(GetActionButtonForID(slot))
Nenue@6 150 end
Nenue@6 151
Nenue@6 152 hotkey.player = function()
Nenue@6 153 hotkey.actionbar()
Nenue@6 154 end
Nenue@6 155
Nenue@6 156
Nenue@6 157 hotkey.pet = function(self, event, arg1)
Nenue@6 158 if event == 'UNIT_PET' and arg1 == 'player' then
Nenue@6 159 if PetHasActionBar() and UnitIsVisible("pet") then
Nenue@6 160 hotkey.wrapEvent('PET_UI_CLOSE', 'pet')
Nenue@6 161 hotkey.wrapEvent('PET_BAR_UPDATE', 'pet')
Nenue@6 162 else
Nenue@6 163 hotkey.unwrapEvent('PET_UI_CLOSE')
Nenue@6 164 hotkey.unwrapEvent('PET_BAR_UPDATE')
Nenue@6 165 return
Nenue@6 166 end
Nenue@6 167 end
Nenue@6 168
Nenue@6 169 for i=1, NUM_PET_ACTION_SLOTS, 1 do
Nenue@6 170 local button = _G['PetActionButton'.. i]
Nenue@6 171 --print(button:GetName())
Nenue@6 172 for k, v in pairs(button) do
Nenue@6 173 --print(' ', k, type(v))
Nenue@6 174 end
Nenue@6 175 end
Nenue@6 176 end
Nenue@6 177
Nenue@6 178