|
- local hejiangPdkRoomViewConfig = require("pk_hejiangpdk.luaScript.Views.Room.hejiangPdkRoomViewConfig")
- local GameOverItem = require("pk_hejiangpdk.luaScript.Views.Room.Node.hejiangPdkGameOverItem")
- local PdkGameOverView = class("PdkGameOverView", cc.UIView)
- --[[
- "onResponseGameOver" = {
- "players" = {
- 1 = {
- "extString" = "{"bombTimes":0,"loseTimes":2,"maxScore":0,"winTimes":0}"
- "totalScore" = -6
- "userId" = 1023546
- }
- 2 = {
- "extString" = "{"bombTimes":0,"loseTimes":0,"maxScore":3,"winTimes":2}"
- "totalScore" = 6
- "userId" = 1023544
- }
- }
- }
- ]]
- function PdkGameOverView:ctor( overData )
- self._data = overData
- local ui = loadUI("pk_luzhoupdk/res/ui/ui_room/ui_lzpdk_daju.ui")
- self.ui = ui
- self:addChild(ui)
- self:initUi()
- self:setPlayerInfo()
- self:initPlayGameAgain()
- end
-
- function PdkGameOverView:initUi()
- local roomInfo = app.room:getRoomInfo()
- self.ui.Items.btnShare:registerClick(handler(self , self.onClickShare))
- self.ui.Items.btnOk:registerClick(handler(self , self.onClickOk))
- self.ui.Items.btnFFQShare:registerClick(handler(self , self.onClickFFQShare))
-
- if not app.config.ModuleConfig.IsSupportZhanJiUrl then
- self.ui.Items.Layout_5:setVisible(false)
- end
-
- if isReviewVersion() then
- self.ui.Items.Layout_4:setVisible(false)
- self.ui.Items.Layout_5:setVisible(false)
- end
- --self.ui.Items.btnFFQShare:setVisible(false)
- --self.ui.Items.txtRoomID:setString(string.format("房号:%06d", self._data.nShowTableId or 0))
- --self.ui.Items.txtRoundNum:setString(string.format("%s", os.date("%m-%d %H:%M", os.time()) ))
- local newRule = "" .."合江跑得快"
- newRule = newRule.." 房间号:"..tostring(self._data.nShowTableId)
- local curCount = roomInfo.nGameStartCount or 0
- local str = string.format("%02d/%02d局", curCount, roomInfo.nTotalGameNum)
- newRule = newRule.." "..str
- self.ui.Items.txtRoomRule:setString(newRule)--(string.format("%s", self._data.roomRule or ""))
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- self.ui.Items.txtRoundNum:setText((app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME).."ID:"..app.club_php.clubID)
- else
- self.ui.Items.txtRoundNum:setText("")
- end
- self.ui.Items.txtRoomID:setText(os.date("%Y-%m-%d %X",app.room.roomInfo.endtime))
- end
-
- function PdkGameOverView:setPlayerInfo()
- local maxUserId = self._data.players[1].userId
- local maxScore = tonumber(self._data.players[1].totalScore)
- for i,v in ipairs(self._data.players) do
- v.totalScore = tonumber(v.totalScore)
- if v.totalScore > maxScore then
- maxUserId = v.userId
- maxScore = v.totalScore
- end
- end
- local roomInfo = app.room:getRoomInfo()
- for i,v in ipairs(self._data.players) do
- v.isBigWin = v.userId == maxUserId
- v.isHost = v.userId == roomInfo.nRoomOwnedUid
- local item = self:createItem(v)
- self.ui.Items.Layout_items:addChild(item)
- end
- end
-
- function PdkGameOverView:onClickShare( sender )
- playBtnEffect()
- local fileName = cc.FileUtils:getInstance():getWritablePath()..tostring(self._data.nShowTableId).."_screen.jpg"
- cc.FileUtils:getInstance():screenToFile(fileName, function(ret)
- if 1 == tonumber(ret) then
- local info = {}
- info.scene = "talk"
- info.contentType = "image"
- info.image = fileName
- info.isShareZhanjiUrl = true
- info.imageWidth = 800
- info.thumbWidth = 100
- --app.plugin:shareGame(info)
- info.copyData={
- type=1,
- tableId=self._data.nShowTableId,
- userInfos={},
- gameId=40,
- }
- for nUserId,totalData in pairsByKeys(self._data.players) do
- local userInfo = app.room:getUserInfo(totalData.userId)
- --昵称
- local nickname = totalData.nickname or ""
- local totalScore = totalData.totalScore
- table.insert(info.copyData.userInfos,{nickname=nickname,totalScore=totalScore})
- end
-
- local view = import("luaScript.Views.Main.ShareView"):new(info,nil,{endtime=self._data.endTime})
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
-
- else
- showTooltip("截图保存失败")
- end
- end )
- end
-
- function PdkGameOverView:onClickOk( sender )
- playBtnEffect()
- --app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.hejiangPaoDeKuai))
- gotoMainView(GAME_IDS.hejiangPaoDeKuai)
- end
-
- function PdkGameOverView:onClickFFQShare()
- --[[local info = {}
- info.scene = "talk"
- info.contentType = "image"
- info.image = fileName
- info.isShareZhanjiUrl = true
- info.imageWidth = 1000
- info.thumbWidth = 100
- info.copyData={
- type=1,
- tableId=self._data.nShowTableId,
- userInfos={},
- gameId=35,
- }
- for nUserId,totalData in pairsByKeys(self._data.players) do
- local userInfo = app.room:getUserInfo(totalData.userId)
- --昵称
- local nickname = totalData.nickname or ""
- local totalScore = totalData.totalScore
- table.insert(info.copyData.userInfos,{nickname=nickname,totalScore=totalScore})
- end
-
- local onGetUrlCallback = function(url)
- if url then
- self.zhanjiUrl = url
- self.dataForUrl = {
- app = getAppId(),
- uid = app.user.loginInfo.uid,
- gameid = 35,
- roomid = self._data.nShowTableId,
- endtime = os.time(),
- }
-
- local url = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
- self.zhanjiUrl,
- self.dataForUrl.uid,
- self.dataForUrl.gameid,
- self.dataForUrl.app,
- self.dataForUrl.roomid,
- self.dataForUrl.endtime);
-
- local content = nil;
- if info and info.copyData and info.copyData.userInfos then
- for k,v in pairs(info.copyData.userInfos) do
-
-
- local userInfo = ""
- if v.totalScore > 0 then
- userInfo = string.format("%s(+%s)", getShortName(v.nickname), v.totalScore)
- else
- userInfo = string.format("%s(%s)", getShortName(v.nickname), v.totalScore)
- end
- if content then
- content = content .. "," .. userInfo
- else
- content = userInfo
- end
- end
- end
-
- local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
-
- local gameName = getSubGameName(35) or "悠闲麻将"
-
- local shareInfo =
- {
- contentType = "url",
- scene = "talk",
- url = url,
- title = gameName.."战绩",
- description = content,
- image = imagePath,
- imageWidth = 100,
- };
- dump(shareInfo)
- app.plugin:shareGame(shareInfo, self.shareCallbakc);
- else
- showTooltip("获取分享用的链接失败");
- end
- end
- app.php:initShareZhanJiToUrl(onGetUrlCallback);--]]
-
- app.waitDialogManager:showWaitNetworkDialog("获取分享链接")
- local onGetUrlCallback = function(url)
- app.waitDialogManager:closeWaitNetworkDialog()
- if url then
- local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
- local gameName = getSubGameName(GAME_IDS.hejiangPaoDeKuai) or "悠闲麻将"
-
- local info = {}
- -- info.contentType = "image"
- info.image = fileName
- info.title = gameName.."战绩"
- -- info.imageWidth = 800
- info.menuIdxs = {1, 4, 5, 6}
- info.FFQFlag = true
- -- info.isShareZhanjiUrl = false
- info.copyData={
- type=1,
- tableId=self._data.nShowTableId,
- userInfos={},
- gameId=GAME_IDS.hejiangPaoDeKuai,
- }
- local content = nil;
- local memberList = app.room.roomInfo.memberList--self._overData.nTotalPlayerInfos
-
- for k,v in pairs(self._data.players) do
- local userInfo = app.room:getUserInfo(v.userId)
- --昵称
- local nickname = v.nickname or ""
- local totalScore = v.totalScore
- table.insert(info.copyData.userInfos,{nickname=nickname,totalScore=totalScore})
-
- local strUserInfo = ""
- if totalScore > 0 then
- strUserInfo = string.format("%s(+%s)", getShortName(nickname), totalScore)
- else
- strUserInfo = string.format("%s(%s)", getShortName(nickname), totalScore)
- end
- if content then
- content = content .. "," .. strUserInfo
- else
- content = strUserInfo
- end
- end
-
- local sharUrl = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
- url,
- app.user.loginInfo.uid,
- GAME_IDS.hejiangPaoDeKuai,
- getAppId(),
- self._data.nShowTableId,
- self._data.endTime or os.time())
- info.url = sharUrl
- info.description = content
- dump(info)
- local view = import("luaScript.Views.Main.ShareView"):new(info)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- else
- showTooltip("获取分享用的链接失败")
- end
- end
- app.php:initShareZhanJiToUrl(onGetUrlCallback)
- end
-
- function PdkGameOverView:onEnter()
- PdkGameOverView.super.onEnter()
- setShowCountAll(true)
- stopBGMusic()
- end
-
- function PdkGameOverView:onExit()
- PdkGameOverView.super.onExit(self)
- setShowCountAll(false)
- end
-
- function PdkGameOverView:createItem( info )
- local node = loadUI("pk_luzhoupdk/res/ui/ui_room/ui_lzpdk_dajuitem.ui")
- setPlayerHeadImage(info.userId, info.headimgurl, node.Items.imgHead)
- node.Items.txtNick:setString(getSubStringNickname(info.nickname or ""))
- node.Items.txtID:setString("ID:"..info.userId)
-
- --显示隐藏游戏内选手id(主办人和管理员不限制,只针对海选赛) -- todo lwq
- -- begin
- local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- if app.club_php:getCestIsOpen(app.club_php.clubID) then
- --隐私数据
- local clubInfo = app.club_php.clubList[app.club_php.clubID]
- self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
- if not self.cliext or not self.cliext.is_hideUid or (self.cliext and self.cliext.is_hideUid == 1) then
- if clubInfo.role == ClubDefine.Job.Creator or clubInfo.role == ClubDefine.Job.Manager then
- node.Items.txtID:setVisible(true)
- else
- node.Items.txtID:setVisible(false)
- end
- end
- end
- end
- if info.userId == tonumber(app.user.loginInfo.uid) then
- node.Items.txtID:setVisible(true)
- end
- -- end
-
- node.Items.imgBest:setVisible(info.isBigWin and info.totalScore>0)
- node.Items.imgHost:setVisible(info.isHost)
- node.Items.imgHost:setVisible(false)--隐藏房主标签
- --"extString" = "{"bombTimes":0,"loseTimes":0,"maxScore":3,"winTimes":2}"
- local extData = json.decode(info.extString)
- --[[node.Items.txtDjzgfs_1:setString(""..extData.maxScore)
- node.Items.txtDczds_1:setString(""..extData.bombTimes)
- node.Items.txtSyjs_1:setString(string.format("%d/%d", extData.loseTimes , extData.winTimes))--]]
- local countInfo = json.decode(info.countInfo)
- node.Items.txtDiamond:setText("-"..countInfo.DeInfo)
-
- if info.totalScore > 0 then
- node.Items.txtTotalScore:setString("+"..info.totalScore)
- --node.Items.txtTotalScore:setColor(cc.c3b(212, 16, 16))
- node.Items.ImageView_light:setVisible(info.isBigWin)
- else
- node.Items.txtTotalScore:setFntFile("res/fonts/dt_jian_num.fnt")
- node.Items.txtTotalScore:setString(""..info.totalScore)
- node.Items.ImageView_light:setVisible(false)
- end
- if self._data.stopFlag == 9 or self._data.stopFlag == 8 then--解散游戏
- local jiesanData = json.decode(self._data.stopResult)
- local jiesanLab = node.Items.txtID:getCopied()
- local jiesanPos = node.Items.txtID:getPosition()
- local jiesaninfo = {
- [0] = "超时解散",
- [1] = "申请解散",
- [2] = "同意解散",
- [3] = "拒绝",
- }
- if jiesanData and jiesanData[tostring(info.userId)] then
- jiesanLab:setPositionY(jiesanPos.y - 50)
- jiesanLab:setAnchorPoint(cc.p(0.5, 0.5))
- jiesanLab:setColor(cc.c3b(255,155,155))
- if self._data.stopFlag == 9 then
- jiesanLab:setText(jiesaninfo[jiesanData[tostring(info.userId)]])
- elseif self._data.stopFlag == 8 then
- jiesanLab:setText("系统解散")
- end
- node.Items.ImageView_item_bg_1:addChild(jiesanLab)
- end
- end
- return node
- end
-
- function PdkGameOverView:test()
- local data = {{}, {}, {}}
- local dltWidth = 1273/#data
- for i,v in ipairs(data) do
- local item = GameOverItem:new(v)
- if i==1 then
- item:setPosition(cc.p((i-1)*dltWidth+dltWidth/2, 225))
- elseif i==3 then
- else
- item:setPosition(cc.p((i-1)*dltWidth+dltWidth/2, 225))
- end
- self.ui.Items.Layout_items:addChild(item)
- end
- end
- ---
- -- 初始化大结算再来一局
- -- @return
- --
- function PdkGameOverView:initPlayGameAgain ()
- local roomInfo = app.room.roomInfo or {};
- local gameId = roomInfo.gameId or app.gameId
- if dd.IClub.isInClub() and roomInfo.nShowTableId then
- local inviteList = {}
- for k,v in pairsByKeys(roomInfo.memberList) do
- if tonumber(v.nUserId) ~= app.user.loginInfo.uid then
- table.insert(inviteList, v.nUserId)
- end
- end
-
- local strInvite = hejiangPdkRoomViewConfig.getClubInviteWanFa(roomInfo.gameId or GAME_IDS.hejiangPaoDeKuai, roomInfo)
- local btnPlayAgain = self.ui.Items.Button_PlayAgain
- dd.IPlayGameAgain.bindPlayAgainButton(btnPlayAgain, gameId, strInvite, inviteList, function ()
- -- 初始化成功后干嘛干嘛
- local visible = btnPlayAgain:isVisible()
- self.ui.Items.Layout_Button_PlayAgain:setVisible(visible)
- if self.ui.Items.Layout_Operate_Buttons then
- self.ui.Items.Layout_Operate_Buttons:requestDoLayout()
- self.ui.Items.Layout_Operate_Buttons:doLayout()
- self.ui.Items.Layout_Operate_Buttons:setPositionX(cc.Director:getInstance():getVisibleSize().width / 2)
- end
- end)
- --绑定消息通知回调
- self:bindEvent(app.club_php , GAME_EVENT.CLUB_INVITE , handler(self , self.onClubInviteEvent))
- else
- logD("PdkGameOverView:initPlayGameAgain", "不在亲友圈或桌子id为空,不能进行再来一局操作")
- if self.ui.Items.Layout_Button_PlayAgain then
- self.ui.Items.Layout_Button_PlayAgain:setVisible(false)
- end
- if self.ui.Items.Layout_Operate_Buttons then
- self.ui.Items.Layout_Operate_Buttons:requestDoLayout()
- self.ui.Items.Layout_Operate_Buttons:doLayout()
- self.ui.Items.Layout_Operate_Buttons:setPositionX(cc.Director:getInstance():getVisibleSize().width / 2)
- end
- end
- end
- ---
- -- 监听亲友圈邀请信息
- -- @param event
- -- @return
- --
- function PdkGameOverView:onClubInviteEvent(event)
- dd.IPlayGameAgain.showClubInviteDialog(event, nil, nil)
- end
-
- return PdkGameOverView
|