Mercurial > wow > reaction
comparison classes/ReBinder.lua @ 4:dfd829db3ad0
(none)
| author | Flick <flickerstreak@gmail.com> |
|---|---|
| date | Tue, 20 Mar 2007 21:19:34 +0000 |
| parents | ReBinder.lua@8e0ff8ae4c08 |
| children |
comparison
equal
deleted
inserted
replaced
| 3:f5607e135c37 | 4:dfd829db3ad0 |
|---|---|
| 1 -- ReBinder.lua | |
| 2 -- | |
| 3 | |
| 4 ReBinder = { } | |
| 5 | |
| 6 -- initial values | |
| 7 ReBinder.active = false | |
| 8 | |
| 9 ReBinder.targets = { } | |
| 10 | |
| 11 function ReBinder:AddKeybindTarget( t ) | |
| 12 if t then | |
| 13 self.targets[t] = CreateFrame("Button", nil, t, "ReBinderClickBindingTemplate") | |
| 14 self.targets[t].keybindTarget = t:GetName() | |
| 15 end | |
| 16 end | |
| 17 | |
| 18 function ReBinder:RemoveKeybindTarget( t ) | |
| 19 if t then | |
| 20 self.targets[t] = nil | |
| 21 end | |
| 22 end | |
| 23 | |
| 24 function ReBinder:ShowClickBindingButtons() | |
| 25 for _, clickFrame in pairs(self.targets) do | |
| 26 clickFrame:Show() | |
| 27 end | |
| 28 end | |
| 29 | |
| 30 function ReBinder:HideClickBindingButtons() | |
| 31 for _, clickFrame in pairs(self.targets) do | |
| 32 clickFrame:Hide() | |
| 33 end | |
| 34 end | |
| 35 | |
| 36 function ReBinder:ClearSelectedKey() | |
| 37 self.selectedKey = nil | |
| 38 end | |
| 39 | |
| 40 function ReBinder:ToggleEnabled() | |
| 41 if self:IsEnabled() then | |
| 42 self:Disable() | |
| 43 else | |
| 44 self:Enable() | |
| 45 end | |
| 46 end | |
| 47 | |
| 48 function ReBinder:IsEnabled() | |
| 49 return ReBinderFrame:IsVisible() | |
| 50 end | |
| 51 | |
| 52 function ReBinder:Enable() | |
| 53 ReBinderFrame:Show() | |
| 54 end | |
| 55 | |
| 56 function ReBinder:Disable() | |
| 57 ReBinderFrame:Hide() | |
| 58 end | |
| 59 | |
| 60 | |
| 61 function ReBinder:HandleKeyPressed( key ) | |
| 62 if key == nil or key == "UNKNOWN" or key == "SHIFT" or key == "CTRL" or key == "ALT" then | |
| 63 return | |
| 64 end | |
| 65 if IsShiftKeyDown() then | |
| 66 key = "SHIFT-"..key | |
| 67 end | |
| 68 if IsControlKeyDown() then | |
| 69 key = "CTRL-"..key | |
| 70 end | |
| 71 if IsAltKeyDown() then | |
| 72 key = "ALT-"..key | |
| 73 end | |
| 74 if key == "ESCAPE" or GetBindingAction(key) == "REBINDER_TOGGLEBINDINGMODE" then | |
| 75 ReBinderFrame:Hide() | |
| 76 return nil, nil | |
| 77 end | |
| 78 | |
| 79 self.selectedKey = key | |
| 80 | |
| 81 local keyTxt = GetBindingText(key, "KEY_") | |
| 82 local cmd = GetBindingAction(key) | |
| 83 local cmdTxt | |
| 84 | |
| 85 if cmd then | |
| 86 cmdTxt = GetBindingText(cmd, "BINDING_NAME_") | |
| 87 end | |
| 88 | |
| 89 -- make click-bindings look prettier | |
| 90 local btnName | |
| 91 if cmdTxt then | |
| 92 btnName = string.match(cmdTxt,"CLICK (.+)\:LeftButton") | |
| 93 btnName = btnName or string.match(cmdTxt,"CLICK (.+)\:RightButton") | |
| 94 end | |
| 95 | |
| 96 return keyTxt, btnName or cmdTxt | |
| 97 end | |
| 98 | |
| 99 -- TODO: move to override-binding model and store data in profile | |
| 100 function ReBinder:BindSelectedKeyTo( btnName ) | |
| 101 if self.selectedKey and btnName then | |
| 102 self:ClearBinding(btnName) | |
| 103 SetBindingClick(self.selectedKey, btnName, "LeftButton") | |
| 104 SaveBindings(2) -- 2 = character-specific | |
| 105 ReBinderFrame.statusMsg:SetText(GetBindingText(self.selectedKey, "KEY_") .. " is now bound to " .. btnName) | |
| 106 ReBinderFrame.selectedKey:SetText("(none)") | |
| 107 ReBinderFrame.currentAction:SetText("(none)") | |
| 108 self.selectedKey = nil | |
| 109 end | |
| 110 end | |
| 111 | |
| 112 | |
| 113 function ReBinder:ClearBinding( btnName ) | |
| 114 if btnName then | |
| 115 local current = GetBindingKey("CLICK "..btnName..":LeftButton") | |
| 116 if current then | |
| 117 SetBinding(current, nil) | |
| 118 ReBinderFrame.statusMsg:SetText("|cFFFF3333"..btnName .. " is now unbound|r") | |
| 119 end | |
| 120 end | |
| 121 end | |
| 122 | |
| 123 | |
| 124 function ReBinder:UpdateCurrentTarget( btnName ) | |
| 125 local msg = "" | |
| 126 if btnName then | |
| 127 msg = btnName.." is currently " | |
| 128 local current = GetBindingKey("CLICK "..btnName..":LeftButton") | |
| 129 if current then | |
| 130 msg = msg .. "bound to " .. GetBindingText(current, "KEY_") | |
| 131 else | |
| 132 msg = msg .. " not bound" | |
| 133 end | |
| 134 end | |
| 135 ReBinderFrame.statusMsg:SetText(msg) | |
| 136 end |
