Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

468 linhas
15 KiB

  1. -- 总结算界面
  2. local ZPFunc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
  3. local ZPWanFa=ZPFramework.ImportWanFa("luaScript.SubGameDefine.ZiPai.ZPWanFa")
  4. local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
  5. local ZPRoomCountAllView = class("ZPRoomCountAllView", cc.UIView)
  6. function ZPRoomCountAllView:ctor(response,endTime)
  7. ZPRoomCountAllView.super.ctor(self);
  8. self.response = response
  9. self.endTime = endTime
  10. end
  11. function ZPRoomCountAllView:loadUI()
  12. local ui = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_daju.ui");
  13. self.ui = ui;
  14. self:addChild(ui);
  15. end
  16. function ZPRoomCountAllView:onEnter()
  17. ZPRoomCountAllView.super.onEnter(self)
  18. local config = getSubGameConfig(ZPDef.GameID or app.gameId)
  19. setShowCountAll(true);
  20. self:loadUI()
  21. self.ui.Items.Layout_1:setTouchEnabled(true)
  22. -- 关闭
  23. self.ui.Items.Button_Sure:registerClick(handler(self , self.onClickClose))
  24. -- 防封群分享
  25. self.ui.Items.Button_ffqShare:registerClick(handler(self , self.onClickFFQShare))
  26. -- 分享,如果没安装微信则不展示分享按钮
  27. local showShare = app.plugin:isShowThirdLogin() or false
  28. self.ui.Items.Button_Share:registerClick(handler(self , self.onClickShare))
  29. if not showShare then
  30. self.ui.Items.Layout_5:setVisible(false);
  31. end
  32. if not app.config.ModuleConfig.IsSupportZhanJiUrl then
  33. self.ui.Items.Layout_8:setVisible(false)
  34. end
  35. if isReviewVersion() then
  36. self.ui.Items.Layout_8:setVisible(false)
  37. self.ui.Items.Layout_5:setVisible(false);
  38. end
  39. --两个连打才有的按钮功能先屏蔽
  40. self.ui.Items.Layout_7:setVisible(false);--结束离开
  41. self.ui.Items.Layout_3:requestDoLayout()
  42. self.ui.Items.Layout_3:doLayout();
  43. self.ui.Items.Layout_3:setVisible(false);
  44. self.ui.Items.ImageView_tip:setVisible(false)--再玩一轮提示隐藏
  45. local roomInfo = app.room.roomInfo
  46. --房间玩法
  47. --local ruleAll = ZPWanFa.getRuleInfo(roomInfo.strGameInfo)
  48. local newRule = "" ..ZPDef.GameName
  49. newRule = newRule.." 房间号:"..tostring(roomInfo.nShowTableId)
  50. local curCount = roomInfo.nGameStartCount or 0
  51. local str = string.format("%02d/%02d局", curCount, roomInfo.nTotalGameNum)
  52. newRule = newRule.." "..str
  53. self.ui.Items.Text_Rule:setText(newRule)
  54. -- 设置房间号和开始时间
  55. --[[ local tableId = roomInfo.nShowTableId
  56. self.ui.Items.Text_RoomNum:setText("房号:"..tableId)--]]
  57. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  58. self.ui.Items.Text_RoomNum:setText((app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME).."ID:"..app.club_php.clubID)
  59. else
  60. self.ui.Items.Text_RoomNum:setText("")
  61. end
  62. --self.ui.Items.Text_Time:setText(os.date("%Y-%m-%d %X"))--用服务器发的时间
  63. self.ui.Items.Text_Time:setText(os.date("%Y-%m-%d %X",app.room.roomInfo.endtime))
  64. --分数uid,标志
  65. -- 玩家头像
  66. self.headSize = {}
  67. self.headSize.width = self.ui.Items.ImageView_head_1:getContentSize().width;
  68. self.headSize.height = self.ui.Items.ImageView_head_1:getContentSize().height;
  69. self:setAllDaYingJiaVisible(false)
  70. --找到大赢家的分数
  71. local dayingjiaScore = 0
  72. for nUserId,totalData in pairsByKeys(self.response) do
  73. totalData.nTotalScore = tonumber(totalData.nTotalScore)
  74. if totalData.nTotalScore > dayingjiaScore then
  75. dayingjiaScore = totalData.nTotalScore
  76. end
  77. end
  78. local index = 1
  79. for nUserId,totalData in pairsByKeys(self.response) do
  80. -- 玩家头像 名字
  81. local userInfo = app.room:getUserInfo(nUserId)
  82. local name = string.format("Text_Name_%d",index)
  83. local uid = string.format("Text_ID_%d",index)
  84. local head = string.format("ImageView_head_%d",index)
  85. local headBg = string.format("ImageView_head_bg_%d",index)
  86. local infoBg = string.format("ImageView_bg_%d",index)
  87. local beizi = string.format("ImageView_Bei_%d",index)
  88. local roomer = string.format("ImageView_roomer_%d",index)
  89. local leftDia = string.format("Text_Diamond_%d",index)
  90. local yingLight = string.format("ImageView_light_%d",index)
  91. --胡牌次数
  92. local hupaiTimes = string.format("Text_count_hp_%d",index)
  93. --点炮
  94. local dpTimes = string.format("Text_count_dp_%d",index)
  95. --连庄
  96. local lzTimes = string.format("Text_count_zz_%d",index)
  97. --分数
  98. local score = string.format("TextBMFont_Score_%d",index)
  99. --头像
  100. local nickname = ""
  101. if userInfo and userInfo.nickname then
  102. nickname = getSubStringNickname(userInfo.nickname)
  103. self:updateUserHead(self.ui.Items[head],nUserId, userInfo.sex, userInfo.headimgurl);
  104. end
  105. self.ui.Items[name]:setText(nickname)
  106. local totalScore = tonumber(totalData.nTotalScore)
  107. --分数
  108. if totalScore >= 0 then
  109. --self.ui.Items[infoBg]:loadTextureFromPlist("zipai_daju_win_bg.png")
  110. --self.ui.Items[headBg]:loadTextureFromPlist("zipai_daju_win_img.png")
  111. self.ui.Items[score]:setText(tostring("+"..totalScore))
  112. self.ui.Items[score]:setFntFile("res/fonts/dt_jia_num.fnt")--("zp_base/res/ui/zy_fangjian/jia_num.fnt")
  113. else
  114. --self.ui.Items[infoBg]:loadTextureFromPlist("zipai_daju_lose_bg.png")
  115. --self.ui.Items[headBg]:loadTextureFromPlist("zipai_daju_lose_img.png")
  116. self.ui.Items[score]:setText(tostring(totalScore))
  117. self.ui.Items[score]:setFntFile("res/fonts/dt_jian_num.fnt")--("zp_base/res/ui/zy_fangjian/jian_num.fnt")
  118. end
  119. if totalScore == dayingjiaScore then
  120. self.ui.Items[beizi]:setVisible(true)
  121. self.ui.Items[yingLight]:setVisible(true)
  122. end
  123. --uid
  124. self.ui.Items[uid]:setText("ID:"..tostring(nUserId))
  125. --显示隐藏游戏内选手id(主办人和管理员不限制,只针对海选赛) -- todo lwq
  126. -- begin
  127. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  128. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  129. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  130. --隐私数据
  131. local clubInfo = app.club_php.clubList[app.club_php.clubID]
  132. self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
  133. if not self.cliext or not self.cliext.is_hideUid or (self.cliext and self.cliext.is_hideUid == 1) then
  134. if clubInfo.role == ClubDefine.Job.Creator or clubInfo.role == ClubDefine.Job.Manager then
  135. self.ui.Items[uid]:setVisible(true)
  136. else
  137. self.ui.Items[uid]:setVisible(false)
  138. end
  139. end
  140. end
  141. end
  142. if nUserId == tonumber(app.user.loginInfo.uid) then
  143. self.ui.Items[uid]:setVisible(true)
  144. end
  145. -- end
  146. --显示房主
  147. if app.room.roomInfo.nRoomOwnedUid ~= nUserId then
  148. self.ui.Items[roomer]:setVisible(false)
  149. end
  150. self.ui.Items[roomer]:setVisible(false)--隐藏房主
  151. --用户金币信息 如"120,80,10"表示历史房卡数量为120,当前房卡数量80,金币10
  152. if totalData.propertyInfo then
  153. local ppInfo = string.split(totalData.propertyInfo, ",")
  154. --self.ui.Items[leftDia]:setText(ppInfo[2])
  155. end
  156. if totalData.nTextJson then
  157. local dataJson = json.decode(totalData.nTextJson)
  158. --消耗房卡数
  159. if dataJson and dataJson.DeInfo then
  160. self.ui.Items[leftDia]:setText("-"..dataJson.DeInfo)
  161. end
  162. --[[--胡牌次数
  163. self.ui.Items[hupaiTimes]:setText(tostring(dataJson.hupaiCnt))
  164. --中庄
  165. self.ui.Items[lzTimes]:setText(tostring(dataJson.zhongBankCnt))
  166. --点炮次数
  167. self.ui.Items[dpTimes]:setText(tostring(dataJson.dianPaoCnt))--]]
  168. end
  169. index = index + 1
  170. end
  171. if app.room:getActualPlayerNum() == 3 then
  172. self.ui.Items.Layout_player_4:setVisible(false)
  173. self.ui.Items.Layout_Player:doLayout()
  174. self.ui.Items.Layout_Player:requestDoLayout()
  175. elseif app.room:getActualPlayerNum() == 2 then
  176. self.ui.Items.Layout_player_3:setVisible(false)
  177. self.ui.Items.Layout_player_4:setVisible(false)
  178. self.ui.Items.Layout_Player:doLayout()
  179. self.ui.Items.Layout_Player:requestDoLayout()
  180. end
  181. self:initPlayGameAgain()
  182. end
  183. ---
  184. -- 初始化大结算再来一局
  185. -- @return
  186. --
  187. function ZPRoomCountAllView:initPlayGameAgain ()
  188. local roomInfo = app.room.roomInfo or {};
  189. local gameId = roomInfo.gameId or app.gameId
  190. if dd.IClub.isInClub() and roomInfo.nShowTableId then
  191. local inviteList = {}
  192. for k,v in pairsByKeys(roomInfo.memberList) do
  193. if tonumber(v.nUserId) ~= app.user.loginInfo.uid then
  194. table.insert(inviteList, v.nUserId)
  195. end
  196. end
  197. local strInvite = ZPFunc.getClubInviteWanFa(gameId, roomInfo)
  198. local btnPlayAgain = self.ui.Items.Button_Play
  199. dd.IPlayGameAgain.bindPlayAgainButton(btnPlayAgain, gameId, strInvite, inviteList, function ()
  200. -- 初始化成功后干嘛干嘛
  201. local visible = btnPlayAgain:isVisible()
  202. self.ui.Items.Layout_6:setVisible(visible)
  203. if self.ui.Items.Layout_3 then
  204. self.ui.Items.Layout_3:requestDoLayout()
  205. self.ui.Items.Layout_3:doLayout()
  206. end
  207. end)
  208. --绑定消息通知回调
  209. self:bindEvent(app.club_php , GAME_EVENT.CLUB_INVITE , handler(self , self.onClubInviteEvent))
  210. else
  211. logD("ZPRoomCountAllView:initPlayGameAgain", "不在亲友圈或桌子id为空,不能进行再来一局操作")
  212. if self.ui.Items.Layout_6 then
  213. self.ui.Items.Layout_6:setVisible(false)
  214. end
  215. if self.ui.Items.Layout_3 then
  216. self.ui.Items.Layout_3:requestDoLayout()
  217. self.ui.Items.Layout_3:doLayout()
  218. end
  219. end
  220. end
  221. ---
  222. -- 监听亲友圈邀请信息
  223. -- @param event
  224. -- @return
  225. --
  226. function ZPRoomCountAllView:onClubInviteEvent(event)
  227. dd.IPlayGameAgain.showClubInviteDialog(event, nil, nil)
  228. end
  229. --设置所有大赢家visible
  230. function ZPRoomCountAllView:setAllDaYingJiaVisible(vis)
  231. for i = 1,4 do
  232. local beizi = string.format("ImageView_Bei_%d",i)
  233. local yingLight = string.format("ImageView_light_%d",i)
  234. if self.ui.Items[beizi] then
  235. self.ui.Items[beizi]:setVisible(vis)
  236. end
  237. if self.ui.Items[yingLight] then
  238. self.ui.Items[yingLight]:setVisible(vis)
  239. end
  240. end
  241. end
  242. function ZPRoomCountAllView:playAni()
  243. --判断大赢家和土豪
  244. local tuhaoScore = -999999
  245. local winerScore = -999999
  246. local tt = {}
  247. --排除都为0的情况
  248. local zeorNum = 0
  249. for k,v in pairs(self.response) do
  250. if v.nTotalScore == 0 then
  251. zeorNum = zeorNum + 1
  252. end
  253. end
  254. local maxPeople = table.nums(self.response)
  255. if zeorNum ~= maxPeople then
  256. for k,v in pairs(self.response) do
  257. table.insert(tt,v.nTotalScore)
  258. end
  259. local function sortFunc(a,b)
  260. return a < b
  261. end
  262. table.sort(tt,sortFunc)
  263. tuhaoScore = tt[1]
  264. winerScore = tt[maxPeople]
  265. end
  266. self:setAllDaYingJiaVisible(false)
  267. local index = 1
  268. for nUserId,totalData in pairsByKeys(self.response) do
  269. if (not (tolua.type(app.room.isLianDa) == "function")) or (tolua.type(app.room.isLianDa) == "function" and app.room:checkUserIDIsInTable(nUserId)) then
  270. -- 玩家头像 名字
  271. local beizi = string.format("ImageView_Bei_%d",index)
  272. local yingLight = string.format("ImageView_light_%d",index)
  273. local nodePlayer = string.format("Layout_player_%d",index)
  274. local totalScore = totalData.nTotalScore
  275. --分数
  276. if totalScore == winerScore then
  277. local tarPos = cc.pAdd(self.ui.Items[beizi]:getPosition(),cc.p(0,30))
  278. self.ui.Items[beizi]:setScale(3)
  279. self.ui.Items[beizi]:setOpacity(0)
  280. local mSpawn = cc.Spawn:create(cc.ScaleTo:create(0.2,1.0),cc.FadeIn:create(0.2))
  281. local seq = cc.Sequence:create(cc.DelayTime:create(0.15 * 5),mSpawn)
  282. self.ui.Items[beizi]:runAction(seq)
  283. self.ui.Items[beizi]:setVisible(true)
  284. if self.ui.Items[yingLight] then
  285. self.ui.Items[yingLight]:setVisible(true)
  286. end
  287. else
  288. self.ui.Items[beizi]:setVisible(false)
  289. if self.ui.Items[yingLight] then
  290. self.ui.Items[yingLight]:setVisible(false)
  291. end
  292. end
  293. self.ui.Items[nodePlayer]:setOpacity(0)
  294. local mSpawn = cc.Spawn:create(cc.MoveBy:create(0.2,cc.p(0,120)),cc.FadeIn:create(0.2))
  295. local seq = cc.Sequence:create(cc.DelayTime:create(0.15 * index),cc.CallFunc:create(function ()
  296. self.ui.Items[nodePlayer]:setPositionY(self.ui.Items[nodePlayer]:getPositionY() - 120)
  297. end),mSpawn)
  298. self.ui.Items[nodePlayer]:runAction(seq)
  299. index = index + 1
  300. end
  301. end
  302. local seq = cc.Sequence:create(cc.DelayTime:create(0.35*index),cc.CallFunc:create(function ()
  303. self.ui.Items.Layout_3:setVisible(true);
  304. end))
  305. self.ui:runAction(seq)
  306. end
  307. function ZPRoomCountAllView:onExit()
  308. ZPRoomCountAllView.super.onExit(self);
  309. setShowCountAll(false);
  310. end
  311. -- 关闭
  312. function ZPRoomCountAllView:onClickClose()
  313. app.room:dispatchEvent({name = "onGameOverResponse"});
  314. self:removeFromParent()
  315. runInNextFrame(function()
  316. local roomInfo = app.room.roomInfo
  317. -- 房间号
  318. local roomId = roomInfo.nShowTableId
  319. gotoMainView(app.gameId,roomId)
  320. end)
  321. end
  322. -- 防封群分享
  323. function ZPRoomCountAllView:onClickFFQShare()
  324. app.waitDialogManager:showWaitNetworkDialog("获取分享链接")
  325. local onGetUrlCallback = function(url)
  326. app.waitDialogManager:closeWaitNetworkDialog()
  327. if url then
  328. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  329. local gameName = getSubGameName(app.gameId) or "川南棋牌"
  330. local info = {}
  331. -- info.contentType = "image"
  332. info.image = fileName
  333. info.title = gameName.."战绩"
  334. -- info.imageWidth = 800
  335. info.menuIdxs = {1, 4, 5, 6}
  336. -- info.isShareZhanjiUrl = false
  337. info.copyData={
  338. type=1,
  339. tableId=app.room.roomInfo.nShowTableId,
  340. userInfos={},
  341. }
  342. local content = nil;
  343. local memberList = app.room.roomInfo.memberList--self._overData.nTotalPlayerInfos
  344. for k,v in pairs(self.response) do
  345. local userInfo = app.room:getUserInfo(k)
  346. --昵称
  347. local nickname = userInfo.nickname or ""
  348. local totalScore = v.nTotalScore or v.nTotalMoney
  349. table.insert(info.copyData.userInfos,{nickname=nickname,totalScore=totalScore})
  350. local strUserInfo = ""
  351. if totalScore > 0 then
  352. strUserInfo = string.format("%s(+%s)", getShortName(nickname), totalScore)
  353. else
  354. strUserInfo = string.format("%s(%s)", getShortName(nickname), totalScore)
  355. end
  356. if content then
  357. content = content .. "," .. strUserInfo
  358. else
  359. content = strUserInfo
  360. end
  361. end
  362. local sharUrl = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
  363. url,
  364. app.user.loginInfo.uid,
  365. app.gameId,
  366. getAppId(),
  367. app.room.roomInfo.nShowTableId,
  368. os.time())
  369. info.url = sharUrl
  370. info.description = content
  371. dump(info)
  372. local view = import("luaScript.Views.Main.ShareView"):new(info)
  373. view:setAnchorPoint(cc.p(0.5, 0.5))
  374. app:showWaitDialog(view)
  375. else
  376. showTooltip("获取分享用的链接失败")
  377. end
  378. end
  379. app.php:initShareZhanJiToUrl(onGetUrlCallback)
  380. end
  381. -- 分享
  382. function ZPRoomCountAllView:onClickShare()
  383. local fileName = cc.FileUtils:getInstance():getWritablePath()..tostring(app.room.roomInfo.nShowTableId).."_screen.jpg"
  384. cc.FileUtils:getInstance():screenToFile(fileName, function(ret)
  385. if 1 == tonumber(ret) then
  386. local info = {}
  387. info.contentType = "image"
  388. info.image = fileName
  389. info.imageWidth = 800
  390. info.isShareZhanjiUrl = true
  391. info.copyData={
  392. type=1,
  393. tableId=app.room.roomInfo.nShowTableId,
  394. userInfos={},
  395. gameId = ZPDef.GameID or app.gameId,
  396. }
  397. for nUserId,totalData in pairsByKeys(self.response) do
  398. local userInfo = app.room:getUserInfo(nUserId)
  399. --昵称
  400. local nickname = userInfo.nickname or ""
  401. local totalScore = totalData.nTotalScore
  402. table.insert(info.copyData.userInfos,{nickname=nickname,totalScore=totalScore})
  403. end
  404. local view = import("luaScript.Views.Main.ShareView"):new(info)
  405. view:setAnchorPoint(cc.p(0.5, 0.5))
  406. app:showWaitDialog(view)
  407. else
  408. showTooltip("截图保存失败");
  409. end
  410. end);
  411. end
  412. function ZPRoomCountAllView:updateUserHead(nodeHead,nUserId, sex, headimgurl)
  413. setPlayerHeadImage(nUserId,headimgurl,nodeHead)
  414. end
  415. return ZPRoomCountAllView;