Mercurial > wow > skeletonkey
comparison SkeletonKey/KeySlot.lua @ 16:cdd387d39137
filename refactor
author | Nenue |
---|---|
date | Fri, 29 Jul 2016 21:18:15 -0400 |
parents | 32d64e42ec9b |
children | 500f9b2bd9ac |
comparison
equal
deleted
inserted
replaced
15:32d64e42ec9b | 16:cdd387d39137 |
---|---|
1 -- SkeletonKey | 1 -- SkeletonKey |
2 -- KeySlot.lua | 2 -- KeySlot.lua |
3 -- Created: 7/28/2016 11:26 PM | 3 -- Created: 7/28/2016 11:26 PM |
4 -- %file-revision% | 4 -- %file-revision% |
5 -- All the internal slot logic is kept here | 5 -- Code dealing with the slot button innards; they are invoked by frame script and should only chain to Set/Release |
6 | 6 |
7 local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot') | 7 local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot') |
8 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION | 8 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION |
9 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 | 9 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 |
10 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1} | 10 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1} |
11 local BORDER_ASSIGNED = {1,1,1,1} | 11 local BORDER_ASSIGNED = {1,1,1,1} |
12 local BORDER_DYNAMIC = {1,1,0,1} | 12 local BORDER_DYNAMIC = {1,1,0,1} |
13 local BORDER_PENDING = {1,0.5,0,1 } | 13 local BORDER_PENDING = {1,0.5,0,1 } |
14 | |
15 local BUTTON_HEADERS = { | 14 local BUTTON_HEADERS = { |
16 ['spell'] = SPELLS, | 15 ['spell'] = SPELLS, |
17 ['macro'] = MACRO, | 16 ['macro'] = MACRO, |
18 ['petaction'] = PET, | 17 ['petaction'] = PET, |
19 ['mount'] = MOUNT, | 18 ['mount'] = MOUNT, |
442 self.profile = kb.db.bindMode | 441 self.profile = kb.db.bindMode |
443 self:RegisterForDrag('LeftButton') | 442 self:RegisterForDrag('LeftButton') |
444 end | 443 end |
445 | 444 |
446 | 445 |
446 --- Updates the current KeyBinding for the button's command | |
447 kb.SaveSlot = function(self, key) | |
448 | |
449 if not self.command then | |
450 return | |
451 end | |
452 | |
453 if key:match('[RL]SHIFT') or key:match('[RL]ALT') or key:match('[RL]CTRL') then | |
454 return | |
455 end | |
456 print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key) | |
457 | |
458 local modifier = '' | |
459 if IsAltKeyDown() then | |
460 modifier = 'ALT-' | |
461 end | |
462 if IsControlKeyDown() then | |
463 modifier = modifier.. 'CTRL-' | |
464 end | |
465 if IsShiftKeyDown() then | |
466 modifier = modifier..'SHIFT-' | |
467 end | |
468 local binding = modifier..key | |
469 | |
470 if key == 'ESCAPE' then | |
471 local keys = {GetBindingKey(self.command) } | |
472 --print('detected', #keys, 'bindings') | |
473 for i, key in pairs(keys) do | |
474 --print('clearing', key) | |
475 SetBinding(key, nil) | |
476 SaveBindings(GetCurrentBindingSet()) | |
477 if kb.currentProfile.bindings[key] then | |
478 kb:print(L('BINDING_REMOVED', self.actionName, kb.configHeaders[db.bindMode])) | |
479 kb.currentProfile.bindings[key] = nil | |
480 end | |
481 if kb.currentProfile.talents[self.actionName] then | |
482 kb.currentProfile.talents[self.actionName] = nil | |
483 end | |
484 bindings[self.actionType][self.actionID] = nil | |
485 end | |
486 if kb.currentProfile.bound[self.command] then | |
487 kb.currentProfile.bound[self.command] = nil | |
488 --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode])) | |
489 end | |
490 | |
491 self.active = false | |
492 else | |
493 if kb.SystemBinds[binding] then | |
494 kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, kb.SystemBinds[binding])) | |
495 return | |
496 end | |
497 | |
498 | |
499 if self.command then | |
500 | |
501 local previousKeys | |
502 local previousAction = GetBindingAction(binding) | |
503 local binding1, binding2, new1, new2 | |
504 print(type(previousAction), previousAction) | |
505 if previousAction ~= "" and previousAction ~= self.command then | |
506 if protected[previousAction] then | |
507 -- bounce out if trying to use a protected key | |
508 kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, GetBindingAction(binding))) | |
509 kb.bindingstext:SetText(nil) | |
510 return | |
511 else | |
512 kb:print('Discarding keybind for', previousAction) | |
513 -- todo: sort out retcon'd talent spells | |
514 end | |
515 end | |
516 | |
517 self.binding = binding | |
518 | |
519 SetBinding(self.binding, self.command) | |
520 SaveBindings(GetCurrentBindingSet()) | |
521 | |
522 local talentInfo | |
523 if self.actionType == 'spell' and kb.TalentCache[self.actionID] then | |
524 print('conditional binding (talent = "'..self.actionName..'")') | |
525 talentInfo = {self.macroName, self.actionName, self.actionType, self.actionID} | |
526 local bindings = {GetBindingKey(self.command) } | |
527 for i, key in ipairs(bindings) do | |
528 tinsert(talentInfo, key) | |
529 end | |
530 end | |
531 | |
532 for level, profile in ipairs(kb.orderedProfiles) do | |
533 if (level == db.bindMode) then | |
534 profile.bound[self.command] = true | |
535 if talentInfo then | |
536 profile.bindings[self.binding] = nil | |
537 else | |
538 profile.bindings[self.binding] = self.command | |
539 end | |
540 profile.talents[self.actionName] = talentInfo | |
541 else | |
542 profile.bindings[self.binding] = nil | |
543 profile.bound[self.command] = nil | |
544 kb.currentProfile.talents[self.actionName] = nil | |
545 end | |
546 if kb.currentProfile.talents[self.actionID] then | |
547 kb.currentProfile.talents[self.actionID] = nil | |
548 end | |
549 end | |
550 | |
551 kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.configHeaders[db.bindMode])) | |
552 end | |
553 end | |
554 kb.UpdateSlot(self, true) | |
555 KeyBinderSaveButton:Enable() | |
556 end | |
557 | |
558 | |
447 | 559 |
448 --- Add to blizzard interfaces | 560 --- Add to blizzard interfaces |
449 StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = { | 561 StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = { |
450 text = "Confirm moving an assigned command.", | 562 text = "Confirm moving an assigned command.", |
451 button1 = OKAY, | 563 button1 = OKAY, |