-- 战绩单元Layout -- local ZhanjiAllGame = require("luaScript.Protocol.ProtocolZhanJiGame"):new(-1, "zhanji_AllGame"); local ZhanJiItem = class("ZhanJiItem") function ZhanJiItem:ctor(zhanjiType, infoData,index) self.zhanjiType = zhanjiType self.roomInfo = infoData --序号 self.index = index self.detailTxtColor = cc.c4b(213,255,249,255) self:initView() end --初始化界面 function ZhanJiItem:initView() self.ui = loadUI("res/ui/ui_zhanji/ui_zhanji_item.ui") autoAdaptWidth(self.ui) 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 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_Sure:registerClick(handler(self , self.onClickSure)) self:init() end function ZhanJiItem:getRoot() return self.ui end function ZhanJiItem:init() self.ui.Items.Layout_player_count:setSize(cc.size(885,105)) self.ui.Items.Button_Sure:getParent():setVisible(false) 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 gameConfig = getSubGameConfig(gameID) or {} local gameName = getSubGameRuleName(gameID,ruleID) self.ui.Items.Layout_game_title_club:setVisible(false) self.ui.Items.Layout_game_title_me:setVisible(true) --结果 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.Text_game_me:setString(gameName) self.ui.Items.Text_game_me_1:setString(gameName) --序号 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 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) --[[--大赢家 local isWin = (v == maxScore); if isWin then self.ui.Items.Text_winer_name:setText(playerInfo.name) 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 ZhanJiItem:setCallBackFun(callbackFun, object) self.m_callbackFun = callbackFun self.m_object = object end function ZhanJiItem:onClickDetails() playBtnEffect() local ui = loadUI("res/ui/ui_zhanji/ui_zhanji_item_menu.ui") ui.Items.Layout_Btn_4:setVisible(false) --查看详情 ui.Items.Layout_Btn_1:registerClick(function() self:onClickLookDetails() ui:getParent():removeFromParent() end) --复制战绩 ui.Items.Layout_Btn_2:registerClick(function() self:onClickCopy() ui:getParent():removeFromParent() end) --分享回放码 ui.Items.Layout_Btn_3:registerClick(function() ui:getParent():removeFromParent() 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.title = title info.description = content --TODO 战绩URL需要获取 info.url = app.allZhanji.shareUrl.."?app="..getAppId().."&code="..self.roomInfo.pid --info.url = "http://m.ddpenghu.com/replay.php?app="..getAppId().."&code="..self.roomInfo.pid --ZhanjiAllGame.shareUrl.. -- print("用户开始分享") --需要显示的按钮(1:微信 2:复制 3:茶馆) info.menuIdxs = {1,4,5,6} 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) -- 分享网页战绩 -- ui.Items.Button_4:registerClick(function() -- self:onClickSure() -- end) local totalMenuCount = ui.Items.Layout_btn_menu:getChildrenCount() for idx = 1, totalMenuCount do ui.Items["Text_" .. idx]:setTextColor(self.detailTxtColor) 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 ZhanJiItem:onClickLookDetails() playBtnEffect() 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 -- -- 先注册战绩协议 -- app:addProtocolZhanJi(gameID) -- -- 拉取战绩数据 -- local protocolZhanJi = app:getProtocolZhanJi(gameID) -- if protocolZhanJi then -- protocolZhanJi:init() -- end local function showDanJuView() local zhanjiDanJuView = getSubGameZhanjiDanJuView(gameID) if zhanjiDanJuView then local view = import(zhanjiDanJuView):new(self.roomInfo) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) else showTooltip("未找到单局战绩详情的配置文件!!!") end end --有回放的统一使用大厅战绩界面 local view = import("luaScript.Views.ZhanJi.ZhanJiDanjuView"):new(self.roomInfo) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function ZhanJiItem:onClickCopy() playBtnEffect() 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 if gameConfig.isUseDivision10 then score = score / 10 end --名字 local playerInfo = app.playerInfoManager:getPlayerInfo(k) if playerInfo then local len = string.len(playerInfo.name) if len == 0 then playerInfo.name = "未知昵称" 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 function ZhanJiItem: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 ZhanJiItem: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 return ZhanJiItem