madcatzinc@0: --~ Warcraft Plugin for Cyborg MMO7 madcatzinc@0: --~ Filename: OptionView.lua madcatzinc@0: --~ Description: The code for the Option page in the UI, not much here because we dont have many options. Probably could refactor. madcatzinc@0: --~ Copyright (C) 2012 Mad Catz Inc. madcatzinc@0: --~ Author: Christopher Hooks madcatzinc@0: madcatzinc@0: --~ This program is free software; you can redistribute it and/or madcatzinc@0: --~ modify it under the terms of the GNU General Public License madcatzinc@0: --~ as published by the Free Software Foundation; either version 2 madcatzinc@0: --~ of the License, or (at your option) any later version. madcatzinc@0: madcatzinc@0: --~ This program is distributed in the hope that it will be useful, madcatzinc@0: --~ but WITHOUT ANY WARRANTY; without even the implied warranty of madcatzinc@0: --~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the madcatzinc@0: --~ GNU General Public License for more details. madcatzinc@0: madcatzinc@0: --~ You should have received a copy of the GNU General Public License madcatzinc@0: --~ along with this program; if not, write to the Free Software madcatzinc@0: --~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. madcatzinc@0: madcatzinc@4: CyborgMMO_OptionView = { madcatzinc@0: new = function(self) madcatzinc@0: self.name = "Cyborg MMO7 Plugin" madcatzinc@0: InterfaceOptions_AddCategory(self); madcatzinc@0: return self madcatzinc@0: madcatzinc@0: end madcatzinc@0: } madcatzinc@1: madcatzinc@1: local lastButton = nil madcatzinc@1: madcatzinc@4: function CyborgMMO_BindButton(name) madcatzinc@2: lastButton = name madcatzinc@4: local index = CyborgMMO_GetButtonIndex(name) madcatzinc@2: local mode = 1 madcatzinc@2: while(index > 13) do madcatzinc@2: mode = mode + 1 madcatzinc@2: index = index - 13 madcatzinc@2: end madcatzinc@4: local buttonStr = StringTable[("CyborgMMO_OptionPageRebindMouseRow"..index.."Name")] madcatzinc@2: madcatzinc@4: getglobal("CyborgMMO_BindingFrameButtonName"):SetText(buttonStr.." Mode "..mode) madcatzinc@4: getglobal("CyborgMMO_BindingFrameKey"):SetText(StringTable["CyborgMMO_CurrentBinding"].." "..WowCommands[CyborgMMO_GetButtonIndex(lastButton)]) madcatzinc@4: CyborgMMO_BindingFrame:Show() madcatzinc@1: madcatzinc@1: end madcatzinc@1: madcatzinc@4: function CyborgMMO_GetBindingButtonText(name) madcatzinc@1: if(nil == WowCommands) then madcatzinc@4: CyborgMMO_LoadWowCommands(); madcatzinc@1: end madcatzinc@1: madcatzinc@4: local binding = WowCommands[CyborgMMO_GetButtonIndex(name)] madcatzinc@1: getglobal(name):SetText(binding) madcatzinc@1: end madcatzinc@1: madcatzinc@4: function CyborgMMO_GetButtonIndex(name) madcatzinc@1: local row,mode = string.find(name,"Mode") madcatzinc@1: local modeStr = string.sub(name, mode +1,mode+2) madcatzinc@1: local rowStr = string.sub(name, row-1,row-1) madcatzinc@4: return (CyborgMMO_GetNumberFromHexLetter(rowStr) + ((CyborgMMO_GetNumberFromHexLetter(modeStr) - 1) * 13)) madcatzinc@1: end madcatzinc@1: madcatzinc@4: function CyborgMMO_GetNumberFromHexLetter(str) madcatzinc@1: local number = 0 madcatzinc@1: if("A" == str) then madcatzinc@1: number = 10 madcatzinc@1: elseif("B" == str) then madcatzinc@1: number = 11 madcatzinc@1: elseif("C" == str) then madcatzinc@1: number = 12 madcatzinc@1: elseif("D" == str) then madcatzinc@1: number = 13 madcatzinc@1: elseif("E" == str) then madcatzinc@1: number = 14 madcatzinc@1: elseif("F" == str) then madcatzinc@1: number = 15 madcatzinc@1: else madcatzinc@1: number = tonumber(str) madcatzinc@1: end madcatzinc@1: return number madcatzinc@1: end madcatzinc@1: madcatzinc@4: function CyborgMMO_SetNewKeybind(keyOrButton) madcatzinc@4: local previous = WowCommands[CyborgMMO_GetButtonIndex(lastButton)] madcatzinc@4: WowCommands[CyborgMMO_GetButtonIndex(lastButton)] = keyOrButton; madcatzinc@4: CyborgMMO_GetBindingButtonText(lastButton); madcatzinc@4: CyborgMMO_BindingFrame:Hide() madcatzinc@4: CyborgMMO_RatPageModel.Instance().LoadData() madcatzinc@1: end madcatzinc@1: madcatzinc@4: function CyborgMMO_BindingFrameOnKeyDown(self, keyOrButton) madcatzinc@1: if keyOrButton=="ESCAPE" then madcatzinc@4: CyborgMMO_BindingFrame:Hide() madcatzinc@1: return madcatzinc@1: end madcatzinc@1: madcatzinc@1: if ( GetBindingFromClick(keyOrButton) == "SCREENSHOT" ) then madcatzinc@1: RunBinding("SCREENSHOT"); madcatzinc@1: return; madcatzinc@1: end madcatzinc@1: madcatzinc@1: local keyPressed = keyOrButton; madcatzinc@1: madcatzinc@1: if ( keyPressed == "UNKNOWN" ) then madcatzinc@1: return; madcatzinc@1: end madcatzinc@1: madcatzinc@1: -- Convert the mouse button names madcatzinc@1: if ( keyPressed == "LeftButton" ) then madcatzinc@1: keyPressed = "BUTTON1"; madcatzinc@1: elseif ( keyPressed == "RightButton" ) then madcatzinc@1: keyPressed = "BUTTON2"; madcatzinc@1: elseif ( keyPressed == "MiddleButton" ) then madcatzinc@1: keyPressed = "BUTTON3"; madcatzinc@1: elseif ( keyPressed == "Button4" ) then madcatzinc@1: keyPressed = "BUTTON4" madcatzinc@1: elseif ( keyOrButton == "Button5" ) then madcatzinc@1: keyPressed = "BUTTON5" madcatzinc@1: elseif ( keyPressed == "Button6" ) then madcatzinc@1: keyPressed = "BUTTON6" madcatzinc@1: elseif ( keyOrButton == "Button7" ) then madcatzinc@1: keyPressed = "BUTTON7" madcatzinc@1: elseif ( keyPressed == "Button8" ) then madcatzinc@1: keyPressed = "BUTTON8" madcatzinc@1: elseif ( keyOrButton == "Button9" ) then madcatzinc@1: keyPressed = "BUTTON9" madcatzinc@1: elseif ( keyPressed == "Button10" ) then madcatzinc@1: keyPressed = "BUTTON10" madcatzinc@1: elseif ( keyOrButton == "Button11" ) then madcatzinc@1: keyPressed = "BUTTON11" madcatzinc@1: elseif ( keyPressed == "Button12" ) then madcatzinc@1: keyPressed = "BUTTON12" madcatzinc@1: elseif ( keyOrButton == "Button13" ) then madcatzinc@1: keyPressed = "BUTTON13" madcatzinc@1: elseif ( keyPressed == "Button14" ) then madcatzinc@1: keyPressed = "BUTTON14" madcatzinc@1: elseif ( keyOrButton == "Button15" ) then madcatzinc@1: keyPressed = "BUTTON15" madcatzinc@1: elseif ( keyPressed == "Button16" ) then madcatzinc@1: keyPressed = "BUTTON16" madcatzinc@1: elseif ( keyOrButton == "Button17" ) then madcatzinc@1: keyPressed = "BUTTON17" madcatzinc@1: elseif ( keyPressed == "Button18" ) then madcatzinc@1: keyPressed = "BUTTON18" madcatzinc@1: elseif ( keyOrButton == "Button19" ) then madcatzinc@1: keyPressed = "BUTTON19" madcatzinc@1: elseif ( keyPressed == "Button20" ) then madcatzinc@1: keyPressed = "BUTTON20" madcatzinc@1: elseif ( keyOrButton == "Button21" ) then madcatzinc@1: keyPressed = "BUTTON21" madcatzinc@1: elseif ( keyPressed == "Button22" ) then madcatzinc@1: keyPressed = "BUTTON22" madcatzinc@1: elseif ( keyOrButton == "Button23" ) then madcatzinc@1: keyPressed = "BUTTON23" madcatzinc@1: elseif ( keyPressed == "Button24" ) then madcatzinc@1: keyPressed = "BUTTON24" madcatzinc@1: elseif ( keyOrButton == "Button25" ) then madcatzinc@1: keyPressed = "BUTTON25" madcatzinc@1: elseif ( keyPressed == "Button26" ) then madcatzinc@1: keyPressed = "BUTTON26" madcatzinc@1: elseif ( keyOrButton == "Button27" ) then madcatzinc@1: keyPressed = "BUTTON27" madcatzinc@1: elseif ( keyPressed == "Button28" ) then madcatzinc@1: keyPressed = "BUTTON28" madcatzinc@1: elseif ( keyOrButton == "Button29" ) then madcatzinc@1: keyPressed = "BUTTON29" madcatzinc@1: elseif ( keyPressed == "Button30" ) then madcatzinc@1: keyPressed = "BUTTON30" madcatzinc@1: elseif ( keyOrButton == "Button31" ) then madcatzinc@1: keyPressed = "BUTTON31" madcatzinc@1: end madcatzinc@1: madcatzinc@1: if ( keyPressed == "LSHIFT" or madcatzinc@1: keyPressed == "RSHIFT" or madcatzinc@1: keyPressed == "LCTRL" or madcatzinc@1: keyPressed == "RCTRL" or madcatzinc@1: keyPressed == "LALT" or madcatzinc@1: keyPressed == "RALT" ) then madcatzinc@1: return; madcatzinc@1: end madcatzinc@1: if ( IsShiftKeyDown() ) then madcatzinc@1: keyPressed = "SHIFT-"..keyPressed madcatzinc@1: end madcatzinc@1: if ( IsControlKeyDown() ) then madcatzinc@1: keyPressed = "CTRL-"..keyPressed madcatzinc@1: end madcatzinc@1: if ( IsAltKeyDown() ) then madcatzinc@1: keyPressed = "ALT-"..keyPressed madcatzinc@1: end madcatzinc@1: if ( keyPressed == "BUTTON1" or keyPressed == "BUTTON2" ) then madcatzinc@1: return; madcatzinc@1: end madcatzinc@1: madcatzinc@4: CyborgMMO_SetNewKeybind(keyPressed) madcatzinc@1: madcatzinc@1: end