-- 单局战绩界面 local ZhanJiDanjuView = class("ZhanJiDanjuView", cc.UIView) function ZhanJiDanjuView:ctor(zhanjiInfo) ZhanJiDanjuView.super.ctor(self) --所有游戏战绩协议 -- app.allZhanji = ZhanjiAllGame; --战绩数据 self.zhanjiInfo = zhanjiInfo; self.ui = loadUI("res/ui/ui_zhanji/zhanji_danju.ui") self:addChild(self.ui) self.gameID = tonumber(self.zhanjiInfo.gameid) self.isTouch = {} end function ZhanJiDanjuView:onEnter() ZhanJiDanjuView.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 ZhanJiDanjuView: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 ZhanJiDanjuView: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 scoreLayout:removeAllChildren() 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.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 uiTemplate = self.ui.Items.Layout_item; for idx, detailInfo in pairsByKeys(self.zhanjiInfo.detail) do local tt = {} if type(detailInfo) == "table" then for k, v in pairsByKeys(detailInfo) do table.insert(tt,v) end table.sort(tt,sortFuncEx) else tt = detailInfo end for lunshu, detail in pairsByKeys(tt) do local uiItem = uiTemplate:getCopied() autoAdaptWidth(uiItem) uiItem.Items = getUIItems(uiItem) uiItem.Items.ImageView_Flag:setVisible(false) --第几局 uiItem.Items.TextBMFont_num:setText(tonumber(idx)) --时间 local time = os.date("%m-%d %H:%M",detail.endtime or self.zhanjiInfo.endtime) uiItem.Items.Text_time:setText(time) -- 0=正常结束 1=吃臭牌 2=吃牌不比 3=无牌赔包子 4=胡臭牌 7=黄庄 8=长时间自动解散 9=解散游戏 , 如果为0、8、9则表示正常结束 local endFlag = detail.flag if endFlag == 8 or endFlag == 9 or endFlag == 22 or endFlag == 25 or endFlag == 10 then uiItem.Items.ImageView_Flag:setVisible(true) local function updatePlayerScore()--解散的局,需要解散信息, app.waitDialogManager:closeWaitNetworkDialog(); self:showZhanJiDanjuInfo() end if (not detail.ext or not detail.ext.disbandStatus) and not self.alreadyReq then self.alreadyReq = true--已经请求过了,保证只请求一次 app.waitDialogManager:showWaitNetworkDialog("请求数据中..."); app.allZhanji:getZhanJiDetail(self.zhanjiInfo.pid, detail.subid, updatePlayerScore) return end end if endFlag == 8 then uiItem.Items.Text_disbandUids:setText('房间占用超时解散') end if endFlag == 22 then--管理解散 uiItem.Items.Text_disbandUids:setText('解散人: ' .. detail.ext.disbandUids) end --玩家分数 self:showPlayerScore(uiItem.Items.Layout_score, detail) uiItem.Items.Button_record:setVisible(true) uiItem.Items.Button_down:setVisible(false) uiItem.Items.Button_up:setVisible(false) -- 回放 uiItem.Items.Button_record:registerClick(function () playBtnEffect() local pid = self.zhanjiInfo.pid local subid = detail.subid -- 显示加载界面,直到加载完毕 local function showZhanjiRecord() local zhanjiInfo = app.allZhanji.zhanjiInfoList[pid] if not zhanjiInfo then logD("zhanjiInfo:"..table.tostring(zhanjiInfo)) showTooltip("回放数据不存在") return end if not zhanjiInfo.detail then logD("zhanjiInfo.detail:"..table.tostring(zhanjiInfo.detail)) showTooltip("回放数据不存在") return end local lunDetail for jushu, jushuInfo in pairs(zhanjiInfo.detail) do for lunshu, lunshuInfo in pairs(jushuInfo) do if lunshuInfo.subid == subid then lunDetail = lunshuInfo end end end if not lunDetail then logD("lunDetail:"..table.tostring(lunDetail)) showTooltip("回放数据不存在") return end --拼接字段,此字段php未下发 lunDetail.curCount = self.idx lunDetail.totalCount = self.zhanjiInfo.nbound lunDetail.roomNum = self.zhanjiInfo.roomid lunDetail.roomid = self.zhanjiInfo.roomid--兼容跑得快回放数据 lunDetail.nbound = self.zhanjiInfo.nbound--兼容跑得快回放数据 logD("lunDetail:"..table.tostring(lunDetail)) if not lunDetail or not lunDetail.user then showTooltip("回放数据不存在") return end if table.nums(lunDetail.user) <= 0 then showTooltip("游戏解散了") return end --[[if lunDetail.flag == 8 or lunDetail.flag == 9 then showTooltip("游戏解散了") return end--]] for uid, userInfo in pairs(lunDetail.user) do --玩家信息 local playerInfo = app.playerInfoManager:getPlayerInfo(uid) if playerInfo then userInfo.nick = playerInfo.name or "" userInfo.head = playerInfo.head or "" userInfo.sex = playerInfo.sex or 0 else userInfo.nick = "游客"..tostring(uid) userInfo.head = "" userInfo.sex = 0 end --总分 userInfo.tscore = zhanjiInfo.tscore[tostring(uid)] if not userInfo.hand then showTooltip("游戏解散了") return end end local recordClass = getSubGameZhanjiRecordView(self.zhanjiInfo.gameid); local config = getSubGameConfig(tonumber(self.zhanjiInfo.gameid)) app:changeGameProtocol(tonumber(self.zhanjiInfo.gameid), 1) if config and config.belongType==3 then local MJRoomReplayView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomReplayView") local view = MJRoomReplayView:new(lunDetail) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) elseif recordClass then local view = import(recordClass):new(lunDetail); view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end end app.allZhanji:getZhanJiDetail(self.zhanjiInfo.pid, detail.subid, showZhanjiRecord) end); uiItem:setTag(idx) --查看牌型(与回放不会同时出现) uiScrollView:addChild(uiItem) end end uiScrollView:jumpToTop() uiScrollView:requestDoLayout() uiScrollView:doLayout(); end function ZhanJiDanjuView:showPlayerScore(scoreNode, detail) local uiTemplate = self.ui.Items.Layout_player_score; local scoreList = detail.score local endFlag = detail.flag local jiesanInfo if detail.ext and detail.ext.disbandStatus then jiesanInfo = detail.ext.disbandStatus elseif detail.ext and detail.ext.jiesan then jiesanInfo = detail.ext.jiesan end local extUidInfo if detail.ext and detail.ext.disbandUids then extUidInfo = detail.ext.disbandUids end local contentSize = scoreNode:getContentSize(); local scoreSize = table.nums(scoreList) local gameConfig = getSubGameConfig(self.gameID) or {} 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 gameConfig.isUseDivision10 then score = score / 10 end 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 if endFlag == 9 and jiesanInfo then uiItem.Items.Text_jiesanInfo:setVisible(true) if jiesanInfo[uid] and jiesanInfo[uid] == 0 then uiItem.Items.Text_jiesanInfo:setText("超时解散") uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(0,255,0)) elseif jiesanInfo[uid] and jiesanInfo[uid] == 1 then uiItem.Items.Text_jiesanInfo:setText("申请解散") uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0)) elseif jiesanInfo[uid] and jiesanInfo[uid] == 2 then uiItem.Items.Text_jiesanInfo:setText("同意解散") uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(0,255,0)) elseif jiesanInfo[uid] and jiesanInfo[uid] == 3 then uiItem.Items.Text_jiesanInfo:setText("拒绝解散") end elseif endFlag == 8 then--系统解散 uiItem.Items.Text_jiesanInfo:setVisible(true) uiItem.Items.Text_jiesanInfo:setText("系统解散") uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0)) elseif endFlag == 10 then--托管解散 local autoDisArr = string.split(extUidInfo,";") or {} if table.indexOf(autoDisArr, uid) >= 0 then uiItem.Items.Text_jiesanInfo:setVisible(true) uiItem.Items.Text_jiesanInfo:setText("托管解散") uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0)) else uiItem.Items.Text_jiesanInfo:setVisible(false) end elseif endFlag == 23 then--其他解散 uiItem.Items.Text_jiesanInfo:setVisible(true) uiItem.Items.Text_jiesanInfo:setText("房卡不足") uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0)) elseif endFlag == 25 then--比赛淘汰 local eliminateArr = string.split(extUidInfo,";") or {} if table.indexOf(eliminateArr, uid) >= 0 then uiItem.Items.Text_jiesanInfo:setVisible(true) uiItem.Items.Text_jiesanInfo:setText("比赛淘汰") uiItem.Items.Text_jiesanInfo:setColor(cc.c3b(255,0,0)) else uiItem.Items.Text_jiesanInfo:setVisible(false) end else uiItem.Items.Text_jiesanInfo:setVisible(false) end scoreNode:addChild(uiItem); end end -- 关闭响应函数 function ZhanJiDanjuView:onClickClose() playBtnCloseEffect() self:removeFromParent() end --显示玩家牌型 function ZhanJiDanjuView: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 return ZhanJiDanjuView