您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

418 行
14 KiB

  1. local luzhouPdkRoomViewConfig = require("pk_luzhoupdk.luaScript.Views.Room.luzhouPdkRoomViewConfig")
  2. local PdkGameOverView = class("PdkGameOverView", cc.UIView)
  3. local GameOverItem = require("pk_luzhoupdk.luaScript.Views.Room.Node.luzhouPdkGameOverItem")
  4. --[[
  5. "onResponseGameOver" = {
  6. "players" = {
  7. 1 = {
  8. "extString" = "{"bombTimes":0,"loseTimes":2,"maxScore":0,"winTimes":0}"
  9. "totalScore" = -6
  10. "userId" = 1023546
  11. }
  12. 2 = {
  13. "extString" = "{"bombTimes":0,"loseTimes":0,"maxScore":3,"winTimes":2}"
  14. "totalScore" = 6
  15. "userId" = 1023544
  16. }
  17. }
  18. }
  19. ]]
  20. function PdkGameOverView:ctor( overData )
  21. self._data = overData
  22. local ui = loadUI("pk_luzhoupdk/res/ui/ui_room/ui_lzpdk_daju.ui")
  23. self.ui = ui
  24. self:addChild(ui)
  25. self:initUi()
  26. self:setPlayerInfo()
  27. self:initPlayGameAgain()
  28. end
  29. function PdkGameOverView:initUi()
  30. local config = getSubGameConfig(GAME_IDS.luzhouPaoDeKuai or app.gameId)
  31. local roomInfo = app.room:getRoomInfo()
  32. self.ui.Items.btnShare:registerClick(handler(self , self.onClickShare))
  33. self.ui.Items.btnOk:registerClick(handler(self , self.onClickOk))
  34. self.ui.Items.btnFFQShare:registerClick(handler(self , self.onClickFFQShare))
  35. if not app.config.ModuleConfig.IsSupportZhanJiUrl then
  36. self.ui.Items.Layout_5:setVisible(false)
  37. end
  38. --self.ui.Items.btnFFQShare:setVisible(false)
  39. --self.ui.Items.txtRoomID:setString(string.format("房号:%06d", self._data.nShowTableId or 0))
  40. --self.ui.Items.txtRoundNum:setString(string.format("%s", os.date("%m-%d %H:%M", os.time()) ))
  41. if isReviewVersion() then
  42. self.ui.Items.Layout_4:setVisible(false)
  43. self.ui.Items.Layout_5:setVisible(false)
  44. end
  45. local newRule = "" .."泸州跑得快"
  46. newRule = newRule.." 房间号:"..tostring(self._data.nShowTableId)
  47. local curCount = roomInfo.nGameStartCount or 0
  48. local str = string.format("%02d/%02d局", curCount, roomInfo.nTotalGameNum)
  49. newRule = newRule.." "..str
  50. self.ui.Items.txtRoomRule:setString(newRule)--(string.format("%s", self._data.roomRule or ""))
  51. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  52. self.ui.Items.txtRoundNum:setText((app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME).."ID:"..app.club_php.clubID)
  53. else
  54. self.ui.Items.txtRoundNum:setText("")
  55. end
  56. self.ui.Items.txtRoomID:setText(os.date("%Y-%m-%d %X",app.room.roomInfo.endtime))
  57. end
  58. function PdkGameOverView:setPlayerInfo()
  59. local maxUserId = self._data.players[1].userId
  60. local maxScore = self._data.players[1].totalScore
  61. maxScore = tonumber(maxScore)
  62. for i,v in ipairs(self._data.players) do
  63. v.totalScore = tonumber(v.totalScore)
  64. if v.totalScore > maxScore then
  65. maxUserId = v.userId
  66. maxScore = v.totalScore
  67. end
  68. end
  69. local roomInfo = app.room:getRoomInfo()
  70. for i,v in ipairs(self._data.players) do
  71. v.isBigWin = v.userId == maxUserId
  72. v.isHost = v.userId == roomInfo.nRoomOwnedUid
  73. local item = self:createItem(v)
  74. self.ui.Items.Layout_items:addChild(item)
  75. end
  76. end
  77. function PdkGameOverView:onClickShare( sender )
  78. playBtnEffect()
  79. local fileName = cc.FileUtils:getInstance():getWritablePath()..tostring(self._data.nShowTableId).."_screen.jpg"
  80. cc.FileUtils:getInstance():screenToFile(fileName, function(ret)
  81. if 1 == tonumber(ret) then
  82. local info = {}
  83. info.scene = "talk"
  84. info.contentType = "image"
  85. info.image = fileName
  86. info.isShareZhanjiUrl = true
  87. info.imageWidth = 800
  88. info.thumbWidth = 100
  89. --app.plugin:shareGame(info)
  90. info.copyData={
  91. type=1,
  92. tableId=self._data.nShowTableId,
  93. userInfos={},
  94. gameId=35,
  95. }
  96. for nUserId,totalData in pairsByKeys(self._data.players) do
  97. local userInfo = app.room:getUserInfo(totalData.userId)
  98. --昵称
  99. local nickname = getShortName2(totalData.nickname) or ""
  100. local totalScore = totalData.totalScore
  101. table.insert(info.copyData.userInfos,{nickname=nickname,totalScore=totalScore})
  102. end
  103. local view = import("luaScript.Views.Main.ShareView"):new(info,nil,{endtime=self._data.endTime})
  104. view:setAnchorPoint(cc.p(0.5, 0.5))
  105. app:showWaitDialog(view)
  106. else
  107. showTooltip("截图保存失败")
  108. end
  109. end )
  110. end
  111. function PdkGameOverView:onClickOk( sender )
  112. playBtnEffect()
  113. --app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.luzhouPaoDeKuai))
  114. gotoMainView(GAME_IDS.luzhouPaoDeKuai)
  115. end
  116. function PdkGameOverView:onClickFFQShare()
  117. --[[local info = {}
  118. info.scene = "talk"
  119. info.contentType = "image"
  120. info.image = fileName
  121. info.isShareZhanjiUrl = true
  122. info.imageWidth = 1000
  123. info.thumbWidth = 100
  124. info.copyData={
  125. type=1,
  126. tableId=self._data.nShowTableId,
  127. userInfos={},
  128. gameId=35,
  129. }
  130. for nUserId,totalData in pairsByKeys(self._data.players) do
  131. local userInfo = app.room:getUserInfo(totalData.userId)
  132. --昵称
  133. local nickname = totalData.nickname or ""
  134. local totalScore = totalData.totalScore
  135. table.insert(info.copyData.userInfos,{nickname=nickname,totalScore=totalScore})
  136. end
  137. local onGetUrlCallback = function(url)
  138. if url then
  139. self.zhanjiUrl = url
  140. self.dataForUrl = {
  141. app = getAppId(),
  142. uid = app.user.loginInfo.uid,
  143. gameid = 35,
  144. roomid = self._data.nShowTableId,
  145. endtime = os.time(),
  146. }
  147. local url = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
  148. self.zhanjiUrl,
  149. self.dataForUrl.uid,
  150. self.dataForUrl.gameid,
  151. self.dataForUrl.app,
  152. self.dataForUrl.roomid,
  153. self.dataForUrl.endtime);
  154. local content = nil;
  155. if info and info.copyData and info.copyData.userInfos then
  156. for k,v in pairs(info.copyData.userInfos) do
  157. local userInfo = ""
  158. if v.totalScore > 0 then
  159. userInfo = string.format("%s(+%s)", getShortName(v.nickname), v.totalScore)
  160. else
  161. userInfo = string.format("%s(%s)", getShortName(v.nickname), v.totalScore)
  162. end
  163. if content then
  164. content = content .. "," .. userInfo
  165. else
  166. content = userInfo
  167. end
  168. end
  169. end
  170. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  171. local gameName = getSubGameName(35) or "悠闲麻将"
  172. local shareInfo =
  173. {
  174. contentType = "url",
  175. scene = "talk",
  176. url = url,
  177. title = gameName.."战绩",
  178. description = content,
  179. image = imagePath,
  180. imageWidth = 100,
  181. };
  182. dump(shareInfo)
  183. app.plugin:shareGame(shareInfo, self.shareCallbakc);
  184. else
  185. showTooltip("获取分享用的链接失败");
  186. end
  187. end
  188. app.php:initShareZhanJiToUrl(onGetUrlCallback);--]]
  189. app.waitDialogManager:showWaitNetworkDialog("获取分享链接")
  190. local onGetUrlCallback = function(url)
  191. app.waitDialogManager:closeWaitNetworkDialog()
  192. if url then
  193. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  194. local gameName = getSubGameName(GAME_IDS.luzhouPaoDeKuai) or "悠闲麻将"
  195. local info = {}
  196. -- info.contentType = "image"
  197. info.image = fileName
  198. info.title = gameName.."战绩"
  199. -- info.imageWidth = 800
  200. info.menuIdxs = {1, 4, 5, 6}
  201. info.FFQFlag = true
  202. -- info.isShareZhanjiUrl = false
  203. info.copyData={
  204. type=1,
  205. tableId=self._data.nShowTableId,
  206. userInfos={},
  207. gameId=GAME_IDS.luzhouPaoDeKuai,
  208. }
  209. local content = nil;
  210. local memberList = app.room.roomInfo.memberList--self._overData.nTotalPlayerInfos
  211. for k,v in pairs(self._data.players) do
  212. local userInfo = app.room:getUserInfo(v.userId)
  213. --昵称
  214. local nickname = v.nickname or ""
  215. local totalScore = v.totalScore
  216. table.insert(info.copyData.userInfos,{nickname=getShortName2(nickname),totalScore=totalScore})
  217. local strUserInfo = ""
  218. if totalScore > 0 then
  219. strUserInfo = string.format("%s(+%s)", getShortName2(nickname), totalScore)
  220. else
  221. strUserInfo = string.format("%s(%s)", getShortName2(nickname), totalScore)
  222. end
  223. if content then
  224. content = content .. "," .. strUserInfo
  225. else
  226. content = strUserInfo
  227. end
  228. end
  229. local sharUrl = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
  230. url,
  231. app.user.loginInfo.uid,
  232. GAME_IDS.luzhouPaoDeKuai,
  233. getAppId(),
  234. self._data.nShowTableId,
  235. self._data.endTime or os.time())
  236. info.url = sharUrl
  237. info.description = content
  238. dump(info)
  239. local view = import("luaScript.Views.Main.ShareView"):new(info)
  240. view:setAnchorPoint(cc.p(0.5, 0.5))
  241. app:showWaitDialog(view)
  242. else
  243. showTooltip("获取分享用的链接失败")
  244. end
  245. end
  246. app.php:initShareZhanJiToUrl(onGetUrlCallback)
  247. end
  248. function PdkGameOverView:onEnter()
  249. PdkGameOverView.super.onEnter()
  250. setShowCountAll(true)
  251. stopBGMusic()
  252. end
  253. function PdkGameOverView:onExit()
  254. PdkGameOverView.super.onExit(self)
  255. setShowCountAll(false)
  256. end
  257. function PdkGameOverView:createItem( info )
  258. info.totalScore = tonumber(info.totalScore)
  259. local node = loadUI("pk_luzhoupdk/res/ui/ui_room/ui_lzpdk_dajuitem.ui")
  260. setPlayerHeadImage(info.userId, info.headimgurl, node.Items.imgHead)
  261. node.Items.txtNick:setString(getSubStringNickname(info.nickname or ""))
  262. node.Items.txtID:setString("ID:"..info.userId)
  263. --显示隐藏游戏内选手id(主办人和管理员不限制,只针对海选赛) -- todo lwq
  264. -- begin
  265. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  266. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  267. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  268. --隐私数据
  269. local clubInfo = app.club_php.clubList[app.club_php.clubID]
  270. self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
  271. if not self.cliext or not self.cliext.is_hideUid or (self.cliext and self.cliext.is_hideUid == 1) then
  272. if clubInfo.role == ClubDefine.Job.Creator or clubInfo.role == ClubDefine.Job.Manager then
  273. node.Items.txtID:setVisible(true)
  274. else
  275. node.Items.txtID:setVisible(false)
  276. end
  277. end
  278. end
  279. end
  280. if info.userId == tonumber(app.user.loginInfo.uid) then
  281. node.Items.txtID:setVisible(true)
  282. end
  283. -- end
  284. node.Items.imgBest:setVisible(info.isBigWin and info.totalScore>0)
  285. node.Items.imgHost:setVisible(info.isHost)
  286. node.Items.imgHost:setVisible(false)--隐藏房主标签
  287. --"extString" = "{"bombTimes":0,"loseTimes":0,"maxScore":3,"winTimes":2}"
  288. local extData = json.decode(info.extString)
  289. --[[node.Items.txtDjzgfs_1:setString(""..extData.maxScore)
  290. node.Items.txtDczds_1:setString(""..extData.bombTimes)
  291. node.Items.txtSyjs_1:setString(string.format("%d/%d", extData.loseTimes , extData.winTimes))--]]
  292. local countInfo = json.decode(info.countInfo)
  293. node.Items.txtDiamond:setText("-"..countInfo.DeInfo)
  294. if info.totalScore > 0 then
  295. node.Items.txtTotalScore:setString("+"..info.totalScore)
  296. --node.Items.txtTotalScore:setColor(cc.c3b(212, 16, 16))
  297. node.Items.ImageView_light:setVisible(info.isBigWin)
  298. else
  299. node.Items.txtTotalScore:setFntFile("res/fonts/dt_jian_num.fnt")
  300. node.Items.txtTotalScore:setString(""..info.totalScore)
  301. node.Items.ImageView_light:setVisible(false)
  302. end
  303. if self._data.stopFlag == 9 or self._data.stopFlag == 8 then--解散游戏
  304. local jiesanData = json.decode(self._data.stopResult)
  305. local jiesanLab = node.Items.txtID:getCopied()
  306. local jiesanPos = node.Items.txtID:getPosition()
  307. local jiesaninfo = {
  308. [0] = "超时解散",
  309. [1] = "申请解散",
  310. [2] = "同意解散",
  311. [3] = "拒绝",
  312. }
  313. if jiesanData and jiesanData[tostring(info.userId)] then
  314. jiesanLab:setPositionY(jiesanPos.y - 50)
  315. jiesanLab:setAnchorPoint(cc.p(0.5, 0.5))
  316. jiesanLab:setColor(cc.c3b(255,155,155))
  317. if self._data.stopFlag == 9 then
  318. jiesanLab:setText(jiesaninfo[jiesanData[tostring(info.userId)]])
  319. elseif self._data.stopFlag == 8 then
  320. jiesanLab:setText("系统解散")
  321. end
  322. node.Items.ImageView_item_bg_1:addChild(jiesanLab)
  323. end
  324. end
  325. return node
  326. end
  327. function PdkGameOverView:test()
  328. local data = {{}, {}, {}}
  329. local dltWidth = 1273/#data
  330. for i,v in ipairs(data) do
  331. local item = GameOverItem:new(v)
  332. if i==1 then
  333. item:setPosition(cc.p((i-1)*dltWidth+dltWidth/2, 225))
  334. elseif i==3 then
  335. else
  336. item:setPosition(cc.p((i-1)*dltWidth+dltWidth/2, 225))
  337. end
  338. self.ui.Items.Layout_items:addChild(item)
  339. end
  340. end
  341. ---
  342. -- 初始化大结算再来一局
  343. -- @return
  344. --
  345. function PdkGameOverView:initPlayGameAgain ()
  346. local roomInfo = app.room.roomInfo or {};
  347. local gameId = roomInfo.gameId or app.gameId
  348. if dd.IClub.isInClub() and roomInfo.nShowTableId then
  349. local inviteList = {}
  350. for k,v in pairsByKeys(roomInfo.memberList) do
  351. if tonumber(v.nUserId) ~= app.user.loginInfo.uid then
  352. table.insert(inviteList, v.nUserId)
  353. end
  354. end
  355. local strInvite = luzhouPdkRoomViewConfig.getClubInviteWanFa(roomInfo.gameId or GAME_IDS.luzhouPaoDeKuai, roomInfo)
  356. local btnPlayAgain = self.ui.Items.Button_PlayAgain
  357. dd.IPlayGameAgain.bindPlayAgainButton(btnPlayAgain, gameId, strInvite, inviteList, function ()
  358. -- 初始化成功后干嘛干嘛
  359. local visible = btnPlayAgain:isVisible()
  360. self.ui.Items.Layout_Button_PlayAgain:setVisible(visible)
  361. if self.ui.Items.Layout_Operate_Buttons then
  362. self.ui.Items.Layout_Operate_Buttons:requestDoLayout()
  363. self.ui.Items.Layout_Operate_Buttons:doLayout()
  364. self.ui.Items.Layout_Operate_Buttons:setPositionX(cc.Director:getInstance():getVisibleSize().width / 2)
  365. end
  366. end)
  367. --绑定消息通知回调
  368. self:bindEvent(app.club_php , GAME_EVENT.CLUB_INVITE , handler(self , self.onClubInviteEvent))
  369. else
  370. logD("PdkGameOverView:initPlayGameAgain", "不在亲友圈或桌子id为空,不能进行再来一局操作")
  371. if self.ui.Items.Layout_Button_PlayAgain then
  372. self.ui.Items.Layout_Button_PlayAgain:setVisible(false)
  373. end
  374. if self.ui.Items.Layout_Operate_Buttons then
  375. self.ui.Items.Layout_Operate_Buttons:requestDoLayout()
  376. self.ui.Items.Layout_Operate_Buttons:doLayout()
  377. self.ui.Items.Layout_Operate_Buttons:setPositionX(cc.Director:getInstance():getVisibleSize().width / 2)
  378. end
  379. end
  380. end
  381. ---
  382. -- 监听亲友圈邀请信息
  383. -- @param event
  384. -- @return
  385. --
  386. function PdkGameOverView:onClubInviteEvent(event)
  387. dd.IPlayGameAgain.showClubInviteDialog(event, nil, nil)
  388. end
  389. return PdkGameOverView