您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

137 行
3.2 KiB

  1. -- 实现加载配置进度条
  2. local StartupProgressView = {};
  3. StartupProgressView.__index = StartupProgressView;
  4. -- 创建新对象
  5. function StartupProgressView:new(...)
  6. local instance = {};
  7. setmetatable(instance , StartupProgressView);
  8. instance:ctor(...);
  9. return instance;
  10. end
  11. function StartupProgressView:ctor()
  12. self:onEnter();
  13. end
  14. -- 创建更新界面
  15. local function createUpdateUI()
  16. local ui = loadUI("res/ui/ui_denglu/ui_loading.ui")
  17. return ui
  18. end
  19. function StartupProgressView:initMainScene()
  20. -- initialize director
  21. local director = cc.Director:getInstance();
  22. local resolutionSize = director:getOpenGLView():getDesignResolutionSize()
  23. self.mainScene = cc.Scene:create("mainScene");
  24. self.mainScene:setContentSize(resolutionSize);
  25. self.mainScene:setAnchorPoint({x=0,y=0});
  26. if director:getRunningScene() then
  27. director:replaceScene(self.mainScene);
  28. else
  29. director:runWithScene(self.mainScene);
  30. end
  31. end
  32. function StartupProgressView:onEnter()
  33. self:initMainScene();
  34. self.ui = createUpdateUI();
  35. self.mainScene:addChild(self.ui);
  36. -- 找到所有已经安装的游戏
  37. self.insGameList = {}
  38. for _,gameId in pairs(GAME_IDS) do
  39. local clientUpdateFile = "update_"..tostring(gameId)..".json"
  40. if isWritableFileExist(clientUpdateFile) then
  41. table.insert(self.insGameList, gameId);
  42. end
  43. end
  44. self:initFramework()
  45. self.Count = table.nums(self.insGameList);
  46. self.Current = 0;
  47. self:checkConfig();
  48. end
  49. --添加框架到文件系统
  50. function StartupProgressView:initFramework()
  51. local frameworks={
  52. 1001,--麻将
  53. 1002,--字牌
  54. 1003,--扑克
  55. }
  56. for _,gameId in pairs(frameworks) do
  57. local clientUpdateFile = "update_"..tostring(gameId)..".json"
  58. if isWritableFileExist(clientUpdateFile) then
  59. table.insert(self.insGameList, gameId);
  60. end
  61. end
  62. end
  63. -- 一次只加载一个配置
  64. function StartupProgressView:checkConfig()
  65. self.ui:runInNextFrame(function()
  66. if self.Current < self.Count then
  67. -- 每帧加载一个子游戏的文件列表
  68. self.Current = self.Current + 1
  69. self:loadSubGameFileList(self.insGameList[self.Current]);
  70. -- 循环
  71. self:checkConfig()
  72. else
  73. self:onExit()
  74. end
  75. end)
  76. end
  77. function StartupProgressView:loadSubGameFileList(gameId)
  78. if not gameId then
  79. return
  80. end
  81. local clientUpdateFile = "update_"..tostring(gameId)..".json"
  82. if not isWritableFileExist(clientUpdateFile) then
  83. return
  84. end
  85. -- 加载本地旧的文件列表
  86. local function onStartElementOld(name , atts)
  87. if name == "file" then
  88. local info =
  89. {
  90. isRomFile = false;
  91. origin = atts.origin;
  92. name = atts.name;
  93. md5 = atts.md5;
  94. size = tonumber(atts.size),
  95. realFilePath = getWritableFullName(atts.md5);
  96. };
  97. cc.FilePackage:getInstance():addFile(info);
  98. end
  99. end
  100. local fileData = getWritableFileData(clientUpdateFile);
  101. local fileData = cc.FilePackage:decrypt(fileData)
  102. local ret , result = tiny.eval(fileData , onStartElementOld)
  103. if ret == nil then
  104. log("Error, StartupProgressView:loadSubGameFileList() ", gameId)
  105. logE(result);
  106. end
  107. end
  108. -- 进度加载完毕,退出进度条,真正进入游戏
  109. function StartupProgressView:onExit()
  110. self.ui:removeFromParent();
  111. require("luaScript.ViewTouchEventHelper")
  112. require("luaScript.gameApp"):new():run()
  113. end
  114. return StartupProgressView;