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.

317 lines
11 KiB

  1. local Functions = require("pk_zgwrddz.luaScript.zgwrDdzFunctions")
  2. local DdzGameOverView = class("DdzGameOverView", cc.UIView)
  3. local GameOverItem = require("pk_zgwrddz.luaScript.Views.Room.Node.zgwrDdzGameOverItem")
  4. function DdzGameOverView:ctor( overData )
  5. self._data = overData
  6. local ui = loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_daju.ui")
  7. self.ui = ui
  8. self:addChild(ui)
  9. self:initUi()
  10. self:setPlayerInfo()
  11. -- 初始化再来一轮
  12. self:initPlayGameAgain()
  13. end
  14. function DdzGameOverView:initUi()
  15. local roomInfo = app.room:getRoomInfo()
  16. self.ui.Items.Button_Share:registerClick(handler(self , self.onBtnShareClicked))
  17. self.ui.Items.Button_Over:registerClick(handler(self , self.onBtnGameOverClicked))
  18. self.ui.Items.Button_PreventShare:registerClick(handler(self , self.onBtnPreventShareClicked))
  19. local newRule = "" .."五人斗地主"
  20. newRule = newRule.." 房间号:"..tostring(self._data.nShowTableId)
  21. local curCount = roomInfo.nGameStartCount or 0
  22. local str = string.format("%02d/%02d局", curCount, roomInfo.nTotalGameNum)
  23. newRule = newRule.." "..str
  24. self.ui.Items.txtRoomRule:setString(newRule)--(string.format("%s", self._data.roomRule or ""))
  25. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  26. self.ui.Items.txtRoundNum:setText("茶馆ID:"..app.club_php.clubID)
  27. else
  28. self.ui.Items.txtRoundNum:setText("")
  29. end
  30. self.ui.Items.txtRoomID:setText(os.date("%Y-%m-%d %X",self._data.endTime))
  31. local gameConfig = getSubGameConfig(app.gameId) or {};
  32. if gameConfig.gameDataConfig and gameConfig.gameDataConfig.isClosePlayAgain == true then
  33. self.ui.Items.Layout_Button_PlayAgain:setVisible(false)
  34. end
  35. if not app.config.ModuleConfig.IsSupportZhanJiUrl then
  36. self.ui.Items.Layout_PreventShare:setVisible(false);
  37. end
  38. if isReviewVersion() then
  39. self.ui.Items.Layout_Share:setVisible(false)
  40. self.ui.Items.Layout_PreventShare:setVisible(false)
  41. end
  42. self.ui.Items.Layout_Buttons:requestDoLayout()
  43. self.ui.Items.Layout_Buttons:doLayout()
  44. end
  45. function DdzGameOverView:setPlayerInfo()
  46. local maxUserId = self._data.players[1].userId
  47. local maxScore = tonumber(self._data.players[1].totalScore)
  48. for i,v in ipairs(self._data.players) do
  49. v.totalScore = tonumber(v.totalScore)
  50. if v.totalScore > maxScore then
  51. maxUserId = v.userId
  52. maxScore = v.totalScore
  53. end
  54. end
  55. local roomInfo = app.room:getRoomInfo()
  56. for i,v in ipairs(self._data.players) do
  57. v.isBigWin = v.totalScore == maxScore--v.userId == maxUserId
  58. v.isHost = v.userId == roomInfo.nRoomOwnedUid
  59. local item = self:createItem(v)
  60. self.ui.Items.Layout_items:addChild(item)
  61. end
  62. end
  63. function DdzGameOverView:onBtnShareClicked( sender )
  64. playBtnEffect()
  65. local fileName = cc.FileUtils:getInstance():getWritablePath()..tostring(self._data.nShowTableId).."_screen.jpg"
  66. cc.FileUtils:getInstance():screenToFile(fileName, function(ret)
  67. if 1 == tonumber(ret) then
  68. local info = {}
  69. info.scene = "talk"
  70. info.contentType = "image"
  71. info.image = fileName
  72. info.isShareZhanjiUrl = true
  73. info.imageWidth = 800
  74. info.thumbWidth = 100
  75. --app.plugin:shareGame(info)
  76. info.copyData={
  77. type=1,
  78. tableId=self._data.nShowTableId,
  79. userInfos={},
  80. gameId=GAME_IDS.zgWuRenDouDiZhu,
  81. }
  82. for nUserId,totalData in pairsByKeys(self._data.players) do
  83. local userInfo = app.room:getUserInfo(totalData.userId)
  84. --昵称
  85. local nickname = getShortName2(totalData.nickname) or ""
  86. local totalScore = totalData.totalScore
  87. table.insert(info.copyData.userInfos,{nickname=nickname,totalScore=totalScore})
  88. end
  89. local view = import("luaScript.Views.Main.ShareView"):new(info,nil,{endtime=self._data.endTime})
  90. view:setAnchorPoint(cc.p(0.5, 0.5))
  91. app:showWaitDialog(view)
  92. else
  93. showTooltip("截图保存失败")
  94. end
  95. end )
  96. end
  97. function DdzGameOverView:onBtnGameOverClicked( sender )
  98. playBtnEffect()
  99. app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.zgWuRenDouDiZhu))
  100. end
  101. function DdzGameOverView:onBtnPreventShareClicked()
  102. app.waitDialogManager:showWaitNetworkDialog("获取分享链接")
  103. local onGetUrlCallback = function(url)
  104. app.waitDialogManager:closeWaitNetworkDialog()
  105. if url then
  106. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  107. local gameName = getSubGameName(GAME_IDS.zgWuRenDouDiZhu) or "川南棋牌"
  108. local info = {}
  109. -- info.contentType = "image"
  110. info.image = fileName
  111. info.title = gameName.."战绩"
  112. -- info.imageWidth = 800
  113. info.menuIdxs = {1, 4, 5, 6}
  114. info.FFQFlag = true
  115. -- info.isShareZhanjiUrl = false
  116. info.copyData={
  117. type=1,
  118. tableId=self._data.nShowTableId,
  119. userInfos={},
  120. gameId=GAME_IDS.zgWuRenDouDiZhu,
  121. }
  122. local content = nil;
  123. local memberList = app.room.roomInfo.memberList--self._overData.nTotalPlayerInfos
  124. for k,v in pairs(self._data.players) do
  125. local userInfo = app.room:getUserInfo(v.userId)
  126. --昵称
  127. local nickname = v.nickname or ""
  128. local totalScore = tonumber(v.totalScore)
  129. table.insert(info.copyData.userInfos,{nickname=getShortName2(nickname),totalScore=totalScore})
  130. local strUserInfo = ""
  131. if totalScore > 0 then
  132. strUserInfo = string.format("%s(+%s)", getShortName2(nickname), totalScore)
  133. else
  134. strUserInfo = string.format("%s(%s)", getShortName2(nickname), totalScore)
  135. end
  136. if content then
  137. content = content .. "," .. strUserInfo
  138. else
  139. content = strUserInfo
  140. end
  141. end
  142. local sharUrl = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
  143. url,
  144. app.user.loginInfo.uid,
  145. GAME_IDS.zgWuRenDouDiZhu,
  146. getAppId(),
  147. self._data.nShowTableId,
  148. self._data.endTime or os.time())
  149. info.url = sharUrl
  150. info.description = content
  151. dump(info)
  152. local view = import("luaScript.Views.Main.ShareView"):new(info)
  153. view:setAnchorPoint(cc.p(0.5, 0.5))
  154. app:showWaitDialog(view)
  155. else
  156. showTooltip("获取分享用的链接失败")
  157. end
  158. end
  159. app.php:initShareZhanJiToUrl(onGetUrlCallback)
  160. end
  161. function DdzGameOverView:onEnter()
  162. DdzGameOverView.super.onEnter()
  163. setShowCountAll(true)
  164. stopBGMusic()
  165. end
  166. function DdzGameOverView:onExit()
  167. DdzGameOverView.super.onExit(self)
  168. setShowCountAll(false)
  169. end
  170. function DdzGameOverView:createItem( info )
  171. info.totalScore = tonumber(info.totalScore)
  172. local node = loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_dajuitem.ui")
  173. setPlayerHeadImage(info.userId, info.headimgurl, node.Items.imgHead)
  174. node.Items.txtNick:setString(getSubStringNickname(info.nickname or ""))
  175. node.Items.txtID:setString("ID:"..info.userId)
  176. --显示隐藏游戏内选手id(主办人和管理员不限制,只针对海选赛) -- todo lwq
  177. -- begin
  178. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  179. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  180. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  181. --隐私数据
  182. local clubInfo = app.club_php.clubList[app.club_php.clubID]
  183. self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
  184. if not self.cliext or not self.cliext.is_hideUid or (self.cliext and self.cliext.is_hideUid == 1) then
  185. if clubInfo.role == ClubDefine.Job.Creator or clubInfo.role == ClubDefine.Job.Manager then
  186. node.Items.txtID:setVisible(true)
  187. else
  188. node.Items.txtID:setVisible(false)
  189. end
  190. end
  191. end
  192. end
  193. if info.userId == tonumber(app.user.loginInfo.uid) then
  194. node.Items.txtID:setVisible(true)
  195. end
  196. -- end
  197. node.Items.imgBest:setVisible(info.isBigWin and info.totalScore>0)
  198. node.Items.imgHost:setVisible(info.isHost)
  199. node.Items.imgHost:setVisible(false)--隐藏房主标签
  200. --"extString" = "{"bombTimes":0,"loseTimes":0,"maxScore":3,"winTimes":2}"
  201. local extData = json.decode(info.extString)
  202. --[[node.Items.txtDjzgfs_1:setString(""..extData.maxScore)
  203. node.Items.txtDczds_1:setString(""..extData.bombTimes)
  204. node.Items.txtSyjs_1:setString(string.format("%d/%d", extData.loseTimes , extData.winTimes))--]]
  205. --local countInfo = json.decode(info.countInfo)
  206. --node.Items.txtDiamond:setText("-"..countInfo.DeInfo)
  207. node.Items.txt_ypcs_num:setText(""..extData.wintimes)
  208. node.Items.txt_dzcs_num:setText(""..extData.lordtimes)
  209. node.Items.txt_zcls_num:setText(""..extData.maxwintimes)
  210. if info.totalScore > 0 then
  211. node.Items.txtTotalScore:setString("+"..info.totalScore)
  212. node.Items.ImageView_light:setVisible(info.isBigWin)
  213. else
  214. node.Items.txtTotalScore:setFntFile("res/fonts/dt_jian_num.fnt")
  215. node.Items.txtTotalScore:setString(""..info.totalScore)
  216. node.Items.ImageView_light:setVisible(false)
  217. end
  218. if self._data.stopFlag == 9 or self._data.stopFlag == 8 then--解散游戏
  219. local jiesaninfo = {
  220. [0] = "超时解散",
  221. [1] = "申请解散",
  222. [2] = "同意解散",
  223. [3] = "拒绝",
  224. [4] = "系统解散",
  225. }
  226. if extData.jiesan and extData.jiesan >= 0 then
  227. node.Items.txt_jiesanInfo:setText(jiesaninfo[extData.jiesan])
  228. end
  229. else
  230. node.Items.txt_jiesanInfo:setVisible(false)
  231. end
  232. return node
  233. end
  234. function DdzGameOverView:test()
  235. local data = {{}, {}, {}}
  236. local dltWidth = 1273/#data
  237. for i,v in ipairs(data) do
  238. local item = GameOverItem:new(v)
  239. if i==1 then
  240. item:setPosition(cc.p((i-1)*dltWidth+dltWidth/2, 225))
  241. elseif i==3 then
  242. else
  243. item:setPosition(cc.p((i-1)*dltWidth+dltWidth/2, 225))
  244. end
  245. self.ui.Items.Layout_items:addChild(item)
  246. end
  247. end
  248. ---
  249. -- 初始化大结算再来一局
  250. -- @return
  251. --
  252. function DdzGameOverView:initPlayGameAgain ()
  253. local roomInfo = app.room.roomInfo or {};
  254. local gameId = roomInfo.gameId or app.gameId
  255. if dd.IClub.isInClub() and roomInfo.nShowTableId then
  256. local inviteList = {}
  257. for k,v in pairsByKeys(roomInfo.memberList) do
  258. if tonumber(v.nUserId) ~= app.user.loginInfo.uid then
  259. table.insert(inviteList, v.nUserId)
  260. end
  261. end
  262. local strInvite = Functions.getRuleStrByClubInvite()
  263. local btnPlayAgain = self.ui.Items.Button_PlayAgain
  264. dd.IPlayGameAgain.bindPlayAgainButton(btnPlayAgain, gameId, strInvite, inviteList, function ()
  265. -- 初始化成功后干嘛干嘛
  266. local visible = btnPlayAgain:isVisible()
  267. self.ui.Items.Layout_Button_PlayAgain:setVisible(visible)
  268. if self.ui.Items.Layout_Buttons then
  269. self.ui.Items.Layout_Buttons:requestDoLayout()
  270. self.ui.Items.Layout_Buttons:doLayout()
  271. end
  272. end)
  273. --绑定消息通知回调
  274. self:bindEvent(app.club_php , GAME_EVENT.CLUB_INVITE , handler(self , self.onClubInviteEvent))
  275. else
  276. logD("DdzGameOverView:initPlayGameAgain", "不在亲友圈或桌子id为空,不能进行再来一局操作")
  277. self.ui.Items.Layout_Button_PlayAgain:setVisible(false)
  278. self.ui.Items.Layout_Buttons:requestDoLayout()
  279. self.ui.Items.Layout_Buttons:doLayout()
  280. end
  281. end
  282. ---
  283. -- 监听亲友圈邀请信息
  284. -- @param event
  285. -- @return
  286. --
  287. function DdzGameOverView:onClubInviteEvent(event)
  288. dd.IPlayGameAgain.showClubInviteDialog(event, nil, nil)
  289. end
  290. return DdzGameOverView