Mercurial > wow > cyborg-mmo7
view RatPageModel.lua @ 34:6ce173840e68
Reworked the whole "wow object" system:
- Only save what is strictly necessary.
- Save appropriate persistent information for all objects (like spellIDs instead of spellBook+spellIndex).
- Fixed Battle Pets objects (non-combat pets in pre-MoP).
- Fixed item objects.
- Cleaned and simplified most objects implementation.
- Moved the settings and button profile to the root of the saved data, rather than in a per-character sub-table (that data is already tagged as saved per character).
This should fix most issues with objects changing without user interaction on diverse occasions.
Old profiles are not converted to the new system. This will come soon.
Some issues persist due to the asynchronous loading of some informations:
- Pet icons are never properly loaded from saved data.
- Items are not properly loaded the first time the UI is started (a "/reload ui" or disconnect/connect cycle fixes this problem).
author | madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09 |
---|---|
date | Thu, 25 Apr 2013 01:31:31 +0000 |
parents | e8a004a4177b |
children | ce4ddefb68c2 |
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 ------------------------------------------------------------------------------ local RatPageModel_methods = {} local RatPageModel_mt = {__index=RatPageModel_methods} local function RatPageModel() local self = {} self.mode = 1 self.observers = {} self.data = {} for i=1,RAT7.MODES do self.data[i] = {} for j=1,RAT7.BUTTONS do self.data[i][j] = {} end end setmetatable(self, RatPageModel_mt) return self end function RatPageModel_methods:InitSaveData(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 function RatPageModel_methods:LoadData() 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_CreateWowObject(self.data[mode][button].type, self.data[mode][button].detail, self.data[mode][button].subdetail) self:SetObjectOnButtonNoUpdate(button, mode, object) else local object = CyborgMMO_CreateWowObject() self:SetObjectOnButtonNoUpdate(button, mode, object) self.data[mode][button] = object end end end self:UpdateObservers() end end function RatPageModel_methods:SaveData() CyborgMMO_DPrint("Saving...") CyborgMMO_SetRatSaveData(self.data) end function RatPageModel_methods:SetMode(mode) self.mode = mode self:UpdateObservers() end function RatPageModel_methods:GetMode() return self.mode end function RatPageModel_methods:GetData() return self.data,self.mode end function RatPageModel_methods:GetObjectOnButton(button) if not self.data[self.mode][button] then return nil else return self.data[self.mode][button] end end function RatPageModel_methods:SetObjectOnButtonNoUpdate(button, mode, object) -- CyborgMMO_DPrint("button = "..tostring(button).." mode = "..tostring(mode)) self.data[mode][button] = object if object then object:SetBinding(CyborgMMO_ProfileKeyBindings[((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_ClearBinding(CyborgMMO_ProfileKeyBindings[((mode-1)*RAT7.BUTTONS)+button]) end end function RatPageModel_methods:SetObjectOnButton(button, mode, object) self:SetObjectOnButtonNoUpdate(button, mode, object) self:UpdateObservers() end function RatPageModel_methods:AddObserver(view) table.insert(self.observers, view) end function RatPageModel_methods:GetAllObservers() return self.observers end function RatPageModel_methods:UpdateObservers() for i=1,#self.observers do self.observers[i].Update(self.data, self.mode) end self:SaveData() end ------------------------------------------------------------------------------ CyborgMMO_RatPageModel = RatPageModel()