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.

283 lines
8.8 KiB

  1. -- 单局战绩单元Layout
  2. local ClubZhanJiDanjuItem = class("ClubZhanJiDanjuItem")
  3. function ClubZhanJiDanjuItem:ctor(gameRule, zhanjiInfo, detail, endTime, idx, tableIdx)
  4. self.gameRule = gameRule;
  5. self.zhanjiInfo = zhanjiInfo
  6. self.detail = detail
  7. --logD("idx:",idx)
  8. --logD("detail.endtime :",detail.endtime)
  9. --logD("endTime :",endTime)
  10. self.endTime = detail.endtime or endTime
  11. --logD("self.endTime :",self.endTime)
  12. self.idx = idx
  13. self.gameid = self.zhanjiInfo.gameid
  14. --从房间返回茶馆的桌子标识
  15. self.tableIdx = tableIdx
  16. self.ui = loadUI("res/ui/ui_club/ui_club_zhanji_danju_item.ui")
  17. autoAdaptWidth(self.ui)
  18. self.ui.Items.Layout_player:setVisible(false)
  19. self:initView()
  20. end
  21. function ClubZhanJiDanjuItem:initView()
  22. -- 回放
  23. self.ui.Items.Button_record:registerClick(handler(self, self.onClickRecord));
  24. --隐藏下拉按钮
  25. self.ui.Items.Button_down:setVisible(false)
  26. self.ui.Items.Button_up:setVisible(false)
  27. self.ui.Items.ImageView_Flag:setVisible(false)
  28. --积分
  29. self:showScoreCount();
  30. -- 时间
  31. local time = os.date("%Y-%m-%d %H:%M",self.endTime)
  32. --logD("time:",time)
  33. local timeInfo = time;
  34. self.ui.Items.Text_time:setText(timeInfo)
  35. self.ui.Items.TextBMFont_num:setText(tonumber(self.idx))
  36. end
  37. --输赢分数
  38. function ClubZhanJiDanjuItem:showScoreCount()
  39. local isMe = false;
  40. -- 0=正常结束 1=吃臭牌 2=吃牌不比 3=无牌赔包子 4=胡臭牌 7=黄庄 8=长时间自动解散 9=解散游戏 , 如果为0、8、9则表示正常结束
  41. local endFlag = self.detail.flag
  42. if endFlag == 8 or endFlag == 9 then
  43. self.ui.Items.ImageView_Flag:setVisible(true)
  44. elseif endFlag == 22 then--管理解散
  45. self.ui.Items.Text_disbandUids:setText('解散人: ' .. self.detail.ext.disbandUids)
  46. end
  47. if endFlag == 8 then
  48. self.ui.Items.Text_disbandUids:setText('房间占用超时解散')
  49. end
  50. local jiesanInfo
  51. if self.detail.ext and self.detail.ext.disbandStatus then
  52. jiesanInfo = self.detail.ext.disbandStatus
  53. elseif self.detail.ext and self.detail.ext.jiesan then
  54. jiesanInfo = self.detail.ext.jiesan
  55. end
  56. local extUidInfo
  57. if self.detail.ext and self.detail.ext.disbandUids then
  58. extUidInfo = self.detail.ext.disbandUids
  59. end
  60. local uiTemplate = self.ui.Items.Layout_player;
  61. local contentSize = self.ui.Items.Layout_score:getContentSize();
  62. local scoreList = self.detail.score
  63. local scoreSize = table.nums(scoreList)
  64. local gameConfig = getSubGameConfig(self.gameid) or {}
  65. for uid,score in pairsByKeys(scoreList) do
  66. local uiItem = uiTemplate:getCopied()
  67. uiItem:setSize(cc.size(contentSize.width / scoreSize, contentSize.height))
  68. uiItem.Items = getUIItems(uiItem)
  69. if gameConfig.isUseDivision10 then
  70. score = score / 10
  71. end
  72. if score > 0 then
  73. score = "+"..tostring(score)
  74. uiItem.Items.Text_score:setFntFile("res/fonts/zhanji_win.fnt")
  75. else
  76. uiItem.Items.Text_score:setFntFile("res/fonts/zhanji_lose.fnt")
  77. end
  78. uiItem.Items.Text_score:setText(score)
  79. --名字
  80. local playerInfo = app.playerInfoManager:getPlayerInfo(uid);
  81. if playerInfo then
  82. local len = string.len(playerInfo.name)
  83. if len == 0 then
  84. playerInfo.name = "未知昵称"
  85. end
  86. playerInfo.name = getSubStringNickname(playerInfo.name)
  87. uiItem.Items.Text_player_name:setText(playerInfo.name)
  88. --战绩用户列表中是否有自己
  89. if tonumber(uid) == app.user.loginInfo.uid then
  90. isMe = true;
  91. end
  92. end
  93. if endFlag == 9 and jiesanInfo then
  94. uiItem.Items.Text_jiesanInfo:setVisible(true)
  95. if jiesanInfo[uid] and jiesanInfo[uid] == 0 then
  96. uiItem.Items.Text_jiesanInfo:setText("超时解散")
  97. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(0,255,0))
  98. elseif jiesanInfo[uid] and jiesanInfo[uid] == 1 then
  99. uiItem.Items.Text_jiesanInfo:setText("申请解散")
  100. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0))
  101. elseif jiesanInfo[uid] and jiesanInfo[uid] == 2 then
  102. uiItem.Items.Text_jiesanInfo:setText("同意解散")
  103. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(0,255,0))
  104. elseif jiesanInfo[uid] and jiesanInfo[uid] == 3 then
  105. uiItem.Items.Text_jiesanInfo:setText("拒绝解散")
  106. end
  107. elseif endFlag == 8 then--系统解散
  108. uiItem.Items.Text_jiesanInfo:setVisible(true)
  109. uiItem.Items.Text_jiesanInfo:setText("系统解散")
  110. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0))
  111. elseif endFlag == 10 then--托管解散
  112. local autoDisArr = string.split(extUidInfo,";") or {}
  113. if table.indexOf(autoDisArr, uid) >= 0 then
  114. uiItem.Items.Text_jiesanInfo:setVisible(true)
  115. uiItem.Items.Text_jiesanInfo:setText("托管解散")
  116. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0))
  117. else
  118. uiItem.Items.Text_jiesanInfo:setVisible(false)
  119. end
  120. elseif endFlag == 23 then--房卡不足
  121. uiItem.Items.Text_jiesanInfo:setVisible(true)
  122. uiItem.Items.Text_jiesanInfo:setText("房卡不足")
  123. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0))
  124. elseif endFlag == 25 then--其他解散
  125. local eliminateArr = string.split(extUidInfo,";") or {}
  126. if table.indexOf(eliminateArr, uid) >= 0 then
  127. uiItem.Items.Text_jiesanInfo:setVisible(true)
  128. uiItem.Items.Text_jiesanInfo:setText("比赛淘汰")
  129. uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0))
  130. else
  131. uiItem.Items.Text_jiesanInfo:setVisible(false)
  132. end
  133. else
  134. uiItem.Items.Text_jiesanInfo:setVisible(false)
  135. end
  136. self.ui.Items.Layout_score:addChild(uiItem);
  137. end
  138. --如果自己不参与牌局,则不显示回放按钮
  139. --[[if isMe then
  140. self.ui.Items.Layout_record:setVisible(true)
  141. else
  142. self.ui.Items.Layout_record:setVisible(false)
  143. end--]]
  144. self.ui.Items.Layout_btn:requestDoLayout()
  145. self.ui.Items.Layout_btn:doLayout();
  146. end
  147. function ClubZhanJiDanjuItem:onClickRecord()
  148. playBtnEffect()
  149. local room = app.club_php:getMyInRoom(app.club_php.clubID)
  150. local view = app:getCurrentView()
  151. if room or view.__cname ~= "MainView" then
  152. showTooltip("正在游戏中,禁止查看回放")
  153. return
  154. end
  155. if self.tableIdx then
  156. --从房间切换回茶馆时,不能使用回放按钮
  157. showTooltip("当前正在游戏中,禁止使用回放")
  158. return
  159. end
  160. if not app.subGameManager:isInstaller(tonumber(self.zhanjiInfo.gameid)) or app.subGameManager:isNeedUpdate(tonumber(self.zhanjiInfo.gameid)) then
  161. requestDownloadSubGame(tonumber(self.zhanjiInfo.gameid), function ()
  162. showTooltip("下载完成")
  163. end, true)
  164. return
  165. end
  166. local pid = self.zhanjiInfo.pid
  167. local subid = self.detail.subid
  168. -- 显示加载界面,直到加载完毕
  169. local function showZhanjiRecord()
  170. local zhanjiInfo = app.club_zhanji.zhanjiInfoList[pid]
  171. if not zhanjiInfo then
  172. logD("zhanjiInfo:"..table.tostring(zhanjiInfo))
  173. showTooltip("回放数据不存在")
  174. return
  175. end
  176. if not zhanjiInfo.detail then
  177. logD("zhanjiInfo.detail:"..table.tostring(zhanjiInfo.detail))
  178. showTooltip("回放数据不存在")
  179. return
  180. end
  181. local lunDetail
  182. for jushu, jushuInfo in pairs(zhanjiInfo.detail) do
  183. for lunshu, lunshuInfo in pairs(jushuInfo) do
  184. if lunshuInfo.subid == subid then
  185. lunDetail = lunshuInfo
  186. end
  187. end
  188. end
  189. if not lunDetail then
  190. logD("lunDetail:"..table.tostring(lunDetail))
  191. showTooltip("回放数据不存在")
  192. return
  193. end
  194. --拼接字段,此字段php未下发
  195. lunDetail.curCount = self.idx
  196. lunDetail.totalCount = self.zhanjiInfo.nbound--总局数
  197. lunDetail.nTotalGameNum = self.zhanjiInfo.nbound--总局数(每个游戏字段定义不同)
  198. lunDetail.nbound = self.zhanjiInfo.nbound--总局数(每个游戏字段定义不同)
  199. lunDetail.roomNum = self.zhanjiInfo.roomid
  200. lunDetail.roomid = self.zhanjiInfo.roomid
  201. logD("lunDetail:"..table.tostring(lunDetail))
  202. if not lunDetail or not lunDetail.user then
  203. showTooltip("回放数据不存在")
  204. return
  205. end
  206. if table.nums(lunDetail.user) <= 0 then
  207. showTooltip("游戏解散了")
  208. return
  209. end
  210. --[[if lunDetail.flag == 8 or lunDetail.flag == 9 then
  211. showTooltip("游戏解散了")
  212. return
  213. end--]]
  214. for uid, userInfo in pairs(lunDetail.user) do
  215. --玩家信息
  216. local playerInfo = app.playerInfoManager:getPlayerInfo(uid)
  217. if playerInfo then
  218. userInfo.nick = playerInfo.name or ""
  219. userInfo.head = playerInfo.head or ""
  220. userInfo.sex = playerInfo.sex or 0
  221. else
  222. userInfo.nick = "未知昵称"
  223. userInfo.head = ""
  224. userInfo.sex = 0
  225. end
  226. --总分
  227. userInfo.tscore = zhanjiInfo.tscore[tostring(uid)]
  228. if not userInfo.hand then
  229. showTooltip("游戏解散了")
  230. return
  231. end
  232. end
  233. local recordClass = getSubGameZhanjiRecordView(self.zhanjiInfo.gameid);
  234. if recordClass then
  235. app:changeGameProtocol(tonumber(self.zhanjiInfo.gameid), 1)
  236. local view = import(recordClass):new(lunDetail);
  237. view:setAnchorPoint(cc.p(0.5, 0.5))
  238. app:showWaitDialog(view)
  239. end
  240. end
  241. app.club_zhanji:getZhanJiDetail(self.zhanjiInfo.pid, self.detail.subid, showZhanjiRecord)
  242. end
  243. return ClubZhanJiDanjuItem