Mercurial > wow > reaction
comparison modules/ReAction_Action/ReAction_Action.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 | 3499ac7c3a9b |
| children | 7cabc8ac6c16 |
comparison
equal
deleted
inserted
replaced
| 87:3499ac7c3a9b | 88:fc83b3f5b322 |
|---|---|
| 13 -- local imports | 13 -- local imports |
| 14 local ReAction = ReAction | 14 local ReAction = ReAction |
| 15 local L = ReAction.L | 15 local L = ReAction.L |
| 16 local _G = _G | 16 local _G = _G |
| 17 local CreateFrame = CreateFrame | 17 local CreateFrame = CreateFrame |
| 18 local format = string.format | |
| 18 | 19 |
| 19 ReAction:UpdateRevision("$Revision$") | 20 ReAction:UpdateRevision("$Revision$") |
| 21 | |
| 22 -- libraries | |
| 23 local KB = LibStub("LibKeyBound-1.0") | |
| 20 | 24 |
| 21 -- module declaration | 25 -- module declaration |
| 22 local moduleID = "Action" | 26 local moduleID = "Action" |
| 23 local module = ReAction:NewModule( moduleID ) | 27 local module = ReAction:NewModule( moduleID ) |
| 24 | 28 |
| 59 ReAction.RegisterCallback(self, "OnRefreshBar") | 63 ReAction.RegisterCallback(self, "OnRefreshBar") |
| 60 ReAction.RegisterCallback(self, "OnEraseBar") | 64 ReAction.RegisterCallback(self, "OnEraseBar") |
| 61 ReAction.RegisterCallback(self, "OnRenameBar") | 65 ReAction.RegisterCallback(self, "OnRenameBar") |
| 62 ReAction.RegisterCallback(self, "OnConfigModeChanged") | 66 ReAction.RegisterCallback(self, "OnConfigModeChanged") |
| 63 | 67 |
| 68 KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") | |
| 69 KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") | |
| 70 KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") | |
| 64 end | 71 end |
| 65 | 72 |
| 66 function module:OnEnable() | 73 function module:OnEnable() |
| 67 ReAction:RegisterBarType(L["Action Bar"], | 74 ReAction:RegisterBarType(L["Action Bar"], |
| 68 { | 75 { |
| 149 function module:OnConfigModeChanged(event, mode) | 156 function module:OnConfigModeChanged(event, mode) |
| 150 for _, bar in pairs(self.buttons) do | 157 for _, bar in pairs(self.buttons) do |
| 151 for _, b in pairs(bar) do | 158 for _, b in pairs(bar) do |
| 152 b:ShowGrid(mode) | 159 b:ShowGrid(mode) |
| 153 b:ShowActionIDLabel(mode) | 160 b:ShowActionIDLabel(mode) |
| 161 end | |
| 162 end | |
| 163 end | |
| 164 | |
| 165 function module:LIBKEYBOUND_ENABLED(evt) | |
| 166 -- set the border for all buttons to the keybind-enable color | |
| 167 local r,g,b,a = KB:GetColorKeyBoundMode() | |
| 168 for _, bar in pairs(self.buttons) do | |
| 169 for _, b in pairs(bar) do | |
| 170 b.border:SetVertexColor(r,g,b,a) | |
| 171 b.border:Show() | |
| 172 end | |
| 173 end | |
| 174 end | |
| 175 | |
| 176 function module:LIBKEYBOUND_DISABLED(evt) | |
| 177 for _, bar in pairs(self.buttons) do | |
| 178 for _, b in pairs(bar) do | |
| 179 b.border:Hide() | |
| 154 end | 180 end |
| 155 end | 181 end |
| 156 end | 182 end |
| 157 | 183 |
| 158 | 184 |
| 650 end | 676 end |
| 651 end | 677 end |
| 652 end | 678 end |
| 653 end | 679 end |
| 654 | 680 |
| 681 ------ Button class ------ | |
| 682 | |
| 655 local frameRecycler = { } | 683 local frameRecycler = { } |
| 656 | 684 local trash = CreateFrame("Frame") |
| 657 ------ Button class ------ | 685 local OnUpdate, KBAttach, GetActionName, GetHotkey, SetKey, FreeKey, ClearBindings, GetBindings |
| 686 do | |
| 687 local ATTACK_BUTTON_FLASH_TIME = ATTACK_BUTTON_FLASH_TIME | |
| 688 local IsActionInRange = IsActionInRange | |
| 689 | |
| 690 local buttonLookup = setmetatable({},{__mode="kv"}) | |
| 691 | |
| 692 function OnUpdate(frame, elapsed) | |
| 693 -- note: This function taints frame.flashtime and frame.rangeTimer. Both of these | |
| 694 -- are only read by ActionButton_OnUpdate (which this function replaces). In | |
| 695 -- all other places they're just written, so it doesn't taint any secure code. | |
| 696 if frame.flashing == 1 then | |
| 697 frame.flashtime = frame.flashtime - elapsed | |
| 698 if frame.flashtime <= 0 then | |
| 699 local overtime = -frame.flashtime | |
| 700 if overtime >= ATTACK_BUTTON_FLASH_TIME then | |
| 701 overtime = 0 | |
| 702 end | |
| 703 frame.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime | |
| 704 | |
| 705 local flashTexture = frame.flash | |
| 706 if flashTexture:IsShown() then | |
| 707 flashTexture:Hide() | |
| 708 else | |
| 709 flashTexture:Show() | |
| 710 end | |
| 711 end | |
| 712 end | |
| 713 | |
| 714 if frame.rangeTimer then | |
| 715 frame.rangeTimer = frame.rangeTimer - elapsed; | |
| 716 | |
| 717 if frame.rangeTimer <= 0 then | |
| 718 if IsActionInRange(frame.action) == 0 then | |
| 719 frame.icon:SetVertexColor(1.0,0.1,0.1) | |
| 720 else | |
| 721 ActionButton_UpdateUsable() | |
| 722 end | |
| 723 frame.rangeTimer = 0.1 | |
| 724 end | |
| 725 end | |
| 726 end | |
| 727 | |
| 728 -- Use KeyBound-1.0 for binding, but use Override bindings instead of | |
| 729 -- regular bindings to support multiple profile use. This is a little | |
| 730 -- weird with the KeyBound dialog box (which has per-char selector as well | |
| 731 -- as an OK/Cancel box) but it's the least amount of effort to implement. | |
| 732 function GetActionName(f) | |
| 733 local b = buttonLookup[f] | |
| 734 if b then | |
| 735 return format("%s:%s", b.bar:GetName(), b.idx) | |
| 736 end | |
| 737 end | |
| 738 | |
| 739 function GetHotkey(f) | |
| 740 local b = buttonLookup[f] | |
| 741 if b then | |
| 742 return KB:ToShortKey(b:GetConfig().hotkey) | |
| 743 end | |
| 744 end | |
| 745 | |
| 746 function SetKey(f, key) | |
| 747 local b = buttonLookup[f] | |
| 748 if b then | |
| 749 local c = b:GetConfig() | |
| 750 if c.hotkey then | |
| 751 SetOverrideBinding(f, false, c.hotkey, nil) | |
| 752 end | |
| 753 if key then | |
| 754 SetOverrideBindingClick(f, false, key, f:GetName(), nil) | |
| 755 end | |
| 756 c.hotkey = key | |
| 757 b:DisplayHotkey(GetHotkey(f)) | |
| 758 end | |
| 759 end | |
| 760 | |
| 761 function FreeKey(f, key) | |
| 762 local b = buttonLookup[f] | |
| 763 if b then | |
| 764 local c = b:GetConfig() | |
| 765 if c.hotkey == key then | |
| 766 local action = f:GetActionName() | |
| 767 SetOverrideBinding(f, false, c.hotkey, nil) | |
| 768 c.hotkey = nil | |
| 769 b:DisplayHotkey(nil) | |
| 770 return action | |
| 771 end | |
| 772 end | |
| 773 return ReAction:FreeOverrideHotkey(key) | |
| 774 end | |
| 775 | |
| 776 function ClearBindings(f) | |
| 777 SetKey(f, nil) | |
| 778 end | |
| 779 | |
| 780 function GetBindings(f) | |
| 781 local b = buttonLookup[f] | |
| 782 if b then | |
| 783 return b:GetConfig().hotkey | |
| 784 end | |
| 785 end | |
| 786 | |
| 787 function KBAttach( button ) | |
| 788 local f = button:GetFrame() | |
| 789 f.GetActionName = GetActionName | |
| 790 f.GetHotkey = GetHotkey | |
| 791 f.SetKey = SetKey | |
| 792 f.FreeKey = FreeKey | |
| 793 f.ClearBindings = ClearBindings | |
| 794 f.GetBindings = GetBindings | |
| 795 buttonLookup[f] = button | |
| 796 f:SetKey(button:GetConfig().hotkey) | |
| 797 ReAction:RegisterKeybindFrame(f) | |
| 798 end | |
| 799 end | |
| 800 | |
| 801 | |
| 658 function Button:New( bar, idx, config, barConfig ) | 802 function Button:New( bar, idx, config, barConfig ) |
| 659 -- create new self | 803 -- create new self |
| 660 self = setmetatable( { }, {__index = Button} ) | 804 self = setmetatable( { }, {__index = Button} ) |
| 661 self.bar, self.idx, self.config, self.barConfig = bar, idx, config, barConfig | 805 self.bar, self.idx, self.config, self.barConfig = bar, idx, config, barConfig |
| 662 | 806 |
| 674 local f = frameRecycler[name] | 818 local f = frameRecycler[name] |
| 675 if f then | 819 if f then |
| 676 f:SetParent(parent) | 820 f:SetParent(parent) |
| 677 else | 821 else |
| 678 f = CreateFrame("CheckButton", name, parent, "ActionBarButtonTemplate") | 822 f = CreateFrame("CheckButton", name, parent, "ActionBarButtonTemplate") |
| 679 end | 823 -- ditch the old hotkey text because it's tied in ActionButton_Update() to the |
| 824 -- standard binding. We use override bindings. | |
| 825 local hotkey = _G[name.."HotKey"] | |
| 826 hotkey:SetParent(trash) | |
| 827 hotkey = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmallGray") | |
| 828 hotkey:SetWidth(36) | |
| 829 hotkey:SetHeight(18) | |
| 830 hotkey:SetJustifyH("RIGHT") | |
| 831 hotkey:SetJustifyV("TOP") | |
| 832 hotkey:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2) | |
| 833 f.hotkey = hotkey | |
| 834 f.icon = _G[name.."Icon"] | |
| 835 f.flash = _G[name.."Flash"] | |
| 836 f:SetScript("OnUpdate",OnUpdate) | |
| 837 end | |
| 838 | |
| 839 self.hotkey = f.hotkey | |
| 840 self.border = _G[name.."Border"] | |
| 680 | 841 |
| 681 f:SetAttribute("action", config.actionID) | 842 f:SetAttribute("action", config.actionID) |
| 682 -- install mind control action support for all buttons here just for simplicity | 843 -- install mind control action support for all buttons here just for simplicity |
| 683 if self.idx <= 12 then | 844 if self.idx <= 12 then |
| 684 f:SetAttribute("*action-mc", 120 + self.idx) | 845 f:SetAttribute("*action-mc", 120 + self.idx) |
| 694 self:ShowGrid(true) | 855 self:ShowGrid(true) |
| 695 end | 856 end |
| 696 | 857 |
| 697 -- show the ID label if applicable | 858 -- show the ID label if applicable |
| 698 self:ShowActionIDLabel(ReAction:GetConfigMode()) | 859 self:ShowActionIDLabel(ReAction:GetConfigMode()) |
| 860 | |
| 861 -- attach the keybinder | |
| 862 KBAttach(self) | |
| 699 | 863 |
| 700 self:Refresh() | 864 self:Refresh() |
| 701 return self | 865 return self |
| 702 end | 866 end |
| 703 | 867 |
| 736 return self.frame | 900 return self.frame |
| 737 end | 901 end |
| 738 | 902 |
| 739 function Button:GetName() | 903 function Button:GetName() |
| 740 return self.name | 904 return self.name |
| 905 end | |
| 906 | |
| 907 function Button:GetConfig() | |
| 908 return self.config | |
| 741 end | 909 end |
| 742 | 910 |
| 743 function Button:GetActionID(page) | 911 function Button:GetActionID(page) |
| 744 if page == nil then | 912 if page == nil then |
| 745 -- get the effective ID | 913 -- get the effective ID |
| 854 elseif f.actionIDLabel then | 1022 elseif f.actionIDLabel then |
| 855 f.actionIDLabel:Hide() | 1023 f.actionIDLabel:Hide() |
| 856 end | 1024 end |
| 857 end | 1025 end |
| 858 | 1026 |
| 1027 function Button:DisplayHotkey( key ) | |
| 1028 self.hotkey:SetText(key or "") | |
| 1029 end |
