Mercurial > wow > reaction
comparison classes/ReBound.lua @ 7:f920db5fc6b1
version 0.3
| author | Flick <flickerstreak@gmail.com> | 
|---|---|
| date | Tue, 20 Mar 2007 21:25:29 +0000 | 
| parents | 27aeec452e7f | 
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| 6:2da5089ab7ff | 7:f920db5fc6b1 | 
|---|---|
| 1 -- ReBinder.lua | 1 -- ReBound.lua | 
| 2 -- | 2 -- | 
| 3 | 3 | 
| 4 ReBinder = { } | 4 | 
| 5 local AceEvent = AceLibrary("AceEvent-2.0") | |
| 6 | |
| 7 ReBound = { } | |
| 5 | 8 | 
| 6 -- initial values | 9 -- initial values | 
| 7 ReBinder.active = false | 10 ReBound.active = false | 
| 8 | 11 | 
| 9 ReBinder.targets = { } | 12 ReBound.targets = { } | 
| 10 | 13 | 
| 11 function ReBinder:AddKeybindTarget( t ) | 14 function ReBound:AddKeybindTarget( t ) | 
| 12 if t then | 15 if t then | 
| 13 self.targets[t] = CreateFrame("Button", nil, t, "ReBinderClickBindingTemplate") | 16 self.targets[t] = CreateFrame("Button", nil, t, "ReBoundClickBindingTemplate") | 
| 14 self.targets[t].keybindTarget = t:GetName() | 17 self.targets[t].keybindTarget = t:GetName() | 
| 15 end | 18 end | 
| 16 end | 19 end | 
| 17 | 20 | 
| 18 function ReBinder:RemoveKeybindTarget( t ) | 21 function ReBound:RemoveKeybindTarget( t ) | 
| 19 if t then | 22 if t then | 
| 20 self.targets[t] = nil | 23 self.targets[t] = nil | 
| 21 end | 24 end | 
| 22 end | 25 end | 
| 23 | 26 | 
| 24 function ReBinder:ShowClickBindingButtons() | 27 function ReBound:ShowClickBindingButtons() | 
| 25 for _, clickFrame in pairs(self.targets) do | 28 AceEvent:TriggerEvent("EVENT_REBOUND_KEYBINDING_MODE", true) | 
| 29 for tgt, clickFrame in pairs(self.targets) do | |
| 26 clickFrame:Show() | 30 clickFrame:Show() | 
| 27 end | 31 end | 
| 28 end | 32 end | 
| 29 | 33 | 
| 30 function ReBinder:HideClickBindingButtons() | 34 function ReBound:HideClickBindingButtons() | 
| 31 for _, clickFrame in pairs(self.targets) do | 35 AceEvent:TriggerEvent("EVENT_REBOUND_KEYBINDING_MODE", false) | 
| 36 for tgt, clickFrame in pairs(self.targets) do | |
| 32 clickFrame:Hide() | 37 clickFrame:Hide() | 
| 33 end | 38 end | 
| 34 end | 39 end | 
| 35 | 40 | 
| 36 function ReBinder:ClearSelectedKey() | 41 function ReBound:ClearSelectedKey() | 
| 37 self.selectedKey = nil | 42 self.selectedKey = nil | 
| 43 SetCursor(nil) -- reset cursor to default state | |
| 38 end | 44 end | 
| 39 | 45 | 
| 40 function ReBinder:ToggleEnabled() | 46 function ReBound:ToggleEnabled() | 
| 41 if self:IsEnabled() then | 47 if self:IsEnabled() then | 
| 42 self:Disable() | 48 self:Disable() | 
| 43 else | 49 else | 
| 44 self:Enable() | 50 self:Enable() | 
| 45 end | 51 end | 
| 46 end | 52 end | 
| 47 | 53 | 
| 48 function ReBinder:IsEnabled() | 54 function ReBound:IsEnabled() | 
| 49 return ReBinderFrame:IsVisible() | 55 return ReBoundFrame:IsVisible() | 
| 50 end | 56 end | 
| 51 | 57 | 
| 52 function ReBinder:Enable() | 58 function ReBound:Enable() | 
| 53 ReBinderFrame:Show() | 59 if InCombatLockdown() then | 
| 60 UIErrorsFrame:AddMessage("Can't set keybindings in combat") | |
| 61 else | |
| 62 ReBoundFrame:Show() | |
| 63 end | |
| 54 end | 64 end | 
| 55 | 65 | 
| 56 function ReBinder:Disable() | 66 function ReBound:Disable() | 
| 57 ReBinderFrame:Hide() | 67 ReBoundFrame:Hide() | 
| 58 end | 68 end | 
| 59 | 69 | 
| 60 | 70 | 
| 61 function ReBinder:HandleKeyPressed( key ) | 71 local mouseButtonConvert = { | 
| 72 LeftButton = "BUTTON1", | |
| 73 RightButton = "BUTTON2", | |
| 74 MiddleButton = "BUTTON3", | |
| 75 Button4 = "BUTTON4", | |
| 76 Button5 = "BUTTON5" | |
| 77 } | |
| 78 | |
| 79 function ReBound:HandleKeyPressed( key ) | |
| 62 if key == nil or key == "UNKNOWN" or key == "SHIFT" or key == "CTRL" or key == "ALT" then | 80 if key == nil or key == "UNKNOWN" or key == "SHIFT" or key == "CTRL" or key == "ALT" then | 
| 63 return | 81 return | 
| 64 end | 82 end | 
| 65 if IsShiftKeyDown() then | 83 if IsShiftKeyDown() then | 
| 66 key = "SHIFT-"..key | 84 key = "SHIFT-"..key | 
| 69 key = "CTRL-"..key | 87 key = "CTRL-"..key | 
| 70 end | 88 end | 
| 71 if IsAltKeyDown() then | 89 if IsAltKeyDown() then | 
| 72 key = "ALT-"..key | 90 key = "ALT-"..key | 
| 73 end | 91 end | 
| 74 if key == "ESCAPE" or GetBindingAction(key) == "REBINDER_TOGGLEBINDINGMODE" then | 92 if key == "ESCAPE" or GetBindingAction(key) == "ReBound_TOGGLEBINDINGMODE" then | 
| 75 ReBinderFrame:Hide() | 93 ReBoundFrame:Hide() | 
| 76 return nil, nil | 94 return nil, nil | 
| 77 end | 95 end | 
| 78 | 96 key = mouseButtonConvert[key] or key | 
| 97 | |
| 79 self.selectedKey = key | 98 self.selectedKey = key | 
| 99 | |
| 100 -- change cursor to glowing hand | |
| 101 SetCursor("CAST_CURSOR") | |
| 80 | 102 | 
| 81 local keyTxt = GetBindingText(key, "KEY_") | 103 local keyTxt = GetBindingText(key, "KEY_") | 
| 82 local cmd = GetBindingAction(key) | 104 local cmd = GetBindingAction(key) | 
| 83 local cmdTxt | 105 local cmdTxt | 
| 84 | 106 | 
| 95 | 117 | 
| 96 return keyTxt, btnName or cmdTxt | 118 return keyTxt, btnName or cmdTxt | 
| 97 end | 119 end | 
| 98 | 120 | 
| 99 -- TODO: move to override-binding model and store data in profile | 121 -- TODO: move to override-binding model and store data in profile | 
| 100 function ReBinder:BindSelectedKeyTo( btnName ) | 122 function ReBound:BindSelectedKeyTo( btnName ) | 
| 101 if self.selectedKey and btnName then | 123 if self.selectedKey and btnName then | 
| 102 self:ClearBinding(btnName) | 124 self:ClearBinding(btnName) | 
| 103 SetBindingClick(self.selectedKey, btnName, "LeftButton") | 125 SetBindingClick(self.selectedKey, btnName, "LeftButton") | 
| 104 SaveBindings(2) -- 2 = character-specific | 126 SaveBindings(2) -- 2 = character-specific | 
| 105 ReBinderFrame.statusMsg:SetText(GetBindingText(self.selectedKey, "KEY_") .. " is now bound to " .. btnName) | 127 ReBoundFrame.statusMsg:SetText(GetBindingText(self.selectedKey, "KEY_") .. " is now bound to " .. btnName) | 
| 106 ReBinderFrame.selectedKey:SetText("(none)") | 128 ReBoundFrame.selectedKey:SetText("(none)") | 
| 107 ReBinderFrame.currentAction:SetText("(none)") | 129 ReBoundFrame.currentAction:SetText("(none)") | 
| 108 self.selectedKey = nil | 130 self:ClearSelectedKey() | 
| 109 end | 131 end | 
| 110 end | 132 end | 
| 111 | 133 | 
| 112 | 134 | 
| 113 function ReBinder:ClearBinding( btnName ) | 135 function ReBound:ClearBinding( btnName ) | 
| 114 if btnName then | 136 if btnName then | 
| 115 local current = GetBindingKey("CLICK "..btnName..":LeftButton") | 137 local current = GetBindingKey("CLICK "..btnName..":LeftButton") | 
| 116 if current then | 138 if current then | 
| 117 SetBinding(current, nil) | 139 SetBinding(current, nil) | 
| 118 ReBinderFrame.statusMsg:SetText("|cFFFF3333"..btnName .. " is now unbound|r") | 140 ReBoundFrame.statusMsg:SetText("|cFFFF3333"..btnName .. " is now unbound|r") | 
| 119 end | 141 end | 
| 120 end | 142 end | 
| 121 end | 143 end | 
| 122 | 144 | 
| 123 | 145 | 
| 124 function ReBinder:UpdateCurrentTarget( btnName ) | 146 function ReBound:UpdateCurrentTarget( btnName ) | 
| 125 local msg = "" | 147 local msg = "" | 
| 126 if btnName then | 148 if btnName then | 
| 127 msg = btnName.." is currently " | 149 msg = btnName.." is currently " | 
| 128 local current = GetBindingKey("CLICK "..btnName..":LeftButton") | 150 local current = GetBindingKey("CLICK "..btnName..":LeftButton") | 
| 129 if current then | 151 if current then | 
| 130 msg = msg .. "bound to " .. GetBindingText(current, "KEY_") | 152 msg = msg .. "bound to " .. GetBindingText(current, "KEY_") | 
| 131 else | 153 else | 
| 132 msg = msg .. " not bound" | 154 msg = msg .. " not bound" | 
| 133 end | 155 end | 
| 134 end | 156 end | 
| 135 ReBinderFrame.statusMsg:SetText(msg) | 157 ReBoundFrame.statusMsg:SetText(msg) | 
| 136 end | 158 end | 
