WoWInterface SVN fernir_UI

[/] [binder.lua] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Wildbreath-135052
local Binder=CreateFrame("Frame")
2 Wildbreath-135052
 
3 Wildbreath-135052
Binder:SetScript("OnEvent",function(self,event,...) self[event](self,event,...) end)
4 Wildbreath-135052
 
5 Wildbreath-135052
--Binder:RegisterEvent("PLAYER_LOGIN")
6 Wildbreath-135052
Binder:RegisterEvent("PLAYER_ENTERING_WORLD")
7 Wildbreath-135052
Binder:RegisterEvent("VARIABLES_LOADED")
8 Wildbreath-135052
 
9 Wildbreath-135052
-- OnLoad
10 Wildbreath-135052
function Binder.VARIABLES_LOADED()
11 Wildbreath-135052
        if Binder_BindPerChar == nil then
12 Wildbreath-135052
                Binder_BindPerChar = true
13 Wildbreath-135052
        end
14 Wildbreath-135052
        Binder.IsOn = false
15 Wildbreath-135052
end
16 Wildbreath-135052
 
17 Wildbreath-135052
function Binder.PLAYER_ENTERING_WORLD(addon)
18 Wildbreath-135052
        Binder:UnregisterEvent("PLAYER_ENTERING_WORLD")
19 Wildbreath-135052
        print("|c66FF66FF/sb|cFFFFFFFF for change your binds.")
20 Wildbreath-135052
 
21 Wildbreath-135052
        Binder.CreateGUI()
22 Wildbreath-135052
        KeyBindingFrame_LoadUI()
23 Wildbreath-135052
 
24 Wildbreath-135052
        SLASH_BINDER1 = "/sb";
25 Wildbreath-135052
        SlashCmdList["BINDER"] = Binder.SlashCommand;
26 Wildbreath-135052
end
27 Wildbreath-135052
 
28 Wildbreath-135052
-- OnEnter
29 Wildbreath-135052
function BinderFrame_OnEnter(self)
30 Wildbreath-135052
        local keyBind = GetBindingKey(strupper(self.button))
31 Wildbreath-135052
        local bind = _G[self:GetName().."Binding"]
32 Wildbreath-135052
        local midText = BinderBindingKey
33 Wildbreath-135052
        if keyBind then keyBind = gsub(gsub(keyBind, "BUTTON3", "Middle Mouse"), '-', ' ') end
34 Wildbreath-135052
 
35 Wildbreath-135052
        bind:SetText(keyBind)
36 Wildbreath-135052
        midText:SetText(keyBind)
37 Wildbreath-135052
        midText:Show()
38 Wildbreath-135052
 
39 Wildbreath-135052
        self:SetBackdropColor(1,0,0,.5)
40 Wildbreath-135052
        self:EnableKeyboard(true)
41 Wildbreath-135052
end
42 Wildbreath-135052
 
43 Wildbreath-135052
-- OnLeave
44 Wildbreath-135052
function BinderFrame_OnLeave(self)
45 Wildbreath-135052
        local bind = _G[self:GetName().."Binding"]
46 Wildbreath-135052
        BinderBindingKey:Hide()
47 Wildbreath-135052
 
48 Wildbreath-135052
        self:SetBackdropColor(1,1,1,.5)
49 Wildbreath-135052
        self:EnableKeyboard(false)
50 Wildbreath-135052
end
51 Wildbreath-135052
 
52 Wildbreath-135052
-- OnKeyDown
53 Wildbreath-135052
function BinderFrame_OnKeyDown(self, key, ...)
54 Wildbreath-135052
        local bind = _G[self:GetName().."Binding"] -- Sets up a local variable for our text file
55 Wildbreath-135052
 
56 Wildbreath-135052
        if key == "LSHIFT" or key == "RSHIFT" or key == "LCTRL" or key == "RCTRL" or key == "LALT" or key == "RALT" or key == "LeftButton" or key == "RightButton" then
57 Wildbreath-135052
                return -- stop running function if it's being run from a modifier key down
58 Wildbreath-135052
        end
59 Wildbreath-135052
 
60 Wildbreath-135052
        if key == "MiddleButton" then key = "BUTTON3" end
61 Wildbreath-135052
        if key == "Button4" then key = "BUTTON4" end
62 Wildbreath-135052
        if key == "Button5" then key = "BUTTON5" end
63 Wildbreath-135052
 
64 Wildbreath-135052
        if key == "ESCAPE" then
65 Wildbreath-135052
                SetBinding(GetBindingKey(strupper(self.button)))
66 Wildbreath-135052
        else
67 Wildbreath-135052
                if IsShiftKeyDown() then key = "SHIFT-"..key end
68 Wildbreath-135052
                if IsControlKeyDown() then key = "CTRL-"..key end
69 Wildbreath-135052
                if IsAltKeyDown() then key = "ALT-"..key end
70 Wildbreath-135052
                if GetBindingKey(strupper(self.button)) then
71 Wildbreath-135052
                        SetBinding(GetBindingKey(strupper(self.button)))
72 Wildbreath-135052
                end
73 Wildbreath-135052
                SetBinding(key, strupper(self.button))
74 Wildbreath-135052
        end
75 Wildbreath-135052
 
76 Wildbreath-135052
        BinderFrame_OnEnter(self)
77 Wildbreath-135052
 
78 Wildbreath-135052
        for i = 1, 60 do
79 Wildbreath-135052
                local f = _G["BinderFrame"..i]
80 Wildbreath-135052
                local keyBind = GetBindingKey(strupper(f.button))
81 Wildbreath-135052
                local bind = _G[f:GetName().."Binding"]
82 Wildbreath-135052
 
83 Wildbreath-135052
                if keyBind then keyBind = gsub(gsub(keyBind, "BUTTON3", "Middle Mouse"), '-', ' ') end
84 Wildbreath-135052
                bind:SetText(keyBind)
85 Wildbreath-135052
        end
86 Wildbreath-135052
end
87 Wildbreath-135052
 
88 Wildbreath-135052
function Binder.CreateGUI()
89 Wildbreath-135052
        Binder.CharSpecFrame=CreateFrame("frame")
90 Wildbreath-135052
        Binder.CharSpecFrame:EnableMouse(true)
91 Wildbreath-135052
        Binder.CharSpecFrame:SetMovable(true)
92 Wildbreath-135052
        Binder.CharSpecFrame:SetScript("OnMouseDown", function(self) self:StartMoving() end)
93 Wildbreath-135052
        Binder.CharSpecFrame:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
94 Wildbreath-135052
        Binder.CharSpecFrame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
95 Wildbreath-135052
        Binder.CharSpecFrame:SetBackdropColor(0, 0, 0, .4)
96 Wildbreath-135052
        Binder.CharSpecFrame:SetWidth(125) Binder.CharSpecFrame:SetHeight(55)
97 Wildbreath-135052
        Binder.CharSpecFrame:SetPoint("CENTER",UIParent)
98 Wildbreath-135052
        local tt = Binder.CharSpecFrame:CreateTexture(nil,"BACKGROUND") tt:SetTexture(0.19,0.19,0.19,1) tt:SetAllPoints(Binder.CharSpecFrame)
99 Wildbreath-135052
 
100 Wildbreath-135052
        Binder.CharSpecButton=CreateFrame("checkbutton",nil,Binder.CharSpecFrame,"OptionsCheckButtonTemplate")
101 Wildbreath-135052
        Binder.CharSpecButton:SetText("Char Specific")
102 Wildbreath-135052
        Binder.CharSpecButton:SetChecked(Binder_BindPerChar)
103 Wildbreath-135052
        Binder.CharSpecButton:SetPoint("TOPLEFT",7,-5)
104 Wildbreath-135052
        Binder.CharSpecButton:SetScript("OnClick", function()
105 Wildbreath-135052
                Binder_BindPerChar = this:GetChecked()
106 Wildbreath-135052
                if not Binder_BindPerChar then Binder_BindPerChar = false end
107 Wildbreath-135052
        end)
108 Wildbreath-135052
        Binder.CharSpecButton:SetScript("OnMouseDown", function() this:GetParent():StartMoving() end)
109 Wildbreath-135052
        Binder.CharSpecButton:SetScript("OnMouseUp", function() this:GetParent():StopMovingOrSizing() end)
110 Wildbreath-135052
        Binder.CharSpecButton:Show()
111 Wildbreath-135052
        local fstring1 = Binder.CharSpecFrame:CreateFontString("fs1","OVERLAY","GameFontNormal")
112 Wildbreath-135052
        fstring1:SetText("Char Specific")
113 Wildbreath-135052
        fstring1:SetPoint("LEFT", Binder.CharSpecButton, "RIGHT", 2, 0)
114 Wildbreath-135052
 
115 Wildbreath-135052
        Binder.SaveButton=CreateFrame("button",nil,Binder.CharSpecFrame,"OptionsButtonTemplate")
116 Wildbreath-135052
        Binder.SaveButton:SetWidth(55) Binder.SaveButton:SetHeight(21)
117 Wildbreath-135052
        Binder.SaveButton:SetText("Save")
118 Wildbreath-135052
        Binder.SaveButton:SetPoint("BOTTOMLEFT",7,7)
119 Wildbreath-135052
        Binder.SaveButton:SetScript("OnClick", function() Binder.SlashCommand("bind") end)
120 Wildbreath-135052
        Binder.SaveButton:Show()
121 Wildbreath-135052
 
122 Wildbreath-135052
        Binder.CancelButton=CreateFrame("button",nil,Binder.CharSpecFrame,"OptionsButtonTemplate")
123 Wildbreath-135052
        Binder.CancelButton:SetWidth(55) Binder.CancelButton:SetHeight(21)
124 Wildbreath-135052
        Binder.CancelButton:SetText("Cancel")
125 Wildbreath-135052
        Binder.CancelButton:SetPoint("LEFT",Binder.SaveButton,"RIGHT",2,0)
126 Wildbreath-135052
        Binder.CancelButton:SetScript("OnClick", function() Binder.SlashCommand("bind", true) end)
127 Wildbreath-135052
        Binder.CancelButton:Show()
128 Wildbreath-135052
        Binder.CharSpecFrame:Hide()
129 Wildbreath-135052
 
130 Wildbreath-135052
        local function setUp(frame, anchor, str_action)
131 Wildbreath-135052
                frame:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 32,})
132 Wildbreath-135052
                frame:SetAllPoints(anchor)
133 Wildbreath-135052
                frame:SetBackdropColor(1,1,1,.5)
134 Wildbreath-135052
                frame:Hide()
135 Wildbreath-135052
                frame:SetAlpha(1)
136 Wildbreath-135052
                frame:EnableMouse(true)
137 Wildbreath-135052
                frame:SetFrameStrata("TOOLTIP")
138 Wildbreath-135052
                frame.button = str_action
139 Wildbreath-135052
                --print (str_action)
140 Wildbreath-135052
 
141 Wildbreath-135052
                frame:SetScript("OnEnter", BinderFrame_OnEnter)
142 Wildbreath-135052
                frame:SetScript("OnLeave", BinderFrame_OnLeave)
143 Wildbreath-135052
                frame:SetScript("OnKeyDown", BinderFrame_OnKeyDown)
144 Wildbreath-135052
                frame:SetScript("OnMouseDown", BinderFrame_OnKeyDown)
145 Wildbreath-135052
 
146 Wildbreath-135052
                local s = frame:CreateFontString("$parentBinding", "ARTWORK", "GameFontNormal")
147 Wildbreath-135052
                s:SetPoint("CENTER")
148 Wildbreath-135052
                s:SetHeight(anchor:GetHeight())
149 Wildbreath-135052
                s:SetWidth(anchor:GetWidth())
150 Wildbreath-135052
 
151 Wildbreath-135052
                local keyBind = GetBindingKey(strupper(frame.button))
152 Wildbreath-135052
                if keyBind then keyBind = gsub(gsub(keyBind, "BUTTON3", "Middle Mouse"), '-', ' ') end
153 Wildbreath-135052
                s:SetText(keyBind)
154 Wildbreath-135052
        end
155 Wildbreath-135052
 
156 Wildbreath-135052
        for i=1, GetNumShapeshiftForms() do
157 Wildbreath-135052
                local f = CreateFrame("Frame", "ShapeshiftBinderFrame"..i, UIParent)
158 Wildbreath-135052
                local anchor = _G["ShapeshiftButton"..i]
159 Wildbreath-135052
                setUp(f, anchor, anchor:GetName())
160 Wildbreath-135052
        end
161 Wildbreath-135052
 
162 Wildbreath-135052
        if select(2, UnitClass("player")) == "SHAMAN" then
163 Wildbreath-135052
                for i = 1, 4 do
164 Wildbreath-135052
                        local f = CreateFrame("Frame", "MultiCastBinderFrame"..i, UIParent)
165 Wildbreath-135052
                        local anchor = _G["MultiCastActionButton"..i]
166 Wildbreath-135052
                        setUp(f, anchor, anchor:GetName())
167 Wildbreath-135052
                end
168 Wildbreath-135052
        end
169 Wildbreath-135052
 
170 Wildbreath-135052
        for i = 1, 12 do
171 Wildbreath-135052
                local f = CreateFrame("Frame", "BinderFrame"..i, UIParent)
172 Wildbreath-135052
                local anchor = _G["ActionButton"..i]
173 Wildbreath-135052
                setUp(f, anchor, anchor:GetName())
174 Wildbreath-135052
 
175 Wildbreath-135052
                f = CreateFrame("Frame", "BinderFrame"..i+12, UIParent)
176 Wildbreath-135052
                anchor = _G["MultiBarBottomLeftButton"..i]
177 Wildbreath-135052
                setUp(f, anchor, "MULTIACTIONBAR1BUTTON"..i)
178 Wildbreath-135052
 
179 Wildbreath-135052
                f = CreateFrame("Frame", "BinderFrame"..i+24, UIParent)
180 Wildbreath-135052
                anchor = _G["MultiBarBottomRightButton"..i]
181 Wildbreath-135052
                setUp(f, anchor, "MULTIACTIONBAR2BUTTON"..i)
182 Wildbreath-135052
 
183 Wildbreath-135052
                f = CreateFrame("Frame", "BinderFrame"..i+36, UIParent)
184 Wildbreath-135052
                anchor = _G["MultiBarRightButton"..i]
185 Wildbreath-135052
                setUp(f, anchor, "MULTIACTIONBAR3BUTTON"..i)
186 Wildbreath-135052
 
187 Wildbreath-135052
                f = CreateFrame("Frame", "BinderFrame"..i+48, UIParent)
188 Wildbreath-135052
                anchor = _G["MultiBarLeftButton"..i]
189 Wildbreath-135052
                setUp(f, anchor, "MULTIACTIONBAR4BUTTON"..i)
190 Wildbreath-135052
 
191 Wildbreath-135052
                f = CreateFrame("Frame", "BinderFrame"..i+60, UIParent)
192 Wildbreath-135052
                anchor = _G["MultiBarLeftButton"..i]
193 Wildbreath-135052
                setUp(f, anchor, "MULTIACTIONBAR5BUTTON"..i)
194 Wildbreath-135052
        end
195 Wildbreath-135052
 
196 Wildbreath-135052
        local s = UIParent:CreateFontString("BinderBindingKey", "ARTWORK", "GameFontNormalLarge")
197 Wildbreath-135052
        s:SetPoint("CENTER")
198 Wildbreath-135052
        s:Hide()
199 Wildbreath-135052
end
200 Wildbreath-135052
 
201 Wildbreath-135052
function Binder.SlashCommand(cmd, cancel)
202 Wildbreath-135052
        local updString = "|c00aa00fBinder|cFFFFFFFF "
203 Wildbreath-135052
        local text
204 Wildbreath-135052
 
205 Wildbreath-135052
        Binder.IsOn = not Binder.IsOn
206 Wildbreath-135052
 
207 Wildbreath-135052
        for i=1, GetNumShapeshiftForms() do
208 Wildbreath-135052
                local f = _G["ShapeshiftBinderFrame"..i]
209 Wildbreath-135052
                if Binder.IsOn then
210 Wildbreath-135052
                        f:Show()
211 Wildbreath-135052
                else
212 Wildbreath-135052
                        f:Hide()
213 Wildbreath-135052
                end
214 Wildbreath-135052
        end
215 Wildbreath-135052
 
216 Wildbreath-135052
        if select(2, UnitClass("player")) == "SHAMAN" then
217 Wildbreath-135052
                for i=1, 4 do
218 Wildbreath-135052
                        local f = _G["MultiCastBinderFrame"..i]
219 Wildbreath-135052
                        if Binder.IsOn then
220 Wildbreath-135052
                                f:Show()
221 Wildbreath-135052
                        else
222 Wildbreath-135052
                                f:Hide()
223 Wildbreath-135052
                        end
224 Wildbreath-135052
                end
225 Wildbreath-135052
        end
226 Wildbreath-135052
 
227 Wildbreath-135052
        for i = 1, 60 do
228 Wildbreath-135052
                local f = _G["BinderFrame"..i]
229 Wildbreath-135052
                if Binder.IsOn then
230 Wildbreath-135052
                        f:Show()
231 Wildbreath-135052
                else
232 Wildbreath-135052
                        f:Hide()
233 Wildbreath-135052
                end
234 Wildbreath-135052
        end
235 Wildbreath-135052
 
236 Wildbreath-135052
        if Binder.IsOn then
237 Wildbreath-135052
                text = "enabled!"
238 Wildbreath-135052
                Binder.CharSpecFrame:Show()
239 Wildbreath-135052
        elseif not cancel then
240 Wildbreath-135052
                text = "saved!"
241 Wildbreath-135052
 
242 Wildbreath-135052
                Binder.CharSpecFrame:Hide()
243 Wildbreath-135052
                if Binder_BindPerChar then
244 Wildbreath-135052
                        SaveBindings(2)
245 Wildbreath-135052
                else
246 Wildbreath-135052
                        SaveBindings(1)
247 Wildbreath-135052
                end
248 Wildbreath-135052
        else
249 Wildbreath-135052
                text = "canceled!"
250 Wildbreath-135052
                Binder.CharSpecFrame:Hide()
251 Wildbreath-135052
        end
252 Wildbreath-135052
 
253 Wildbreath-135052
        print(updString.."bindings "..text)
254 Wildbreath-135052
end