madcatzinc@13
|
1 --~ Warcraft Plugin for Cyborg MMO7
|
madcatzinc@0
|
2 --~ Filename: RatPageModel.lua
|
madcatzinc@0
|
3 --~ Description: Code model of the MMO7 mouse
|
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 -- Constants --
|
madcatzinc@0
|
21
|
madcatzinc@13
|
22 local RAT7 = {
|
madcatzinc@13
|
23 BUTTONS = 13,
|
madcatzinc@13
|
24 MODES = 3,
|
madcatzinc@13
|
25 SHIFT = 0,
|
madcatzinc@13
|
26 }
|
madcatzinc@0
|
27
|
madcatzinc@13
|
28 local MIDDLEMOUSE = 1
|
madcatzinc@0
|
29
|
madcatzinc@18
|
30 ------------------------------------------------------------------------------
|
madcatzinc@0
|
31
|
madcatzinc@18
|
32 local RatPageModel_methods = {}
|
madcatzinc@18
|
33 local RatPageModel_mt = {__index=RatPageModel_methods}
|
madcatzinc@18
|
34
|
madcatzinc@18
|
35 local function RatPageModel()
|
madcatzinc@18
|
36 local self = {}
|
madcatzinc@18
|
37 self.mode = 1
|
madcatzinc@18
|
38 self.observers = {}
|
madcatzinc@51
|
39 self.objects = {}
|
madcatzinc@18
|
40
|
madcatzinc@51
|
41 for mode=1,RAT7.MODES do
|
madcatzinc@51
|
42 self.objects[mode] = {}
|
madcatzinc@18
|
43 end
|
madcatzinc@18
|
44
|
madcatzinc@18
|
45 setmetatable(self, RatPageModel_mt)
|
madcatzinc@18
|
46
|
madcatzinc@18
|
47 return self
|
madcatzinc@18
|
48 end
|
madcatzinc@18
|
49
|
madcatzinc@51
|
50 function RatPageModel_methods:LoadData()
|
madcatzinc@51
|
51 CyborgMMO_DPrint("Loading...")
|
madcatzinc@51
|
52 local data = CyborgMMO_GetRatSaveData()
|
madcatzinc@51
|
53 for mode=1,RAT7.MODES do
|
madcatzinc@51
|
54 for button=1,RAT7.BUTTONS do
|
madcatzinc@51
|
55 local buttonData = data and data[mode] and data[mode][button]
|
madcatzinc@51
|
56 if buttonData and buttonData.type then
|
madcatzinc@51
|
57 local object = CyborgMMO_CreateWowObject(buttonData.type, buttonData.detail, buttonData.subdetail)
|
madcatzinc@51
|
58 self:SetObjectOnButtonNoUpdate(button, mode, object)
|
madcatzinc@51
|
59 else
|
madcatzinc@51
|
60 self:SetObjectOnButtonNoUpdate(button, mode, nil)
|
madcatzinc@0
|
61 end
|
madcatzinc@0
|
62 end
|
madcatzinc@18
|
63 end
|
madcatzinc@51
|
64 self:UpdateObservers()
|
madcatzinc@18
|
65 end
|
madcatzinc@0
|
66
|
madcatzinc@18
|
67 function RatPageModel_methods:SaveData()
|
madcatzinc@18
|
68 CyborgMMO_DPrint("Saving...")
|
madcatzinc@51
|
69 CyborgMMO_SetRatSaveData(self.objects)
|
madcatzinc@18
|
70 end
|
madcatzinc@0
|
71
|
madcatzinc@18
|
72 function RatPageModel_methods:SetMode(mode)
|
madcatzinc@18
|
73 self.mode = mode
|
madcatzinc@18
|
74 self:UpdateObservers()
|
madcatzinc@18
|
75 end
|
madcatzinc@0
|
76
|
madcatzinc@18
|
77 function RatPageModel_methods:GetMode()
|
madcatzinc@18
|
78 return self.mode
|
madcatzinc@18
|
79 end
|
madcatzinc@18
|
80
|
madcatzinc@18
|
81 function RatPageModel_methods:GetObjectOnButton(button)
|
madcatzinc@51
|
82 if not self.objects[self.mode][button] then
|
madcatzinc@18
|
83 return nil
|
madcatzinc@18
|
84 else
|
madcatzinc@51
|
85 return self.objects[self.mode][button]
|
madcatzinc@18
|
86 end
|
madcatzinc@18
|
87 end
|
madcatzinc@18
|
88
|
madcatzinc@18
|
89 function RatPageModel_methods:SetObjectOnButtonNoUpdate(button, mode, object)
|
madcatzinc@51
|
90 self.objects[mode][button] = object
|
madcatzinc@18
|
91 if object then
|
madcatzinc@29
|
92 object:SetBinding(CyborgMMO_ProfileKeyBindings[((mode-1)*RAT7.BUTTONS)+button])
|
madcatzinc@18
|
93 else
|
madcatzinc@29
|
94 CyborgMMO_ClearBinding(CyborgMMO_ProfileKeyBindings[((mode-1)*RAT7.BUTTONS)+button])
|
madcatzinc@18
|
95 end
|
madcatzinc@18
|
96 end
|
madcatzinc@0
|
97
|
madcatzinc@18
|
98 function RatPageModel_methods:SetObjectOnButton(button, mode, object)
|
madcatzinc@39
|
99 if not object then
|
madcatzinc@39
|
100 CyborgMMO_DPrint("clearing "..button)
|
madcatzinc@39
|
101 end
|
madcatzinc@18
|
102 self:SetObjectOnButtonNoUpdate(button, mode, object)
|
madcatzinc@18
|
103 self:UpdateObservers()
|
madcatzinc@18
|
104 end
|
madcatzinc@0
|
105
|
madcatzinc@18
|
106 function RatPageModel_methods:AddObserver(view)
|
madcatzinc@18
|
107 table.insert(self.observers, view)
|
madcatzinc@18
|
108 end
|
madcatzinc@0
|
109
|
madcatzinc@18
|
110 function RatPageModel_methods:GetAllObservers()
|
madcatzinc@18
|
111 return self.observers
|
madcatzinc@18
|
112 end
|
madcatzinc@0
|
113
|
madcatzinc@18
|
114 function RatPageModel_methods:UpdateObservers()
|
madcatzinc@18
|
115 for i=1,#self.observers do
|
madcatzinc@51
|
116 self.observers[i].Update(self.objects, self.mode)
|
madcatzinc@18
|
117 end
|
madcatzinc@18
|
118 self:SaveData()
|
madcatzinc@18
|
119 end
|
madcatzinc@0
|
120
|
madcatzinc@18
|
121 ------------------------------------------------------------------------------
|
madcatzinc@0
|
122
|
madcatzinc@18
|
123 CyborgMMO_RatPageModel = RatPageModel()
|
madcatzinc@0
|
124
|