comparison SkeletonKey/BindingsFrame.lua @ 57:9eebce04e69b

- Prevent bind settings from being updated in combat. - Close the UI during combat. - Resolve conflicting keybinds and inform the user of any results. - Resolve conflicts for talents, but only when they are active.
author Nenue
date Mon, 22 Aug 2016 09:24:02 -0400
parents 81a7c71c4483
children 2409fe9b81e1
comparison
equal deleted inserted replaced
56:2a95f4010c5a 57:9eebce04e69b
49 local tonumber, tostring = tonumber, tostring 49 local tonumber, tostring = tonumber, tostring
50 local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor 50 local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor
51 local IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown = IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown 51 local IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown = IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown
52 local GetBindingAction, GetBindingKey, GetCurrentBindingSet = GetBindingAction, GetBindingKey, GetCurrentBindingSet 52 local GetBindingAction, GetBindingKey, GetCurrentBindingSet = GetBindingAction, GetBindingKey, GetCurrentBindingSet
53 local SetBinding, SaveBindings = SetBinding, SaveBindings 53 local SetBinding, SaveBindings = SetBinding, SaveBindings
54 local GetSpellInfo, InCombatLockdown = GetSpellInfo, InCombatLockdown
54 55
55 kb.ProcessInput = function(key) 56 kb.ProcessInput = function(key)
56 if key == 'ESCAPE' then 57 if key == 'ESCAPE' then
57 kb.DeactivateSlot(kb.saveTarget) 58 kb.DeactivateSlot(kb.saveTarget)
58 kb.ui() 59 kb.ui()
497 kb.SaveSlot = function(self, key) 498 kb.SaveSlot = function(self, key)
498 499
499 if not self.command then 500 if not self.command then
500 return 501 return
501 end 502 end
503 if InCombatLockdown() then
504 kb:print(L('Bindings cannot be changed during combat.'))
505 return
506 end
507
508
502 print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key) 509 print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key)
503 510
504 local modifier = '' 511 local modifier = ''
505 if IsAltKeyDown() then 512 if IsAltKeyDown() then
506 modifier = 'ALT-' 513 modifier = 'ALT-'
542 local currentHotKeys = {GetBindingKey(self.command)} 549 local currentHotKeys = {GetBindingKey(self.command)}
543 local found 550 local found
544 for i, key in ipairs(currentHotKeys) do 551 for i, key in ipairs(currentHotKeys) do
545 if key == binding then 552 if key == binding then
546 found = true 553 found = true
547 kb:print('hotkey already assigned') 554 print('|cFFFF4400key already bound to this')
555 return true
548 end 556 end
549 end 557 end
550 if not found then 558 if not found then
551 tinsert(currentHotKeys, 1, binding) 559 tinsert(currentHotKeys, 1, binding)
552 kb.UpdateBindingsCache(self.actionType, self.actionID, currentHotKeys) 560 kb.UpdateBindingsCache(self.actionType, self.actionID, currentHotKeys)
553 end 561 end
554 562
563 -- scour profile data for any conflicting binds
564 local currentAction = GetBindingAction(binding)
565 if match(currentAction, 'KeyBinder') then
566 if currentAction ~= self.command then
567 print('|cFFFF4400removing bindings for:', currentAction)
568 for profileID, profileData in ipairs(kb.loadedProfiles) do
569 local buttonID = profileData.commands[currentAction]
570 if buttonID then
571 local buttonAction = profileData.buttons[buttonID][2]
572 if buttonAction then
573 local talentInfo = profileData.talents[buttonAction]
574 if talentInfo and GetSpellInfo(buttonAction) then
575 for i = #talentInfo, 5, -1 do
576 if binding == talentInfo[i] then
577 tremove(talentInfo, i)
578 end
579 end
580 kb:print(L('Overwrote talent |cFF88FF00%s|r in |cFF00FFFF%s|r', buttonAction, kb.configHeaders[profileID]))
581 else
582
583 kb:print(L('Overwrote |cFFFFFF00%s|r in |cFF00FFFF%s|r', buttonAction, kb.configHeaders[profileID]))
584 end
585 profileData.bindings[binding] = nil
586 end
587 end
588 end
589 end
590 end
555 591
556 592
557 print('SetBinding', binding, self.command) 593 print('SetBinding', binding, self.command)
558 SetBinding(binding, self.command) 594 SetBinding(binding, self.command)
559 SaveBindings(GetCurrentBindingSet()) 595 SaveBindings(GetCurrentBindingSet())
586 if kb.currentProfile.talents[self.actionID] then 622 if kb.currentProfile.talents[self.actionID] then
587 kb.currentProfile.talents[self.actionID] = nil 623 kb.currentProfile.talents[self.actionID] = nil
588 end 624 end
589 end 625 end
590 626
627
591 kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.currentHeader)) 628 kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.currentHeader))
592 kb.UpdateSlot(self, true) 629 kb.ui()
593 return true 630 return true
594 end 631 end
595 632
596 633
597 kb.UnbindSlot = function(self) 634 kb.UnbindSlot = function(self)