annotate OptionView.lua @ 5:8428fa7cf0e4

Updated the profile to use macros and rename all the variables and functions with the prefix CyborgMMO. Added a tooltip to inform the user to assign the profile.
author madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09
date Tue, 29 May 2012 10:26:40 +0000
parents d186f8cd5000
children 6cb9a2936580
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@4 21 CyborgMMO_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@4 32 function CyborgMMO_BindButton(name)
madcatzinc@2 33 lastButton = name
madcatzinc@4 34 local index = CyborgMMO_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@5 40 local buttonStr = CyborgMMO_StringTable[("CyborgMMO_OptionPageRebindMouseRow"..index.."Name")]
madcatzinc@2 41
madcatzinc@4 42 getglobal("CyborgMMO_BindingFrameButtonName"):SetText(buttonStr.." Mode "..mode)
madcatzinc@5 43 getglobal("CyborgMMO_BindingFrameKey"):SetText(CyborgMMO_StringTable["CyborgMMO_CurrentBinding"].." "..CyborgMMO_WowCommands[CyborgMMO_GetButtonIndex(lastButton)])
madcatzinc@4 44 CyborgMMO_BindingFrame:Show()
madcatzinc@1 45
madcatzinc@1 46 end
madcatzinc@1 47
madcatzinc@4 48 function CyborgMMO_GetBindingButtonText(name)
madcatzinc@5 49 if(nil == CyborgMMO_WowCommands) then
madcatzinc@4 50 CyborgMMO_LoadWowCommands();
madcatzinc@1 51 end
madcatzinc@1 52
madcatzinc@5 53 local binding = CyborgMMO_WowCommands[CyborgMMO_GetButtonIndex(name)]
madcatzinc@1 54 getglobal(name):SetText(binding)
madcatzinc@1 55 end
madcatzinc@1 56
madcatzinc@4 57 function CyborgMMO_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@4 61 return (CyborgMMO_GetNumberFromHexLetter(rowStr) + ((CyborgMMO_GetNumberFromHexLetter(modeStr) - 1) * 13))
madcatzinc@1 62 end
madcatzinc@1 63
madcatzinc@5 64 function CyborgMMO_ShowProfileTooltip(self)
madcatzinc@5 65 local red, green, blue, _ = self:GetVertexColor()
madcatzinc@5 66 if((red == 0) and (green == 0) and (blue == 0)) then
madcatzinc@5 67 GameTooltip:SetOwner(self:GetParent(), "ANCHOR_RIGHT");
madcatzinc@5 68 GameTooltip:SetText(CyborgMMO_StringTable["CyborgMMO_ToolTipLine1"], nil, nil, nil, nil, 1);
madcatzinc@5 69 GameTooltip:AddLine(nil, 0.8, 1.0, 0.8);
madcatzinc@5 70 GameTooltip:AddLine(CyborgMMO_StringTable["CyborgMMO_ToolTipLine2"], 0.8, 1.0, 0.8);
madcatzinc@5 71 GameTooltip:AddLine(nil, 0.8, 1.0, 0.8);
madcatzinc@5 72 GameTooltip:AddLine(CyborgMMO_StringTable["CyborgMMO_ToolTipLine3"], 0.8, 1.0, 0.8);
madcatzinc@5 73 GameTooltip:AddLine(CyborgMMO_StringTable["CyborgMMO_ToolTipLine4"], 0.8, 1.0, 0.8);
madcatzinc@5 74 GameTooltip:AddLine(CyborgMMO_StringTable["CyborgMMO_ToolTipLine5"], 0.8, 1.0, 0.8);
madcatzinc@5 75 GameTooltip:AddLine(nil, 0.8, 1.0, 0.8);
madcatzinc@5 76 GameTooltip:AddLine(CyborgMMO_StringTable["CyborgMMO_ToolTipLine6"], 0.8, 1.0, 0.8);
madcatzinc@5 77 GameTooltip:Show();
madcatzinc@5 78 end
madcatzinc@5 79 end
madcatzinc@5 80
madcatzinc@5 81 function CyborgMMO_HideProfileTooltip(self)
madcatzinc@5 82 GameTooltip:Hide();
madcatzinc@5 83 end
madcatzinc@5 84
madcatzinc@4 85 function CyborgMMO_GetNumberFromHexLetter(str)
madcatzinc@1 86 local number = 0
madcatzinc@1 87 if("A" == str) then
madcatzinc@1 88 number = 10
madcatzinc@1 89 elseif("B" == str) then
madcatzinc@1 90 number = 11
madcatzinc@1 91 elseif("C" == str) then
madcatzinc@1 92 number = 12
madcatzinc@1 93 elseif("D" == str) then
madcatzinc@1 94 number = 13
madcatzinc@1 95 elseif("E" == str) then
madcatzinc@1 96 number = 14
madcatzinc@1 97 elseif("F" == str) then
madcatzinc@1 98 number = 15
madcatzinc@1 99 else
madcatzinc@1 100 number = tonumber(str)
madcatzinc@1 101 end
madcatzinc@1 102 return number
madcatzinc@1 103 end
madcatzinc@1 104
madcatzinc@4 105 function CyborgMMO_SetNewKeybind(keyOrButton)
madcatzinc@5 106 local previous = CyborgMMO_WowCommands[CyborgMMO_GetButtonIndex(lastButton)]
madcatzinc@5 107 CyborgMMO_WowCommands[CyborgMMO_GetButtonIndex(lastButton)] = keyOrButton;
madcatzinc@4 108 CyborgMMO_GetBindingButtonText(lastButton);
madcatzinc@4 109 CyborgMMO_BindingFrame:Hide()
madcatzinc@4 110 CyborgMMO_RatPageModel.Instance().LoadData()
madcatzinc@1 111 end
madcatzinc@1 112
madcatzinc@4 113 function CyborgMMO_BindingFrameOnKeyDown(self, keyOrButton)
madcatzinc@1 114 if keyOrButton=="ESCAPE" then
madcatzinc@4 115 CyborgMMO_BindingFrame:Hide()
madcatzinc@1 116 return
madcatzinc@1 117 end
madcatzinc@1 118
madcatzinc@1 119 if ( GetBindingFromClick(keyOrButton) == "SCREENSHOT" ) then
madcatzinc@1 120 RunBinding("SCREENSHOT");
madcatzinc@1 121 return;
madcatzinc@1 122 end
madcatzinc@1 123
madcatzinc@1 124 local keyPressed = keyOrButton;
madcatzinc@1 125
madcatzinc@1 126 if ( keyPressed == "UNKNOWN" ) then
madcatzinc@1 127 return;
madcatzinc@1 128 end
madcatzinc@1 129
madcatzinc@1 130 -- Convert the mouse button names
madcatzinc@1 131 if ( keyPressed == "LeftButton" ) then
madcatzinc@1 132 keyPressed = "BUTTON1";
madcatzinc@1 133 elseif ( keyPressed == "RightButton" ) then
madcatzinc@1 134 keyPressed = "BUTTON2";
madcatzinc@1 135 elseif ( keyPressed == "MiddleButton" ) then
madcatzinc@1 136 keyPressed = "BUTTON3";
madcatzinc@1 137 elseif ( keyPressed == "Button4" ) then
madcatzinc@1 138 keyPressed = "BUTTON4"
madcatzinc@1 139 elseif ( keyOrButton == "Button5" ) then
madcatzinc@1 140 keyPressed = "BUTTON5"
madcatzinc@1 141 elseif ( keyPressed == "Button6" ) then
madcatzinc@1 142 keyPressed = "BUTTON6"
madcatzinc@1 143 elseif ( keyOrButton == "Button7" ) then
madcatzinc@1 144 keyPressed = "BUTTON7"
madcatzinc@1 145 elseif ( keyPressed == "Button8" ) then
madcatzinc@1 146 keyPressed = "BUTTON8"
madcatzinc@1 147 elseif ( keyOrButton == "Button9" ) then
madcatzinc@1 148 keyPressed = "BUTTON9"
madcatzinc@1 149 elseif ( keyPressed == "Button10" ) then
madcatzinc@1 150 keyPressed = "BUTTON10"
madcatzinc@1 151 elseif ( keyOrButton == "Button11" ) then
madcatzinc@1 152 keyPressed = "BUTTON11"
madcatzinc@1 153 elseif ( keyPressed == "Button12" ) then
madcatzinc@1 154 keyPressed = "BUTTON12"
madcatzinc@1 155 elseif ( keyOrButton == "Button13" ) then
madcatzinc@1 156 keyPressed = "BUTTON13"
madcatzinc@1 157 elseif ( keyPressed == "Button14" ) then
madcatzinc@1 158 keyPressed = "BUTTON14"
madcatzinc@1 159 elseif ( keyOrButton == "Button15" ) then
madcatzinc@1 160 keyPressed = "BUTTON15"
madcatzinc@1 161 elseif ( keyPressed == "Button16" ) then
madcatzinc@1 162 keyPressed = "BUTTON16"
madcatzinc@1 163 elseif ( keyOrButton == "Button17" ) then
madcatzinc@1 164 keyPressed = "BUTTON17"
madcatzinc@1 165 elseif ( keyPressed == "Button18" ) then
madcatzinc@1 166 keyPressed = "BUTTON18"
madcatzinc@1 167 elseif ( keyOrButton == "Button19" ) then
madcatzinc@1 168 keyPressed = "BUTTON19"
madcatzinc@1 169 elseif ( keyPressed == "Button20" ) then
madcatzinc@1 170 keyPressed = "BUTTON20"
madcatzinc@1 171 elseif ( keyOrButton == "Button21" ) then
madcatzinc@1 172 keyPressed = "BUTTON21"
madcatzinc@1 173 elseif ( keyPressed == "Button22" ) then
madcatzinc@1 174 keyPressed = "BUTTON22"
madcatzinc@1 175 elseif ( keyOrButton == "Button23" ) then
madcatzinc@1 176 keyPressed = "BUTTON23"
madcatzinc@1 177 elseif ( keyPressed == "Button24" ) then
madcatzinc@1 178 keyPressed = "BUTTON24"
madcatzinc@1 179 elseif ( keyOrButton == "Button25" ) then
madcatzinc@1 180 keyPressed = "BUTTON25"
madcatzinc@1 181 elseif ( keyPressed == "Button26" ) then
madcatzinc@1 182 keyPressed = "BUTTON26"
madcatzinc@1 183 elseif ( keyOrButton == "Button27" ) then
madcatzinc@1 184 keyPressed = "BUTTON27"
madcatzinc@1 185 elseif ( keyPressed == "Button28" ) then
madcatzinc@1 186 keyPressed = "BUTTON28"
madcatzinc@1 187 elseif ( keyOrButton == "Button29" ) then
madcatzinc@1 188 keyPressed = "BUTTON29"
madcatzinc@1 189 elseif ( keyPressed == "Button30" ) then
madcatzinc@1 190 keyPressed = "BUTTON30"
madcatzinc@1 191 elseif ( keyOrButton == "Button31" ) then
madcatzinc@1 192 keyPressed = "BUTTON31"
madcatzinc@1 193 end
madcatzinc@1 194
madcatzinc@1 195 if ( keyPressed == "LSHIFT" or
madcatzinc@1 196 keyPressed == "RSHIFT" or
madcatzinc@1 197 keyPressed == "LCTRL" or
madcatzinc@1 198 keyPressed == "RCTRL" or
madcatzinc@1 199 keyPressed == "LALT" or
madcatzinc@1 200 keyPressed == "RALT" ) then
madcatzinc@1 201 return;
madcatzinc@1 202 end
madcatzinc@1 203 if ( IsShiftKeyDown() ) then
madcatzinc@1 204 keyPressed = "SHIFT-"..keyPressed
madcatzinc@1 205 end
madcatzinc@1 206 if ( IsControlKeyDown() ) then
madcatzinc@1 207 keyPressed = "CTRL-"..keyPressed
madcatzinc@1 208 end
madcatzinc@1 209 if ( IsAltKeyDown() ) then
madcatzinc@1 210 keyPressed = "ALT-"..keyPressed
madcatzinc@1 211 end
madcatzinc@1 212 if ( keyPressed == "BUTTON1" or keyPressed == "BUTTON2" ) then
madcatzinc@1 213 return;
madcatzinc@1 214 end
madcatzinc@1 215
madcatzinc@4 216 CyborgMMO_SetNewKeybind(keyPressed)
madcatzinc@1 217
madcatzinc@1 218 end