Mercurial > wow > cyborg-mmo7
view RatPageModel.lua @ 15:80192bc4a108
Replaced the global msg function with CyborgMMO_DPrint:
- avoids conflicts with other addons ('msg' is too generic)
- has 'print' semantics (several values accepted, calls tostring)
- use AddMessage with a colored prefix, instead of plain SendChatMessage
author | madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09 |
---|---|
date | Thu, 25 Apr 2013 01:29:55 +0000 |
parents | 9f2d838d4f8e |
children | cccc7661a2e6 |
line wrap: on
line source
--~ Warcraft Plugin for Cyborg MMO7 --~ Filename: RatPageModel.lua --~ Description: Code model of the MMO7 mouse --~ Copyright (C) 2012 Mad Catz Inc. --~ Author: Christopher Hooks --~ This program is free software; you can redistribute it and/or --~ modify it under the terms of the GNU General Public License --~ as published by the Free Software Foundation; either version 2 --~ of the License, or (at your option) any later version. --~ This program is distributed in the hope that it will be useful, --~ but WITHOUT ANY WARRANTY; without even the implied warranty of --~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --~ GNU General Public License for more details. --~ You should have received a copy of the GNU General Public License --~ along with this program; if not, write to the Free Software --~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -- Constants -- local RAT7 = { BUTTONS = 13, MODES = 3, SHIFT = 0, } local MIDDLEMOUSE = 1 CyborgMMO_RatPageModel = { new = function() local self = {} self.m_Mode = 1 self.ObserverCount = 0 self.ObserverList = {} self.Data = {} for i=1,RAT7.MODES do self.Data[i] = {} for j=1,RAT7.BUTTONS do self.Data[i][j] = {} end end self.InitSaveData = function(data) for i=1,RAT7.MODES do if not data["Rat"][i] then data["Rat"][i] = {} end for j=1,RAT7.BUTTONS do if not data["Rat"][i][j] then data["Rat"][i][j] = {} end end end end self.LoadData = function() CyborgMMO_DPrint("Loading...") local data = CyborgMMO_GetSaveData() if not data["Rat"] then data["Rat"] = {} self.InitSaveData(data) end self.Data = data["Rat"] if data then for mode=1,RAT7.MODES do for button=1,RAT7.BUTTONS do if self.Data[mode][button] then local object = CyborgMMO_WowObject.Create(self.Data[mode][button].Type, self.Data[mode][button].Detail, self.Data[mode][button].Subdetail) self.SetObjectOnButtonNoUpdate(button, mode, object) else local object = CyborgMMO_WowObject.Create("", "", "") self.SetObjectOnButtonNoUpdate(button, mode, object) self.Data[mode][button] = object end end end self.UpdateObservers() end end self.SaveData = function() CyborgMMO_DPrint("Saving...") CyborgMMO_SetSaveData(self.Data, "Rat") end self.SetMode = function(mode) self.m_Mode = mode self.UpdateObservers() end self.GetMode = function() return self.m_Mode end self.GetData = function() return self.Data,self.m_Mode end self.GetObjectOnButton = function(button) if not self.Data[self.m_Mode][button] then return nil else return self.Data[self.m_Mode][button] end end self.SetObjectOnButtonNoUpdate = function(button, mode, object) -- CyborgMMO_DPrint("button = "..tostring(button).." mode = "..tostring(mode)) self.Data[mode][button] = object if object then object.SetBinding(CyborgMMO_WowCommands[((mode-1)*RAT7.BUTTONS)+button]) if("callback" == object.Type) then CyborgMMO_DPrint("trying to set texture") local slot = getglobal("CyborgMMO_MainPageSlotListSlot"..button) slot:SetNormalTexture(object.Texture) end else CyborgMMO_DPrint("clearing "..button) CyborgMMO_WowObject.ClearBinding(CyborgMMO_WowCommands[((mode-1)*RAT7.BUTTONS)+button]) end end self.SetObjectOnButton = function(button, mode, object) self.SetObjectOnButtonNoUpdate(button, mode, object) self.UpdateObservers() end self.AddObserver = function(view) table.insert(self.ObserverList, view) self.observerCount = #self.ObserverList end self.GetAllObservers = function() return self.ObserverList end self.UpdateObservers = function() for i=1,#self.ObserverList do self.ObserverList[i].Update(self.Data, self.m_Mode) end self.SaveData() end return self end, m_Instance = nil, Instance = function() if not CyborgMMO_RatPageModel.m_Instance then CyborgMMO_RatPageModel.m_Instance = CyborgMMO_RatPageModel.new() end return CyborgMMO_RatPageModel.m_Instance end, }