Mercurial > wow > skeletonkey
comparison SkeletonKey/HotKey.lua @ 50:1aba8a6fd4a9
- fix kb.bindings content and define a generic function for constructing its keystrings
- handle hotkey text for actions placed in multiple slots
-- hotkey.actionbar generates a cache table for use during binding changes
author | Nenue |
---|---|
date | Fri, 19 Aug 2016 01:12:56 -0400 |
parents | bb160c04de88 |
children | a545933ddf3d |
comparison
equal
deleted
inserted
replaced
49:9a9d7f2a7c07 | 50:1aba8a6fd4a9 |
---|---|
2 -- HotKey.lua | 2 -- HotKey.lua |
3 -- Created: 7/22/2016 10:28 PM | 3 -- Created: 7/22/2016 10:28 PM |
4 -- %file-revision% | 4 -- %file-revision% |
5 -- Module for fixing actionbar hotkey text | 5 -- Module for fixing actionbar hotkey text |
6 | 6 |
7 local _G, wipe, tContains, tinsert = _G, table.wipe, tContains, tinsert | |
7 local kb, print, wrap = LibStub("LibKraken").register(KeyBinder, 'HotKey') | 8 local kb, print, wrap = LibStub("LibKraken").register(KeyBinder, 'HotKey') |
8 local hotkey = {} | 9 local hotkey = {} |
9 local hotkeyText = {} | 10 local hotkeyText = {} |
10 local blizHotKey = {} | 11 local blizHotKey = {} |
11 local bindings | 12 local bindings |
97 hotkey.pet() | 98 hotkey.pet() |
98 | 99 |
99 end | 100 end |
100 | 101 |
101 -- requires all these arguments since non-actionbar buttons don't have all of said methods | 102 -- requires all these arguments since non-actionbar buttons don't have all of said methods |
102 hotkey.UpdateSkeletonKeyText = function(frame, actionType, actionID, hasAction) | 103 hotkey.UpdateHotKey = function(frame, actionType, actionID, hasAction) |
103 bindings = kb.GetBindings() | 104 bindings = kb.GetBindings() |
104 print(frame, actionType, actionID, hasAction) | 105 |
105 | 106 local indexKey = kb.FormatActionID(actionType, actionID) |
106 local indexKey = tostring(actionType) .. '_' .. tostring(actionID) | 107 print('|cFF00FFFFUpdate|r', frame, indexKey, hasAction) |
107 local oldKey = actionIndex[frame] | 108 |
108 if hasAction and not actionFrames[indexKey] then | 109 |
109 actionFrames[indexKey] = frame | 110 if bindings[indexKey] then |
110 actionIndex[frame] = indexKey | |
111 print('|cFF00FF00['..indexKey.. '] = '.. tostring(frame)) | |
112 end | |
113 | |
114 if bindings[actionType] then | |
115 --print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction) | 111 --print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction) |
116 local binds = bindings[actionType][actionID] | 112 local binds = bindings[indexKey] |
117 if binds then | 113 if binds then |
118 if hasAction and not frame.HotKey:IsVisible() then | 114 if hasAction then |
115 local bindingsText = kb.BindingString(unpack(binds)) | |
116 | |
119 if not hotkeyText[frame] then | 117 if not hotkeyText[frame] then |
120 hotkeyText[frame] = frame:CreateFontString('KeyBinderHotKeyText', 'OVERLAY') | 118 print('-new hotkey element') |
119 hotkeyText[frame] = frame:CreateFontString(frame:GetName()..'SkeletonKey', 'OVERLAY') | |
121 hotkeyText[frame]:SetFont(frame.HotKey:GetFont()) | 120 hotkeyText[frame]:SetFont(frame.HotKey:GetFont()) |
122 hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor()) | 121 hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor()) |
123 hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT') | 122 hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT') |
124 end | 123 end |
125 | 124 |
126 hotkeyText[frame]:SetText(kb.BindingString(unpack(binds))) | 125 hotkeyText[frame]:SetText(bindingsText) |
127 print('|cFF00FFFFUpdate text for', frame:GetName()) | 126 hotkeyText[frame]:Show() |
128 print(unpack(binds)) | 127 print('|cFF00FFFFUpdate text for', frame:GetName(), '|cFFFFFF00'..tostring(bindingsText)..'|r') |
128 | |
129 return | 129 return |
130 end | 130 end |
131 end | 131 end |
132 end | 132 end |
133 | 133 |
136 --print('|cFFFF4400cleared text from', frame:GetName()) | 136 --print('|cFFFF4400cleared text from', frame:GetName()) |
137 end | 137 end |
138 end | 138 end |
139 | 139 |
140 hotkey.actionbar = function() | 140 hotkey.actionbar = function() |
141 wipe(actionFrames) | |
142 -- reset frames list | |
143 | |
141 if ActionBarButtonEventsFrame.frames then | 144 if ActionBarButtonEventsFrame.frames then |
142 for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do | 145 for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do |
143 local actionType, actionID = GetActionInfo(frame.action) | 146 local slot = frame.action |
144 local hasAction = HasAction(frame.action) | 147 local actionType, actionID = GetActionInfo(slot) |
145 actionSlots[frame.action] = frame | 148 local hasAction = HasAction(slot) |
146 hotkey.UpdateSkeletonKeyText(frame, actionType, actionID, hasAction) | 149 local indexKey = kb.FormatActionID(actionType, actionID) |
150 actionSlots[slot] = frame | |
151 actionFrames[indexKey] = actionFrames[indexKey] or {} | |
152 if not tContains(actionFrames[indexKey]) then | |
153 tinsert(actionFrames[indexKey], frame) | |
154 actionIndex[slot] = indexKey | |
155 end | |
156 | |
157 hotkey.UpdateHotKey(frame, actionType, actionID, hasAction) | |
147 end | 158 end |
148 end | 159 end |
149 end | 160 end |
150 | 161 |
151 hotkey.actionslot = function(self, event, slot) | 162 hotkey.actionslot = function(self, event, slot) |
152 print(actionSlots[slot], event, slot, GetActionInfo(slot)) | 163 print(actionSlots[slot], event, slot, GetActionInfo(slot)) |
153 --print(GetActionButtonForID(slot)) | 164 --print(GetActionButtonForID(slot)) |
154 local atype, aid = GetActionInfo(slot) | 165 local atype, aid = GetActionInfo(slot) |
155 if actionSlots[slot] then | 166 local indexKey = kb.FormatActionID(atype, aid) |
156 hotkey.UpdateSkeletonKeyText(actionSlots[slot], atype, aid, HasAction(slot)) | 167 local frame = actionSlots[slot] |
168 if frame then | |
169 hotkey.UpdateHotKey(frame, atype, aid, HasAction(slot)) | |
157 end | 170 end |
158 | 171 |
159 end | 172 end |
160 | 173 |
161 hotkey.player = function() | 174 hotkey.player = function() |
190 local changeIndex = 1 | 203 local changeIndex = 1 |
191 hotkey.binding = function() | 204 hotkey.binding = function() |
192 print('|cFFFF0088BindingsUpdate') | 205 print('|cFFFF0088BindingsUpdate') |
193 local changeNum = #kb.ChangedBindings | 206 local changeNum = #kb.ChangedBindings |
194 if changeNum >= changeIndex then | 207 if changeNum >= changeIndex then |
208 | |
209 | |
195 for i = changeIndex, changeNum do | 210 for i = changeIndex, changeNum do |
196 local actionType, actionID, name = unpack(kb.ChangedBindings[i]) | 211 local actionType, actionID, name = unpack(kb.ChangedBindings[i]) |
197 local key = actionType .. '_' .. actionID | 212 local actionKey = kb.FormatActionID(actionType, actionID) |
198 if actionFrames[key] then | 213 local frames = actionFrames[actionKey] |
199 hotkey.UpdateSkeletonKeyText(actionFrames[key] , actionType, actionID, HasAction(actionFrames[key].action)) | 214 if frames then |
215 for i, frame in ipairs(frames) do | |
216 print('|cFFFF0088'..actionKey..'|r', frame) | |
217 if frame then | |
218 hotkey.UpdateHotKey(frame , actionType, actionID, HasAction(frame.action)) | |
219 end | |
220 end | |
221 else | |
222 print('no frames picked up, rebuild') | |
223 hotkey.actionbar() | |
200 end | 224 end |
201 | 225 |
202 changeIndex = i + 1 | 226 changeIndex = i + 1 |
203 end | 227 end |
204 | 228 |