You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7 KiB

  1. require("luaScript.Protocol.ProtocolCommon")
  2. require("luaScript.GameTypeDef")
  3. local ProtocolSystemSetting = class("ProtocolSystemSetting")
  4. -- 系统设置
  5. SystemSettingEntity = defClass("SystemSettingEntity"
  6. -- 开启声音
  7. , defVar("sound", VT_Bool, true)
  8. -- 开启音乐
  9. , defVar("music", VT_Bool, true)
  10. --音效音量[0-1]
  11. , defVar("soundVolume", VT_Float, 1.0)
  12. --音乐音量[0-1]
  13. , defVar("musicVolume", VT_Float, 1,0)
  14. -- 省点模式
  15. , defVar("safePower", VT_Bool, false)
  16. -- 画面质量(0低质量,1高质量)
  17. , defVar("graphicQuality", VT_Int, 1)
  18. -- 视图类型 2D 3D
  19. , defVar("viewType", VT_String, "2d")
  20. )
  21. SystemSettingEntity:setVersion(1);
  22. local ReadedFilePath = cc.FileUtils:getInstance():getWritablePath() .. "SystemSetting.data";
  23. local effectData = true
  24. -- 保存
  25. function ProtocolSystemSetting:save()
  26. effectData = self.info.sound
  27. SystemSettingEntity:saveToFile(self.info , ReadedFilePath);
  28. end
  29. -- 加载
  30. function ProtocolSystemSetting:load()
  31. local function loadFromFile()
  32. local data = SystemSettingEntity:loadFromFile(ReadedFilePath);
  33. if data then
  34. self.info = data;
  35. effectData = self.info.sound
  36. print("aaaaaaaa:"..table.tostring(data))
  37. else
  38. self.info = SystemSettingEntity:new();
  39. end
  40. end
  41. -- 容错处理
  42. xpcall(loadFromFile , function()self.info = SystemSettingEntity:new();end);
  43. end
  44. -- 恢复默认
  45. function ProtocolSystemSetting:restore()
  46. self.info = SystemSettingEntity:new():updateTo(self.info);
  47. end
  48. --重置音效
  49. function ProtocolSystemSetting:resetEffect()
  50. self.info.sound = effectData
  51. end
  52. function ProtocolSystemSetting:ctor()
  53. self.info = nil;
  54. self:load();
  55. end
  56. return ProtocolSystemSetting;