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.

264 lines
7.6 KiB

  1. -- 单局战绩界面
  2. local ClubZhanJiDanjuView = class("ClubZhanJiDanjuView", cc.UIView)
  3. function ClubZhanJiDanjuView:ctor(gid, zhanjiInfo, tableIdx)
  4. ClubZhanJiDanjuView.super.ctor(self)
  5. self.gid = gid
  6. self.zhanjiInfo = zhanjiInfo;
  7. --从房间返回茶馆的桌子标识
  8. self.tableIdx = tableIdx
  9. self.gamerule = self.zhanjiInfo.gext.gamerule
  10. self.roomid = self.zhanjiInfo.roomid
  11. self.endTime = self.zhanjiInfo.endtime
  12. self.tscore = self.zhanjiInfo.tscore
  13. self.detail = self.zhanjiInfo.detail
  14. self.ui = loadUI("res/ui/ui_club/ui_club_zhanji_danju.ui")
  15. self:addChild(self.ui)
  16. self.isTouch = {}
  17. end
  18. function ClubZhanJiDanjuView:onEnter()
  19. ClubZhanJiDanjuView.super.onEnter(self)
  20. -- 关闭按钮
  21. self.ui.Items.Button:registerClick(handler(self, self.onClickClose))
  22. self.ui.Items.Layout_item:setVisible(false)
  23. self.ui.Items.Layout_player_score:setVisible(false)
  24. self.ui.Items.Layout_score_count_item:setVisible(false)
  25. --将玩家uid存起来
  26. self:saveUserID()
  27. self:showZhanJiDanjuInfo()
  28. end
  29. function ClubZhanJiDanjuView:saveUserID()
  30. --记录玩家UID顺序
  31. self.userIds = {}
  32. local idx = 0
  33. for uid,v in pairsByKeys(self.zhanjiInfo.tscore) do
  34. idx = idx + 1
  35. self.userIds[idx] = tonumber(uid)
  36. end
  37. end
  38. function ClubZhanJiDanjuView:showZhanJiDanjuInfo()
  39. local function sortFuncEx(a,b)
  40. local numA = toNumber(a.endtime)
  41. local numB = toNumber(b.endtime)
  42. if numA ~= nil and numB ~= nil then
  43. return numA < numB
  44. else
  45. return a < b
  46. end
  47. end
  48. -- 每局信息
  49. local uiScrollView = self.ui.Items.ScrollView;
  50. uiScrollView:getInnerContainer():setAutoSize(true)
  51. uiScrollView:getInnerContainer():setAnchorPoint(cc.p(0,1))
  52. uiScrollView:removeAllChildren()
  53. uiScrollView:hideAllBar()
  54. local scoreLayout = self.ui.Items.Layout_score_count
  55. local uiTemplate = self.ui.Items.Layout_score_count_item
  56. local contentSize = self.ui.Items.Layout_score_count:getContentSize();
  57. local scoreSize = table.nums(self.userIds)
  58. local gameConfig = getSubGameConfig(self.zhanjiInfo.gameid) or {}
  59. for uid, score in pairsByKeys(self.zhanjiInfo.tscore) do
  60. local uiItem = uiTemplate:getCopied()
  61. uiItem:setSize(cc.size(contentSize.width / scoreSize, contentSize.height))
  62. uiItem.Items = getUIItems(uiItem)
  63. if gameConfig.isUseDivision10 then
  64. score = score / 10
  65. end
  66. -- 积分总计
  67. if score > 0 then
  68. score = "+"..tostring(score)
  69. --红色
  70. uiItem.Items.Text_score_count:setFntFile("res/fonts/zhanji_win.fnt")
  71. else
  72. --绿色
  73. uiItem.Items.Text_score_count:setFntFile("res/fonts/zhanji_lose.fnt")
  74. end
  75. uiItem.Items.Text_score_count:setText(score)
  76. scoreLayout:addChild(uiItem);
  77. end
  78. --游戏是否为字牌或麻将
  79. local isCommon = false
  80. if self.zhanjiInfo.gameid then
  81. local gameConfig = getSubGameConfig(self.zhanjiInfo.gameid)
  82. if not gameConfig.zhanjiDanjuView then
  83. isCommon = true
  84. end
  85. end
  86. if isCommon then
  87. --logD("self.detail:",table.tostring(self.detail))
  88. for idx, detail in pairsByKeys(self.detail) do
  89. local tt = {}
  90. if type(detail) == "table" then
  91. for k, v in pairsByKeys(detail) do
  92. table.insert(tt,v)
  93. end
  94. table.sort(tt,sortFuncEx)
  95. else
  96. tt = detail
  97. end
  98. for lunshu, detail2 in pairsByKeys(tt) do
  99. local item = import("luaScript.Views.Club.ClubZhanJiDanjuItem"):new(self.gamerule, self.zhanjiInfo, detail2, self.endTime, idx, self.tableIdx);
  100. if item then
  101. uiScrollView:addChild(item.ui)
  102. end
  103. end
  104. end
  105. else
  106. --这部分应该没有游戏来了
  107. showTooltip("")
  108. for idx, detailInfo in pairsByKeys(self.zhanjiInfo.detail) do
  109. for lunshu, detail in pairsByKeys(detailInfo) do
  110. local zhanjiDanJuView = getSubGameZhanjiDanJuView(self.zhanjiInfo.gameid)
  111. if zhanjiDanJuView then
  112. local fromClub = true;
  113. local view = import(zhanjiDanJuView):new(detail)
  114. view:setAnchorPoint(cc.p(0.5, 0.5))
  115. app:showWaitDialog(view)
  116. else
  117. showTooltip("未找到单局战绩详情的配置文件!!!")
  118. end
  119. end
  120. end
  121. end
  122. uiScrollView:jumpToTop()
  123. uiScrollView:requestDoLayout()
  124. uiScrollView:doLayout();
  125. end
  126. function ClubZhanJiDanjuView:showPlayerScore(scoreNode, detail)
  127. local uiTemplate = self.ui.Items.Layout_player_score;
  128. local scoreList = detail.score
  129. local contentSize = scoreNode:getContentSize();
  130. local scoreSize = table.nums(scoreList)
  131. for uid,score in pairsByKeys(scoreList) do
  132. local uiItem = uiTemplate:getCopied()
  133. uiItem:setSize(cc.size(contentSize.width / scoreSize, contentSize.height))
  134. uiItem.Items = getUIItems(uiItem)
  135. if score > 0 then
  136. score = "+"..tostring(score)
  137. uiItem.Items.TextBMFont_score:setFntFile("res/fonts/zhanji_win.fnt")
  138. else
  139. uiItem.Items.TextBMFont_score:setFntFile("res/fonts/zhanji_lose.fnt")
  140. end
  141. uiItem.Items.TextBMFont_score:setText(score)
  142. --名字
  143. local playerInfo = app.playerInfoManager:getPlayerInfo(uid);
  144. if playerInfo then
  145. local len = string.len(playerInfo.name)
  146. if len == 0 then
  147. playerInfo.name = "未知昵称"
  148. end
  149. playerInfo.name = getSubStringNickname(playerInfo.name)
  150. uiItem.Items.Text_player_name:setText(playerInfo.name)
  151. end
  152. scoreNode:addChild(uiItem);
  153. end
  154. end
  155. --显示玩家牌型
  156. function ClubZhanJiDanjuView:showPaixing(layoutContain, paiTemplate, detail)
  157. local contentSize = layoutContain:getContentSize();
  158. local scoreList = detail.score
  159. local scoreSize = table.nums(scoreList)
  160. for i = 1, scoreSize do
  161. local uid = self.userIds[i]
  162. local uiPlayer = paiTemplate:getCopied()
  163. local copyUISize = uiPlayer:getContentSize();
  164. -- 庄家
  165. local banberId = 0;
  166. if detail.ext then
  167. banberId = detail.ext.banker or 0
  168. end
  169. -- 详情
  170. if detail.user and detail.user[tostring(uid)] then
  171. local info = detail.user[tostring(uid)]
  172. uiPlayer:setSize(cc.size(contentSize.width / scoreSize, contentSize.height))
  173. uiPlayer.Items = getUIItems(uiPlayer);
  174. -- 是否庄家
  175. local isBanker = (tonumber(uid) == tonumber(banberId))
  176. uiPlayer.Items.ImageView_Zhuang:setVisible(isBanker)
  177. -- 下注分数
  178. if not isBanker then
  179. uiPlayer.Items.Text_score:setText(tostring(info.chipscore or 0))
  180. else
  181. uiPlayer.Items.Layout_difen:setVisible(false)
  182. end
  183. -- 手牌
  184. local cards = string.split(info.hand, " ")
  185. local cardData = cards[1]
  186. --牌型为0x00时,表示玩家在旁观,不显示牌
  187. if cardData and cardData ~= "" and cardData ~= "0x00" then
  188. if cards and table.nums(cards) > 0 then
  189. for idx, value in ipairs(cards) do
  190. local uiCard = import("Views.ZhanJi.BJZhanJiDanJuCard"):new()
  191. uiCard:updateCardValue(tonumber(value))
  192. local nameLayout = string.format("Layout_Card_%d", idx)
  193. local nodeLayout = uiPlayer.Items[nameLayout]
  194. if nodeLayout then
  195. nodeLayout:addChild(uiCard.ui)
  196. end
  197. end
  198. end
  199. -- 牌型
  200. if info.handtype == 0 or info.handtype < -1 then
  201. uiPlayer.Items.Layout_cardType:setVisible(false)
  202. else
  203. local card_type_image = getImageByCardType(info.handtype)
  204. if card_type_image then
  205. uiPlayer.Items.ImageView_CardType:loadTexture(card_type_image, cc.TextureResType.plistType)
  206. end
  207. end
  208. layoutContain:addChild(uiPlayer);
  209. else
  210. --创建一个空的layout,只占位
  211. local mLayout = cc.Layout:createNode()
  212. mLayout:setAnchorPoint(cc.p(0,0))
  213. mLayout:setSize(copyUISize)
  214. layoutContain:addChild(mLayout);
  215. end
  216. else
  217. --创建一个空的layout,只占位
  218. local mLayout = cc.Layout:createNode()
  219. mLayout:setAnchorPoint(cc.p(0,0))
  220. mLayout:setSize(copyUISize)
  221. layoutContain:addChild(mLayout);
  222. end
  223. end
  224. end
  225. -- 关闭响应函数
  226. function ClubZhanJiDanjuView:onClickClose()
  227. playBtnCloseEffect()
  228. self:removeFromParent()
  229. end
  230. return ClubZhanJiDanjuView