Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

417 rader
14 KiB

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