require("luaScript.Protocol.ProtocolCommon") require("luaScript.GameTypeDef") local ProtocolSystemSetting = class("ProtocolSystemSetting") -- 系统设置 SystemSettingEntity = defClass("SystemSettingEntity" -- 开启声音 , defVar("sound", VT_Bool, true) -- 开启音乐 , defVar("music", VT_Bool, true) --音效音量[0-1] , defVar("soundVolume", VT_Float, 1.0) --音乐音量[0-1] , defVar("musicVolume", VT_Float, 1,0) -- 省点模式 , defVar("safePower", VT_Bool, false) -- 画面质量(0低质量,1高质量) , defVar("graphicQuality", VT_Int, 1) -- 视图类型 2D 3D , defVar("viewType", VT_String, "2d") ) SystemSettingEntity:setVersion(1); local ReadedFilePath = cc.FileUtils:getInstance():getWritablePath() .. "SystemSetting.data"; local effectData = true -- 保存 function ProtocolSystemSetting:save() effectData = self.info.sound SystemSettingEntity:saveToFile(self.info , ReadedFilePath); end -- 加载 function ProtocolSystemSetting:load() local function loadFromFile() local data = SystemSettingEntity:loadFromFile(ReadedFilePath); if data then self.info = data; effectData = self.info.sound print("aaaaaaaa:"..table.tostring(data)) else self.info = SystemSettingEntity:new(); end end -- 容错处理 xpcall(loadFromFile , function()self.info = SystemSettingEntity:new();end); end -- 恢复默认 function ProtocolSystemSetting:restore() self.info = SystemSettingEntity:new():updateTo(self.info); end --重置音效 function ProtocolSystemSetting:resetEffect() self.info.sound = effectData end function ProtocolSystemSetting:ctor() self.info = nil; self:load(); end return ProtocolSystemSetting;