Compare with Previous | Blame | View Log
local Binder=CreateFrame("Frame") Binder:SetScript("OnEvent",function(self,event,...) self[event](self,event,...) end) --Binder:RegisterEvent("PLAYER_LOGIN") Binder:RegisterEvent("PLAYER_ENTERING_WORLD") Binder:RegisterEvent("VARIABLES_LOADED") -- OnLoad function Binder.VARIABLES_LOADED() if Binder_BindPerChar == nil then Binder_BindPerChar = true end Binder.IsOn = false end function Binder.PLAYER_ENTERING_WORLD(addon) Binder:UnregisterEvent("PLAYER_ENTERING_WORLD") print("|c66FF66FF/sb|cFFFFFFFF for change your binds.") Binder.CreateGUI() KeyBindingFrame_LoadUI() SLASH_BINDER1 = "/sb"; SlashCmdList["BINDER"] = Binder.SlashCommand; end -- OnEnter function BinderFrame_OnEnter(self) local keyBind = GetBindingKey(strupper(self.button)) local bind = _G[self:GetName().."Binding"] local midText = BinderBindingKey if keyBind then keyBind = gsub(gsub(keyBind, "BUTTON3", "Middle Mouse"), '-', ' ') end bind:SetText(keyBind) midText:SetText(keyBind) midText:Show() self:SetBackdropColor(1,0,0,.5) self:EnableKeyboard(true) end -- OnLeave function BinderFrame_OnLeave(self) local bind = _G[self:GetName().."Binding"] BinderBindingKey:Hide() self:SetBackdropColor(1,1,1,.5) self:EnableKeyboard(false) end -- OnKeyDown function BinderFrame_OnKeyDown(self, key, ...) local bind = _G[self:GetName().."Binding"] -- Sets up a local variable for our text file 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 return -- stop running function if it's being run from a modifier key down end if key == "MiddleButton" then key = "BUTTON3" end if key == "Button4" then key = "BUTTON4" end if key == "Button5" then key = "BUTTON5" end if key == "ESCAPE" then SetBinding(GetBindingKey(strupper(self.button))) else if IsShiftKeyDown() then key = "SHIFT-"..key end if IsControlKeyDown() then key = "CTRL-"..key end if IsAltKeyDown() then key = "ALT-"..key end if GetBindingKey(strupper(self.button)) then SetBinding(GetBindingKey(strupper(self.button))) end SetBinding(key, strupper(self.button)) end BinderFrame_OnEnter(self) for i = 1, 60 do local f = _G["BinderFrame"..i] local keyBind = GetBindingKey(strupper(f.button)) local bind = _G[f:GetName().."Binding"] if keyBind then keyBind = gsub(gsub(keyBind, "BUTTON3", "Middle Mouse"), '-', ' ') end bind:SetText(keyBind) end end function Binder.CreateGUI() Binder.CharSpecFrame=CreateFrame("frame") Binder.CharSpecFrame:EnableMouse(true) Binder.CharSpecFrame:SetMovable(true) Binder.CharSpecFrame:SetScript("OnMouseDown", function(self) self:StartMoving() end) Binder.CharSpecFrame:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end) Binder.CharSpecFrame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end) Binder.CharSpecFrame:SetBackdropColor(0, 0, 0, .4) Binder.CharSpecFrame:SetWidth(125) Binder.CharSpecFrame:SetHeight(55) Binder.CharSpecFrame:SetPoint("CENTER",UIParent) local tt = Binder.CharSpecFrame:CreateTexture(nil,"BACKGROUND") tt:SetTexture(0.19,0.19,0.19,1) tt:SetAllPoints(Binder.CharSpecFrame) Binder.CharSpecButton=CreateFrame("checkbutton",nil,Binder.CharSpecFrame,"OptionsCheckButtonTemplate") Binder.CharSpecButton:SetText("Char Specific") Binder.CharSpecButton:SetChecked(Binder_BindPerChar) Binder.CharSpecButton:SetPoint("TOPLEFT",7,-5) Binder.CharSpecButton:SetScript("OnClick", function() Binder_BindPerChar = this:GetChecked() if not Binder_BindPerChar then Binder_BindPerChar = false end end) Binder.CharSpecButton:SetScript("OnMouseDown", function() this:GetParent():StartMoving() end) Binder.CharSpecButton:SetScript("OnMouseUp", function() this:GetParent():StopMovingOrSizing() end) Binder.CharSpecButton:Show() local fstring1 = Binder.CharSpecFrame:CreateFontString("fs1","OVERLAY","GameFontNormal") fstring1:SetText("Char Specific") fstring1:SetPoint("LEFT", Binder.CharSpecButton, "RIGHT", 2, 0) Binder.SaveButton=CreateFrame("button",nil,Binder.CharSpecFrame,"OptionsButtonTemplate") Binder.SaveButton:SetWidth(55) Binder.SaveButton:SetHeight(21) Binder.SaveButton:SetText("Save") Binder.SaveButton:SetPoint("BOTTOMLEFT",7,7) Binder.SaveButton:SetScript("OnClick", function() Binder.SlashCommand("bind") end) Binder.SaveButton:Show() Binder.CancelButton=CreateFrame("button",nil,Binder.CharSpecFrame,"OptionsButtonTemplate") Binder.CancelButton:SetWidth(55) Binder.CancelButton:SetHeight(21) Binder.CancelButton:SetText("Cancel") Binder.CancelButton:SetPoint("LEFT",Binder.SaveButton,"RIGHT",2,0) Binder.CancelButton:SetScript("OnClick", function() Binder.SlashCommand("bind", true) end) Binder.CancelButton:Show() Binder.CharSpecFrame:Hide() local function setUp(frame, anchor, str_action) frame:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 32,}) frame:SetAllPoints(anchor) frame:SetBackdropColor(1,1,1,.5) frame:Hide() frame:SetAlpha(1) frame:EnableMouse(true) frame:SetFrameStrata("TOOLTIP") frame.button = str_action --print (str_action) frame:SetScript("OnEnter", BinderFrame_OnEnter) frame:SetScript("OnLeave", BinderFrame_OnLeave) frame:SetScript("OnKeyDown", BinderFrame_OnKeyDown) frame:SetScript("OnMouseDown", BinderFrame_OnKeyDown) local s = frame:CreateFontString("$parentBinding", "ARTWORK", "GameFontNormal") s:SetPoint("CENTER") s:SetHeight(anchor:GetHeight()) s:SetWidth(anchor:GetWidth()) local keyBind = GetBindingKey(strupper(frame.button)) if keyBind then keyBind = gsub(gsub(keyBind, "BUTTON3", "Middle Mouse"), '-', ' ') end s:SetText(keyBind) end for i=1, GetNumShapeshiftForms() do local f = CreateFrame("Frame", "ShapeshiftBinderFrame"..i, UIParent) local anchor = _G["ShapeshiftButton"..i] setUp(f, anchor, anchor:GetName()) end if select(2, UnitClass("player")) == "SHAMAN" then for i = 1, 4 do local f = CreateFrame("Frame", "MultiCastBinderFrame"..i, UIParent) local anchor = _G["MultiCastActionButton"..i] setUp(f, anchor, anchor:GetName()) end end for i = 1, 12 do local f = CreateFrame("Frame", "BinderFrame"..i, UIParent) local anchor = _G["ActionButton"..i] setUp(f, anchor, anchor:GetName()) f = CreateFrame("Frame", "BinderFrame"..i+12, UIParent) anchor = _G["MultiBarBottomLeftButton"..i] setUp(f, anchor, "MULTIACTIONBAR1BUTTON"..i) f = CreateFrame("Frame", "BinderFrame"..i+24, UIParent) anchor = _G["MultiBarBottomRightButton"..i] setUp(f, anchor, "MULTIACTIONBAR2BUTTON"..i) f = CreateFrame("Frame", "BinderFrame"..i+36, UIParent) anchor = _G["MultiBarRightButton"..i] setUp(f, anchor, "MULTIACTIONBAR3BUTTON"..i) f = CreateFrame("Frame", "BinderFrame"..i+48, UIParent) anchor = _G["MultiBarLeftButton"..i] setUp(f, anchor, "MULTIACTIONBAR4BUTTON"..i) f = CreateFrame("Frame", "BinderFrame"..i+60, UIParent) anchor = _G["MultiBarLeftButton"..i] setUp(f, anchor, "MULTIACTIONBAR5BUTTON"..i) end local s = UIParent:CreateFontString("BinderBindingKey", "ARTWORK", "GameFontNormalLarge") s:SetPoint("CENTER") s:Hide() end function Binder.SlashCommand(cmd, cancel) local updString = "|c00aa00fBinder|cFFFFFFFF " local text Binder.IsOn = not Binder.IsOn for i=1, GetNumShapeshiftForms() do local f = _G["ShapeshiftBinderFrame"..i] if Binder.IsOn then f:Show() else f:Hide() end end if select(2, UnitClass("player")) == "SHAMAN" then for i=1, 4 do local f = _G["MultiCastBinderFrame"..i] if Binder.IsOn then f:Show() else f:Hide() end end end for i = 1, 60 do local f = _G["BinderFrame"..i] if Binder.IsOn then f:Show() else f:Hide() end end if Binder.IsOn then text = "enabled!" Binder.CharSpecFrame:Show() elseif not cancel then text = "saved!" Binder.CharSpecFrame:Hide() if Binder_BindPerChar then SaveBindings(2) else SaveBindings(1) end else text = "canceled!" Binder.CharSpecFrame:Hide() end print(updString.."bindings "..text) end