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.

210 lines
5.8 KiB

  1. -- 房间设置界面
  2. local RoomDaJuView = class("RoomDaJuView_53", cc.UIView)
  3. local Functions = require("pk_nanchongdoudizhu.luaScript.Functions_53")
  4. function RoomDaJuView:ctor(response)
  5. RoomDaJuView.super.ctor(self)
  6. self.response = response
  7. end
  8. function RoomDaJuView:onEnter()
  9. RoomDaJuView.super.onEnter(self)
  10. local ui = loadUI("pk_nanchongdoudizhu/res/ui/ui_fangjian/doudizhu_ui_daJu.ui")
  11. self:addChild(ui)
  12. self.ui = ui
  13. -- 分享战绩
  14. self.ui.Items.Button_Share:registerClick(handler(self , self.onClickShare))
  15. -- 结束游戏
  16. self.ui.Items.Button_Over:registerClick(handler(self , self.onClickOver))
  17. if isReviewVersion() then
  18. self.ui.Items.Button_Share:setVisible(false)
  19. end
  20. end
  21. function RoomDaJuView:updateView(data)
  22. --显示
  23. self:setVisible(true)
  24. --更新房间号
  25. self.ui.Items.Text_RoomId:setText("房号: " .. app.room.roomInfo.nShowTableId)
  26. --更新局数
  27. self.ui.Items.Text_JuShu:setText(string.format("%02d / %02d 局", app.room.roomInfo.nGameStartCount, app.room.roomInfo.nTotalGameNum))
  28. --更新时间
  29. self.ui.Items.Text_SystemTime:setText(getTimeString())
  30. --规则
  31. self.ui.Items.Text_GameRules:setText(Functions.getRuleStr())
  32. --更新玩家信息
  33. self:updatePlayer(data)
  34. end
  35. function RoomDaJuView:updatePlayer(data)
  36. --隐藏所有玩家
  37. for i = 1, 4 do
  38. local player = self.ui.Items["Layout_Player_" .. i]
  39. if player then
  40. player:setVisible(false)
  41. end
  42. end
  43. local maxScore = 0
  44. for _,v in pairs(data.memberList) do
  45. v.nTotalScore = tonumber(v.nTotalScore)
  46. if v.nTotalScore > maxScore then
  47. maxScore = v.nTotalScore
  48. end
  49. end
  50. --更新玩家数据
  51. for k,v in pairs(data.memberList) do
  52. local viewId = app.room:getViewIdByUserId(v.nUserId)
  53. local player = self.ui.Items["Layout_Player_" .. viewId]
  54. local userInfo = json.decode(v.userInfo)
  55. if player then
  56. v.nTotalScore = tonumber(v.nTotalScore)
  57. --显示玩家信息
  58. player:setVisible(true)
  59. --更新头像
  60. local head = self.ui.Items["Image_Head_" .. viewId]
  61. if head then
  62. setPlayerHeadImage(v.nUserId, userInfo.headimgurl, head)
  63. end
  64. --名字
  65. local name = self.ui.Items["Text_Name_" .. viewId]
  66. if name then
  67. name:setText("" .. userInfo.nickname)
  68. end
  69. --玩家id
  70. local userId = self.ui.Items["Text_UserId_" .. viewId]
  71. if userId then
  72. userId:setText("" .. v.nUserId)
  73. --显示隐藏游戏内选手id(主办人和管理员不限制,只针对海选赛) -- todo lwq
  74. -- begin
  75. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  76. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  77. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  78. --隐私数据
  79. local clubInfo = app.club_php.clubList[app.club_php.clubID]
  80. self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
  81. if not self.cliext or not self.cliext.is_hideUid or (self.cliext and self.cliext.is_hideUid == 1) then
  82. if clubInfo.role == ClubDefine.Job.Creator or clubInfo.role == ClubDefine.Job.Manager then
  83. userId:setVisible(true)
  84. else
  85. userId:setVisible(false)
  86. end
  87. end
  88. end
  89. end
  90. if v.nUserId == tonumber(app.user.loginInfo.uid) then
  91. userId:setVisible(true)
  92. end
  93. -- end
  94. end
  95. --分数
  96. local score = self.ui.Items["Text_Score_" .. viewId]
  97. if score then
  98. if v.nTotalScore > 0 then
  99. score:setText("+" .. v.nTotalScore)
  100. else
  101. score:setText("" .. v.nTotalScore)
  102. end
  103. end
  104. --更新背景
  105. local bg = self.ui.Items["Image_Bg_" .. viewId]
  106. if bg then
  107. if v.nTotalScore >= 0 then
  108. bg:loadTexture("pk_nanchongdoudizhu/res/ui/zy_fangjian/doudizhu_daju/doudizhu_daju_winbg.png")
  109. else
  110. bg:loadTexture("pk_nanchongdoudizhu/res/ui/zy_fangjian/doudizhu_daju/doudizhu_daju_losebg.png")
  111. end
  112. end
  113. --大赢家
  114. local banker = self.ui.Items["Image_MaxWin_" .. viewId]
  115. if banker then
  116. banker:setVisible(maxScore > 0 and maxScore <= v.nTotalScore)
  117. end
  118. end
  119. end
  120. self.ui.Items.Layout_Players:requestDoLayout()
  121. self.ui.Items.Layout_Players:doLayout()
  122. end
  123. -- 分享
  124. function RoomDaJuView:onClickShare()
  125. playBtnEffect()
  126. function callbackEx(ret, fileName)
  127. if tonumber(ret) == 1 then
  128. local info = {}
  129. info.contentType = "image"
  130. info.image = fileName
  131. info.imageWidth = 800
  132. local gamerule = nil
  133. local roomInfo = app.room.roomInfo
  134. if roomInfo.strGameInfo then
  135. local jsonInfo = json.decode(roomInfo.strGameInfo)
  136. if jsonInfo then
  137. gamerule = jsonInfo.gamerule
  138. end
  139. end
  140. local rulename = ""
  141. if gamerule then
  142. rulename = " - " .. getSubGameRuleName(app.gameId, gamerule)
  143. end
  144. local gameName = getSubGameName(app.gameId) .. rulename
  145. info.copyData = {
  146. type = 1,
  147. gameName = gameName or "",
  148. tableId = app.room.roomInfo.nShowTableId,
  149. userInfos = {},
  150. }
  151. info.isShareZhanjiUrl = true
  152. for nUserId,totalData in pairsByKeys(self.response) do
  153. local userInfo = app.room:getUserInfo(nUserId)
  154. --昵称
  155. local nickname = userInfo.nickname or ""
  156. local totalScore = totalData.nTotalScore
  157. table.insert(info.copyData.userInfos, { nickname = nickname, totalScore = totalScore })
  158. end
  159. local view = import("luaScript.Views.Main.ShareView"):new(info)
  160. view:setAnchorPoint(cc.p(0.5, 0.5))
  161. app:showWaitDialog(view)
  162. else
  163. showTooltip("截图保存失败")
  164. end
  165. end
  166. if isWin32Platform() then
  167. callbackEx(1, "testName")
  168. else
  169. local fileNameEx = cc.FileUtils:getInstance():getWritablePath() .. tostring(app.room.roomInfo.nShowTableId) .. "_screen.jpg"
  170. cc.FileUtils:getInstance():screenToFile(fileNameEx, function(retEx)
  171. callbackEx(retEx, fileNameEx)
  172. end)
  173. end
  174. end
  175. -- 确认
  176. function RoomDaJuView:onClickOver()
  177. playBtnEffect()
  178. app.room:dispatchEvent({name = "onGameOverResponse"})
  179. self:removeFromParent()
  180. app:gotoView(import("luaScript.Views.Main.MainView"):new(app.gameId, app.room.roomInfo.nShowTableId))
  181. end
  182. return RoomDaJuView