comparison SkeletonKey/HotKey.lua @ 27:73df13211b22

- actionbar hotkey text properly updates after hotkeys get switched - remove a unused function call
author Nenue
date Tue, 02 Aug 2016 12:33:13 -0400
parents 82170735e67c
children bb160c04de88
comparison
equal deleted inserted replaced
26:c081f117c19d 27:73df13211b22
13 -- frames obtained via post-load hooks, created by addons like Dominos or BarTender4 13 -- frames obtained via post-load hooks, created by addons like Dominos or BarTender4
14 local loadedFrames = {} 14 local loadedFrames = {}
15 -- frames divided by update categories 15 -- frames divided by update categories
16 local categoryFrames = {} 16 local categoryFrames = {}
17 -- frames indexed by action slot ID (just the action bar, for... reasons) 17 -- frames indexed by action slot ID (just the action bar, for... reasons)
18 local actionSlots = {}
18 local actionFrames = {} 19 local actionFrames = {}
20 local actionIndex = {}
19 21
20 kb.wrap(hotkey) 22 kb.wrap(hotkey)
21 23
22 --- Used to determine which groups of action buttons need updating 24 --- Used to determine which groups of action buttons need updating
23 local hotkeyEvents = { 25 local hotkeyEvents = {
24 ["UPDATE_BONUS_ACTIONBAR"] = {"bonus"}, 26 ["UPDATE_BONUS_ACTIONBAR"] = {"bonus"},
25 ["UPDATE_VEHICLE_ACTIONBAR"] = {"vehicle"}, 27 ["UPDATE_VEHICLE_ACTIONBAR"] = {"vehicle"},
26 ["UPDATE_OVERRIDE_ACTIONBAR"] = {"override"}, 28 ["UPDATE_OVERRIDE_ACTIONBAR"] = {"override"},
27 ["ACTIONBAR_PAGE_CHANGED"] = {"actionbar"}, 29 ["ACTIONBAR_PAGE_CHANGED"] = {"actionbar"},
30 ["ACTIONBAR_SLOT_CHANGED"] = {"actionslot"},
28 ["PLAYER_ENTERING_WORLD"] = {"world","all"}, 31 ["PLAYER_ENTERING_WORLD"] = {"world","all"},
29 ["PET_UI_UPDATE"] = {"pet"}, 32 ["PET_UI_UPDATE"] = {"pet"},
30 } 33 }
31 34
32 35
40 if not kb[event] then 43 if not kb[event] then
41 kb:UnregisterEvent(event) 44 kb:UnregisterEvent(event)
42 end 45 end
43 hotkeyEvents[event] = nil 46 hotkeyEvents[event] = nil
44 hotkey[event] = nil 47 hotkey[event] = nil
45 end
46
47 hotkey.ActionButton_Update = function(frame)
48 wrap(function()
49 local actionType, actionID = GetActionInfo(frame.action)
50 hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, HasAction(frame.action))
51 end)
52 end 48 end
53 49
54 50
55 hotkey.RegisterFrame = function(frame) 51 hotkey.RegisterFrame = function(frame)
56 --wrap(function() 52 --wrap(function()
86 hotkey.init = function() 82 hotkey.init = function()
87 hooksecurefunc("ActionBarButtonEventsFrame_RegisterFrame", hotkey.RegisterFrame) 83 hooksecurefunc("ActionBarButtonEventsFrame_RegisterFrame", hotkey.RegisterFrame)
88 end 84 end
89 85
90 hotkey.ui = function() 86 hotkey.ui = function()
87 --hotkey.player()
88 --hotkey.pet()
89 end
90
91 hotkey.world = function()
92 hotkeyEvents["UPDATE_BINDINGS"] = {"binding"}
93 hotkey.UPDATE_BINDINGS = hotkey.UpdateFromEvent
94 kb:RegisterEvent("UPDATE_BINDINGS")
95
91 hotkey.player() 96 hotkey.player()
92 hotkey.pet() 97 hotkey.pet()
93 end 98
94
95 hotkey.world = function()
96 hotkeyEvents["UPDATE_BINDINGS"] = {"actionbar"}
97 hotkey.UPDATE_BINDINGS = hotkey.UpdateFromEvent
98 kb:RegisterEvent("UPDATE_BINDINGS")
99
100 hotkey.player()
101 hotkey.pet()
102
103 -- Set this after, since we already full-scanned buttons
104 hooksecurefunc("ActionButton_Update", hotkey.ActionButton_Update)
105 end 99 end
106 100
107 -- requires all these arguments since non-actionbar buttons don't have all of said methods 101 -- requires all these arguments since non-actionbar buttons don't have all of said methods
108 hotkey.UpdateSkeletonKeyText = function(frame, actionType, actionID, hasAction) 102 hotkey.UpdateSkeletonKeyText = function(frame, actionType, actionID, hasAction)
109 bindings = kb.GetBindings() 103 bindings = kb.GetBindings()
110 print(frame, actionType, actionID, hasAction) 104 print(frame, actionType, actionID, hasAction)
105
106 local indexKey = tostring(actionType) .. '_' .. tostring(actionID)
107 local oldKey = actionIndex[frame]
108 if hasAction and not actionFrames[indexKey] then
109 actionFrames[indexKey] = frame
110 actionIndex[frame] = indexKey
111 print('|cFF00FF00['..indexKey.. '] = '.. tostring(frame))
112 end
113
111 if bindings[actionType] then 114 if bindings[actionType] then
112 --print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction) 115 --print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction)
113 local binds = bindings[actionType][actionID] 116 local binds = bindings[actionType][actionID]
114 if binds then 117 if binds then
115 if hasAction and not frame.HotKey:IsVisible() then 118 if hasAction and not frame.HotKey:IsVisible() then
136 139
137 hotkey.actionbar = function() 140 hotkey.actionbar = function()
138 if ActionBarButtonEventsFrame.frames then 141 if ActionBarButtonEventsFrame.frames then
139 for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do 142 for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do
140 local actionType, actionID = GetActionInfo(frame.action) 143 local actionType, actionID = GetActionInfo(frame.action)
141 hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, HasAction(frame.action)) 144 local hasAction = HasAction(frame.action)
145 actionSlots[frame.action] = frame
146 hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, hasAction)
142 end 147 end
143 end 148 end
144 end 149 end
145 150
146 hotkey.actionslot = function(self, event, slot) 151 hotkey.actionslot = function(self, event, slot)
147 --print(event, slot) 152 print(actionSlots[slot], event, slot, GetActionInfo(slot))
148 --print(GetActionButtonForID(slot)) 153 --print(GetActionButtonForID(slot))
149 hotkey.UpdateSkeletonKeyText(GetActionButtonForID(slot)) 154 local atype, aid = GetActionInfo(slot)
155 hotkey.UpdateSkeletonKeyText(actionSlots[slot], atype, aid, HasAction(slot))
150 end 156 end
151 157
152 hotkey.player = function() 158 hotkey.player = function()
153 hotkey.actionbar() 159 hotkey.actionbar()
154 end 160 end
161
155 162
156 163
157 hotkey.pet = function(self, event, arg1) 164 hotkey.pet = function(self, event, arg1)
158 if event == 'UNIT_PET' and arg1 == 'player' then 165 if event == 'UNIT_PET' and arg1 == 'player' then
159 if PetHasActionBar() and UnitIsVisible("pet") then 166 if PetHasActionBar() and UnitIsVisible("pet") then
174 end 181 end
175 end 182 end
176 end 183 end
177 184
178 185
186 --- used to pick up changes from user interaction
187 local changeIndex = 1
188 hotkey.binding = function()
189 print('|cFFFF0088BindingsUpdate')
190 local changeNum = #kb.ChangedBindings
191 if changeNum >= changeIndex then
192 for i = changeIndex, changeNum do
193 local actionType, actionID, name = unpack(kb.ChangedBindings[i])
194 local key = actionType .. '_' .. actionID
195 if actionFrames[key] then
196 hotkey.UpdateSkeletonKeyText(actionFrames[key] , actionType, actionID, HasAction(actionFrames[key].action))
197 end
198
199 changeIndex = i + 1
200 end
201
202 end
203 end