-- 单局战绩界面 local ClubZhanJiDanjuView = class("ClubZhanJiDanjuView", cc.UIView) function ClubZhanJiDanjuView:ctor(gid, zhanjiInfo, tableIdx) ClubZhanJiDanjuView.super.ctor(self) self.gid = gid self.zhanjiInfo = zhanjiInfo; --从房间返回茶馆的桌子标识 self.tableIdx = tableIdx self.gamerule = self.zhanjiInfo.gext.gamerule self.roomid = self.zhanjiInfo.roomid self.endTime = self.zhanjiInfo.endtime self.tscore = self.zhanjiInfo.tscore self.detail = self.zhanjiInfo.detail self.ui = loadUI("res/ui/ui_club/ui_club_zhanji_danju.ui") self:addChild(self.ui) self.isTouch = {} end function ClubZhanJiDanjuView:onEnter() ClubZhanJiDanjuView.super.onEnter(self) -- 关闭按钮 self.ui.Items.Button:registerClick(handler(self, self.onClickClose)) self.ui.Items.Layout_item:setVisible(false) self.ui.Items.Layout_player_score:setVisible(false) self.ui.Items.Layout_score_count_item:setVisible(false) --将玩家uid存起来 self:saveUserID() self:showZhanJiDanjuInfo() end function ClubZhanJiDanjuView:saveUserID() --记录玩家UID顺序 self.userIds = {} local idx = 0 for uid,v in pairsByKeys(self.zhanjiInfo.tscore) do idx = idx + 1 self.userIds[idx] = tonumber(uid) end end function ClubZhanJiDanjuView:showZhanJiDanjuInfo() local function sortFuncEx(a,b) local numA = toNumber(a.endtime) local numB = toNumber(b.endtime) if numA ~= nil and numB ~= nil then return numA < numB else return a < b end end -- 每局信息 local uiScrollView = self.ui.Items.ScrollView; uiScrollView:getInnerContainer():setAutoSize(true) uiScrollView:getInnerContainer():setAnchorPoint(cc.p(0,1)) uiScrollView:removeAllChildren() uiScrollView:hideAllBar() local scoreLayout = self.ui.Items.Layout_score_count local uiTemplate = self.ui.Items.Layout_score_count_item local contentSize = self.ui.Items.Layout_score_count:getContentSize(); local scoreSize = table.nums(self.userIds) local gameConfig = getSubGameConfig(self.zhanjiInfo.gameid) or {} for uid, score in pairsByKeys(self.zhanjiInfo.tscore) do local uiItem = uiTemplate:getCopied() uiItem:setSize(cc.size(contentSize.width / scoreSize, contentSize.height)) uiItem.Items = getUIItems(uiItem) if gameConfig.isUseDivision10 then score = score / 10 end -- 积分总计 if score > 0 then score = "+"..tostring(score) --红色 uiItem.Items.Text_score_count:setFntFile("res/fonts/zhanji_win.fnt") else --绿色 uiItem.Items.Text_score_count:setFntFile("res/fonts/zhanji_lose.fnt") end uiItem.Items.Text_score_count:setText(score) scoreLayout:addChild(uiItem); end --游戏是否为字牌或麻将 local isCommon = false if self.zhanjiInfo.gameid then local gameConfig = getSubGameConfig(self.zhanjiInfo.gameid) if not gameConfig.zhanjiDanjuView then isCommon = true end end if isCommon then --logD("self.detail:",table.tostring(self.detail)) for idx, detail in pairsByKeys(self.detail) do local tt = {} if type(detail) == "table" then for k, v in pairsByKeys(detail) do table.insert(tt,v) end table.sort(tt,sortFuncEx) else tt = detail end for lunshu, detail2 in pairsByKeys(tt) do local item = import("luaScript.Views.Club.ClubZhanJiDanjuItem"):new(self.gamerule, self.zhanjiInfo, detail2, self.endTime, idx, self.tableIdx); if item then uiScrollView:addChild(item.ui) end end end else --这部分应该没有游戏来了 showTooltip("") for idx, detailInfo in pairsByKeys(self.zhanjiInfo.detail) do for lunshu, detail in pairsByKeys(detailInfo) do local zhanjiDanJuView = getSubGameZhanjiDanJuView(self.zhanjiInfo.gameid) if zhanjiDanJuView then local fromClub = true; local view = import(zhanjiDanJuView):new(detail) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) else showTooltip("未找到单局战绩详情的配置文件!!!") end end end end uiScrollView:jumpToTop() uiScrollView:requestDoLayout() uiScrollView:doLayout(); end function ClubZhanJiDanjuView:showPlayerScore(scoreNode, detail) local uiTemplate = self.ui.Items.Layout_player_score; local scoreList = detail.score local contentSize = scoreNode:getContentSize(); local scoreSize = table.nums(scoreList) for uid,score in pairsByKeys(scoreList) do local uiItem = uiTemplate:getCopied() uiItem:setSize(cc.size(contentSize.width / scoreSize, contentSize.height)) uiItem.Items = getUIItems(uiItem) if score > 0 then score = "+"..tostring(score) uiItem.Items.TextBMFont_score:setFntFile("res/fonts/zhanji_win.fnt") else uiItem.Items.TextBMFont_score:setFntFile("res/fonts/zhanji_lose.fnt") end uiItem.Items.TextBMFont_score:setText(score) --名字 local playerInfo = app.playerInfoManager:getPlayerInfo(uid); if playerInfo then local len = string.len(playerInfo.name) if len == 0 then playerInfo.name = "未知昵称" end playerInfo.name = getSubStringNickname(playerInfo.name) uiItem.Items.Text_player_name:setText(playerInfo.name) end scoreNode:addChild(uiItem); end end --显示玩家牌型 function ClubZhanJiDanjuView:showPaixing(layoutContain, paiTemplate, detail) local contentSize = layoutContain:getContentSize(); local scoreList = detail.score local scoreSize = table.nums(scoreList) for i = 1, scoreSize do local uid = self.userIds[i] local uiPlayer = paiTemplate:getCopied() local copyUISize = uiPlayer:getContentSize(); -- 庄家 local banberId = 0; if detail.ext then banberId = detail.ext.banker or 0 end -- 详情 if detail.user and detail.user[tostring(uid)] then local info = detail.user[tostring(uid)] uiPlayer:setSize(cc.size(contentSize.width / scoreSize, contentSize.height)) uiPlayer.Items = getUIItems(uiPlayer); -- 是否庄家 local isBanker = (tonumber(uid) == tonumber(banberId)) uiPlayer.Items.ImageView_Zhuang:setVisible(isBanker) -- 下注分数 if not isBanker then uiPlayer.Items.Text_score:setText(tostring(info.chipscore or 0)) else uiPlayer.Items.Layout_difen:setVisible(false) end -- 手牌 local cards = string.split(info.hand, " ") local cardData = cards[1] --牌型为0x00时,表示玩家在旁观,不显示牌 if cardData and cardData ~= "" and cardData ~= "0x00" then if cards and table.nums(cards) > 0 then for idx, value in ipairs(cards) do local uiCard = import("Views.ZhanJi.BJZhanJiDanJuCard"):new() uiCard:updateCardValue(tonumber(value)) local nameLayout = string.format("Layout_Card_%d", idx) local nodeLayout = uiPlayer.Items[nameLayout] if nodeLayout then nodeLayout:addChild(uiCard.ui) end end end -- 牌型 if info.handtype == 0 or info.handtype < -1 then uiPlayer.Items.Layout_cardType:setVisible(false) else local card_type_image = getImageByCardType(info.handtype) if card_type_image then uiPlayer.Items.ImageView_CardType:loadTexture(card_type_image, cc.TextureResType.plistType) end end layoutContain:addChild(uiPlayer); else --创建一个空的layout,只占位 local mLayout = cc.Layout:createNode() mLayout:setAnchorPoint(cc.p(0,0)) mLayout:setSize(copyUISize) layoutContain:addChild(mLayout); end else --创建一个空的layout,只占位 local mLayout = cc.Layout:createNode() mLayout:setAnchorPoint(cc.p(0,0)) mLayout:setSize(copyUISize) layoutContain:addChild(mLayout); end end end -- 关闭响应函数 function ClubZhanJiDanjuView:onClickClose() playBtnCloseEffect() self:removeFromParent() end return ClubZhanJiDanjuView