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.

433 lines
14 KiB

  1. -- 单局战绩界面
  2. local ZhanJiDanjuView = class("ZhanJiDanjuView", cc.UIView)
  3. function ZhanJiDanjuView:ctor(zhanjiInfo)
  4. ZhanJiDanjuView.super.ctor(self)
  5. --所有游戏战绩协议
  6. -- app.allZhanji = ZhanjiAllGame;
  7. --战绩数据
  8. self.zhanjiInfo = zhanjiInfo;
  9. self.ui = loadUI("res/ui/ui_zhanji/zhanji_danju.ui")
  10. self:addChild(self.ui)
  11. self.gameID = tonumber(self.zhanjiInfo.gameid)
  12. self.isTouch = {}
  13. end
  14. function ZhanJiDanjuView:onEnter()
  15. ZhanJiDanjuView.super.onEnter(self)
  16. -- 关闭按钮
  17. self.ui.Items.Button:registerClick(handler(self, self.onClickClose))
  18. self.ui.Items.Layout_item:setVisible(false)
  19. self.ui.Items.Layout_player_score:setVisible(false)
  20. self.ui.Items.Layout_score_count_item:setVisible(false)
  21. --将玩家uid存起来
  22. self:saveUserID()
  23. self:showZhanJiDanjuInfo()
  24. end
  25. function ZhanJiDanjuView:saveUserID()
  26. --记录玩家UID顺序
  27. self.userIds = {}
  28. local idx = 0
  29. for uid,v in pairsByKeys(self.zhanjiInfo.tscore) do
  30. idx = idx + 1
  31. self.userIds[idx] = tonumber(uid)
  32. end
  33. end
  34. function ZhanJiDanjuView:showZhanJiDanjuInfo()
  35. local function sortFuncEx(a,b)
  36. local numA = toNumber(a.endtime)
  37. local numB = toNumber(b.endtime)
  38. if numA ~= nil and numB ~= nil then
  39. return numA < numB
  40. else
  41. return a < b
  42. end
  43. end
  44. -- 每局信息
  45. local uiScrollView = self.ui.Items.ScrollView;
  46. uiScrollView:getInnerContainer():setAutoSize(true)
  47. uiScrollView:getInnerContainer():setAnchorPoint(cc.p(0,1))
  48. uiScrollView:removeAllChildren()
  49. uiScrollView:hideAllBar()
  50. local scoreLayout = self.ui.Items.Layout_score_count
  51. scoreLayout:removeAllChildren()
  52. local uiTemplate = self.ui.Items.Layout_score_count_item
  53. local contentSize = self.ui.Items.Layout_score_count:getContentSize();
  54. local scoreSize = table.nums(self.userIds)
  55. local gameConfig = getSubGameConfig(self.gameID) or {}
  56. for uid, score in pairsByKeys(self.zhanjiInfo.tscore) do
  57. local uiItem = uiTemplate:getCopied()
  58. uiItem:setSize(cc.size(contentSize.width / scoreSize, contentSize.height))
  59. uiItem.Items = getUIItems(uiItem)
  60. if gameConfig.isUseDivision10 then
  61. score = score / 10
  62. end
  63. -- 积分总计
  64. if score > 0 then
  65. score = "+"..tostring(score)
  66. --红色
  67. uiItem.Items.Text_score_count:setFntFile("res/fonts/zhanji_win.fnt")
  68. else
  69. --绿色
  70. uiItem.Items.Text_score_count:setFntFile("res/fonts/zhanji_lose.fnt")
  71. end
  72. uiItem.Items.Text_score_count:setText(score)
  73. scoreLayout:addChild(uiItem);
  74. end
  75. local uiTemplate = self.ui.Items.Layout_item;
  76. for idx, detailInfo in pairsByKeys(self.zhanjiInfo.detail) do
  77. local tt = {}
  78. if type(detailInfo) == "table" then
  79. for k, v in pairsByKeys(detailInfo) do
  80. table.insert(tt,v)
  81. end
  82. table.sort(tt,sortFuncEx)
  83. else
  84. tt = detailInfo
  85. end
  86. for lunshu, detail in pairsByKeys(tt) do
  87. local uiItem = uiTemplate:getCopied()
  88. autoAdaptWidth(uiItem)
  89. uiItem.Items = getUIItems(uiItem)
  90. uiItem.Items.ImageView_Flag:setVisible(false)
  91. --第几局
  92. uiItem.Items.TextBMFont_num:setText(tonumber(idx))
  93. --时间
  94. local time = os.date("%m-%d %H:%M",detail.endtime or self.zhanjiInfo.endtime)
  95. uiItem.Items.Text_time:setText(time)
  96. -- 0=正常结束 1=吃臭牌 2=吃牌不比 3=无牌赔包子 4=胡臭牌 7=黄庄 8=长时间自动解散 9=解散游戏 , 如果为0、8、9则表示正常结束
  97. local endFlag = detail.flag
  98. if endFlag == 8 or endFlag == 9 or endFlag == 22 or endFlag == 25 or endFlag == 10 then
  99. uiItem.Items.ImageView_Flag:setVisible(true)
  100. local function updatePlayerScore()--解散的局,需要解散信息,
  101. app.waitDialogManager:closeWaitNetworkDialog();
  102. self:showZhanJiDanjuInfo()
  103. end
  104. if (not detail.ext or not detail.ext.disbandStatus) and not self.alreadyReq then
  105. self.alreadyReq = true--已经请求过了,保证只请求一次
  106. app.waitDialogManager:showWaitNetworkDialog("请求数据中...");
  107. app.allZhanji:getZhanJiDetail(self.zhanjiInfo.pid, detail.subid, updatePlayerScore)
  108. return
  109. end
  110. end
  111. if endFlag == 8 then
  112. uiItem.Items.Text_disbandUids:setText('房间占用超时解散')
  113. end
  114. if endFlag == 22 then--管理解散
  115. uiItem.Items.Text_disbandUids:setText('解散人: ' .. detail.ext.disbandUids)
  116. end
  117. --玩家分数
  118. self:showPlayerScore(uiItem.Items.Layout_score, detail)
  119. uiItem.Items.Button_record:setVisible(true)
  120. uiItem.Items.Button_down:setVisible(false)
  121. uiItem.Items.Button_up:setVisible(false)
  122. -- 回放
  123. uiItem.Items.Button_record:registerClick(function ()
  124. playBtnEffect()
  125. local pid = self.zhanjiInfo.pid
  126. local subid = detail.subid
  127. -- 显示加载界面,直到加载完毕
  128. local function showZhanjiRecord()
  129. local zhanjiInfo = app.allZhanji.zhanjiInfoList[pid]
  130. if not zhanjiInfo then
  131. logD("zhanjiInfo:"..table.tostring(zhanjiInfo))
  132. showTooltip("回放数据不存在")
  133. return
  134. end
  135. if not zhanjiInfo.detail then
  136. logD("zhanjiInfo.detail:"..table.tostring(zhanjiInfo.detail))
  137. showTooltip("回放数据不存在")
  138. return
  139. end
  140. local lunDetail
  141. for jushu, jushuInfo in pairs(zhanjiInfo.detail) do
  142. for lunshu, lunshuInfo in pairs(jushuInfo) do
  143. if lunshuInfo.subid == subid then
  144. lunDetail = lunshuInfo
  145. end
  146. end
  147. end
  148. if not lunDetail then
  149. logD("lunDetail:"..table.tostring(lunDetail))
  150. showTooltip("回放数据不存在")
  151. return
  152. end
  153. --拼接字段,此字段php未下发
  154. lunDetail.curCount = self.idx
  155. lunDetail.totalCount = self.zhanjiInfo.nbound
  156. lunDetail.roomNum = self.zhanjiInfo.roomid
  157. lunDetail.roomid = self.zhanjiInfo.roomid--兼容跑得快回放数据
  158. lunDetail.nbound = self.zhanjiInfo.nbound--兼容跑得快回放数据
  159. logD("lunDetail:"..table.tostring(lunDetail))
  160. if not lunDetail or not lunDetail.user then
  161. showTooltip("回放数据不存在")
  162. return
  163. end
  164. if table.nums(lunDetail.user) <= 0 then
  165. showTooltip("游戏解散了")
  166. return
  167. end
  168. --[[if lunDetail.flag == 8 or lunDetail.flag == 9 then
  169. showTooltip("游戏解散了")
  170. return
  171. end--]]
  172. for uid, userInfo in pairs(lunDetail.user) do
  173. --玩家信息
  174. local playerInfo = app.playerInfoManager:getPlayerInfo(uid)
  175. if playerInfo then
  176. userInfo.nick = playerInfo.name or ""
  177. userInfo.head = playerInfo.head or ""
  178. userInfo.sex = playerInfo.sex or 0
  179. else
  180. userInfo.nick = "游客"..tostring(uid)
  181. userInfo.head = ""
  182. userInfo.sex = 0
  183. end
  184. --总分
  185. userInfo.tscore = zhanjiInfo.tscore[tostring(uid)]
  186. if not userInfo.hand then
  187. showTooltip("游戏解散了")
  188. return
  189. end
  190. end
  191. local recordClass = getSubGameZhanjiRecordView(self.zhanjiInfo.gameid);
  192. local config = getSubGameConfig(tonumber(self.zhanjiInfo.gameid))
  193. app:changeGameProtocol(tonumber(self.zhanjiInfo.gameid), 1)
  194. if config and config.belongType==3 then
  195. local MJRoomReplayView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomReplayView")
  196. local view = MJRoomReplayView:new(lunDetail)
  197. view:setAnchorPoint(cc.p(0.5, 0.5))
  198. app:showWaitDialog(view)
  199. elseif recordClass then
  200. local view = import(recordClass):new(lunDetail);
  201. view:setAnchorPoint(cc.p(0.5, 0.5))
  202. app:showWaitDialog(view)
  203. end
  204. end
  205. app.allZhanji:getZhanJiDetail(self.zhanjiInfo.pid, detail.subid, showZhanjiRecord)
  206. end);
  207. uiItem:setTag(idx)
  208. --查看牌型(与回放不会同时出现)
  209. uiScrollView:addChild(uiItem)
  210. end
  211. end
  212. uiScrollView:jumpToTop()
  213. uiScrollView:requestDoLayout()
  214. uiScrollView:doLayout();
  215. end
  216. function ZhanJiDanjuView:showPlayerScore(scoreNode, detail)
  217. local uiTemplate = self.ui.Items.Layout_player_score;
  218. local scoreList = detail.score
  219. local endFlag = detail.flag
  220. local jiesanInfo
  221. if detail.ext and detail.ext.disbandStatus then
  222. jiesanInfo = detail.ext.disbandStatus
  223. elseif detail.ext and detail.ext.jiesan then
  224. jiesanInfo = detail.ext.jiesan
  225. end
  226. local extUidInfo
  227. if detail.ext and detail.ext.disbandUids then
  228. extUidInfo = detail.ext.disbandUids
  229. end
  230. local contentSize = scoreNode:getContentSize();
  231. local scoreSize = table.nums(scoreList)
  232. local gameConfig = getSubGameConfig(self.gameID) or {}
  233. for uid,score in pairsByKeys(scoreList) do
  234. local uiItem = uiTemplate:getCopied()
  235. uiItem:setSize(cc.size(contentSize.width / scoreSize, contentSize.height))
  236. uiItem.Items = getUIItems(uiItem)
  237. if gameConfig.isUseDivision10 then
  238. score = score / 10
  239. end
  240. if score > 0 then
  241. score = "+"..tostring(score)
  242. uiItem.Items.TextBMFont_score:setFntFile("res/fonts/zhanji_win.fnt")
  243. else
  244. uiItem.Items.TextBMFont_score:setFntFile("res/fonts/zhanji_lose.fnt")
  245. end
  246. uiItem.Items.TextBMFont_score:setText(score)
  247. --名字
  248. local playerInfo = app.playerInfoManager:getPlayerInfo(uid);
  249. if playerInfo then
  250. local len = string.len(playerInfo.name)
  251. if len == 0 then
  252. playerInfo.name = "未知昵称"
  253. end
  254. playerInfo.name = getSubStringNickname(playerInfo.name)
  255. uiItem.Items.Text_player_name:setText(playerInfo.name)
  256. end
  257. if endFlag == 9 and jiesanInfo then
  258. uiItem.Items.Text_jiesanInfo:setVisible(true)
  259. if jiesanInfo[uid] and jiesanInfo[uid] == 0 then
  260. uiItem.Items.Text_jiesanInfo:setText("超时解散")
  261. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(0,255,0))
  262. elseif jiesanInfo[uid] and jiesanInfo[uid] == 1 then
  263. uiItem.Items.Text_jiesanInfo:setText("申请解散")
  264. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0))
  265. elseif jiesanInfo[uid] and jiesanInfo[uid] == 2 then
  266. uiItem.Items.Text_jiesanInfo:setText("同意解散")
  267. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(0,255,0))
  268. elseif jiesanInfo[uid] and jiesanInfo[uid] == 3 then
  269. uiItem.Items.Text_jiesanInfo:setText("拒绝解散")
  270. end
  271. elseif endFlag == 8 then--系统解散
  272. uiItem.Items.Text_jiesanInfo:setVisible(true)
  273. uiItem.Items.Text_jiesanInfo:setText("系统解散")
  274. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0))
  275. elseif endFlag == 10 then--托管解散
  276. local autoDisArr = string.split(extUidInfo,";") or {}
  277. if table.indexOf(autoDisArr, uid) >= 0 then
  278. uiItem.Items.Text_jiesanInfo:setVisible(true)
  279. uiItem.Items.Text_jiesanInfo:setText("托管解散")
  280. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0))
  281. else
  282. uiItem.Items.Text_jiesanInfo:setVisible(false)
  283. end
  284. elseif endFlag == 23 then--其他解散
  285. uiItem.Items.Text_jiesanInfo:setVisible(true)
  286. uiItem.Items.Text_jiesanInfo:setText("房卡不足")
  287. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0))
  288. elseif endFlag == 25 then--比赛淘汰
  289. local eliminateArr = string.split(extUidInfo,";") or {}
  290. if table.indexOf(eliminateArr, uid) >= 0 then
  291. uiItem.Items.Text_jiesanInfo:setVisible(true)
  292. uiItem.Items.Text_jiesanInfo:setText("比赛淘汰")
  293. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0))
  294. else
  295. uiItem.Items.Text_jiesanInfo:setVisible(false)
  296. end
  297. else
  298. uiItem.Items.Text_jiesanInfo:setVisible(false)
  299. end
  300. scoreNode:addChild(uiItem);
  301. end
  302. end
  303. -- 关闭响应函数
  304. function ZhanJiDanjuView:onClickClose()
  305. playBtnCloseEffect()
  306. self:removeFromParent()
  307. end
  308. --显示玩家牌型
  309. function ZhanJiDanjuView:showPaixing(layoutContain, paiTemplate, detail)
  310. local contentSize = layoutContain:getContentSize();
  311. local scoreList = detail.score
  312. local scoreSize = table.nums(scoreList)
  313. for i = 1, scoreSize do
  314. local uid = self.userIds[i]
  315. local uiPlayer = paiTemplate:getCopied()
  316. local copyUISize = uiPlayer:getContentSize();
  317. -- 庄家
  318. local banberId = 0;
  319. if detail.ext then
  320. banberId = detail.ext.banker or 0
  321. end
  322. -- 详情
  323. if detail.user and detail.user[tostring(uid)] then
  324. local info = detail.user[tostring(uid)]
  325. uiPlayer:setSize(cc.size(contentSize.width / scoreSize, contentSize.height))
  326. uiPlayer.Items = getUIItems(uiPlayer);
  327. -- 是否庄家
  328. local isBanker = (tonumber(uid) == tonumber(banberId))
  329. uiPlayer.Items.ImageView_Zhuang:setVisible(isBanker)
  330. -- 下注分数
  331. if not isBanker then
  332. uiPlayer.Items.Text_score:setText(tostring(info.chipscore or 0))
  333. else
  334. uiPlayer.Items.Layout_difen:setVisible(false)
  335. end
  336. -- 手牌
  337. local cards = string.split(info.hand, " ")
  338. local cardData = cards[1]
  339. --牌型为0x00时,表示玩家在旁观,不显示牌
  340. if cardData and cardData ~= "" and cardData ~= "0x00" then
  341. if cards and table.nums(cards) > 0 then
  342. for idx, value in ipairs(cards) do
  343. local uiCard = import("Views.ZhanJi.BJZhanJiDanJuCard"):new()
  344. uiCard:updateCardValue(tonumber(value))
  345. local nameLayout = string.format("Layout_Card_%d", idx)
  346. local nodeLayout = uiPlayer.Items[nameLayout]
  347. if nodeLayout then
  348. nodeLayout:addChild(uiCard.ui)
  349. end
  350. end
  351. end
  352. -- 牌型
  353. if info.handtype == 0 or info.handtype < -1 then
  354. uiPlayer.Items.Layout_cardType:setVisible(false)
  355. else
  356. local card_type_image = getImageByCardType(info.handtype)
  357. if card_type_image then
  358. uiPlayer.Items.ImageView_CardType:loadTexture(card_type_image, cc.TextureResType.plistType)
  359. end
  360. end
  361. layoutContain:addChild(uiPlayer);
  362. else
  363. --创建一个空的layout,只占位
  364. local mLayout = cc.Layout:createNode()
  365. mLayout:setAnchorPoint(cc.p(0,0))
  366. mLayout:setSize(copyUISize)
  367. layoutContain:addChild(mLayout);
  368. end
  369. else
  370. --创建一个空的layout,只占位
  371. local mLayout = cc.Layout:createNode()
  372. mLayout:setAnchorPoint(cc.p(0,0))
  373. mLayout:setSize(copyUISize)
  374. layoutContain:addChild(mLayout);
  375. end
  376. end
  377. end
  378. return ZhanJiDanjuView