Mercurial > wow > reaction
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/classes/ReBinder.lua Tue Mar 20 21:19:34 2007 +0000 @@ -0,0 +1,136 @@ +-- ReBinder.lua +-- + +ReBinder = { } + +-- initial values +ReBinder.active = false + +ReBinder.targets = { } + +function ReBinder:AddKeybindTarget( t ) + if t then + self.targets[t] = CreateFrame("Button", nil, t, "ReBinderClickBindingTemplate") + self.targets[t].keybindTarget = t:GetName() + end +end + +function ReBinder:RemoveKeybindTarget( t ) + if t then + self.targets[t] = nil + end +end + +function ReBinder:ShowClickBindingButtons() + for _, clickFrame in pairs(self.targets) do + clickFrame:Show() + end +end + +function ReBinder:HideClickBindingButtons() + for _, clickFrame in pairs(self.targets) do + clickFrame:Hide() + end +end + +function ReBinder:ClearSelectedKey() + self.selectedKey = nil +end + +function ReBinder:ToggleEnabled() + if self:IsEnabled() then + self:Disable() + else + self:Enable() + end +end + +function ReBinder:IsEnabled() + return ReBinderFrame:IsVisible() +end + +function ReBinder:Enable() + ReBinderFrame:Show() +end + +function ReBinder:Disable() + ReBinderFrame:Hide() +end + + +function ReBinder:HandleKeyPressed( key ) + if key == nil or key == "UNKNOWN" or key == "SHIFT" or key == "CTRL" or key == "ALT" then + return + end + if IsShiftKeyDown() then + key = "SHIFT-"..key + end + if IsControlKeyDown() then + key = "CTRL-"..key + end + if IsAltKeyDown() then + key = "ALT-"..key + end + if key == "ESCAPE" or GetBindingAction(key) == "REBINDER_TOGGLEBINDINGMODE" then + ReBinderFrame:Hide() + return nil, nil + end + + self.selectedKey = key + + local keyTxt = GetBindingText(key, "KEY_") + local cmd = GetBindingAction(key) + local cmdTxt + + if cmd then + cmdTxt = GetBindingText(cmd, "BINDING_NAME_") + end + + -- make click-bindings look prettier + local btnName + if cmdTxt then + btnName = string.match(cmdTxt,"CLICK (.+)\:LeftButton") + btnName = btnName or string.match(cmdTxt,"CLICK (.+)\:RightButton") + end + + return keyTxt, btnName or cmdTxt +end + +-- TODO: move to override-binding model and store data in profile +function ReBinder:BindSelectedKeyTo( btnName ) + if self.selectedKey and btnName then + self:ClearBinding(btnName) + SetBindingClick(self.selectedKey, btnName, "LeftButton") + SaveBindings(2) -- 2 = character-specific + ReBinderFrame.statusMsg:SetText(GetBindingText(self.selectedKey, "KEY_") .. " is now bound to " .. btnName) + ReBinderFrame.selectedKey:SetText("(none)") + ReBinderFrame.currentAction:SetText("(none)") + self.selectedKey = nil + end +end + + +function ReBinder:ClearBinding( btnName ) + if btnName then + local current = GetBindingKey("CLICK "..btnName..":LeftButton") + if current then + SetBinding(current, nil) + ReBinderFrame.statusMsg:SetText("|cFFFF3333"..btnName .. " is now unbound|r") + end + end +end + + +function ReBinder:UpdateCurrentTarget( btnName ) + local msg = "" + if btnName then + msg = btnName.." is currently " + local current = GetBindingKey("CLICK "..btnName..":LeftButton") + if current then + msg = msg .. "bound to " .. GetBindingText(current, "KEY_") + else + msg = msg .. " not bound" + end + end + ReBinderFrame.statusMsg:SetText(msg) +end