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