-- 主界面子游戏图标 --[[ 从 subGameManger 获取版本号、更新地址、更新状态 并使用 subGameManger 进行更新 --]] local MainViewGameIcon = class("MainViewGameIcon") function MainViewGameIcon:ctor(gameId) local ui = loadUI("res/ui/ui_dating/ui_dating_icon.ui"); self.ui = ui; self.gameId = tonumber(gameId); self.isDownloading = false; self:init(); end function MainViewGameIcon:init() -- 默认不显示下载相关的节点 self.ui.Items.Button_Download:setVisible(false) self.ui.Items.ImageView_RedPoint:setVisible(false) self.ui.Items.Layout_Downloading:setVisible(false) -- 图标点击事件 self.ui.Items.ImageView_Icon:registerClick(handler(self, self.onClickIcon)) -- 下载/更新按钮 self.ui.Items.Button_Download:registerClick(handler(self, self.onClickDownload)) --免费标签 local gameFangKaConfig = app.user:getGameConfig(self.gameId); if gameFangKaConfig then --isFree 1表示免费 0: 收费 local isFree = gameFangKaConfig.isFree == 1 self.ui.Items.ImageView_FreeTag:setVisible(isFree) else self.ui.Items.ImageView_FreeTag:setVisible(false) end -- 如果是更多游戏,后面的都不用处理了 if self.gameId == GAME_IDS.More then return end local gameConfig = app.serverConfigs.subGameList[self.gameId] if not gameConfig then return end -- 游戏图标 -- self.ui.Items.ImageView_Icon:loadTexture("res/ui/zy_dating/icon/game_icon_"..self.gameId..".png") -- 是否已下载 local isInstaller = app.subGameManager:isInstaller(self.gameId) --self.ui.Items.Button_Download:setVisible(not isInstaller); -- 是否需要更新 --local isNeedUpdate = app.subGameManager:isNeedUpdate(self.gameId) --self.ui.Items.ImageView_RedPoint:setVisible(isInstaller and isNeedUpdate) if isRuanZhu() then if tonumber(self.gameId) == GAME_IDS.HongZhong then --软著版本,不下载红中的icon图标(红中麻将改为悠闲湖南麻将) self.ui.Items.ImageView_Icon:loadTexture("dating_game_icon_ddhnmj.png", cc.TextureResType.plistType) self.ui.Items.ImageView_Icon:setVisible(true) elseif tonumber(self.gameId) == GAME_IDS.PaoDeKuai then self.ui.Items.ImageView_Icon:loadTexture("dating_game_icon_ddpdk.png", cc.TextureResType.plistType) self.ui.Items.ImageView_Icon:setVisible(true) elseif tonumber(self.gameId) == GAME_IDS.LiuZhou then --软著版本,不下载柳州字牌的icon图标(柳州字牌改为悠闲柳州字牌) self.ui.Items.ImageView_Icon:loadTexture("dating_game_icon_ddlzzp.png", cc.TextureResType.plistType) self.ui.Items.ImageView_Icon:setVisible(true) elseif tonumber(self.gameId) == GAME_IDS.LaiBing then --软著版本,不下载来宾麻将的icon图标(来宾麻将改为悠闲来宾麻将) self.ui.Items.ImageView_Icon:loadTexture("dating_game_icon_ddlbmj.png", cc.TextureResType.plistType) self.ui.Items.ImageView_Icon:setVisible(true) elseif tonumber(self.gameId) == GAME_IDS.LiuZhouMJ then --软著版本,不下载柳州麻将的icon图标(柳州麻将改为悠闲柳州麻将) self.ui.Items.ImageView_Icon:loadTexture("dating_game_icon_ddlzmj.png", cc.TextureResType.plistType) self.ui.Items.ImageView_Icon:setVisible(true) else local iconPath = gameConfig.gameIcon local iconUrl, iconTime = convertIconUrl(gameConfig.gameIcon) local uiIcon = self.ui.Items.ImageView_Icon local pngName = getImageNameFromUrl(iconUrl) getImageFromUrlWithTime(iconUrl, pngName, tonumber(iconTime), function(ret) if ret then local texture = loadTextureFromFile(pngName) if not texture then return end if not uiIcon or tolua.isnull(uiIcon) then return end uiIcon:setTexture2(texture) uiIcon:setVisible(true) end end) end else -- http://img.dingdingqipai.com/images/games/hlpwz.png?v=1517298843 local iconPath = gameConfig.gameIcon local iconUrl, iconTime = convertIconUrl(gameConfig.gameIcon) local uiIcon = self.ui.Items.ImageView_Icon local pngName = getImageNameFromUrl(iconUrl) getImageFromUrlWithTime(iconUrl, pngName, tonumber(iconTime), function(ret) if ret then local texture = loadTextureFromFile(pngName) if not texture then return end if not uiIcon or tolua.isnull(uiIcon) then return end uiIcon:setTexture2(texture) uiIcon:setVisible(true) end end) end if app.serverConfigs:isNewGame(self.gameId) then self.ui.Items.ImageView_FreeTag:loadTexture("res/ui/zy_dating/dating/img_newTag.png") self.ui.Items.ImageView_FreeTag:setVisible(true) end -- 游戏是否正在更新 local isUpdating = app.subGameManager:isUpdating(self.gameId) if isUpdating then self.isDownloading = true; app.subGameManager:updateCallback(self.gameId, handler(self, self.onDownloadPercent), handler(self, self.onDownloadFinished)) end end -- 更新进度 function MainViewGameIcon:onDownloadPercent(percent) --因为是异步操作,所以要检测节点的有效性 if tolua.isnull(self.ui) then return; end self.ui.Items.Layout_Downloading:setVisible(true); self.ui.Items.Text_Percent:setText(string.format("%d%%", math.floor(percent))) percent = 100 - percent self.ui.Items.LoadingBar:setPercent(percent) end -- 更新完成 function MainViewGameIcon:onDownloadFinished() logD("MainViewGameIcon:onDownloadFinished()") --showTooltip("下载完成") if tolua.isnull(self.ui) then logD("MainViewGameIcon:onDownloadFinished() self.ui is nil") return; end -- 隐藏下载相关的节点 self.ui.Items.Layout_Downloading:setVisible(false) self.ui.Items.Button_Download:setVisible(false) -- 更新红点也要隐藏 self.ui.Items.ImageView_RedPoint:setVisible(false) self.isDownloading = false; logD("MainViewGameIcon:onDownloadFinished() end") end -- 点击进入比赛场 function MainViewGameIcon:gotoMatch() local view = import("luaScript.Views.Match.MatchMainView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end -- 点击进入对应图标 function MainViewGameIcon:gotoSubGame() cc.UserDefault:getInstance():setBoolForKey("firstLogin",false) -- 打开对应的创建界面 --规定>=20000是游戏,10000是比赛场,10001是金币场 if self.gameId == 10000 then self:gotoMatch() return elseif self.gameId == 10001 then return end self.gameRule = nil local gameId = self.gameId if self.gameId >= 20000 then self.gameRule = math.floor(self.gameId%10000) self.gameId = math.floor(self.gameId/10000) end local gameConfig = getSubGameConfig(self.gameId) if not gameConfig then showTooltip("开发中") return end app.gameId = self.gameId -- app.subGameManager:saveToFile(gameId) local gameData = {} if GAME_IDS.More == self.gameId then gameData.gameId = nil else gameData.gameId = self.gameId end gameData.defaultPlayType = self.gameRule local createView = import("luaScript.Views.CreateRoom.CreateRoomBase"):new(gameData) createView:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(createView) self.gameId = gameId end -- 点击开始下载 function MainViewGameIcon:gotoDownload() if app.subGameManager then self.isDownloading = true; app.subGameManager:updateSubGame(self.gameId, handler(self, self.onDownloadPercent), handler(self, self.onDownloadFinished)) -- 立刻更新界面 self:onDownloadPercent(0); end end -- 点击事件 - 下载按钮 function MainViewGameIcon:onClickDownload() if not self:checkIsOpen() then showTooltip("开发中") return end if self.isDownloading then showTooltip("正在下载中,请稍后...") return end -- 如果未安装,提示是否安装 if not app.subGameManager:isInstaller(self.gameId) then local gameConfig = app.serverConfigs.subGameList[self.gameId] if gameConfig then --如果有框架ID 的游戏 先判断框架是否正在更新 local subGameConfig=getSubGameConfig(self.gameId) if subGameConfig.fremworkId and app.subGameManager:isUpdating(subGameConfig.fremworkId) then showTooltip("请等待其他游戏更新完成后再试!") return end local strContent = gameConfig.desc or string.format("是否下载[%s]", gameConfig.gameName or "") showConfirmDialog(strContent, handler(self, self.gotoDownload), function() end); return end end --showTooltip("无需下载") end -- 点击事件 - 图标 function MainViewGameIcon:onClickIcon() playBtnEffect() self:gotoSubGame(); do return end if self.gameId == GAME_IDS.More then self:gotoSubGame() return; end if not self:checkIsOpen() then showTooltip("开发中") return end -- 如果未安装,必须先安装 if not app.subGameManager:isInstaller(self.gameId) then self:onClickDownload() return end -- 如果需更新,则直接更新,更新完成后进入游戏 if app.subGameManager:isNeedUpdate(self.gameId) then --如果有框架ID 的游戏 先判断框架是否正在更新 local subGameConfig=getSubGameConfig(self.gameId) if subGameConfig.fremworkId and app.subGameManager:isUpdating(subGameConfig.fremworkId) then showTooltip("请等待其他游戏更新完成后再试!") return end self.isDownloading = true; local function onUpdateFinished() self:onDownloadFinished() self:gotoSubGame() end app.subGameManager:updateSubGame(self.gameId, handler(self, self.onDownloadPercent), onUpdateFinished) -- 立刻更新界面 self:onDownloadPercent(0); return else self:gotoSubGame(); end end function MainViewGameIcon:checkIsOpen() local gameConfig = getSubGameConfig(self.gameId) if not gameConfig then return false end -- 是否对外开发 if not isWin32Platform() and not gameConfig.open then return false end return true end return MainViewGameIcon