Mercurial > wow > cyborg-mmo7
comparison RatPageModel.lua @ 0:bf9220814fb5
The first version of the Cyborg MMO7 addon for warcraft
| author | madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09 |
|---|---|
| date | Tue, 24 Jan 2012 17:14:21 +0000 |
| parents | |
| children | a4e2eaf9cad9 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:bf9220814fb5 |
|---|---|
| 1 --~ Warcraft Plugin for Cyborg MMO7 | |
| 2 --~ Filename: RatPageModel.lua | |
| 3 --~ Description: Code model of the MMO7 mouse | |
| 4 --~ Copyright (C) 2012 Mad Catz Inc. | |
| 5 --~ Author: Christopher Hooks | |
| 6 | |
| 7 --~ This program is free software; you can redistribute it and/or | |
| 8 --~ modify it under the terms of the GNU General Public License | |
| 9 --~ as published by the Free Software Foundation; either version 2 | |
| 10 --~ of the License, or (at your option) any later version. | |
| 11 | |
| 12 --~ This program is distributed in the hope that it will be useful, | |
| 13 --~ but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 --~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 --~ GNU General Public License for more details. | |
| 16 | |
| 17 --~ You should have received a copy of the GNU General Public License | |
| 18 --~ along with this program; if not, write to the Free Software | |
| 19 --~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 -- Constants -- | |
| 21 | |
| 22 local RAT7 = { BUTTONS = 13, MODES = 3, SHIFT = 0} | |
| 23 | |
| 24 local MIDDLEMOUSE = 1; | |
| 25 | |
| 26 RatPageModel = { | |
| 27 new = function() | |
| 28 local self = {} | |
| 29 self.m_Mode = 1; | |
| 30 self.ObserverCount = 0; | |
| 31 self.ObserverList = {} | |
| 32 self.Data = {} | |
| 33 | |
| 34 for i = 1,RAT7.MODES do | |
| 35 self.Data[i] = {} | |
| 36 for j = 1, RAT7.BUTTONS do | |
| 37 self.Data[i][j] = {}; | |
| 38 end | |
| 39 end | |
| 40 | |
| 41 self.InitSaveData = function(data) | |
| 42 for i = 1,RAT7.MODES do | |
| 43 if (nil == data["Rat"][i]) then | |
| 44 data["Rat"][i] = {} | |
| 45 end | |
| 46 for j = 1, RAT7.BUTTONS do | |
| 47 if (nil == data["Rat"][i][j]) then | |
| 48 data["Rat"][i][j] = {} | |
| 49 end | |
| 50 end | |
| 51 end | |
| 52 end | |
| 53 | |
| 54 | |
| 55 self.LoadData = function() | |
| 56 msg("Loading...") | |
| 57 local data = GetSaveData(); | |
| 58 | |
| 59 | |
| 60 if (nil == data["Rat"]) then | |
| 61 data["Rat"] = {} | |
| 62 self.InitSaveData(data); | |
| 63 end | |
| 64 | |
| 65 self.Data = data["Rat"] | |
| 66 if(data ~= nil) then | |
| 67 for mode = 1,RAT7.MODES do | |
| 68 for button = 1, RAT7.BUTTONS do | |
| 69 if(self.Data[mode][button] ~= nil) then | |
| 70 object = WowObject.Create(self.Data[mode][button].Type, self.Data[mode][button].Detail, self.Data[mode][button].Subdetail); | |
| 71 self.SetObjectOnButtonNoUpdate(button, mode, object); | |
| 72 else | |
| 73 object = WowObject.Create("", "", ""); | |
| 74 self.SetObjectOnButtonNoUpdate(button, mode, object); | |
| 75 self.Data[mode][button] = object; | |
| 76 end | |
| 77 end | |
| 78 end | |
| 79 self.UpdateObservers(); | |
| 80 end | |
| 81 end | |
| 82 | |
| 83 self.SaveData = function() | |
| 84 msg("Saving...") | |
| 85 SetSaveData(self.Data, "Rat"); | |
| 86 end | |
| 87 | |
| 88 self.SetMode = function(mode) | |
| 89 self.m_Mode = mode; | |
| 90 self.UpdateObservers(); | |
| 91 end | |
| 92 | |
| 93 self.GetMode = function() | |
| 94 return self.m_Mode; | |
| 95 end | |
| 96 | |
| 97 self.GetData = function() | |
| 98 return self.Data, self.m_Mode; | |
| 99 end | |
| 100 | |
| 101 self.GetObjectOnButton = function(button) | |
| 102 if(nil == self.Data[self.m_Mode][button]) then | |
| 103 return nil; | |
| 104 else | |
| 105 return self.Data[self.m_Mode][button] | |
| 106 end | |
| 107 end | |
| 108 | |
| 109 self.SetObjectOnButtonNoUpdate = function(button, mode, object) | |
| 110 --msg("button = "..tostring(button).." mode = "..tostring(mode)) | |
| 111 self.Data[mode][button] = object; | |
| 112 | |
| 113 if(nil ~= object) then | |
| 114 object.SetBinding(WowCommands[GetLocale()][((mode-1)*RAT7.BUTTONS)+button]); | |
| 115 if("callback" == object.Type) then | |
| 116 msg("trying to set texture") | |
| 117 local slot = getglobal("defaultPageSlot"..button); | |
| 118 slot:SetNormalTexture(object.Texture) | |
| 119 end | |
| 120 else | |
| 121 msg("clearing "..button) | |
| 122 WowObject.ClearBinding(WowCommands[GetLocale()][((mode-1)*RAT7.BUTTONS)+button]) | |
| 123 end | |
| 124 end | |
| 125 | |
| 126 self.SetObjectOnButton = function(button, mode, object) | |
| 127 self.SetObjectOnButtonNoUpdate(button, mode, object); | |
| 128 self.UpdateObservers() | |
| 129 end | |
| 130 | |
| 131 self.AddObserver = function(view) | |
| 132 table.insert(self.ObserverList,view) | |
| 133 self.observerCount = # self.ObserverList | |
| 134 end | |
| 135 | |
| 136 self.GetAllObservers = function() | |
| 137 return self.ObserverList; | |
| 138 end | |
| 139 | |
| 140 self.UpdateObservers = function() | |
| 141 for i = 1, (# self.ObserverList) do | |
| 142 self.ObserverList[i].Update(self.Data, self.m_Mode) | |
| 143 end | |
| 144 self.SaveData() | |
| 145 end | |
| 146 return self; | |
| 147 end, | |
| 148 | |
| 149 m_Instance = nil, | |
| 150 | |
| 151 Instance = function() | |
| 152 if(nil == RatPageModel.m_Instance) then | |
| 153 RatPageModel.m_Instance = RatPageModel.new(); | |
| 154 end | |
| 155 return RatPageModel.m_Instance; | |
| 156 end | |
| 157 } |
