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.

245 lines
7.1 KiB

  1. local MatchDefined = require("luaScript.Views.Match.Constant.MatchDefined")
  2. local MatchEvents = require("luaScript.Views.Match.Constant.MatchEvents")
  3. -- 主界面
  4. local MatchMainView = class("MatchMainView", cc.UIView)
  5. function MatchMainView:ctor()
  6. MatchMainView.super.ctor(self)
  7. self.MatchRoomWaitView = "zp_hsb.luaScript.Views.Match.yxhsbMatchRoomWaitView"
  8. end
  9. function MatchMainView:onEnter()
  10. MatchMainView.super.onEnter(self)
  11. -- setShowCountAll(true)
  12. local ui = loadUI("res/ui/ui_match/ui_match_hall.ui")
  13. self.ui = ui
  14. self:addChild(ui)
  15. --初始列表
  16. -- self.ui.Items.List_Match:setItemModel(self.ui.Items.Item_Match)
  17. -- self.ui.Items.List_Match:removeAllChildren()
  18. self.ui.Items.List_Match:getVBar():setVisible(false)
  19. self.ui.Items.List_Tag:setItemModel(self.ui.Items.Item_Tag)
  20. self.ui.Items.List_Tag:removeAllChildren()
  21. self.ui.Items.List_Tag:getVBar():setVisible(false)
  22. self.ui.Items.List_Tag:pushBackDefaultItem()
  23. self.ui.Items.Button_Back:registerClick(function()
  24. playBtnCloseEffect()
  25. self:removeFromParent()
  26. end)
  27. -- self.ui.Items.Button_Rule:registerClick(function()
  28. -- playBtnEffect()
  29. -- -- local view = import("Views.Match.MatchRule"):new()
  30. -- -- view:setAnchorPoint(cc.p(0.5, 0.5))
  31. -- -- app:showWaitDialog(view)
  32. -- -- app:gotoView(view)
  33. -- end)
  34. -- self.ui.Items.Button_RenZheng:registerClick(function()
  35. -- playBtnEffect()
  36. -- local view = import("Views.Main.MainShiMingRenZheng"):new()
  37. -- view:setAnchorPoint(cc.p(0.5, 0.5))
  38. -- app:showWaitDialog(view)
  39. -- end)
  40. -- self.ui.Items.Button_RenZheng:setVisible(false)
  41. -- self.ui.Items.Button_Rule:setVisible(false)
  42. --比赛场
  43. -- self.ui.Items.Button_Match:setVisible(false)
  44. self.ui.Items.Button_Match:registerClick(handler(self , self.onClickMatch))
  45. -- 玩家信息
  46. self:initPlayerInfo()
  47. app.match:getListRequest();
  48. self:bindAllEvent();
  49. end
  50. -- function MatchMainView:onExit()
  51. -- MatchMainView.super.onExit(self)
  52. -- setShowCountAll(false)
  53. -- end
  54. function MatchMainView:bindAllEvent()
  55. self:bindEvent(app.match , MatchEvents.GET_LIST , handler(self , self.onGetListResponse));
  56. self:bindEvent(app.match , MatchEvents.SIGN_UP_SUCCESS , handler(self , self.onSignUpSuccessResponse));
  57. end
  58. function MatchMainView:initPlayerInfo()
  59. log("app.user.userInfo = ", app.user.userInfo)
  60. local userInfo = json.decode(app.user.userInfo);
  61. local id = tonumber(app.user.loginInfo.uid) or 0
  62. self.ui.Items.Text_ID:setText(string.format("ID:%06d", id))
  63. local nickname = getSubStringNickname(userInfo.nickname,self.ui.Items.Text_MingZi)
  64. self.ui.Items.Text_MingZi:setText(nickname or tostring("未知昵称"))
  65. -- 房卡数量
  66. self.ui.Items.diamondNum:bind(app.user.loginInfo, "curCardNum", function()
  67. self.ui.Items.diamondNum:setString(tostring(app.user.loginInfo.curCardNum))
  68. end )
  69. local nodeHead = self.ui.Items.Image_TouXiang;
  70. local head = {}
  71. head.width = nodeHead:getContentSize().width
  72. head.height = nodeHead:getContentSize().height
  73. setPlayerHeadImage(app.user.loginInfo.uid, userInfo.headimgurl, nodeHead)
  74. end
  75. function MatchMainView:onGetListResponse()
  76. self.ui.Items.List_Match:removeAllChildren()
  77. local matchList = app.match.matchInfo.matchList or {}
  78. local function checkHasCash(configInfo)
  79. local hasCash = false;
  80. if configInfo and configInfo.rewardInfo then
  81. local data = json.decode(configInfo.rewardInfo)
  82. if data and data.rewards then
  83. for k,v in pairs(data.rewards) do
  84. for kk,vv in pairs(v) do
  85. if vv.type == 100 then
  86. hasCash = true
  87. end
  88. end
  89. end
  90. end
  91. end
  92. return hasCash;
  93. end
  94. logD("matchList:",table.tostring(matchList))
  95. for k,v in pairs(matchList) do
  96. local hasCash = checkHasCash(v);
  97. if not isIOSReviewVersion() or not hasCash then
  98. local item=loadUI("res/ui/ui_match/ui_match_item.ui")
  99. self.ui.Items.List_Match:pushBackCustomItem(item)
  100. item.Items.Text_Title:setString(v.matchName)
  101. item.Items.Text_Info:setString(v.matchDes)
  102. if v.matchType==MatchDefined.MATCH_TYPE.FULL_OPENING then
  103. item.Items.Text_Tip:setString("人满开赛")--setVisible(false)
  104. item.Items.ImageView_Time_Bg:setVisible(false)
  105. item.Items.ImageView_Text:loadTexture("match_main_text_bm.png",cc.TextureResType.plistType)
  106. item.Items.Text_Tip:setPositionY(60)
  107. end
  108. local rewardInfo = json.decode(v.rewardInfo)
  109. for _,rewards in pairs(rewardInfo.rewards) do
  110. for _,reward in pairs(rewards) do
  111. if reward.type==MatchDefined.CURRENCY_TYPE.Money then
  112. item.Items.ImageView_Icon:loadTexture("match_main_img_hong_bao.png",cc.TextureResType.plistType)
  113. break
  114. end
  115. end
  116. end
  117. -- match_main_img_hong_bao
  118. item.Items.Text_Player_Num:setString(v.signUpCnt.."/"..v.maxMatchCnt)
  119. local cost = json.decode(v.signupInfo)
  120. local costStr=""
  121. for n,signInfos in pairs(cost.signInfo) do
  122. for _,info in pairs(signInfos) do
  123. if info.type==13 then
  124. costStr=costStr.."房卡x"..info.value
  125. elseif info.type==1 then
  126. costStr=costStr.."金币x"..info.value
  127. end
  128. end
  129. if n~=#cost.signInfo then
  130. costStr=costStr.." 或 "
  131. end
  132. end
  133. item.Items.Text_Cost:setString(costStr)
  134. item:registerClick(function()
  135. playBtnEffect()
  136. app.match.matchInfo.matchIndex=v.matchIndex
  137. local rewardInfo = json.decode(v.rewardInfo)
  138. app.match.matchInfo.rewards = rewardInfo.rewards
  139. local view = import("luaScript.Views.Match.MatchInfo"):new(v)
  140. view:setAnchorPoint(cc.p(0.5, 0.5))
  141. app:showWaitDialog(view)
  142. end)
  143. item.Items.Button_BaoMing:registerClick(function()
  144. playBtnEffect()
  145. local function btnCallbackOk()
  146. app.match:signUp(v);
  147. -- self:removeParent()
  148. -- runInNextFrame(function()
  149. -- local view = import("Views.Match.MatchRoomWaitView"):new()
  150. -- app:gotoView(view)
  151. -- end)
  152. end
  153. local function btnCallbackCancel()
  154. end
  155. if not app.subGameManager:isInstaller(tonumber(v.gameId)) or app.subGameManager:isNeedUpdate(tonumber(v.gameId)) then
  156. --未下载时提示下载
  157. requestDownloadSubGame(tonumber(v.gameId), function ()
  158. showTooltip("下载完成")
  159. end, true)
  160. return;
  161. end
  162. showConfirmDialog("确定花费["..costStr.."]报名?",btnCallbackOk,btnCallbackCancel)
  163. end)
  164. end
  165. end
  166. end
  167. function MatchMainView:onClickMatch()
  168. playBtnEffect()
  169. -- local view = import("Views.Match.MatchMainView"):new();
  170. -- view:setAnchorPoint(cc.p(0.5, 0.5))
  171. -- app:showWaitDialog(view)
  172. local view = import("luaScript.Views.Match.MatchRecord"):new();
  173. view:setAnchorPoint(cc.p(0.5, 0.5))
  174. app:showWaitDialog(view)
  175. end
  176. function MatchMainView:onSignUpSuccessResponse()
  177. if self.MatchRoomWaitView then
  178. local view = import(self.MatchRoomWaitView):new()
  179. app:gotoView(view)
  180. end
  181. end
  182. -- -- 房间获取结果
  183. -- function MatchMainView:onGetRoomListResponse(data)
  184. -- local response = data.response
  185. -- local roomList = response.roomList
  186. -- local aMax = table.nums(roomList)
  187. -- if table.nums(roomList) > 0 then
  188. -- self:updateRoomList(roomList)
  189. -- elseif table.nums(roomList) == 0 then
  190. -- self.ui.Items.mScrollView:removeAllChildren()
  191. -- self.ui.Items.mScrollView:getInnerContainer():setAutoSize(true)
  192. -- self.ui.Items.mScrollView:jumpToTopOnSizeChanged()
  193. -- end
  194. -- end
  195. return MatchMainView