annotate OptionView.lua @ 1:a4e2eaf9cad9

Initial Fixes for ticket 1: Added a menu to the interface options page to allow the syncing of the addon to the mouse profile. This should resolve i8n issues
author madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09
date Wed, 23 May 2012 08:26:07 +0000
parents bf9220814fb5
children 08c83fa555a5
rev   line source
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@1 33 lastButton = name;
madcatzinc@1 34 BindingFrame:Show()
madcatzinc@1 35
madcatzinc@1 36 end
madcatzinc@1 37
madcatzinc@1 38 function GetBindingButtonText(name)
madcatzinc@1 39 if(nil == WowCommands) then
madcatzinc@1 40 LoadWowCommands();
madcatzinc@1 41 end
madcatzinc@1 42
madcatzinc@1 43 local binding = WowCommands[GetButtonIndex(name)]
madcatzinc@1 44 getglobal(name):SetText(binding)
madcatzinc@1 45 end
madcatzinc@1 46
madcatzinc@1 47 function GetButtonIndex(name)
madcatzinc@1 48 local row,mode = string.find(name,"Mode")
madcatzinc@1 49 local modeStr = string.sub(name, mode +1,mode+2)
madcatzinc@1 50 local rowStr = string.sub(name, row-1,row-1)
madcatzinc@1 51 return (GetNumberFromHexLetter(rowStr) + ((GetNumberFromHexLetter(modeStr) - 1) * 13))
madcatzinc@1 52 end
madcatzinc@1 53
madcatzinc@1 54 function GetNumberFromHexLetter(str)
madcatzinc@1 55 local number = 0
madcatzinc@1 56 if("A" == str) then
madcatzinc@1 57 number = 10
madcatzinc@1 58 elseif("B" == str) then
madcatzinc@1 59 number = 11
madcatzinc@1 60 elseif("C" == str) then
madcatzinc@1 61 number = 12
madcatzinc@1 62 elseif("D" == str) then
madcatzinc@1 63 number = 13
madcatzinc@1 64 elseif("E" == str) then
madcatzinc@1 65 number = 14
madcatzinc@1 66 elseif("F" == str) then
madcatzinc@1 67 number = 15
madcatzinc@1 68 else
madcatzinc@1 69 number = tonumber(str)
madcatzinc@1 70 end
madcatzinc@1 71 return number
madcatzinc@1 72 end
madcatzinc@1 73
madcatzinc@1 74 function SetNewKeybind(keyOrButton)
madcatzinc@1 75 local previous = WowCommands[GetButtonIndex(lastButton)]
madcatzinc@1 76 WowCommands[GetButtonIndex(lastButton)] = keyOrButton;
madcatzinc@1 77 GetBindingButtonText(lastButton);
madcatzinc@1 78 BindingFrame:Hide()
madcatzinc@1 79 RatPageModel.Instance().LoadData()
madcatzinc@1 80 end
madcatzinc@1 81
madcatzinc@1 82 function BindingFrame_OnKeyDown(self, keyOrButton)
madcatzinc@1 83 if keyOrButton=="ESCAPE" then
madcatzinc@1 84 BindingFrame:Hide()
madcatzinc@1 85 return
madcatzinc@1 86 end
madcatzinc@1 87
madcatzinc@1 88 if ( GetBindingFromClick(keyOrButton) == "SCREENSHOT" ) then
madcatzinc@1 89 RunBinding("SCREENSHOT");
madcatzinc@1 90 return;
madcatzinc@1 91 end
madcatzinc@1 92
madcatzinc@1 93 local keyPressed = keyOrButton;
madcatzinc@1 94
madcatzinc@1 95 if ( keyPressed == "UNKNOWN" ) then
madcatzinc@1 96 return;
madcatzinc@1 97 end
madcatzinc@1 98
madcatzinc@1 99 -- Convert the mouse button names
madcatzinc@1 100 if ( keyPressed == "LeftButton" ) then
madcatzinc@1 101 keyPressed = "BUTTON1";
madcatzinc@1 102 elseif ( keyPressed == "RightButton" ) then
madcatzinc@1 103 keyPressed = "BUTTON2";
madcatzinc@1 104 elseif ( keyPressed == "MiddleButton" ) then
madcatzinc@1 105 keyPressed = "BUTTON3";
madcatzinc@1 106 elseif ( keyPressed == "Button4" ) then
madcatzinc@1 107 keyPressed = "BUTTON4"
madcatzinc@1 108 elseif ( keyOrButton == "Button5" ) then
madcatzinc@1 109 keyPressed = "BUTTON5"
madcatzinc@1 110 elseif ( keyPressed == "Button6" ) then
madcatzinc@1 111 keyPressed = "BUTTON6"
madcatzinc@1 112 elseif ( keyOrButton == "Button7" ) then
madcatzinc@1 113 keyPressed = "BUTTON7"
madcatzinc@1 114 elseif ( keyPressed == "Button8" ) then
madcatzinc@1 115 keyPressed = "BUTTON8"
madcatzinc@1 116 elseif ( keyOrButton == "Button9" ) then
madcatzinc@1 117 keyPressed = "BUTTON9"
madcatzinc@1 118 elseif ( keyPressed == "Button10" ) then
madcatzinc@1 119 keyPressed = "BUTTON10"
madcatzinc@1 120 elseif ( keyOrButton == "Button11" ) then
madcatzinc@1 121 keyPressed = "BUTTON11"
madcatzinc@1 122 elseif ( keyPressed == "Button12" ) then
madcatzinc@1 123 keyPressed = "BUTTON12"
madcatzinc@1 124 elseif ( keyOrButton == "Button13" ) then
madcatzinc@1 125 keyPressed = "BUTTON13"
madcatzinc@1 126 elseif ( keyPressed == "Button14" ) then
madcatzinc@1 127 keyPressed = "BUTTON14"
madcatzinc@1 128 elseif ( keyOrButton == "Button15" ) then
madcatzinc@1 129 keyPressed = "BUTTON15"
madcatzinc@1 130 elseif ( keyPressed == "Button16" ) then
madcatzinc@1 131 keyPressed = "BUTTON16"
madcatzinc@1 132 elseif ( keyOrButton == "Button17" ) then
madcatzinc@1 133 keyPressed = "BUTTON17"
madcatzinc@1 134 elseif ( keyPressed == "Button18" ) then
madcatzinc@1 135 keyPressed = "BUTTON18"
madcatzinc@1 136 elseif ( keyOrButton == "Button19" ) then
madcatzinc@1 137 keyPressed = "BUTTON19"
madcatzinc@1 138 elseif ( keyPressed == "Button20" ) then
madcatzinc@1 139 keyPressed = "BUTTON20"
madcatzinc@1 140 elseif ( keyOrButton == "Button21" ) then
madcatzinc@1 141 keyPressed = "BUTTON21"
madcatzinc@1 142 elseif ( keyPressed == "Button22" ) then
madcatzinc@1 143 keyPressed = "BUTTON22"
madcatzinc@1 144 elseif ( keyOrButton == "Button23" ) then
madcatzinc@1 145 keyPressed = "BUTTON23"
madcatzinc@1 146 elseif ( keyPressed == "Button24" ) then
madcatzinc@1 147 keyPressed = "BUTTON24"
madcatzinc@1 148 elseif ( keyOrButton == "Button25" ) then
madcatzinc@1 149 keyPressed = "BUTTON25"
madcatzinc@1 150 elseif ( keyPressed == "Button26" ) then
madcatzinc@1 151 keyPressed = "BUTTON26"
madcatzinc@1 152 elseif ( keyOrButton == "Button27" ) then
madcatzinc@1 153 keyPressed = "BUTTON27"
madcatzinc@1 154 elseif ( keyPressed == "Button28" ) then
madcatzinc@1 155 keyPressed = "BUTTON28"
madcatzinc@1 156 elseif ( keyOrButton == "Button29" ) then
madcatzinc@1 157 keyPressed = "BUTTON29"
madcatzinc@1 158 elseif ( keyPressed == "Button30" ) then
madcatzinc@1 159 keyPressed = "BUTTON30"
madcatzinc@1 160 elseif ( keyOrButton == "Button31" ) then
madcatzinc@1 161 keyPressed = "BUTTON31"
madcatzinc@1 162 end
madcatzinc@1 163
madcatzinc@1 164 if ( keyPressed == "LSHIFT" or
madcatzinc@1 165 keyPressed == "RSHIFT" or
madcatzinc@1 166 keyPressed == "LCTRL" or
madcatzinc@1 167 keyPressed == "RCTRL" or
madcatzinc@1 168 keyPressed == "LALT" or
madcatzinc@1 169 keyPressed == "RALT" ) then
madcatzinc@1 170 return;
madcatzinc@1 171 end
madcatzinc@1 172 if ( IsShiftKeyDown() ) then
madcatzinc@1 173 keyPressed = "SHIFT-"..keyPressed
madcatzinc@1 174 end
madcatzinc@1 175 if ( IsControlKeyDown() ) then
madcatzinc@1 176 keyPressed = "CTRL-"..keyPressed
madcatzinc@1 177 end
madcatzinc@1 178 if ( IsAltKeyDown() ) then
madcatzinc@1 179 keyPressed = "ALT-"..keyPressed
madcatzinc@1 180 end
madcatzinc@1 181 if ( keyPressed == "BUTTON1" or keyPressed == "BUTTON2" ) then
madcatzinc@1 182 return;
madcatzinc@1 183 end
madcatzinc@1 184
madcatzinc@1 185 SetNewKeybind(keyPressed)
madcatzinc@1 186
madcatzinc@1 187 --~ if keyPressed then
madcatzinc@1 188 --~ BindPadCore.keyPressed = keyPressed
madcatzinc@1 189 --~ local oldAction = GetBindingAction(keyPressed)
madcatzinc@1 190 --~
madcatzinc@1 191 --~ local keyText = BindPadCore.GetBindingText(keyPressed, "KEY_");
madcatzinc@1 192 --~ if oldAction~="" and oldAction ~= BindPadCore.selectedSlot.action then
madcatzinc@1 193 --~ if StaticPopupDialogs["BINDPAD_CONFIRM_BINDING"] == nil then
madcatzinc@1 194 --~ StaticPopupDialogs["BINDPAD_CONFIRM_BINDING"] = {
madcatzinc@1 195 --~ button1 = YES,
madcatzinc@1 196 --~ button2 = NO,
madcatzinc@1 197 --~ timeout = 0,
madcatzinc@1 198 --~ hideOnEscape = 1,
madcatzinc@1 199 --~ OnAccept = BindPadBindFrame_SetBindKey,
madcatzinc@1 200 --~ OnCancel = BindPadBindFrame_Update,
madcatzinc@1 201 --~ whileDead = 1
madcatzinc@1 202 --~ }
madcatzinc@1 203 --~ end
madcatzinc@1 204 --~ StaticPopupDialogs["BINDPAD_CONFIRM_BINDING"].text = format(BINDPAD_TEXT_CONFIRM_BINDING, keyText, oldAction, keyText, BindPadCore.selectedSlot.action);
madcatzinc@1 205 --~ StaticPopup_Show("BINDPAD_CONFIRM_BINDING")
madcatzinc@1 206 --~ else
madcatzinc@1 207 --~ BindPadBindFrame_SetBindKey();
madcatzinc@1 208 --~ end
madcatzinc@1 209 --~ end
madcatzinc@1 210 end