Mercurial > wow > reaction
comparison ReAction.lua @ 88:fc83b3f5b322
Added keybindings using LibKeyBound-1.0, with modifications for Override bindings instead of standard bindings.
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Sun, 31 Aug 2008 06:02:18 +0000 |
parents | 57f8151ea0f0 |
children | 7cabc8ac6c16 |
comparison
equal
deleted
inserted
replaced
87:3499ac7c3a9b | 88:fc83b3f5b322 |
---|---|
49 end | 49 end |
50 ReAction.dbprint = dbprint | 50 ReAction.dbprint = dbprint |
51 | 51 |
52 ------ LIBRARIES ------ | 52 ------ LIBRARIES ------ |
53 local callbacks = LibStub("CallbackHandler-1.0"):New(ReAction) | 53 local callbacks = LibStub("CallbackHandler-1.0"):New(ReAction) |
54 local KB = LibStub("LibKeyBound-1.0") | |
54 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction") | 55 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction") |
55 ReAction.L = L | 56 ReAction.L = L |
56 | 57 |
57 ------ PRIVATE ------ | 58 ------ PRIVATE ------ |
58 local private = { } | 59 local weak = {__mode="k"} |
60 local private = { | |
61 allKB = setmetatable({}, weak), | |
62 kbHooked = setmetatable({}, weak), | |
63 } | |
59 local bars = {} | 64 local bars = {} |
60 local defaultBarConfig = {} | 65 local defaultBarConfig = {} |
61 local barOptionGenerators = { } | 66 local barOptionGenerators = { } |
62 local options = { | 67 local options = { |
63 type = "group", | 68 type = "group", |
196 self:ShowEditor() | 201 self:ShowEditor() |
197 elseif option == "unlock" then | 202 elseif option == "unlock" then |
198 self:SetConfigMode(true) | 203 self:SetConfigMode(true) |
199 elseif option == "lock" then | 204 elseif option == "lock" then |
200 self:SetConfigMode(false) | 205 self:SetConfigMode(false) |
206 elseif option == "kb" then | |
207 self:SetKeybindMode(true) | |
201 else | 208 else |
202 self:Print(("%3.1f.%d"):format(version,self.revision)) | 209 self:Print(("%3.1f.%d"):format(version,self.revision)) |
203 self:Print("/rxn config") | 210 self:Print("/rxn config") |
204 self:Print("/rxn edit") | 211 self:Print("/rxn edit") |
205 self:Print("/rxn lock") | 212 self:Print("/rxn lock") |
206 self:Print("/rxn unlock") | 213 self:Print("/rxn unlock") |
214 self:Print("/rxn kb") | |
207 end | 215 end |
208 end | 216 end |
209 end | 217 end |
210 | 218 |
211 | 219 |
221 -- default profile is character-specific | 229 -- default profile is character-specific |
222 ) | 230 ) |
223 self.db.RegisterCallback(self,"OnProfileChanged") | 231 self.db.RegisterCallback(self,"OnProfileChanged") |
224 self.db.RegisterCallback(self,"OnProfileReset","OnProfileChanged") | 232 self.db.RegisterCallback(self,"OnProfileReset","OnProfileChanged") |
225 | 233 |
234 KB.RegisterCallback(self,"LIBKEYBOUND_ENABLED") | |
235 KB.RegisterCallback(self,"LIBKEYBOUND_DISABLED") | |
236 | |
226 options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) | 237 options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) |
227 | 238 |
228 self:RegisterChatCommand("reaction", SlashHandler) | 239 self:RegisterChatCommand("reaction", SlashHandler) |
229 self:RegisterChatCommand("rxn", SlashHandler) | 240 self:RegisterChatCommand("rxn", SlashHandler) |
230 self:RegisterEvent("PLAYER_REGEN_DISABLED") | 241 self:RegisterEvent("PLAYER_REGEN_DISABLED") |
245 | 256 |
246 function ReAction:PLAYER_REGEN_DISABLED() | 257 function ReAction:PLAYER_REGEN_DISABLED() |
247 if private.configMode == true then | 258 if private.configMode == true then |
248 self:UserError(L["ReAction config mode disabled during combat."]) | 259 self:UserError(L["ReAction config mode disabled during combat."]) |
249 self:SetConfigMode(false) | 260 self:SetConfigMode(false) |
250 end | 261 self:SetKeybindMode(false) |
262 end | |
263 end | |
264 | |
265 function ReAction:LIBKEYBOUND_ENABLED( evt ) | |
266 self:SetKeybindMode(true) | |
267 end | |
268 | |
269 function ReAction:LIBKEYBOUND_DISABLED( evt ) | |
270 return self:SetKeybindMode(false) | |
251 end | 271 end |
252 | 272 |
253 | 273 |
254 | 274 |
255 ------ API ------ | 275 ------ API ------ |
463 end | 483 end |
464 | 484 |
465 function ReAction:ShowEditor(bar, ...) | 485 function ReAction:ShowEditor(bar, ...) |
466 CallModuleMethod("ConfigUI","LaunchBarEditor",bar, ...) | 486 CallModuleMethod("ConfigUI","LaunchBarEditor",bar, ...) |
467 end | 487 end |
488 | |
489 | |
490 local kb_onEnter | |
491 do | |
492 function kb_onEnter( self ) | |
493 if ReAction:GetKeybindMode() then | |
494 KB:Set(self) | |
495 end | |
496 end | |
497 end | |
498 | |
499 function ReAction:SetKeybindMode( mode ) | |
500 if mode ~= private.kbMode then | |
501 if mode then | |
502 for f in pairs(private.allKB) do | |
503 if not private.kbHooked[f] then | |
504 -- avoid taint, particularly with SecureAnchorEnterTemplate | |
505 -- don't hook scripts multiple times, there isn't any unhook! | |
506 f:HookScript("OnEnter",kb_onEnter) | |
507 private.kbHooked[f] = true | |
508 end | |
509 end | |
510 KB:Activate() | |
511 else | |
512 KB:Deactivate() | |
513 end | |
514 private.kbMode = KB:IsShown() or false | |
515 end | |
516 end | |
517 | |
518 function ReAction:GetKeybindMode( mode ) | |
519 return private.kbMode | |
520 end | |
521 | |
522 function ReAction:RegisterKeybindFrame( f ) | |
523 private.allKB[f] = true | |
524 end | |
525 | |
526 function ReAction:FreeOverrideHotkey( key ) | |
527 for f in pairs(private.allKB) do | |
528 if f.GetBindings then | |
529 for i = 1, select('#', f:GetBindings()) do | |
530 if select(i, f:GetBindings()) == key then | |
531 if f.FreeKey then | |
532 return f:FreeKey(key) | |
533 else | |
534 local action = f.GetActionName and f:GetActionName() or f:GetName() | |
535 SetOverrideBinding(f, false, key, nil) | |
536 return action | |
537 end | |
538 end | |
539 end | |
540 end | |
541 end | |
542 end |