Mercurial > wow > skeletonkey
comparison SkeletonKey/HotKey.lua @ 62:04c23ceaf9e0
- fix taint caused by loading in combat
| author | Nenue |
|---|---|
| date | Mon, 05 Sep 2016 14:56:38 -0400 |
| parents | b7be92f62b05 |
| children | 2409fe9b81e1 |
comparison
equal
deleted
inserted
replaced
| 61:b7be92f62b05 | 62:04c23ceaf9e0 |
|---|---|
| 29 ["UPDATE_OVERRIDE_ACTIONBAR"] = {"override"}, | 29 ["UPDATE_OVERRIDE_ACTIONBAR"] = {"override"}, |
| 30 ["ACTIONBAR_PAGE_CHANGED"] = {"actionbar"}, | 30 ["ACTIONBAR_PAGE_CHANGED"] = {"actionbar"}, |
| 31 ["ACTIONBAR_SLOT_CHANGED"] = {"actionslot"}, | 31 ["ACTIONBAR_SLOT_CHANGED"] = {"actionslot"}, |
| 32 ["PLAYER_ENTERING_WORLD"] = {"world","all"}, | 32 ["PLAYER_ENTERING_WORLD"] = {"world","all"}, |
| 33 ["PET_UI_UPDATE"] = {"pet"}, | 33 ["PET_UI_UPDATE"] = {"pet"}, |
| 34 ["PLAYER_SPECIALIZATION_CHANGED"] = {"player"}, | |
| 35 ["PLAYER_TALENTS_UPDATED"] = {"player"}, | |
| 34 } | 36 } |
| 35 | 37 |
| 36 | 38 |
| 37 hotkey.wrapEvent = function(event, ...) | 39 hotkey.wrapEvent = function(event, ...) |
| 38 kb:RegisterEvent(event) | 40 hotkey:RegisterEvent(event) |
| 39 hotkeyEvents[event] = {...} | 41 hotkeyEvents[event] = {...} |
| 40 hotkey[event] = hotkey.UpdateFromEvent | 42 hotkey[event] = hotkey.UpdateFromEvent |
| 41 end | 43 end |
| 42 | 44 |
| 43 hotkey.unwrapEvent = function(event) | 45 hotkey.unwrapEvent = function(event) |
| 61 if hotkeyEvents[event] then | 63 if hotkeyEvents[event] then |
| 62 --print('call batch', event, ...) | 64 --print('call batch', event, ...) |
| 63 for i, func in ipairs(hotkeyEvents[event]) do | 65 for i, func in ipairs(hotkeyEvents[event]) do |
| 64 | 66 |
| 65 if hotkey[func] then | 67 if hotkey[func] then |
| 66 --print(' ', func) | 68 print('->|cFF88FF00', func) |
| 67 hotkey[func](self, event, ...) | 69 hotkey[func](self, event, ...) |
| 68 end | 70 end |
| 69 end | 71 end |
| 70 end | 72 end |
| 71 return true | 73 return true |
| 73 | 75 |
| 74 hotkey.variables = function() | 76 hotkey.variables = function() |
| 75 print('variables') | 77 print('variables') |
| 76 bindings = kb.GetBindings() | 78 bindings = kb.GetBindings() |
| 77 for event, manifest in pairs(hotkeyEvents) do | 79 for event, manifest in pairs(hotkeyEvents) do |
| 78 kb:RegisterEvent(event) | 80 print('-', event, table.concat(manifest, ', ')) |
| 81 hotkey:RegisterEvent(event) | |
| 79 hotkey[event] = hotkey.UpdateFromEvent | 82 hotkey[event] = hotkey.UpdateFromEvent |
| 80 end | 83 end |
| 81 hotkey.wrapEvent('UNIT_PET', 'pet') | 84 hotkey.wrapEvent('UNIT_PET', 'pet') |
| 82 hotkey.player() | 85 hotkey.player() |
| 83 end | 86 end |
| 88 hooksecurefunc("ActionBarButtonEventsFrame_RegisterFrame", hotkey.RegisterFrame) | 91 hooksecurefunc("ActionBarButtonEventsFrame_RegisterFrame", hotkey.RegisterFrame) |
| 89 | 92 |
| 90 end | 93 end |
| 91 | 94 |
| 92 hotkey.ui = function() | 95 hotkey.ui = function() |
| 93 print('ui') | 96 hotkey.player() |
| 94 --hotkey.player() | 97 hotkey.pet() |
| 95 --hotkey.pet() | |
| 96 end | 98 end |
| 97 | 99 |
| 98 | 100 |
| 99 hotkey.world = function() | 101 hotkey.world = function() |
| 100 print('world') | 102 -- needs to be delayed so it isn't fired 50 times at login |
| 101 hotkeyEvents["UPDATE_BINDINGS"] = {"binding"} | 103 hotkeyEvents["UPDATE_BINDINGS"] = {"binding"} |
| 102 hotkey.UPDATE_BINDINGS = hotkey.UpdateFromEvent | 104 hotkey.UPDATE_BINDINGS = hotkey.UpdateFromEvent |
| 103 hotkey:RegisterEvent("UPDATE_BINDINGS") | 105 hotkey:RegisterEvent("UPDATE_BINDINGS") |
| 104 | 106 |
| 105 hotkey.player() | 107 hotkey.player() |
| 106 hotkey.pet() | 108 hotkey.pet() |
| 107 | |
| 108 end | 109 end |
| 109 | 110 |
| 110 -- requires all these arguments since non-actionbar buttons don't have all of said methods | 111 -- requires all these arguments since non-actionbar buttons don't have all of said methods |
| 112 local kprint = (DEVIAN_WORKSPACE and function(...) _G.print('HotKeyUpdate', ...) end) or function() end | |
| 111 hotkey.UpdateHotKey = function(frame, actionType, actionID, hasAction) | 113 hotkey.UpdateHotKey = function(frame, actionType, actionID, hasAction) |
| 112 bindings = kb.GetBindings() | 114 bindings = kb.GetBindings() |
| 113 | 115 |
| 114 local indexKey = kb.FormatActionID(actionType, actionID) | 116 local indexKey = kb.FormatActionID(actionType, actionID) |
| 115 print('|cFF00FFFFUpdate|r', frame, indexKey, hasAction) | 117 --kprint(frame:GetName(), '|cFF88FF00'..indexKey..'|r', hasAction) |
| 116 | 118 |
| 117 | 119 |
| 118 if bindings[indexKey] then | 120 if bindings[indexKey] then |
| 119 print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction) | 121 kprint(' |cFFFF0088', actionType ..'|r', actionID, hasAction) |
| 120 local binds = bindings[indexKey] | 122 local binds = bindings[indexKey] |
| 121 if binds and (not frame.HotKey:IsVisible()) then | 123 if binds and (not frame.HotKey:IsVisible()) then |
| 122 if hasAction then | 124 if hasAction then |
| 123 local bindingsText = kb.BindingString(unpack(binds)) | 125 local bindingsText = kb.BindingString(unpack(binds)) |
| 124 | 126 |
| 125 if not hotkeyText[frame] then | 127 if not hotkeyText[frame] then |
| 126 print('-new hotkey element') | 128 kprint('-new hotkey element') |
| 127 hotkeyText[frame] = frame:CreateFontString(frame:GetName()..'SkeletonKey', 'OVERLAY') | 129 hotkeyText[frame] = frame:CreateFontString(frame:GetName()..'SkeletonKey', 'OVERLAY') |
| 128 hotkeyText[frame]:SetFont(frame.HotKey:GetFont()) | 130 hotkeyText[frame]:SetFont(frame.HotKey:GetFont()) |
| 129 hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor()) | 131 hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor()) |
| 130 hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT') | 132 hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT') |
| 131 | 133 |
| 134 end) | 136 end) |
| 135 end | 137 end |
| 136 | 138 |
| 137 hotkeyText[frame]:SetText(bindingsText) | 139 hotkeyText[frame]:SetText(bindingsText) |
| 138 hotkeyText[frame]:Show() | 140 hotkeyText[frame]:Show() |
| 139 print('|cFF00FFFFUpdate text for', frame:GetName(), '|cFFFFFF00'..tostring(bindingsText)..'|r') | 141 kprint(' |cFF00FFFF', frame:GetName(), '|cFFFFFF00'..tostring(bindingsText)..'|r') |
| 140 | 142 |
| 141 return | 143 return |
| 142 end | 144 end |
| 143 end | 145 end |
| 144 end | 146 end |
| 145 | 147 |
| 146 if hotkeyText[frame] then | 148 if hotkeyText[frame] then |
| 147 hotkeyText[frame]:SetText(nil) | 149 hotkeyText[frame]:SetText(nil) |
| 148 --print('|cFFFF4400cleared text from', frame:GetName()) | 150 print('|cFFFF4400' .. frame:GetName() .. '|r', 'remove text') |
| 149 end | 151 end |
| 150 end | 152 end |
| 151 | 153 |
| 152 hotkey.actionbar = function() | 154 hotkey.actionbar = function() |
| 153 wipe(actionFrames) | 155 wipe(actionFrames) |
| 158 | 160 |
| 159 local slot = frame.action | 161 local slot = frame.action |
| 160 local actionType, actionID = GetActionInfo(slot) | 162 local actionType, actionID = GetActionInfo(slot) |
| 161 local hasAction = HasAction(slot) | 163 local hasAction = HasAction(slot) |
| 162 local indexKey = kb.FormatActionID(actionType, actionID) | 164 local indexKey = kb.FormatActionID(actionType, actionID) |
| 165 | |
| 163 actionSlots[slot] = frame | 166 actionSlots[slot] = frame |
| 164 actionFrames[indexKey] = actionFrames[indexKey] or {} | 167 actionFrames[indexKey] = actionFrames[indexKey] or {} |
| 165 if not tContains(actionFrames[indexKey]) then | 168 if not tContains(actionFrames[indexKey]) then |
| 166 tinsert(actionFrames[indexKey], frame) | 169 tinsert(actionFrames[indexKey], frame) |
| 167 actionIndex[slot] = indexKey | 170 actionIndex[slot] = indexKey |
| 172 end | 175 end |
| 173 end | 176 end |
| 174 | 177 |
| 175 hotkey.actionslot = function(self, event, slot) | 178 hotkey.actionslot = function(self, event, slot) |
| 176 print(actionSlots[slot], event, slot, GetActionInfo(slot)) | 179 print(actionSlots[slot], event, slot, GetActionInfo(slot)) |
| 177 --print(GetActionButtonForID(slot)) | |
| 178 local atype, aid = GetActionInfo(slot) | 180 local atype, aid = GetActionInfo(slot) |
| 179 local indexKey = kb.FormatActionID(atype, aid) | 181 local indexKey = kb.FormatActionID(atype, aid) |
| 180 local frame = actionSlots[slot] | 182 local frame = actionSlots[slot] |
| 183 actionFrames[indexKey] = actionFrames[indexKey] or {} | |
| 184 if not tContains(actionFrames[indexKey]) then | |
| 185 tinsert(actionFrames[indexKey], frame) | |
| 186 actionIndex[slot] = indexKey | |
| 187 end | |
| 181 if frame then | 188 if frame then |
| 182 hotkey.UpdateHotKey(frame, atype, aid, HasAction(slot)) | 189 hotkey.UpdateHotKey(frame, atype, aid, HasAction(slot)) |
| 183 end | 190 end |
| 184 | 191 |
| 185 end | 192 end |
