|
- -- 实现加载配置进度条
- local StartupProgressView = {};
- StartupProgressView.__index = StartupProgressView;
-
- -- 创建新对象
- function StartupProgressView:new(...)
- local instance = {};
- setmetatable(instance , StartupProgressView);
- instance:ctor(...);
- return instance;
- end
-
- function StartupProgressView:ctor()
- self:onEnter();
- end
-
- -- 创建更新界面
- local function createUpdateUI()
- local ui = loadUI("res/ui/ui_denglu/ui_loading.ui")
- return ui
- end
-
- function StartupProgressView:initMainScene()
- -- initialize director
- local director = cc.Director:getInstance();
- local resolutionSize = director:getOpenGLView():getDesignResolutionSize()
- self.mainScene = cc.Scene:create("mainScene");
- self.mainScene:setContentSize(resolutionSize);
- self.mainScene:setAnchorPoint({x=0,y=0});
-
- if director:getRunningScene() then
- director:replaceScene(self.mainScene);
- else
- director:runWithScene(self.mainScene);
- end
- end
-
- function StartupProgressView:onEnter()
- self:initMainScene();
-
- self.ui = createUpdateUI();
- self.mainScene:addChild(self.ui);
-
-
-
- -- 找到所有已经安装的游戏
- self.insGameList = {}
- for _,gameId in pairs(GAME_IDS) do
- local clientUpdateFile = "update_"..tostring(gameId)..".json"
- if isWritableFileExist(clientUpdateFile) then
- table.insert(self.insGameList, gameId);
- end
- end
-
- self:initFramework()
-
-
- self.Count = table.nums(self.insGameList);
- self.Current = 0;
-
- self:checkConfig();
- end
-
- --添加框架到文件系统
- function StartupProgressView:initFramework()
- local frameworks={
- 1001,--麻将
- 1002,--字牌
- 1003,--扑克
- }
- for _,gameId in pairs(frameworks) do
- local clientUpdateFile = "update_"..tostring(gameId)..".json"
- if isWritableFileExist(clientUpdateFile) then
- table.insert(self.insGameList, gameId);
- end
- end
- end
-
- -- 一次只加载一个配置
- function StartupProgressView:checkConfig()
- self.ui:runInNextFrame(function()
- if self.Current < self.Count then
-
- -- 每帧加载一个子游戏的文件列表
- self.Current = self.Current + 1
- self:loadSubGameFileList(self.insGameList[self.Current]);
-
- -- 循环
- self:checkConfig()
- else
- self:onExit()
- end
- end)
- end
-
- function StartupProgressView:loadSubGameFileList(gameId)
- if not gameId then
- return
- end
-
- local clientUpdateFile = "update_"..tostring(gameId)..".json"
- if not isWritableFileExist(clientUpdateFile) then
- return
- end
-
- -- 加载本地旧的文件列表
- local function onStartElementOld(name , atts)
- if name == "file" then
- local info =
- {
- isRomFile = false;
- origin = atts.origin;
- name = atts.name;
- md5 = atts.md5;
- size = tonumber(atts.size),
- realFilePath = getWritableFullName(atts.md5);
- };
- cc.FilePackage:getInstance():addFile(info);
- end
- end
- local fileData = getWritableFileData(clientUpdateFile);
- local fileData = cc.FilePackage:decrypt(fileData)
- local ret , result = tiny.eval(fileData , onStartElementOld)
- if ret == nil then
- log("Error, StartupProgressView:loadSubGameFileList() ", gameId)
- logE(result);
- end
- end
-
- -- 进度加载完毕,退出进度条,真正进入游戏
- function StartupProgressView:onExit()
- self.ui:removeFromParent();
- require("luaScript.ViewTouchEventHelper")
- require("luaScript.gameApp"):new():run()
- end
-
- return StartupProgressView;
|