Mercurial > wow > skeletonkey
comparison SkeletonKey/BindingsFrame.lua @ 52:81a7c71c4483
- fixed safety override
- fixed pet journal drag/drop
- fixed confirmation cancel button
author | Nenue |
---|---|
date | Fri, 19 Aug 2016 10:46:36 -0400 |
parents | 1aba8a6fd4a9 |
children | 9eebce04e69b |
comparison
equal
deleted
inserted
replaced
51:d0ee4553061a | 52:81a7c71c4483 |
---|---|
1 -- KrakTool | 1 -- KrakTool |
2 -- BindingsFrame.lua | 2 -- BindingsFrame.lua |
3 -- Created: 7/28/2016 3:39 PM | 3 -- Created: 7/28/2016 3:39 PM |
4 -- %file-revision% | 4 -- %file-revision% |
5 -- Code piecing the interface together | 5 -- Handles the arrangement of and interaction with the SkeletonKey frame |
6 | 6 --[=[ |
7 local kb, print = LibStub("LibKraken").register(KeyBinder, 'KeySlot') | 7 -- some useful texture paths |
8 [[Interface\PaperDollInfoFrame\UI-GearManager-Undo]] | |
9 [[Interface\PetPaperDollFrame\UI-PetHappiness]] | |
10 [[Interface\RAIDFRAME\ReadyCheck-Waiting]] | |
11 [[Interface\RAIDFRAME\ReadyCheck-Read]] | |
12 [[Interface\RAIDFRAME\ReadyCheck-NotReady]] | |
13 [[Interface\TradeSkillFrame\UI-TradeSkill-LinkButton]] | |
14 [[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]] | |
15 [[Interface\UI-TutorialFrame-QuestGiver\UI-TutorialFrame-QuestGray]] | |
16 --]=] | |
17 | |
18 local kb, print = LibStub("LibKraken").register(KeyBinder, 'BindingsUI') | |
19 local L = kb.L | |
8 local BINDS_PER_ROW = 2 | 20 local BINDS_PER_ROW = 2 |
9 local BINDING_TYPE_SPECIALIZATION = 3 | 21 local BINDING_TYPE_SPECIALIZATION = 3 |
10 local BINDING_TYPE_CHARACTER = 2 | 22 local BINDING_TYPE_CHARACTER = 2 |
11 local BINDING_TYPE_GLOBAL = 1 | 23 local BINDING_TYPE_GLOBAL = 1 |
12 local BUTTON_HSPACING = 128 | 24 local BUTTON_HSPACING = 128 |
30 [BINDING_TYPE_SPECIALIZATION] = {0, 1, 1}, | 42 [BINDING_TYPE_SPECIALIZATION] = {0, 1, 1}, |
31 [BINDING_TYPE_CHARACTER] = {0, 1, 0}, | 43 [BINDING_TYPE_CHARACTER] = {0, 1, 0}, |
32 [BINDING_TYPE_GLOBAL] = {0, 1, 1} | 44 [BINDING_TYPE_GLOBAL] = {0, 1, 1} |
33 } | 45 } |
34 | 46 |
35 --[=[ | 47 local match, strupper = string.match, string.upper |
36 -- some useful texture paths | 48 local tremove, tinsert, ipairs, pairs, unpack = table.remove, table.insert, ipairs, pairs, unpack |
37 [[Interface\PaperDollInfoFrame\UI-GearManager-Undo]] | 49 local tonumber, tostring = tonumber, tostring |
38 [[Interface\PetPaperDollFrame\UI-PetHappiness]] | 50 local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor |
39 [[Interface\RAIDFRAME\ReadyCheck-Waiting]] | 51 local IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown = IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown |
40 [[Interface\RAIDFRAME\ReadyCheck-Read]] | 52 local GetBindingAction, GetBindingKey, GetCurrentBindingSet = GetBindingAction, GetBindingKey, GetCurrentBindingSet |
41 [[Interface\RAIDFRAME\ReadyCheck-NotReady]] | 53 local SetBinding, SaveBindings = SetBinding, SaveBindings |
42 [[Interface\TradeSkillFrame\UI-TradeSkill-LinkButton]] | 54 |
43 [[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]] | 55 kb.ProcessInput = function(key) |
44 [[Interface\UI-TutorialFrame-QuestGiver\UI-TutorialFrame-QuestGray]] | |
45 --]=] | |
46 local lastFolder | |
47 local addT = function(frame, key, folder, name) | |
48 folder = folder or lastFolder | |
49 frame[key] = frame:CreateTexture() | |
50 frame[key]:SetTexture('Interface\\' .. folder .. '\\' .. name) | |
51 frame[key]:SetPoint('TOPLEFT') | |
52 lastFolder = folder | |
53 end | |
54 | |
55 local restingAlpha = 0.7 | |
56 local fadeTime, fadeDelay = .30, 0.15 | |
57 local saveButton | |
58 | |
59 local KeyButton_OnKeyDown = function(self, key) | |
60 kb.saveTarget.border:SetColorTexture(1,1,1,1) | |
61 end | |
62 local KeyButton_OnKeyUp = function(self, key) | |
63 kb.UpdateSlot(kb.saveTarget) | |
64 if key == 'ESCAPE' then | 56 if key == 'ESCAPE' then |
65 kb.DeactivateSlot(kb.saveTarget) | 57 kb.DeactivateSlot(kb.saveTarget) |
66 kb.ui() | 58 kb.ui() |
67 return | 59 return |
68 end | 60 end |
69 if key:match('[RL]SHIFT') or key:match('[RL]ALT') or key:match('[RL]CTRL') then | 61 |
62 if (match(key, '[RL]SHIFT') or match(key, '[RL]ALT') or match(key, '[RL]CTRL')) then | |
70 return | 63 return |
71 elseif kb.saveTarget then | 64 end |
65 | |
66 if kb.saveTarget then | |
72 if kb.SaveSlot(kb.saveTarget, key) then | 67 if kb.SaveSlot(kb.saveTarget, key) then |
73 if not (kb.db.stickyMode or kb.db.hoverInput) then | 68 if not (kb.db.stickyMode or kb.db.hoverInput) then |
74 kb.DeactivateSlot(kb.saveTarget) | 69 kb.DeactivateSlot(kb.saveTarget) |
75 end | 70 end |
76 kb.ui() | 71 end |
77 end | 72 kb.ui() |
78 end | 73 end |
74 end | |
75 | |
76 local lastFolder | |
77 local restingAlpha = 0.7 | |
78 local fadeTime, fadeDelay = .30, 0.15 | |
79 local saveButton | |
80 | |
81 local KeyButton_OnKeyDown = function(self, key) | |
82 local st = kb.saveTarget | |
83 kb.ProcessInput(key) | |
84 end | |
85 local KeyButton_OnKeyUp = function(self, key) | |
86 local st = kb.saveTarget | |
79 end | 87 end |
80 | 88 |
81 local KeyButton_OnClick = function(self, click) | 89 local KeyButton_OnClick = function(self, click) |
82 print(self:GetName(), 'OnMouseDown', click) | 90 print(self:GetName(), 'OnMouseDown', click) |
83 local cursorType = GetCursorInfo() | 91 local cursorType = GetCursorInfo() |
95 end | 103 end |
96 end | 104 end |
97 elseif click == 'RightButton' then | 105 elseif click == 'RightButton' then |
98 kb.ReleaseSlot(self) | 106 kb.ReleaseSlot(self) |
99 kb.ui() | 107 kb.ui() |
100 elseif kb.saveTarget then | 108 else |
101 if kb.SaveSlot(kb.saveTarget, string.upper(click)) then | 109 kb.ProcessInput(strupper(click)) |
102 if not (kb.db.stickyMode or kb.db.hoverInput) then | |
103 kb.DeactivateSlot(kb.saveTarget) | |
104 end | |
105 kb.ui() | |
106 end | |
107 end | 110 end |
108 end | 111 end |
109 | 112 |
110 local KeyButton_OnDragStart = function(self) | 113 local KeyButton_OnDragStart = function(self) |
111 kb.PickupSlot(self) | 114 kb.PickupSlot(self) |
211 end | 214 end |
212 | 215 |
213 frame.header:SetText(header) | 216 frame.header:SetText(header) |
214 | 217 |
215 frame:SetScript('OnClick', function(self) | 218 frame:SetScript('OnClick', function(self) |
219 kb.db[dbKey] = self:GetChecked() | |
216 if callback then | 220 if callback then |
217 callback(self) | 221 callback(self) |
218 end | |
219 kb.db[dbKey] = self:GetChecked() | |
220 if not kb.db[dbKey] then | |
221 if kb.saveTarget then | |
222 kb.DeactivateSlot(kb.saveTarget) | |
223 end | |
224 end | 222 end |
225 kb.ui() | 223 kb.ui() |
226 end) | 224 end) |
227 | 225 |
228 frame:SetScript('OnEnter', function(self) | 226 frame:SetScript('OnEnter', function(self) |
358 kb:uibutton( | 356 kb:uibutton( |
359 'KeyBinderInventoryButton', 'Bags', nil, | 357 'KeyBinderInventoryButton', 'Bags', nil, |
360 function() OpenAllBags() end, | 358 function() OpenAllBags() end, |
361 "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1}) | 359 "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1}) |
362 | 360 |
363 KeyBinder_CheckButton(KeyBinderStickyMode, 'Enabled', 'Disabled', 'stickyMode', 'Keep input active after receiving a key.', nil, 'Sticky:') | 361 KeyBinder_CheckButton(KeyBinderStickyMode, 'Enabled', 'Disabled', 'stickyMode', 'Keep input active after receiving a key.', function() |
362 if kb.saveTarget and (not kb.db.stickyMode) then | |
363 kb.DeactivateSlot(kb.saveTarget) | |
364 end | |
365 end, 'Sticky:') | |
364 KeyBinder_CheckButton(KeyBinderHoverInput, 'MouseOver', 'Click', 'hoverInput', 'Enable key input when the cursor is over a binding slot.', nil, 'Bind by:') | 366 KeyBinder_CheckButton(KeyBinderHoverInput, 'MouseOver', 'Click', 'hoverInput', 'Enable key input when the cursor is over a binding slot.', nil, 'Bind by:') |
365 KeyBinder_CheckButton(KeyBinderProtectBindings, 'Block', 'Allow', 'protectBlizKeys', 'Allow overwriting Blizzard UI bindings.', nil, 'Safety:') | 367 KeyBinder_CheckButton(KeyBinderProtectBindings, 'Block', 'Allow', 'protectBlizKeys', 'Allow overwriting Blizzard UI bindings.', nil, 'Safety:') |
366 | 368 |
367 | 369 |
368 KeyBinderUnbindButton:SetScript('OnClick', function() | 370 KeyBinderUnbindButton:SetScript('OnClick', function() |
489 | 491 |
490 -- Reset this so talent cache can be rebuilt | 492 -- Reset this so talent cache can be rebuilt |
491 kb.talentsPushed = nil | 493 kb.talentsPushed = nil |
492 end | 494 end |
493 | 495 |
496 --- Associate processed input with the given slot's metadata | |
497 kb.SaveSlot = function(self, key) | |
498 | |
499 if not self.command then | |
500 return | |
501 end | |
502 print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key) | |
503 | |
504 local modifier = '' | |
505 if IsAltKeyDown() then | |
506 modifier = 'ALT-' | |
507 end | |
508 if IsControlKeyDown() then | |
509 modifier = modifier.. 'CTRL-' | |
510 end | |
511 if IsShiftKeyDown() then | |
512 modifier = modifier..'SHIFT-' | |
513 end | |
514 local binding = modifier..key | |
515 | |
516 -- check for system bindings | |
517 --bprint('|cFFFFFF00SaveBind|r', 'protectKeys', kb.db.protectBlizKeys) | |
518 if kb.db.protectBlizKeys and kb.SystemBindings[binding] then | |
519 kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', binding, kb.SystemBindings[binding])) | |
520 kb.bindingstext:SetText(nil) | |
521 return false | |
522 end | |
523 | |
524 -- check for other keys | |
525 local previousCommand = GetBindingAction(binding) | |
526 if previousCommand ~= "" and previousCommand ~= self.command then | |
527 local actionType, actionID, name = kb.GetCommandAction(previousCommand) | |
528 if actionType then | |
529 local keys = {GetBindingKey(previousCommand) } | |
530 local i = 1 | |
531 while keys[i] do | |
532 if keys[i] == binding then | |
533 tremove(keys, i) | |
534 kb.UpdateBindingsCache(actionType, actionID, keys) | |
535 break | |
536 end | |
537 i = i + 1 | |
538 end | |
539 end | |
540 end | |
541 | |
542 local currentHotKeys = {GetBindingKey(self.command)} | |
543 local found | |
544 for i, key in ipairs(currentHotKeys) do | |
545 if key == binding then | |
546 found = true | |
547 kb:print('hotkey already assigned') | |
548 end | |
549 end | |
550 if not found then | |
551 tinsert(currentHotKeys, 1, binding) | |
552 kb.UpdateBindingsCache(self.actionType, self.actionID, currentHotKeys) | |
553 end | |
554 | |
555 | |
556 | |
557 print('SetBinding', binding, self.command) | |
558 SetBinding(binding, self.command) | |
559 SaveBindings(GetCurrentBindingSet()) | |
560 self.binding = binding | |
561 | |
562 local talentInfo | |
563 if self.actionType == 'spell' and kb.TalentCache[self.actionID] then | |
564 print('store dynamicType talent') | |
565 talentInfo = {self.macroName, self.actionName, self.actionType, self.actionID} | |
566 local bindings = {GetBindingKey(self.command) } | |
567 for i, key in ipairs(bindings) do | |
568 tinsert(talentInfo, key) | |
569 end | |
570 end | |
571 | |
572 for level, profile in ipairs(kb.orderedProfiles) do | |
573 if (level == kb.db.bindMode) then | |
574 profile.bound[self.command] = true | |
575 if talentInfo then | |
576 profile.bindings[self.binding] = nil | |
577 else | |
578 profile.bindings[self.binding] = self.command | |
579 end | |
580 profile.talents[self.actionName] = talentInfo | |
581 else | |
582 profile.bindings[self.binding] = nil | |
583 profile.bound[self.command] = nil | |
584 kb.currentProfile.talents[self.actionName] = nil | |
585 end | |
586 if kb.currentProfile.talents[self.actionID] then | |
587 kb.currentProfile.talents[self.actionID] = nil | |
588 end | |
589 end | |
590 | |
591 kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.currentHeader)) | |
592 kb.UpdateSlot(self, true) | |
593 return true | |
594 end | |
595 | |
596 | |
597 kb.UnbindSlot = function(self) | |
598 | |
599 local keys = {GetBindingKey(self.command) } | |
600 if #keys >= 1 then | |
601 kb.UpdateBindingsCache(self.actionType, self.actionID, {}) | |
602 end | |
603 | |
604 | |
605 --print('detected', #keys, 'bindings') | |
606 for i, key in pairs(keys) do | |
607 --print('clearing', key) | |
608 SetBinding(key, nil) | |
609 SaveBindings(GetCurrentBindingSet()) | |
610 if kb.currentProfile.bindings[key] then | |
611 --kb:print(L('BINDING_REMOVED', self.actionName, kb.currentHeader)) | |
612 kb.currentProfile.bindings[key] = nil | |
613 end | |
614 if kb.currentProfile.talents[self.actionName] then | |
615 kb.currentProfile.talents[self.actionName] = nil | |
616 end | |
617 | |
618 kb.bindings[tostring(self.actionType)..'_'..tostring(self.actionID)] = nil | |
619 end | |
620 if kb.currentProfile.bound[self.command] then | |
621 kb.currentProfile.bound[self.command] = nil | |
622 --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode])) | |
623 end | |
624 | |
625 | |
626 self.active = false | |
627 kb.UpdateSlot(self, true) | |
628 end | |
629 | |
494 kb.AcceptAssignment = function(self, ...) | 630 kb.AcceptAssignment = function(self, ...) |
495 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] | 631 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] |
496 local source = kb. loadedProfiles[popup.oldProfile] | 632 local source = kb. loadedProfiles[popup.oldProfile] |
497 kb.SetSlot(popup.slot, unpack(popup.args)) | 633 kb.SetSlot(popup.slot, unpack(popup.args)) |
498 kb.UpdateSlot(popup.slot) | 634 kb.UpdateSlot(popup.slot) |
499 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) -- re-enable scrolling | 635 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) -- re-enable scrolling |
500 ClearCursor() | 636 ClearCursor() |
501 ResetCursor() | 637 ResetCursor() |
502 end | 638 end |
639 | |
640 --- Add to blizzard interfaces | |
641 StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = { | |
642 text = "Confirm moving an assigned command.", | |
643 button1 = OKAY, | |
644 button2 = CANCEL, | |
645 timeout = 0, | |
646 whileDead = 1, | |
647 showAlert = 1, | |
648 OnAccept = kb.AcceptAssignment, | |
649 OnCancel = function() kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) end | |
650 } |