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.

327 lines
9.6 KiB

  1. -- 主界面子游戏图标
  2. --[[
  3. 从 subGameManger 获取版本号、更新地址、更新状态
  4. 并使用 subGameManger 进行更新
  5. --]]
  6. local MainViewGameIcon = class("MainViewGameIcon")
  7. function MainViewGameIcon:ctor(gameId)
  8. local ui = loadUI("res/ui/ui_dating/ui_dating_icon.ui");
  9. self.ui = ui;
  10. self.gameId = tonumber(gameId);
  11. self.isDownloading = false;
  12. self:init();
  13. end
  14. function MainViewGameIcon:init()
  15. -- 默认不显示下载相关的节点
  16. self.ui.Items.Button_Download:setVisible(false)
  17. self.ui.Items.ImageView_RedPoint:setVisible(false)
  18. self.ui.Items.Layout_Downloading:setVisible(false)
  19. -- 图标点击事件
  20. self.ui.Items.ImageView_Icon:registerClick(handler(self, self.onClickIcon))
  21. -- 下载/更新按钮
  22. self.ui.Items.Button_Download:registerClick(handler(self, self.onClickDownload))
  23. --免费标签
  24. local gameFangKaConfig = app.user:getGameConfig(self.gameId);
  25. if gameFangKaConfig then
  26. --isFree 1表示免费 0: 收费
  27. local isFree = gameFangKaConfig.isFree == 1
  28. self.ui.Items.ImageView_FreeTag:setVisible(isFree)
  29. else
  30. self.ui.Items.ImageView_FreeTag:setVisible(false)
  31. end
  32. -- 如果是更多游戏,后面的都不用处理了
  33. if self.gameId == GAME_IDS.More then
  34. return
  35. end
  36. local gameConfig = app.serverConfigs.subGameList[self.gameId]
  37. if not gameConfig then
  38. return
  39. end
  40. -- 游戏图标
  41. -- self.ui.Items.ImageView_Icon:loadTexture("res/ui/zy_dating/icon/game_icon_"..self.gameId..".png")
  42. -- 是否已下载
  43. local isInstaller = app.subGameManager:isInstaller(self.gameId)
  44. --self.ui.Items.Button_Download:setVisible(not isInstaller);
  45. -- 是否需要更新
  46. --local isNeedUpdate = app.subGameManager:isNeedUpdate(self.gameId)
  47. --self.ui.Items.ImageView_RedPoint:setVisible(isInstaller and isNeedUpdate)
  48. if isRuanZhu() then
  49. if tonumber(self.gameId) == GAME_IDS.HongZhong then
  50. --软著版本,不下载红中的icon图标(红中麻将改为悠闲湖南麻将)
  51. self.ui.Items.ImageView_Icon:loadTexture("dating_game_icon_ddhnmj.png", cc.TextureResType.plistType)
  52. self.ui.Items.ImageView_Icon:setVisible(true)
  53. elseif tonumber(self.gameId) == GAME_IDS.PaoDeKuai then
  54. self.ui.Items.ImageView_Icon:loadTexture("dating_game_icon_ddpdk.png", cc.TextureResType.plistType)
  55. self.ui.Items.ImageView_Icon:setVisible(true)
  56. elseif tonumber(self.gameId) == GAME_IDS.LiuZhou then
  57. --软著版本,不下载柳州字牌的icon图标(柳州字牌改为悠闲柳州字牌)
  58. self.ui.Items.ImageView_Icon:loadTexture("dating_game_icon_ddlzzp.png", cc.TextureResType.plistType)
  59. self.ui.Items.ImageView_Icon:setVisible(true)
  60. elseif tonumber(self.gameId) == GAME_IDS.LaiBing then
  61. --软著版本,不下载来宾麻将的icon图标(来宾麻将改为悠闲来宾麻将)
  62. self.ui.Items.ImageView_Icon:loadTexture("dating_game_icon_ddlbmj.png", cc.TextureResType.plistType)
  63. self.ui.Items.ImageView_Icon:setVisible(true)
  64. elseif tonumber(self.gameId) == GAME_IDS.LiuZhouMJ then
  65. --软著版本,不下载柳州麻将的icon图标(柳州麻将改为悠闲柳州麻将)
  66. self.ui.Items.ImageView_Icon:loadTexture("dating_game_icon_ddlzmj.png", cc.TextureResType.plistType)
  67. self.ui.Items.ImageView_Icon:setVisible(true)
  68. else
  69. local iconPath = gameConfig.gameIcon
  70. local iconUrl, iconTime = convertIconUrl(gameConfig.gameIcon)
  71. local uiIcon = self.ui.Items.ImageView_Icon
  72. local pngName = getImageNameFromUrl(iconUrl)
  73. getImageFromUrlWithTime(iconUrl, pngName, tonumber(iconTime), function(ret)
  74. if ret then
  75. local texture = loadTextureFromFile(pngName)
  76. if not texture then
  77. return
  78. end
  79. if not uiIcon or tolua.isnull(uiIcon) then
  80. return
  81. end
  82. uiIcon:setTexture2(texture)
  83. uiIcon:setVisible(true)
  84. end
  85. end)
  86. end
  87. else
  88. -- http://img.dingdingqipai.com/images/games/hlpwz.png?v=1517298843
  89. local iconPath = gameConfig.gameIcon
  90. local iconUrl, iconTime = convertIconUrl(gameConfig.gameIcon)
  91. local uiIcon = self.ui.Items.ImageView_Icon
  92. local pngName = getImageNameFromUrl(iconUrl)
  93. getImageFromUrlWithTime(iconUrl, pngName, tonumber(iconTime), function(ret)
  94. if ret then
  95. local texture = loadTextureFromFile(pngName)
  96. if not texture then
  97. return
  98. end
  99. if not uiIcon or tolua.isnull(uiIcon) then
  100. return
  101. end
  102. uiIcon:setTexture2(texture)
  103. uiIcon:setVisible(true)
  104. end
  105. end)
  106. end
  107. if app.serverConfigs:isNewGame(self.gameId) then
  108. self.ui.Items.ImageView_FreeTag:loadTexture("res/ui/zy_dating/dating/img_newTag.png")
  109. self.ui.Items.ImageView_FreeTag:setVisible(true)
  110. end
  111. -- 游戏是否正在更新
  112. local isUpdating = app.subGameManager:isUpdating(self.gameId)
  113. if isUpdating then
  114. self.isDownloading = true;
  115. app.subGameManager:updateCallback(self.gameId, handler(self, self.onDownloadPercent), handler(self, self.onDownloadFinished))
  116. end
  117. end
  118. -- 更新进度
  119. function MainViewGameIcon:onDownloadPercent(percent)
  120. --因为是异步操作,所以要检测节点的有效性
  121. if tolua.isnull(self.ui) then
  122. return;
  123. end
  124. self.ui.Items.Layout_Downloading:setVisible(true);
  125. self.ui.Items.Text_Percent:setText(string.format("%d%%", math.floor(percent)))
  126. percent = 100 - percent
  127. self.ui.Items.LoadingBar:setPercent(percent)
  128. end
  129. -- 更新完成
  130. function MainViewGameIcon:onDownloadFinished()
  131. logD("MainViewGameIcon:onDownloadFinished()")
  132. --showTooltip("下载完成")
  133. if tolua.isnull(self.ui) then
  134. logD("MainViewGameIcon:onDownloadFinished() self.ui is nil")
  135. return;
  136. end
  137. -- 隐藏下载相关的节点
  138. self.ui.Items.Layout_Downloading:setVisible(false)
  139. self.ui.Items.Button_Download:setVisible(false)
  140. -- 更新红点也要隐藏
  141. self.ui.Items.ImageView_RedPoint:setVisible(false)
  142. self.isDownloading = false;
  143. logD("MainViewGameIcon:onDownloadFinished() end")
  144. end
  145. -- 点击进入比赛场
  146. function MainViewGameIcon:gotoMatch()
  147. local view = import("luaScript.Views.Match.MatchMainView"):new()
  148. view:setAnchorPoint(cc.p(0.5, 0.5))
  149. app:showWaitDialog(view)
  150. end
  151. -- 点击进入对应图标
  152. function MainViewGameIcon:gotoSubGame()
  153. cc.UserDefault:getInstance():setBoolForKey("firstLogin",false)
  154. -- 打开对应的创建界面
  155. --规定>=20000是游戏,10000是比赛场,10001是金币场
  156. if self.gameId == 10000 then
  157. self:gotoMatch()
  158. return
  159. elseif self.gameId == 10001 then
  160. return
  161. end
  162. self.gameRule = nil
  163. local gameId = self.gameId
  164. if self.gameId >= 20000 then
  165. self.gameRule = math.floor(self.gameId%10000)
  166. self.gameId = math.floor(self.gameId/10000)
  167. end
  168. local gameConfig = getSubGameConfig(self.gameId)
  169. if not gameConfig then
  170. showTooltip("开发中")
  171. return
  172. end
  173. app.gameId = self.gameId
  174. -- app.subGameManager:saveToFile(gameId)
  175. local gameData = {}
  176. if GAME_IDS.More == self.gameId then
  177. gameData.gameId = nil
  178. else
  179. gameData.gameId = self.gameId
  180. end
  181. gameData.defaultPlayType = self.gameRule
  182. local createView = import("luaScript.Views.CreateRoom.CreateRoomBase"):new(gameData)
  183. createView:setAnchorPoint(cc.p(0.5, 0.5))
  184. app:showWaitDialog(createView)
  185. self.gameId = gameId
  186. end
  187. -- 点击开始下载
  188. function MainViewGameIcon:gotoDownload()
  189. if app.subGameManager then
  190. self.isDownloading = true;
  191. app.subGameManager:updateSubGame(self.gameId, handler(self, self.onDownloadPercent), handler(self, self.onDownloadFinished))
  192. -- 立刻更新界面
  193. self:onDownloadPercent(0);
  194. end
  195. end
  196. -- 点击事件 - 下载按钮
  197. function MainViewGameIcon:onClickDownload()
  198. if not self:checkIsOpen() then
  199. showTooltip("开发中")
  200. return
  201. end
  202. if self.isDownloading then
  203. showTooltip("正在下载中,请稍后...")
  204. return
  205. end
  206. -- 如果未安装,提示是否安装
  207. if not app.subGameManager:isInstaller(self.gameId) then
  208. local gameConfig = app.serverConfigs.subGameList[self.gameId]
  209. if gameConfig then
  210. --如果有框架ID 的游戏 先判断框架是否正在更新
  211. local subGameConfig=getSubGameConfig(self.gameId)
  212. if subGameConfig.fremworkId and app.subGameManager:isUpdating(subGameConfig.fremworkId) then
  213. showTooltip("请等待其他游戏更新完成后再试!")
  214. return
  215. end
  216. local strContent = gameConfig.desc or string.format("是否下载[%s]", gameConfig.gameName or "")
  217. showConfirmDialog(strContent, handler(self, self.gotoDownload), function() end);
  218. return
  219. end
  220. end
  221. --showTooltip("无需下载")
  222. end
  223. -- 点击事件 - 图标
  224. function MainViewGameIcon:onClickIcon()
  225. playBtnEffect()
  226. self:gotoSubGame();
  227. do return end
  228. if self.gameId == GAME_IDS.More then
  229. self:gotoSubGame()
  230. return;
  231. end
  232. if not self:checkIsOpen() then
  233. showTooltip("开发中")
  234. return
  235. end
  236. -- 如果未安装,必须先安装
  237. if not app.subGameManager:isInstaller(self.gameId) then
  238. self:onClickDownload()
  239. return
  240. end
  241. -- 如果需更新,则直接更新,更新完成后进入游戏
  242. if app.subGameManager:isNeedUpdate(self.gameId) then
  243. --如果有框架ID 的游戏 先判断框架是否正在更新
  244. local subGameConfig=getSubGameConfig(self.gameId)
  245. if subGameConfig.fremworkId and app.subGameManager:isUpdating(subGameConfig.fremworkId) then
  246. showTooltip("请等待其他游戏更新完成后再试!")
  247. return
  248. end
  249. self.isDownloading = true;
  250. local function onUpdateFinished()
  251. self:onDownloadFinished()
  252. self:gotoSubGame()
  253. end
  254. app.subGameManager:updateSubGame(self.gameId, handler(self, self.onDownloadPercent), onUpdateFinished)
  255. -- 立刻更新界面
  256. self:onDownloadPercent(0);
  257. return
  258. else
  259. self:gotoSubGame();
  260. end
  261. end
  262. function MainViewGameIcon:checkIsOpen()
  263. local gameConfig = getSubGameConfig(self.gameId)
  264. if not gameConfig then
  265. return false
  266. end
  267. -- 是否对外开发
  268. if not isWin32Platform() and not gameConfig.open then
  269. return false
  270. end
  271. return true
  272. end
  273. return MainViewGameIcon