madcatzinc@0
|
1 --~ Warcraft Plugin for Cyborg MMO7
|
madcatzinc@0
|
2 --~ Filename: OptionView.lua
|
madcatzinc@0
|
3 --~ Description: The code for the Option page in the UI, not much here because we dont have many options. Probably could refactor.
|
madcatzinc@0
|
4 --~ Copyright (C) 2012 Mad Catz Inc.
|
madcatzinc@0
|
5 --~ Author: Christopher Hooks
|
madcatzinc@0
|
6
|
madcatzinc@0
|
7 --~ This program is free software; you can redistribute it and/or
|
madcatzinc@0
|
8 --~ modify it under the terms of the GNU General Public License
|
madcatzinc@0
|
9 --~ as published by the Free Software Foundation; either version 2
|
madcatzinc@0
|
10 --~ of the License, or (at your option) any later version.
|
madcatzinc@0
|
11
|
madcatzinc@0
|
12 --~ This program is distributed in the hope that it will be useful,
|
madcatzinc@0
|
13 --~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
madcatzinc@0
|
14 --~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
madcatzinc@0
|
15 --~ GNU General Public License for more details.
|
madcatzinc@0
|
16
|
madcatzinc@0
|
17 --~ You should have received a copy of the GNU General Public License
|
madcatzinc@0
|
18 --~ along with this program; if not, write to the Free Software
|
madcatzinc@0
|
19 --~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
madcatzinc@0
|
20
|
madcatzinc@0
|
21 OptionView = {
|
madcatzinc@0
|
22 new = function(self)
|
madcatzinc@0
|
23 self.name = "Cyborg MMO7 Plugin"
|
madcatzinc@0
|
24 InterfaceOptions_AddCategory(self);
|
madcatzinc@0
|
25 return self
|
madcatzinc@0
|
26
|
madcatzinc@0
|
27 end
|
madcatzinc@0
|
28 }
|
madcatzinc@1
|
29
|
madcatzinc@1
|
30 local lastButton = nil
|
madcatzinc@1
|
31
|
madcatzinc@1
|
32 function BindButton(name)
|
madcatzinc@2
|
33 lastButton = name
|
madcatzinc@2
|
34 local index = GetButtonIndex(name)
|
madcatzinc@2
|
35 local mode = 1
|
madcatzinc@2
|
36 while(index > 13) do
|
madcatzinc@2
|
37 mode = mode + 1
|
madcatzinc@2
|
38 index = index - 13
|
madcatzinc@2
|
39 end
|
madcatzinc@2
|
40 local buttonStr = StringTable[("MouseRow"..index.."Name")]
|
madcatzinc@2
|
41
|
madcatzinc@2
|
42 getglobal("BindingFrameButtonName"):SetText(buttonStr.." Mode "..mode)
|
madcatzinc@2
|
43 getglobal("BindingFrameKey"):SetText(StringTable["CurrentBinding"].." "..WowCommands[GetButtonIndex(lastButton)])
|
madcatzinc@1
|
44 BindingFrame:Show()
|
madcatzinc@1
|
45
|
madcatzinc@1
|
46 end
|
madcatzinc@1
|
47
|
madcatzinc@1
|
48 function GetBindingButtonText(name)
|
madcatzinc@1
|
49 if(nil == WowCommands) then
|
madcatzinc@1
|
50 LoadWowCommands();
|
madcatzinc@1
|
51 end
|
madcatzinc@1
|
52
|
madcatzinc@1
|
53 local binding = WowCommands[GetButtonIndex(name)]
|
madcatzinc@1
|
54 getglobal(name):SetText(binding)
|
madcatzinc@1
|
55 end
|
madcatzinc@1
|
56
|
madcatzinc@1
|
57 function GetButtonIndex(name)
|
madcatzinc@1
|
58 local row,mode = string.find(name,"Mode")
|
madcatzinc@1
|
59 local modeStr = string.sub(name, mode +1,mode+2)
|
madcatzinc@1
|
60 local rowStr = string.sub(name, row-1,row-1)
|
madcatzinc@1
|
61 return (GetNumberFromHexLetter(rowStr) + ((GetNumberFromHexLetter(modeStr) - 1) * 13))
|
madcatzinc@1
|
62 end
|
madcatzinc@1
|
63
|
madcatzinc@1
|
64 function GetNumberFromHexLetter(str)
|
madcatzinc@1
|
65 local number = 0
|
madcatzinc@1
|
66 if("A" == str) then
|
madcatzinc@1
|
67 number = 10
|
madcatzinc@1
|
68 elseif("B" == str) then
|
madcatzinc@1
|
69 number = 11
|
madcatzinc@1
|
70 elseif("C" == str) then
|
madcatzinc@1
|
71 number = 12
|
madcatzinc@1
|
72 elseif("D" == str) then
|
madcatzinc@1
|
73 number = 13
|
madcatzinc@1
|
74 elseif("E" == str) then
|
madcatzinc@1
|
75 number = 14
|
madcatzinc@1
|
76 elseif("F" == str) then
|
madcatzinc@1
|
77 number = 15
|
madcatzinc@1
|
78 else
|
madcatzinc@1
|
79 number = tonumber(str)
|
madcatzinc@1
|
80 end
|
madcatzinc@1
|
81 return number
|
madcatzinc@1
|
82 end
|
madcatzinc@1
|
83
|
madcatzinc@1
|
84 function SetNewKeybind(keyOrButton)
|
madcatzinc@1
|
85 local previous = WowCommands[GetButtonIndex(lastButton)]
|
madcatzinc@1
|
86 WowCommands[GetButtonIndex(lastButton)] = keyOrButton;
|
madcatzinc@1
|
87 GetBindingButtonText(lastButton);
|
madcatzinc@1
|
88 BindingFrame:Hide()
|
madcatzinc@1
|
89 RatPageModel.Instance().LoadData()
|
madcatzinc@1
|
90 end
|
madcatzinc@1
|
91
|
madcatzinc@1
|
92 function BindingFrame_OnKeyDown(self, keyOrButton)
|
madcatzinc@1
|
93 if keyOrButton=="ESCAPE" then
|
madcatzinc@1
|
94 BindingFrame:Hide()
|
madcatzinc@1
|
95 return
|
madcatzinc@1
|
96 end
|
madcatzinc@1
|
97
|
madcatzinc@1
|
98 if ( GetBindingFromClick(keyOrButton) == "SCREENSHOT" ) then
|
madcatzinc@1
|
99 RunBinding("SCREENSHOT");
|
madcatzinc@1
|
100 return;
|
madcatzinc@1
|
101 end
|
madcatzinc@1
|
102
|
madcatzinc@1
|
103 local keyPressed = keyOrButton;
|
madcatzinc@1
|
104
|
madcatzinc@1
|
105 if ( keyPressed == "UNKNOWN" ) then
|
madcatzinc@1
|
106 return;
|
madcatzinc@1
|
107 end
|
madcatzinc@1
|
108
|
madcatzinc@1
|
109 -- Convert the mouse button names
|
madcatzinc@1
|
110 if ( keyPressed == "LeftButton" ) then
|
madcatzinc@1
|
111 keyPressed = "BUTTON1";
|
madcatzinc@1
|
112 elseif ( keyPressed == "RightButton" ) then
|
madcatzinc@1
|
113 keyPressed = "BUTTON2";
|
madcatzinc@1
|
114 elseif ( keyPressed == "MiddleButton" ) then
|
madcatzinc@1
|
115 keyPressed = "BUTTON3";
|
madcatzinc@1
|
116 elseif ( keyPressed == "Button4" ) then
|
madcatzinc@1
|
117 keyPressed = "BUTTON4"
|
madcatzinc@1
|
118 elseif ( keyOrButton == "Button5" ) then
|
madcatzinc@1
|
119 keyPressed = "BUTTON5"
|
madcatzinc@1
|
120 elseif ( keyPressed == "Button6" ) then
|
madcatzinc@1
|
121 keyPressed = "BUTTON6"
|
madcatzinc@1
|
122 elseif ( keyOrButton == "Button7" ) then
|
madcatzinc@1
|
123 keyPressed = "BUTTON7"
|
madcatzinc@1
|
124 elseif ( keyPressed == "Button8" ) then
|
madcatzinc@1
|
125 keyPressed = "BUTTON8"
|
madcatzinc@1
|
126 elseif ( keyOrButton == "Button9" ) then
|
madcatzinc@1
|
127 keyPressed = "BUTTON9"
|
madcatzinc@1
|
128 elseif ( keyPressed == "Button10" ) then
|
madcatzinc@1
|
129 keyPressed = "BUTTON10"
|
madcatzinc@1
|
130 elseif ( keyOrButton == "Button11" ) then
|
madcatzinc@1
|
131 keyPressed = "BUTTON11"
|
madcatzinc@1
|
132 elseif ( keyPressed == "Button12" ) then
|
madcatzinc@1
|
133 keyPressed = "BUTTON12"
|
madcatzinc@1
|
134 elseif ( keyOrButton == "Button13" ) then
|
madcatzinc@1
|
135 keyPressed = "BUTTON13"
|
madcatzinc@1
|
136 elseif ( keyPressed == "Button14" ) then
|
madcatzinc@1
|
137 keyPressed = "BUTTON14"
|
madcatzinc@1
|
138 elseif ( keyOrButton == "Button15" ) then
|
madcatzinc@1
|
139 keyPressed = "BUTTON15"
|
madcatzinc@1
|
140 elseif ( keyPressed == "Button16" ) then
|
madcatzinc@1
|
141 keyPressed = "BUTTON16"
|
madcatzinc@1
|
142 elseif ( keyOrButton == "Button17" ) then
|
madcatzinc@1
|
143 keyPressed = "BUTTON17"
|
madcatzinc@1
|
144 elseif ( keyPressed == "Button18" ) then
|
madcatzinc@1
|
145 keyPressed = "BUTTON18"
|
madcatzinc@1
|
146 elseif ( keyOrButton == "Button19" ) then
|
madcatzinc@1
|
147 keyPressed = "BUTTON19"
|
madcatzinc@1
|
148 elseif ( keyPressed == "Button20" ) then
|
madcatzinc@1
|
149 keyPressed = "BUTTON20"
|
madcatzinc@1
|
150 elseif ( keyOrButton == "Button21" ) then
|
madcatzinc@1
|
151 keyPressed = "BUTTON21"
|
madcatzinc@1
|
152 elseif ( keyPressed == "Button22" ) then
|
madcatzinc@1
|
153 keyPressed = "BUTTON22"
|
madcatzinc@1
|
154 elseif ( keyOrButton == "Button23" ) then
|
madcatzinc@1
|
155 keyPressed = "BUTTON23"
|
madcatzinc@1
|
156 elseif ( keyPressed == "Button24" ) then
|
madcatzinc@1
|
157 keyPressed = "BUTTON24"
|
madcatzinc@1
|
158 elseif ( keyOrButton == "Button25" ) then
|
madcatzinc@1
|
159 keyPressed = "BUTTON25"
|
madcatzinc@1
|
160 elseif ( keyPressed == "Button26" ) then
|
madcatzinc@1
|
161 keyPressed = "BUTTON26"
|
madcatzinc@1
|
162 elseif ( keyOrButton == "Button27" ) then
|
madcatzinc@1
|
163 keyPressed = "BUTTON27"
|
madcatzinc@1
|
164 elseif ( keyPressed == "Button28" ) then
|
madcatzinc@1
|
165 keyPressed = "BUTTON28"
|
madcatzinc@1
|
166 elseif ( keyOrButton == "Button29" ) then
|
madcatzinc@1
|
167 keyPressed = "BUTTON29"
|
madcatzinc@1
|
168 elseif ( keyPressed == "Button30" ) then
|
madcatzinc@1
|
169 keyPressed = "BUTTON30"
|
madcatzinc@1
|
170 elseif ( keyOrButton == "Button31" ) then
|
madcatzinc@1
|
171 keyPressed = "BUTTON31"
|
madcatzinc@1
|
172 end
|
madcatzinc@1
|
173
|
madcatzinc@1
|
174 if ( keyPressed == "LSHIFT" or
|
madcatzinc@1
|
175 keyPressed == "RSHIFT" or
|
madcatzinc@1
|
176 keyPressed == "LCTRL" or
|
madcatzinc@1
|
177 keyPressed == "RCTRL" or
|
madcatzinc@1
|
178 keyPressed == "LALT" or
|
madcatzinc@1
|
179 keyPressed == "RALT" ) then
|
madcatzinc@1
|
180 return;
|
madcatzinc@1
|
181 end
|
madcatzinc@1
|
182 if ( IsShiftKeyDown() ) then
|
madcatzinc@1
|
183 keyPressed = "SHIFT-"..keyPressed
|
madcatzinc@1
|
184 end
|
madcatzinc@1
|
185 if ( IsControlKeyDown() ) then
|
madcatzinc@1
|
186 keyPressed = "CTRL-"..keyPressed
|
madcatzinc@1
|
187 end
|
madcatzinc@1
|
188 if ( IsAltKeyDown() ) then
|
madcatzinc@1
|
189 keyPressed = "ALT-"..keyPressed
|
madcatzinc@1
|
190 end
|
madcatzinc@1
|
191 if ( keyPressed == "BUTTON1" or keyPressed == "BUTTON2" ) then
|
madcatzinc@1
|
192 return;
|
madcatzinc@1
|
193 end
|
madcatzinc@1
|
194
|
madcatzinc@1
|
195 SetNewKeybind(keyPressed)
|
madcatzinc@1
|
196
|
madcatzinc@1
|
197 end
|