Mercurial > wow > skeletonkey
comparison SkeletonKey/KeyBinds.lua @ 1:cd7d06bcd98d
KeyBinds:
set hotkey text for blizzard action buttons
UnitFrame:
prototype templates for the majority of units
author | Nenue |
---|---|
date | Tue, 21 Jun 2016 04:47:52 -0400 |
parents | 69e828f4238a |
children | 07293831dd7b |
comparison
equal
deleted
inserted
replaced
0:69e828f4238a | 1:cd7d06bcd98d |
---|---|
12 -- .refresh(button) update button contents | 12 -- .refresh(button) update button contents |
13 -- .ui() invoke interface | 13 -- .ui() invoke interface |
14 -- .profile(name) set profile character | 14 -- .profile(name) set profile character |
15 -- .loadbinds(bindings) walk table with SetBinding() | 15 -- .loadbinds(bindings) walk table with SetBinding() |
16 | 16 |
17 local KT = LibKT.register(KeyBinder) | |
17 local kb = KeyBinder | 18 local kb = KeyBinder |
18 local KT = select(2,...) | 19 local db |
19 KT.register(KeyBinder) | 20 |
20 local MIN_BIND_SLOTS = 32 | 21 local MIN_BIND_SLOTS = 32 |
21 local BINDS_PER_ROW = 8 | 22 local BINDS_PER_ROW = 8 |
22 local KEY_BUTTON_SIZE = 40 | 23 local KEY_BUTTON_SIZE = 40 |
23 local TAB_OFFSET = 12 | 24 local TAB_OFFSET = 12 |
24 local TAB_HEIGHT = 40 | 25 local TAB_HEIGHT = 40 |
25 local TAB_SPACING = 2 | 26 local TAB_SPACING = 2 |
26 local BUTTON_SPACING = 4 | 27 local BUTTON_SPACING = 4 |
27 local BUTTON_PADDING = 12 | 28 local BUTTON_PADDING = 12 |
28 local HEADER_OFFSET | 29 local HEADER_OFFSET, FOOTER_OFFSET |
29 local FOOTER_OFFSET | |
30 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544; | 30 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544; |
31 local BINDING_TYPE_SPECIALIZATION = 3 | 31 local BINDING_TYPE_SPECIALIZATION = 3 |
32 local BINDING_TYPE_CHARACTER = 2 | 32 local BINDING_TYPE_CHARACTER = 2 |
33 local BINDING_TYPE_GLOBAL = 1 | 33 local BINDING_TYPE_GLOBAL = 1 |
34 local BINDING_ASSIGNED = '|cFF00FF00%s|r assigned to |cFFFFFF00%s|r (%s).' | 34 local BINDING_ASSIGNED = '|cFF00FF00%s|r assigned to |cFFFFFF00%s|r (%s).' |
79 local CLASS_ICON_TEXTURE = "Interface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES" | 79 local CLASS_ICON_TEXTURE = "Interface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES" |
80 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1 } | 80 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1 } |
81 local BORDER_ASSIGNED = {0.5,0.5,0.5,1 } | 81 local BORDER_ASSIGNED = {0.5,0.5,0.5,1 } |
82 local BORDER_PENDING = {1,0.5,0,1 } | 82 local BORDER_PENDING = {1,0.5,0,1 } |
83 | 83 |
84 | 84 local bindMode = 3 |
85 | |
86 local bindMode = 3 -- not to be confused with db.bindMode which is boolean | |
87 local bindHeader = '' | 85 local bindHeader = '' |
88 local specHeader, specTexture, characterHeader = 'SPEC_NAME', 'Interface\\ICONS\\INV_Misc_QuestionMark', 'PLAYER_NAME' | 86 local specHeader, specTexture, characterHeader = 'SPEC_NAME', 'Interface\\ICONS\\INV_Misc_QuestionMark', 'PLAYER_NAME' |
87 local numButtons = BINDS_PER_ROW * 4 | |
89 local bindsCommitted = true | 88 local bindsCommitted = true |
90 | 89 |
91 local profile | 90 local profile, character, specialization, global |
92 local character | |
93 local specialization | |
94 local global | |
95 local priority = {} | 91 local priority = {} |
96 local numButtons = BINDS_PER_ROW * 4 | |
97 local buttons = {} | 92 local buttons = {} |
98 local reverts = {} | 93 local reverts = {} |
99 local KeyButton = {} -- collection of KeyButton template handlers | 94 local KeyButton = {} -- collection of KeyButton template handlers |
100 local Action = {} -- collection of special action buttons for special binds | 95 local Action = {} -- collection of special action buttons for special binds |
101 local protected = { | 96 local protected = { |
506 FOOTER_OFFSET = saveButton:GetHeight() + BUTTON_PADDING | 501 FOOTER_OFFSET = saveButton:GetHeight() + BUTTON_PADDING |
507 end | 502 end |
508 | 503 |
509 --- Invokes the KeyBinder frame (from the /kb function or some other source) | 504 --- Invokes the KeyBinder frame (from the /kb function or some other source) |
510 kb.ui = function() | 505 kb.ui = function() |
511 if not KT.db.bindMode then | 506 if not db.showUI then |
512 return | 507 return |
513 end | 508 end |
514 | 509 |
515 if not kb:IsVisible() then | 510 if not kb:IsVisible() then |
516 kb:Show() | 511 kb:Show() |
517 KT.db.bindMode = true | 512 db.showUI = true |
518 end | 513 end |
519 | 514 |
520 if not kb.loaded then | 515 if not kb.loaded then |
521 SetupUI() | 516 SetupUI() |
522 kb.loaded = true | 517 kb.loaded = true |
581 end | 576 end |
582 SaveBindings() | 577 SaveBindings() |
583 end | 578 end |
584 | 579 |
585 local ACTION_BARS = { | 580 local ACTION_BARS = { |
586 'MultiBarBottomLeftButton', | 581 {'ActionButton', 0}, |
587 'MultiBarBottomRighttButton', | 582 {'MultiBarLeftButton', 24}, |
588 'MultiBarLeftButton', | 583 {'MultiBarRightButton', 36}, |
589 'MultiBarRightButton', | 584 {'MultiBarBottomRighttButton', 48}, |
590 'ActionButton' | 585 {'MultiBarBottomLeftButton', 60}, |
591 } | 586 } |
592 kb.HotKeyText = function () | 587 kb.HotKeyText = function (slot) |
593 for _, prefix in ipairs(ACTION_BARS) do | 588 local i, offset = 0, 0 |
594 for i = 1,12 do | 589 local actionbar |
595 local button = _G[prefix .. i] | 590 |
596 if button and button.action then | 591 -- figure out which bar the slot belongs to |
597 local type, id, subType, subID = GetActionInfo(button.action) | 592 for i, bar in ipairs(ACTION_BARS) do |
598 if type == 'spell' then | 593 actionbar, offset = unpack(ACTION_BARS[i]) |
599 local name = GetSpellInfo(id) | 594 if bar[2] > slot then |
600 local bind, bind2 = GetBindingKey('SPELL '..name) | 595 break |
601 if bind or bind2 then | 596 end |
602 --print('SPELL '..name, GetBindingKey('SPELL '..name)) | 597 end |
603 button.HotKey:SetText(BindingString(bind)) | 598 local button = _G[actionbar .. (slot - offset)] |
604 button.HotKey:Show() | 599 |
605 end | 600 if not button then |
606 end | 601 return |
607 end | 602 end |
608 end | 603 |
604 local type, id, subType, subID = GetActionInfo(slot) | |
605 | |
606 if not type then | |
607 return | |
608 end | |
609 | |
610 local bind, command | |
611 if type == 'spell' then | |
612 local name = GetSpellInfo(id) | |
613 command = 'SPELL '..name | |
614 elseif type == 'macro' then | |
615 command = 'MACRO ' .. id | |
616 else | |
617 return | |
618 end | |
619 bind = GetBindingKey(command) | |
620 print(slot, bind, '->', command) | |
621 if bind then | |
622 button.HotKey:SetText(BindingString(bind)) | |
623 button.HotKey:Show() | |
609 end | 624 end |
610 end | 625 end |
611 | 626 |
612 kb.InitProfile = function(profile) | 627 kb.InitProfile = function(profile) |
613 profile.buttons = profile.buttons or {} | 628 profile.buttons = profile.buttons or {} |
627 profile.macros = {} | 642 profile.macros = {} |
628 end | 643 end |
629 | 644 |
630 --- Gives us the profile structure to work with while instating data | 645 --- Gives us the profile structure to work with while instating data |
631 kb.profile = function(name) | 646 kb.profile = function(name) |
632 KT.db = KT.db or {} | 647 global = kb.InitProfile(db) |
633 global = kb.InitProfile(KT.db) | |
634 profile = global | 648 profile = global |
635 local subtitle | 649 local subtitle |
636 if name then | 650 if name then |
637 KT.db[name] = KT.db[name] or {} | 651 db[name] = db[name] or {} |
638 KT.db[name] = kb.InitProfile(KT.db[name]) | 652 db[name] = kb.InitProfile(db[name]) |
639 character = KT.db[name] | 653 character = db[name] |
640 local spec = GetSpecialization() | 654 local spec = GetSpecialization() |
641 if spec then | 655 if spec then |
642 KT.db[name][spec] = KT.db[name][spec] or {} | 656 db[name][spec] = db[name][spec] or {} |
643 profile = kb.InitProfile(KT.db[name][spec]) | 657 profile = kb.InitProfile(db[name][spec]) |
644 bindMode = BINDING_TYPE_SPECIALIZATION | 658 bindMode = BINDING_TYPE_SPECIALIZATION |
645 subtitle = select(2,GetSpecializationInfo(spec)) | 659 subtitle = select(2,GetSpecializationInfo(spec)) |
646 specialization = KT.db[name][spec] | 660 specialization = db[name][spec] |
647 else | 661 else |
648 profile = kb.InitProfile(KT.db[name]) | 662 profile = kb.InitProfile(db[name]) |
649 bindMode = BINDING_TYPE_CHARACTER | 663 bindMode = BINDING_TYPE_CHARACTER |
650 subtitle = name | 664 subtitle = name |
651 specialization = character | 665 specialization = character |
652 end | 666 end |
653 end | 667 end |
654 priority = {global, character, specialization } | 668 priority = {global, character, specialization } |
655 | 669 |
656 | 670 |
657 | 671 |
658 if not KT.db.bindsPage then | 672 if not db.bindsPage then |
659 KT.db.bindsPage = bindMode | 673 db.bindsPage = bindMode |
660 end | 674 end |
661 bindMode = KT.db.bindsPage | 675 bindMode = db.bindsPage |
662 | 676 |
663 | 677 |
664 if not BINDING_MODE[bindMode] then | 678 if not BINDING_MODE[bindMode] then |
665 bindMode = 3 | 679 bindMode = 3 |
666 KT.db.bindsPage = 3 | 680 db.bindsPage = 3 |
667 print('overriding', bindMode) | 681 print('overriding', bindMode) |
668 end | 682 end |
669 | 683 |
670 profile = priority[bindMode] | 684 profile = priority[bindMode] |
671 | 685 |
680 end | 694 end |
681 | 695 |
682 kb.SelectTab = function(self) | 696 kb.SelectTab = function(self) |
683 bindMode = self:GetID() | 697 bindMode = self:GetID() |
684 profile = priority[self:GetID()] | 698 profile = priority[self:GetID()] |
685 KT.db.bindsPage = self:GetID() | 699 db.bindsPage = self:GetID() |
686 kb.ui() | 700 kb.ui() |
687 end | 701 end |
688 kb.save = function() | 702 kb.save = function() |
689 SaveBindings(GetCurrentBindingSet()) | 703 SaveBindings(GetCurrentBindingSet()) |
690 bindsCommitted = true | 704 bindsCommitted = true |
709 KeyBinderMacro:SetAttribute('*type*', 'macro') | 723 KeyBinderMacro:SetAttribute('*type*', 'macro') |
710 end | 724 end |
711 | 725 |
712 --- Get started | 726 --- Get started |
713 kb.variables = function() | 727 kb.variables = function() |
728 SkeletonKeyDB = SkeletonKeyDB or {} | |
729 db = SkeletonKeyDB | |
714 kb.profile(GetUnitName('player', true)) | 730 kb.profile(GetUnitName('player', true)) |
715 for i = 1, 3 do | 731 for i = 1, 3 do |
716 for attribute, data in pairs(priority[i].macros) do | 732 for attribute, data in pairs(priority[i].macros) do |
717 KeyBinderMacro:SetAttribute(attribute, data[1]) | 733 KeyBinderMacro:SetAttribute(attribute, data[1]) |
718 end | 734 end |
727 kb:RegisterEvent('PLAYER_REGEN_ENABLED') | 743 kb:RegisterEvent('PLAYER_REGEN_ENABLED') |
728 kb:RegisterEvent('ACTIONBAR_SLOT_CHANGED') | 744 kb:RegisterEvent('ACTIONBAR_SLOT_CHANGED') |
729 end | 745 end |
730 | 746 |
731 kb.close = function() | 747 kb.close = function() |
732 KT.db.bindMode = false | 748 db.showUI = false |
733 kb:Hide() | 749 kb:Hide() |
734 end | 750 end |
735 | 751 |
736 kb.PLAYER_REGEN_DISABLED = function() | 752 kb.PLAYER_REGEN_DISABLED = function() |
737 if KT.db.bindMode then | 753 if db.showUI then |
738 | |
739 kb:Hide() | 754 kb:Hide() |
740 end | 755 end |
741 end | 756 end |
742 | 757 |
743 kb.PLAYER_REGEN_ENABLED = function() | 758 kb.PLAYER_REGEN_ENABLED = function() |
744 if KT.db.bindMode then | 759 if db.showUI then |
745 kb.ui() | 760 kb.ui() |
746 end | 761 end |
747 end | 762 end |
748 --- Refresh buttons if macros are updated | 763 --- Refresh buttons if macros are updated |
749 kb.UPDATE_BINDINGS = function() | 764 kb.UPDATE_BINDINGS = function() |
750 if KT.db.bindMode then | 765 for i = 1, 120 do |
766 print(i) | |
767 kb.HotKeyText(i) | |
768 end | |
769 if db.showUI then | |
751 kb.ui() | 770 kb.ui() |
752 end | 771 end |
753 kb.HotKeyText() | 772 end |
754 end | 773 |
755 | 774 kb.ACTIONBAR_SLOT_CHANGED = function(self, event, slot) |
756 kb.ACTIONBAR_SLOT_CHANGED = function() | 775 kb.HotKeyText(slot) |
757 kb.HotKeyText() | 776 end |
758 end | |
759 | |
760 | |
761 | 777 |
762 kb.UPDATE_MACROS = kb.UPDATE_BINDINGS | 778 kb.UPDATE_MACROS = kb.UPDATE_BINDINGS |
763 | |
764 | |
765 SLASH_KB1 = "/kb" | 779 SLASH_KB1 = "/kb" |
766 SlashCmdList.KB = function() | 780 SlashCmdList.KB = function(self, input) |
767 if KT.db.bindMode then | 781 if db.showUI then |
768 KT.db.bindMode = false | 782 db.showUI = false |
769 print('|cFFFFFF00KeyBinds|r trace, |cFFFF0000OFF|r.') | 783 print('|cFFFFFF00KeyBinds|r trace, |cFFFF0000OFF|r.') |
770 kb:Hide() | 784 kb:Hide() |
771 else | 785 else |
772 KT.db.bindMode = true | 786 db.showUI = true |
773 print('|cFFFFFF00KeyBinds|r trace, |cFF00FF00ON|r.') | 787 print('|cFFFFFF00KeyBinds|r trace, |cFF00FF00ON|r.') |
774 kb.ui() | 788 kb.ui() |
775 end | 789 end |
776 end | 790 end |