-- 战绩单元Layout local ClubDefine = require("luaScript.Protocol.Club.ClubDefine") local ClubZhanJiItem = class("ClubZhanJiItem") function ClubZhanJiItem:ctor(gid, zhanjiType, infoData, tableIdx,index) self.gid = gid self.zhanjiType = zhanjiType self.roomInfo = infoData --从房间返回茶馆的桌子标识 self.tableIdx = tableIdx --序号 self.index = index self.detailTxtColor = cc.c4b(213,255,249,255) self:initView() end --初始化界面 function ClubZhanJiItem:initView() self.ui = loadUI("res/ui/ui_zhanji/ui_zhanji_item.ui") local uiSize = self.ui:getSize(); local realSize = {width = uiSize.width * g_radio_x,height = uiSize.height * g_radio_y} self.ui:setSize(realSize) self.ui.Items.Layout_player:setVisible(false) self.ui.Items.Layout_game_title_club:setVisible(false) self.ui.Items.Layout_game_title_me:setVisible(false) self.ui.Items.Button_xiangqing:registerClick(handler(self , self.onClickDetails)) self.ui.Items.Button_url:registerClick(handler(self , self.onClickShareUrl)) if not app.config.ModuleConfig.IsSupportZhanJiUrl or isReviewVersion() then self.ui.Items.Layout_1:setVisible(false) self.ui.Items.Layout_Button:requestDoLayout() self.ui.Items.Layout_Button:doLayout() end -- self.ui.Items.Button_copy:getParent():setVisible(false) self.ui.Items.Button_Sure:registerClick(handler(self , self.onClickSure)) self:init() end function ClubZhanJiItem:getRoot() return self.ui end function ClubZhanJiItem:init() local club = app.club_php.clubList[self.gid] if club and club.role~=ClubDefine.Job.Member and club.role~=ClubDefine.Job.LevelTwoCopartner and club.role~=ClubDefine.Job.LevelOneCopartner and club.role~=ClubDefine.Job.LevelThreeCopartner and self.zhanjiType ~= ClUB_ZHANJI_TYPE.Mine then if app.club_zhanji.zhanJiIdxStatus[self.roomInfo.pid]==2 then --确认过 self.ui.Items.Button_Sure:setVisible(false) end else self.ui.Items.Layout_player_count:setSize(cc.size(885,105)) self.ui.Items.Button_Sure:getParent():setVisible(false) end self.ui.Items.Layout_Button:requestDoLayout() self.ui.Items.Layout_Button:doLayout() local scoreList = self.roomInfo.tscore --游戏icon local gameID = tonumber(self.roomInfo.gameid) local ruleID = tonumber(self.roomInfo.gext.gamerule) local gameName = getSubGameRuleName(gameID,ruleID) local gameConfig = getSubGameConfig(gameID) or {} -- local img = string.format("zhanji_game_%d.png",gameID) local isAAPay = 0 if self.roomInfo.gext and self.roomInfo.gext.isAAPay then isAAPay = tonumber(self.roomInfo.gext.isAAPay) end --结果 if self.zhanjiType == ClUB_ZHANJI_TYPE.Mine then --我的战绩(结果) self.ui.Items.ImageView_flag:setVisible(true) local myscore = scoreList[tostring(app.user.loginInfo.uid)] if myscore and myscore > 0 then self.ui.Items.ImageView_flag:loadTexture("res/ui/zy_dating/zhanji/zhanji_win_icon.png") else self.ui.Items.ImageView_flag:loadTexture("res/ui/zy_dating/zhanji/zhanji_lose_icon.png") end self.ui.Items.Layout_game_title_me:setVisible(true) self.ui.Items.Text_game_me:setString(gameName) self.ui.Items.Text_game_me_1:setString(gameName) -- self.ui.Items.ImageView_game_me:loadTextureFromPlist(img) else --茶馆战绩(房卡消耗) self.ui.Items.Layout_game_title_club:setVisible(true) self.ui.Items.ImageView_flag:setVisible(false) local cards = self.roomInfo.nCards if cards and cards ~= nil then if isAAPay == 1 then-- AA支付 self.ui.Items.Text_fangka:setText(cards.. PLN.CURRENCY_UNIT .. "(AA)"); else self.ui.Items.Text_fangka:setText(cards.. PLN.CURRENCY_UNIT); end end self.ui.Items.Text_game_club:setString(gameName) self.ui.Items.Text_game_club_1:setString(gameName) -- self.ui.Items.ImageView_game_club:loadTextureFromPlist(img) end --序号 self.ui.Items.Text_No:setText(self.index) --时间 local time = os.date("%Y-%m-%d %H:%M",self.roomInfo.endtime) self.ui.Items.Text_time:setText(time) --大赢家 --[[local maxScore = nil; for uid, score in pairs(scoreList) do if not maxScore or maxScore < score then maxScore = score; end end--]] --房号 local roomInfo = self.roomInfo.roomid; self.ui.Items.Text_roomid:setText("房号:"..roomInfo); --最终分数 local scorUI = self.ui.Items.Layout_player_count; --scorUI:getInnerContainer():setAutoSize(true); scorUI:removeAllChildren(); local scoreSize = table.nums(scoreList) --是否显示加减分 if self.ui.Items.ImageView_Rule then self.ui.Items.ImageView_Rule:setVisible(false) local diFenLimit = self.roomInfo.gext.game_ext and self.roomInfo.gext.game_ext.diFenLimit; if diFenLimit and diFenLimit > 0 and scoreSize == 2 then self.ui.Items.ImageView_Rule:setVisible(true) end end local pid = self.roomInfo.pid local listStr = app.club_zhanji.zhanJiIdxLocals[pid] local list = listStr and split(listStr,",") or nil local uiTemplate = self.ui.Items.Layout_player; local contentSize = scorUI:getContentSize(); for k,v in pairsByKeys(scoreList) do local uiItem = uiTemplate:getCopied() uiItem:setSize(cc.size(contentSize.width / scoreSize, contentSize.height)) uiItem.Items = getUIItems(uiItem) --名字 local playerInfo = app.playerInfoManager:getPlayerInfo(k); 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) if list then for _,uid in ipairs(list) do if tonumber(uid) == tonumber(k) then uiItem.Items.Text_player_name:setTextColor(cc.c4b(219,56,35,255)) end end end end if gameConfig.isUseDivision10 then v = v / 10 end --分数 if v > 0 then v = "+"..tostring(v) uiItem.Items.Text_score:setFntFile("res/fonts/zhanji_win.fnt") else --绿色 uiItem.Items.Text_score:setFntFile("res/fonts/zhanji_lose.fnt") end uiItem.Items.Text_score:setText(v) scorUI:addChild(uiItem); end scorUI:requestDoLayout() scorUI:doLayout() end function ClubZhanJiItem:setCallBackFun(callbackFun, object) self.m_callbackFun = callbackFun self.m_object = object end function ClubZhanJiItem:onClickDetails() playBtnEffect() local ui = loadUI("res/ui/ui_zhanji/ui_zhanji_item_menu.ui") local totalMenuCount = ui.Items.Layout_btn_menu:getChildrenCount() for idx = 1, totalMenuCount do ui.Items["Text_" .. idx]:setTextColor(self.detailTxtColor) ui.Items["Layout_Btn_" .. idx]:registerClick(function () ui:getParent():removeFromParent() playBtnEffect() self:onClickOperateMenu(idx) end) end local club = app.club_php.clubList[self.gid] if club and (club.role == 2 or club.role == 3) then ui.Items.Layout_Btn_4:setVisible(true) else ui.Items.Layout_Btn_4:setVisible(false) end if isReviewVersion() then ui.Items.Layout_Btn_3:setVisible(false) end ui.Items.Layout_btn_menu:requestDoLayout() ui.Items.Layout_btn_menu:doLayout() ui.Items.Layout:requestDoLayout() ui.Items.Layout:doLayout() local view = cc.UIView:new() view:setAnchorPoint(cc.p(0.5,0.5)) view:addChild(ui) --计算坐标偏移 local node = self.ui.Items.Button_xiangqing; local worldPos = node:getWorldPosition(); local viewContentSize = ui:getSize() --X坐标 local x = worldPos.x - node:getContentSize().width / 2 - 10; --10个像素间距 local y = worldPos.y --yhj:临界处理 --按钮离屏幕底部的距离 local fromBtnToBottomY = worldPos.y --viewContentSize的一半如果大于fromBtnToBottomY则有一部分的菜单按钮显示到了屏幕外 local distanBottom = viewContentSize.height/2 - fromBtnToBottomY if distanBottom > 0 then y = worldPos.y + distanBottom end --同样的考虑菜单过长时候,离顶部是否超越屏幕 local fromBtnToTopY = getWinSize().height - worldPos.y local distanTop = viewContentSize.height/2 - fromBtnToTopY if distanTop > 0 then y = worldPos.y - distanTop end local newPos = cc.p(x, y); view:setPosition(newPos); app:showWaitDialog(view, 0, true) end function ClubZhanJiItem:onClickOperateMenu(index) if index == 1 then -- 查看详情 -- local room = app.club_php:getMyInRoom() -- local view = app:getCurrentView() -- if room or view.__cname ~= "MainView" then -- showTooltip("正在游戏中,禁止查看回放") -- return -- end self:onBtnShowZhanJiDetailClicked() elseif index == 2 then -- 复制战绩 self:onBtnCopyZhanJiClicked() elseif index == 3 then -- 分享回放码 self:onBtnShareZhanJiCodeClicked() elseif index == 4 then -- 删除战绩 self:onBtnDeleteZhanJiClicked() end end -- 详情按钮 function ClubZhanJiItem:onBtnShowZhanJiDetailClicked() local gameID = tonumber(self.roomInfo.gameid) if not app.subGameManager:isInstaller(tonumber(gameID)) or app.subGameManager:isNeedUpdate(tonumber(gameID)) then --未下载时提示下载 requestDownloadSubGame(tonumber(gameID), function () showTooltip("下载完成") end, true) return; end -- 检查子游戏文件完整性 checkSubGameFiles(tonumber(gameID), function() self:onBtnShowZhanJiDetailClicked_do(gameID) end) end -- 详情按钮 function ClubZhanJiItem:onBtnShowZhanJiDetailClicked_do(gameID) --所有字牌和麻将,这里都不请求详情,而是在下个界面请求 local hasReplay = false local isJieSanGame = false local isNeedDown = false local gameConfig = getSubGameConfig(gameID) if gameConfig and (not gameConfig.zhanjiDanjuView) then local isJieSan = false for idx, detail in pairsByKeys(self.roomInfo.detail) do for lunshu, detail2 in pairsByKeys(detail) do if detail2.flag == 8 or detail2.flag == 9 then isJieSan = true break elseif detail2.flag == 22 or detail2.flag == 10 or detail2.flag == 25 then isNeedDown = true; break end end if isJieSan or isNeedDown then break end end if isJieSan or isNeedDown then isJieSanGame = true end hasReplay = true end local function showZhanJiDanJuView() --检查游戏是否有下载 if not app.subGameManager:isInstaller(tonumber(gameID)) or app.subGameManager:isNeedUpdate(tonumber(gameID)) then requestDownloadSubGame(tonumber(gameID), function () showTooltip("下载完成") end, true) return end local zhanjiDanJuView = getSubGameZhanjiDanJuView(gameID) if zhanjiDanJuView then local fromClub = true; local view = import(zhanjiDanJuView):new(self.roomInfo,true)--第二个参数是茶馆战绩 view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) else showTooltip("未找到单局战绩详情的配置文件!!!") end end local function showClubDanJuView() local view = import("luaScript.Views.Club.ClubZhanJiDanjuView"):new(self.gid, self.roomInfo, self.tableIdx) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end if hasReplay then if isJieSanGame then logD("self.roomInfo.detail:",table.tostring(self.roomInfo.detail)) for idx, detail in pairsByKeys(self.roomInfo.detail) do if toNumber(idx) == table.nums(self.roomInfo.detail) then --取最后一条战绩详情 if type(detail) == "table" then --单局有多个结束的只拉取最后一条 for lunshu, detail2 in pairsByKeys(detail) do if toNumber(lunshu) == table.nums(detail) then app.club_zhanji:getZhanJiDetail(self.roomInfo.pid, detail2.subid, showClubDanJuView) end end else --单局只有一局的 app.club_zhanji:getZhanJiDetail(self.roomInfo.pid, detail.subid, showClubDanJuView) end end end else showClubDanJuView(); end else app.club_zhanji:getZhanJiDetail(self.roomInfo.pid, 0, showZhanJiDanJuView) end end function ClubZhanJiItem:onClickSure() playBtnEffect() local club = app.club_php.clubList[self.gid] if club then if app.club_zhanji.zhanJiIdxStatus[self.roomInfo.pid]==2 then --确认过 self.ui.Items.Button_Sure:setVisible(false) return end end app.club_zhanji:requestZhanjiSure(self.gid,self.roomInfo.pid,function() if not tolua.isnull(self.ui) then self.ui.Items.Button_Sure:setVisible(false) end end) end function ClubZhanJiItem:onClickShareUrl() -- app.waitDialogManager:showWaitNetworkDialog("获取分享链接") -- local onGetUrlCallback = function(url) -- app.waitDialogManager:closeWaitNetworkDialog() -- if url then -- local view = import("luaScript.Views.Main.ShareZhanJiUrlView"):new(url,self.roomInfo) -- view:setAnchorPoint(cc.p(0.5, 0.5)) -- app:showWaitDialog(view) -- else -- showTooltip("获取分享用的链接失败") -- end -- end -- app.php:initShareZhanJiToUrl(onGetUrlCallback); app.serverConfigs:requestClientConfig(function() local url = app.serverConfigs.clientConfig.webgamb or RomSetting.ZhanJiUrl local view = import("luaScript.Views.Main.ShareZhanJiUrlView"):new(url,self.roomInfo) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end) end --- ClubZhanJiItem:onBtnCopyZhanJiClicked 复制战绩 function ClubZhanJiItem:onBtnCopyZhanJiClicked() local gameID = tonumber(self.roomInfo.gameid) local scoreList = self.roomInfo.tscore local roomInfo = self.roomInfo.roomid local ext = self.roomInfo.gext or {} local gameRule = ext.gamerule local time = os.date("%Y-%m-%d %H:%M",self.roomInfo.endtime) local scoreStr = "" local gameConfig = getSubGameConfig(gameID) or {} for k,score in pairsByKeys(scoreList) do --名字 local playerInfo = app.playerInfoManager:getPlayerInfo(k) if playerInfo then local len = string.len(playerInfo.name) if len == 0 then playerInfo.name = "未知昵称" end if gameConfig.isUseDivision10 then score = score / 10 end scoreStr = string.format("%s[%s] %s分\n", scoreStr, playerInfo.name,score>=0 and "+".. score or score) end end local gameName = getSubGameRuleName(gameID, gameRule) local endStr = "竞技成绩仅供娱乐,禁止赌博!" local copyData = string.format("[%s]\n房间号:%s\n结束时间:%s\n成绩:\n%s\n%s", gameName, roomInfo, time, scoreStr, endStr) logD("copyData:"..copyData) copyStringToClipboard(copyData) showTooltip("战绩复制成功!") end --- ClubZhanJiItem:onBtnShareZhanJiCodeClicked 分享回放码 function ClubZhanJiItem:onBtnShareZhanJiCodeClicked() local gameID = tonumber(self.roomInfo.gameid) local ext = self.roomInfo.gext or {} local gameRule = ext.gamerule local gameName = getSubGameRuleName(gameID, gameRule) local title = string.format("[%s]战绩回放码分享", gameName) local content = self.roomInfo.pid local info = {} info.ClubID = self.gid info.title = title info.description = content info.url = app.club_zhanji.shareUrl.."?app="..getAppId().."&code="..self.roomInfo.pid -- print("用户开始分享") --需要显示的按钮(1:微信 2:复制 3:茶馆 ) info.menuIdxs = {1,4,5,6} -- if type(copyData) == "string" then -- info.copyData = copyData -- else -- info.copyData = "" -- end logD("回放分享:",table.tostring(info)) local view = import("luaScript.Views.Main.ShareView"):new(info) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end --- ClubZhanJiItem:onBtnDeleteZhanJiClicked 删除战绩 function ClubZhanJiItem:onBtnDeleteZhanJiClicked() local function confirmCallback () app.club_zhanji:requestDeleteZhanJi(self.gid, self.roomInfo.pid, 1) end local str = "确认删除这条战绩吗?删除后所有玩家将不可见!" local function cancelCallback () end showConfirmDialog(str, confirmCallback, cancelCallback) end return ClubZhanJiItem