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.

564 lines
19 KiB

  1. require("core.luaScript.Protocol.ProtocolHall")
  2. local CoinData = import("luaScript.Views.Coin.Data.CoinData");
  3. local CoinFunctions = import("core.luaScript.Views.Coin.Util.CoinFunctions")
  4. local CoinGameLogic = import("core.luaScript.Views.Coin.CoinGameLogic")
  5. local CoinEvents = import("luaScript.Views.Coin.Constant.CoinEvents");
  6. local RadioManager = import("luaScript.Tools.RadioManager");
  7. -- 主界面
  8. local CoinView = class("CoinView", cc.UIView)
  9. -- mGameId :游戏ID
  10. -- 当 mGameType == 0时,mGameId 表示游戏玩法
  11. function CoinView:ctor(mGameId, mGameRule)
  12. CoinView.super.ctor(self)
  13. self.mGameId = mGameId
  14. self.mGameRule = mGameRule
  15. self.curGameId = nil
  16. self.curGameRule = nil
  17. local ui = loadUI("res/ui/ui_coin/ui_coin_dating.ui")
  18. self.ui = ui
  19. self:addChild(ui)
  20. --默认不显示礼券说明框
  21. self.ui.Items.Layout_liquan_shuoming:setVisible(false)
  22. self.firstEnter = true
  23. end
  24. function CoinView:onEnter()
  25. CoinView.super.onEnter(self)
  26. self.ui.Items.ScrollView:hideAllBar()
  27. self.ui.Items.ScrollView_GameRule:hideAllBar()
  28. self.ui.Items.ScrollView_CoinGame:hideAllBar()
  29. self.ui.Items.Layout_Item:setVisible(false)
  30. self.ui.Items.CheckBox_Item:setVisible(false)
  31. self.ui.Items.Button_Jinbi:setVisible(false)
  32. --buton registerClick
  33. self.ui.Items.Button_Back:registerClick(handler(self, self.onClickClose))
  34. self.ui.Items.Button_Jinbi:registerClick(handler(self, self.onClickFreeCoin))
  35. self.ui.Items.Button_Fuli:registerClick(handler(self, self.onClickFuLi))
  36. self.ui.Items.Button_Fuli:setVisible(false)
  37. self.ui.Items.Text_1:setText("红包券是一种回馈玩家的福利,可直接提现或兑换"..PLN.CURRENCY.."。")
  38. self.ui.Items.ImageView_Card_Add:registerClick(
  39. function()
  40. self:onClickAdd(STORE_TYPE.BUY_ZUANSHI)
  41. end
  42. )
  43. -- by c.mj
  44. -- 房卡数量
  45. self.ui.Items.Text_Card:bind(
  46. app.user.loginInfo,
  47. "curCardNum",
  48. function()
  49. self.ui.Items.Text_Card:setString(tostring(app.user.loginInfo.curCardNum))
  50. end
  51. )
  52. self.ui.Items.ImageView_Gold_Add:registerClick(
  53. function()
  54. self:onClickAdd(STORE_TYPE.CHANGE_COIN)
  55. end
  56. )
  57. --金币
  58. self.ui.Items.Text_Gold:bind(
  59. app.user.loginInfo,
  60. "curJingbiNum",
  61. function()
  62. --超过1w的金币,后面显示文字
  63. local strCoin = CoinFunctions.getCoinDisplayText(app.user.loginInfo.curJingbiNum)
  64. self.ui.Items.Text_Gold:setString(strCoin)
  65. end
  66. )
  67. --礼券
  68. self.ui.Items.Button_liquan:registerClick(handler(self, self.onClickLiquan))
  69. self.ui.Items.Text_Liquan:bind(
  70. app.user.loginInfo,
  71. "curLiquanNum",
  72. function()
  73. --超过1w的金币,后面显示文字
  74. local strLiquan = CoinFunctions.getCoinDisplayText(app.user.loginInfo.curLiquanNum)
  75. self.ui.Items.Text_Liquan:setString(strLiquan)
  76. end
  77. )
  78. self.ui.Items.Layout_HongBao:setVisible(false)
  79. if app.config.ModuleConfig.IsSupportHongBaoKa and not isReviewVersion() then
  80. self.ui.Items.Layout_HongBao:setVisible(true)
  81. end
  82. self.ui.Items.Button_FastStart:registerClick(handler(self, self.onClickStart))
  83. self.ui.Items.Button_FastStart:setVisible(false)
  84. --点击非礼券说明的地方,隐藏礼券说明框
  85. self.ui.Items.Layout_1:registerClick(
  86. function()
  87. self.ui.Items.Layout_liquan_shuoming:setVisible(false)
  88. end
  89. )
  90. local gameData = CoinData.getInstance():getGameData();
  91. if gameData then
  92. self:initLeft()
  93. else
  94. CoinData.getInstance():requestGameServerConfig();
  95. end
  96. if app.config.ModuleConfig.IsSupportCoinFreeCoin then
  97. CoinData.getInstance():requestCoinGameActivity()
  98. end
  99. self.ui.Items.Layout_RightTop:requestDoLayout()
  100. self.ui.Items.Layout_RightTop:doLayout()
  101. self:onActivityRedPoint()
  102. self:bindEvent(app, CoinEvents.EVENT_RESPONSE_GAME_SERVER_CONFIG, handler(self, self.initLeft));
  103. self:bindEvent(app.coinProtocol, "onEnterCoinResponse", handler(self, self.onEnterCoinGameResponse))
  104. self:bindEvent(app,"onActivityRedPoint", handler(self, self.onActivityRedPoint))
  105. if isReviewVersion() then
  106. self.ui.Items.Button_Fuli:setVisible(false)
  107. self.ui.Items.Button_Jinbi:setVisible(false)
  108. end
  109. end
  110. function CoinView:initLeft()
  111. --显示快速开始
  112. self.ui.Items.Button_FastStart:setVisible(true)
  113. self.ruleIds = {}
  114. self.GameIds = {}
  115. local smallGameId = self.mGameId or -1
  116. local ruleList = CoinData.getInstance():getGameData().ruleList;
  117. if ruleList then
  118. for gameId, content in pairsByKeys(ruleList) do
  119. --先判断是否开启了金币场
  120. local gameConfig = getSubGameConfig(gameId);
  121. if gameConfig and gameConfig.bSingleGame then
  122. for gameRule,v in pairsByKeys(gameConfig.GameType) do
  123. if gameConfig and gameConfig.openCoinModeList then
  124. if gameConfig.openCoinModeList[gameRule] then --有开放这个玩法的金币场
  125. --存储游戏id
  126. table.insert(self.GameIds, tonumber(gameId) * 10000 + gameRule)
  127. if smallGameId == -1 then
  128. smallGameId = tonumber(gameId) * 10000 + gameRule
  129. end
  130. for gameRank,v in pairsByKeys(content) do
  131. local list = string.sub(gameRank,-1)
  132. local first = string.sub(gameRank,0,1)
  133. local gameRule = tonumber(list)
  134. first = tonumber(first)
  135. if gameRule then
  136. local isSame = false
  137. if not self.ruleIds[tonumber(gameId) * 10000 + gameRule] then
  138. self.ruleIds[tonumber(gameId) * 10000 + gameRule] = {}
  139. end
  140. for k,rule in ipairs(self.ruleIds[tonumber(gameId) * 10000 + gameRule]) do
  141. if rule == gameRule then
  142. isSame = true;
  143. break;
  144. end
  145. end
  146. if not isSame then
  147. table.insert(self.ruleIds[tonumber(gameId) * 10000 + gameRule],gameRule)
  148. end
  149. end
  150. end
  151. end
  152. else
  153. showTooltip("友情提示:openCoinModeList 未配置!")
  154. end
  155. end
  156. else
  157. --原来不改他
  158. if gameConfig and gameConfig.openCoinMode then
  159. --存储游戏id
  160. table.insert(self.GameIds, tonumber(gameId))
  161. if smallGameId == -1 then
  162. smallGameId = tonumber(gameId)
  163. end
  164. --过滤玩法,同一玩法可能有多个场次,但只保留一个玩法(下面的算法原来的人写应该是有问题的)
  165. for gameRank, v in pairsByKeys(content) do
  166. local list = string.sub(gameRank, -1)
  167. local gameRule = tonumber(list)
  168. if not self.ruleIds[tonumber(gameId)] then
  169. self.ruleIds[tonumber(gameId)] = {}
  170. end
  171. if self.ruleIds[tonumber(gameId)] and self.ruleIds[tonumber(gameId)][v.ruleID] ~= gameRule then
  172. table.insert(self.ruleIds[tonumber(gameId)], tonumber(gameRule))
  173. end
  174. end
  175. end
  176. end
  177. end
  178. end
  179. local gameConfig = getSubGameConfig(smallGameId);
  180. if gameConfig and gameConfig.bSingleGame then
  181. smallGameId = smallGameId * 10000 + self.mGameRule
  182. end
  183. self.curGameId = smallGameId
  184. self.gameRadioManager = nil
  185. self.gameRadioManager = RadioManager:new()
  186. self.ui.Items.Layout_Game:removeAllChildren()
  187. self.gameItems = {}
  188. for k, v in pairsByKeys(self.GameIds) do
  189. local realGameID = tonumber(v)
  190. local realGameRule = tonumber(v)
  191. if tonumber(v) > 10000 then
  192. realGameRule = math.floor(tonumber(v)%10000)
  193. realGameID = math.floor(tonumber(v)/10000)
  194. end
  195. local gameItem = self.ui.Items.CheckBox_Item:getCopied()
  196. gameItem:setVisible(true)
  197. gameItem.Items = getUIItems(gameItem)
  198. if gameItem then
  199. if smallGameId == tonumber(v) then
  200. self.curGameId = tonumber(v)
  201. end
  202. self.ui.Items.Layout_Game:addChild(gameItem)
  203. local nodeSelected = gameItem.Items.Layout_Sel
  204. local nodeUnSelected = gameItem.Items.Layout_UnSel
  205. local gameConfig = getSubGameConfig(realGameID)
  206. if gameConfig and gameConfig.bSingleGame then
  207. --nor
  208. local imgPath = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_%d_nor.png", realGameID,realGameRule);
  209. gameItem.Items.ImageView_8:loadTexture(imgPath, 0);
  210. --sel
  211. imgPath = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_%d_sel.png", realGameID,realGameRule);
  212. gameItem.Items.ImageView_5:loadTexture(imgPath, 0);
  213. else
  214. --nor
  215. local imgPath = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_nor.png", v);
  216. gameItem.Items.ImageView_8:loadTexture(imgPath, 0);
  217. --sel
  218. imgPath = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_sel.png", v);
  219. gameItem.Items.ImageView_5:loadTexture(imgPath, 0);
  220. end
  221. gameItem:setSelectedNode(nodeSelected, nodeUnSelected)
  222. gameItem:setSelectedState(false)
  223. self.gameRadioManager:addItem(gameItem, v)
  224. self.gameItems[v] = gameItem
  225. end
  226. end
  227. --设置默认选项
  228. self.gameRadioManager:setDefault(tonumber(smallGameId))
  229. self.gameRadioManager:setCallback(handler(self, self.onSelecteGame))
  230. --初始化右边
  231. self:initRight(smallGameId)
  232. end
  233. function CoinView:initRight(gameId)
  234. self.ruleRadioManager = nil
  235. self.ruleRadioManager = RadioManager:new()
  236. self.ui.Items.Layout_GameRule:removeAllChildren()
  237. self.ruleItems = {}
  238. local smallRuleId = self.mGameRule or -1
  239. if self.ruleIds[gameId] then
  240. for k, ruleID in pairsByKeys(self.ruleIds[gameId]) do
  241. local ruleItem = self.ui.Items.CheckBox_Rule:getCopied()
  242. ruleItem:setVisible(true)
  243. ruleItem.Items = getUIItems(ruleItem)
  244. if ruleItem then
  245. self.ui.Items.Layout_GameRule:addChild(ruleItem)
  246. local nodeSelected = ruleItem.Items.Layout_Rule_Sel
  247. local nodeUnSelected = ruleItem.Items.Layout_Rule_UnSel
  248. local id = tonumber(gameId)
  249. if id > 10000 then
  250. id = math.floor(id /10000)
  251. end
  252. --nor
  253. local norImgName = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_%d_nor.png", id, tonumber(ruleID))
  254. ruleItem.Items.ImageView_12:loadTexture(norImgName, 0)
  255. --sel
  256. local selImgName = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_%d_sel.png", id, ruleID)
  257. ruleItem.Items.ImageView_11:loadTexture(selImgName, 0)
  258. ruleItem:setSelectedNode(nodeSelected, nodeUnSelected)
  259. ruleItem:setSelectedState(false)
  260. self.ruleRadioManager:addItem(ruleItem, tonumber(ruleID))
  261. self.ruleItems[tonumber(ruleID)] = ruleItem
  262. if smallRuleId == -1 then
  263. smallRuleId = tonumber(ruleID)
  264. end
  265. end
  266. end
  267. end
  268. self.curGameRule = -1
  269. self.ruleRadioManager:setCallback(handler(self, self.onSelecteRule))
  270. --设置默认选项
  271. self.ruleRadioManager:setDefault(tonumber(self.ruleIds[gameId][smallRuleId]))
  272. self.ui.Items.CheckBox_Item:setVisible(false)
  273. self.ui.Items.CheckBox_Rule:setVisible(false)
  274. self.ui.Items.Layout_Game:requestDoLayout()
  275. self.ui.Items.Layout_Game:doLayout()
  276. end
  277. function CoinView:onSelecteGame(gameId)
  278. --点击的是当前已选中的,不做处理
  279. if gameId == self.curGameId then
  280. return
  281. end
  282. self.curGameId = nil
  283. if self.curGameId and self.gameItems[self.curGameId] then
  284. self.gameItems[self.curGameId]:setSelectedState(false)
  285. end
  286. self.curGameId = gameId
  287. --初始化右边
  288. self:initRight(self.curGameId)
  289. if self.curGameId and self.gameItems[self.curGameId] then
  290. self.gameItems[self.curGameId]:setSelectedState(true)
  291. end
  292. end
  293. function CoinView:onSelecteRule(ruleId)
  294. --点击的是当前已选中的,不做处理
  295. if self.curGameRule == ruleId then
  296. return
  297. end
  298. if self.firstEnter then
  299. self.firstEnter = false
  300. else
  301. playBtnTagEffect()
  302. end
  303. --rule永远是真实的rule,gameID是有可能存在大于10000的gameID
  304. self:onSelecteGameRule(self.curGameId, ruleId)
  305. end
  306. function CoinView:onSelecteGameRule(gameId, gameRule)
  307. if gameId > 10000 then
  308. gameId = math.floor(gameId/10000)
  309. end
  310. self.curGameId = gameId
  311. self.curGameRule = gameRule
  312. self.ui.Items.ScrollView_CoinGame:removeAllChildren()
  313. local index = 0
  314. local ruleList = CoinData.getInstance():getGameData().ruleList or {};
  315. if ruleList[tonumber(gameId)] then
  316. for rulelevel, v in pairsByKeys(ruleList[tonumber(gameId)]) do
  317. local rankType = self.ui.Items.Layout_Item:getCopied()
  318. rankType.Items = getUIItems(rankType)
  319. --先隐藏该图标
  320. rankType.Items.ImageView_9:setVisible(false)
  321. local first = string.sub(rulelevel, 0, 1)
  322. local second = string.sub(rulelevel, -1)
  323. first = tonumber(first)
  324. second = tonumber(second)
  325. if second == tonumber(gameRule) then
  326. --修改场次背景图,level表示每个场次,例:10-初级场 20-中级场
  327. local levelImg = string.format("res/ui/zy_coin/dating/jinbichang_btn_level_%d0.png", first)
  328. rankType.Items.ImageView_Level:loadTexture(levelImg, 0)
  329. --礼券
  330. local liquanNum = ""
  331. if v.extra_info and v.extra_info.desc then
  332. liquanNum = v.extra_info.desc
  333. end
  334. rankType.Items.Text_liquan:setText(liquanNum)
  335. --礼券tip动画
  336. if not tolua.isnull(self.imgAction) then
  337. app.mainScene:stopAction(self.imgAction)
  338. end
  339. self.imgAction = nil
  340. local function fontAction(idx)
  341. local seq =
  342. cc.Sequence:create(
  343. cc.ScaleTo:create(0.16, 0.8),
  344. cc.ScaleTo:create(0.16, 1),
  345. cc.ScaleTo:create(0.16, 0.8),
  346. cc.ScaleTo:create(0.16, 1),
  347. cc.ScaleTo:create(0.16, 0.8),
  348. cc.ScaleTo:create(0.16, 1),
  349. cc.DelayTime:create(0.4 + idx),
  350. cc.CallFunc:create(
  351. function()
  352. idx = idx + 1
  353. if idx == 3 then
  354. idx = 0
  355. end
  356. local img = self.ui.Items.ScrollView_CoinGame:getChildByTag(idx)
  357. if img then
  358. img.Items.ImageView_9:runAction(fontAction(idx))
  359. end
  360. end
  361. )
  362. )
  363. self.imgAction = nil
  364. return seq
  365. end
  366. self.imgAction = rankType.Items.ImageView_9:runAction(fontAction(index))
  367. --底分
  368. rankType.Items.Text_Fen:setText(tostring(v.base_chip))
  369. --入场人数
  370. rankType.Items.Text_Ren:setText(tostring(v.cnt))
  371. --最低消费(金币达到此数才允许进入此场)
  372. rankType.Items.Text_Jinbi:setText(tostring(v.min_money) .. "准入")
  373. rankType.Items.ImageView_Level:registerClick(
  374. function()
  375. playBtnEffect()
  376. if
  377. not app.subGameManager:isInstaller(tonumber(self.curGameId)) or
  378. app.subGameManager:isNeedUpdate(tonumber(self.curGameId))
  379. then
  380. requestDownloadSubGame(
  381. tonumber(self.curGameId),
  382. function()
  383. showTooltip("下载完成")
  384. end,
  385. true
  386. )
  387. else
  388. CoinGameLogic.requestEnterCoinGame(self.curGameId, self.curGameRule, rulelevel, v.min_money)
  389. end
  390. end
  391. )
  392. rankType:setTag(index)
  393. index = index + 1
  394. self.ui.Items.ScrollView_CoinGame:addChild(rankType)
  395. end
  396. end
  397. end
  398. self.ui.Items.Layout_Game:requestDoLayout()
  399. self.ui.Items.Layout_Game:doLayout()
  400. local width = self.ui.Items.Layout_Item:getContentSize().width
  401. local height = self.ui.Items.Layout_Item:getContentSize().height
  402. self.ui.Items.ScrollView_CoinGame:setInnerContainerSize(cc.size(width * index, height))
  403. self.ui.Items.ScrollView_CoinGame:requestDoLayout()
  404. self.ui.Items.ScrollView_CoinGame:doLayout()
  405. end
  406. function CoinView:onClickClose()
  407. playBtnCloseEffect()
  408. self:removeFromParent()
  409. end
  410. function CoinView:onClickStart()
  411. playBtnEffect()
  412. if
  413. not app.subGameManager:isInstaller(tonumber(self.curGameId)) or
  414. app.subGameManager:isNeedUpdate(tonumber(self.curGameId))
  415. then
  416. requestDownloadSubGame(
  417. tonumber(self.curGameId),
  418. function()
  419. showTooltip("下载完成")
  420. end,
  421. true
  422. )
  423. else
  424. CoinGameLogic.requestEnterCoinGame(self.curGameId, self.curGameRule)
  425. end
  426. end
  427. function CoinView:onClickFuLi()
  428. playBtnEffect()
  429. showTooltip("即将上线,敬请期待!")
  430. end
  431. function CoinView:onClickAdd(goodType)
  432. playBtnEffect()
  433. local view = import("luaScript.Views.Main.RechargeView"):new(goodType)
  434. view:setAnchorPoint(cc.p(0.5, 0.5))
  435. app:showWaitDialog(view)
  436. end
  437. --礼券说明
  438. function CoinView:onClickLiquan()
  439. playBtnEffect()
  440. self.ui.Items.Layout_liquan_shuoming:setVisible(not self.ui.Items.Layout_liquan_shuoming:isVisible())
  441. end
  442. --- CoinView:onEnterCoinGameResponse 进入金币场回复
  443. -- @param data = {
  444. -- response = {
  445. -- ret = 0
  446. -- }
  447. -- }
  448. function CoinView:onEnterCoinGameResponse (data)
  449. CoinGameLogic.onEnterCoinGameResponse(data);
  450. end
  451. function CoinView:onClickFreeCoin()
  452. playBtnEffect()
  453. if app.config.ModuleConfig.IsSupportCoinFreeCoin then
  454. app.msgManager:removeMsg("gold",ACTIVITY_REDPOINT.COIN_GAME_FREE_GOLD)
  455. self.ui.Items.ImageView_FreeCoin_Tip:setVisible(false)
  456. local view = import("luaScript.Views.Coin.Views.CoinFreeCoin"):new()
  457. view:setAnchorPoint(cc.p(0.5, 0.5))
  458. app:showWaitDialog(view)
  459. else
  460. showTooltip("开发中")
  461. end
  462. end
  463. function CoinView:onActivityRedPoint(event)
  464. local response = app.php.activityRedPoint
  465. if not response then
  466. return;
  467. end
  468. response = response.gold
  469. local ret1 = response[ACTIVITY_REDPOINT.COIN_GAME_FULI] == 1
  470. local ret2 = response[ACTIVITY_REDPOINT.COIN_GAME_FREE_GOLD] == 1
  471. self.ui.Items.ImageView_FuLi_Tip:setVisible(ret1)
  472. self.ui.Items.ImageView_FreeCoin_Tip:setVisible(ret2)
  473. end
  474. return CoinView