annotate classes/ReBound.lua @ 10:f3a7bfebc283

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