|
- -- 房间设置界面
- local RoomDaJuView = class("RoomDaJuView_ERDouDiZhu", cc.UIView)
-
- local Functions = require("pk_erdoudizhu.luaScript.Functions_ERDouDiZhu")
-
- function RoomDaJuView:ctor(response)
- RoomDaJuView.super.ctor(self)
- self.response = response
- self.zhanjiUrl = app.serverConfigs.clientConfig.webgamb or app.config.Setting.httpZhanJiUrl
- end
-
- function RoomDaJuView:onEnter()
- RoomDaJuView.super.onEnter(self)
- local ui = loadUI("pk_erdoudizhu/res/ui/ui_fangjian/doudizhu_ui_daJu.ui")
- self:addChild(ui)
- self.ui = ui
-
- -- 分享战绩
- self.ui.Items.Button_Share:registerClick(handler(self , self.onClickShare))
-
- -- 结束游戏
- self.ui.Items.Button_Over:registerClick(handler(self , self.onClickOver))
-
- -- 防封群分享
- self.ui.Items.Button_PreventShare:registerClick(handler(self , self.onClickShareZhanJiUrl))
-
- self:initPlayGameAgain()
- end
-
- function RoomDaJuView:updateView(data)
- --显示
- self:setVisible(true)
-
- --更新房间号
- self.ui.Items.Text_RoomId:setText("房号: " .. app.room.roomInfo.nShowTableId)
-
- --更新局数
- self.ui.Items.Text_JuShu:setText(string.format("%02d / %02d 局", app.room.roomInfo.nGameStartCount, app.room.roomInfo.nTotalGameNum))
-
- --更新时间
- self.ui.Items.Text_SystemTime:setText(getTimeString())
-
- --规则
- self.ui.Items.Text_GameRules:setText(Functions.getRuleStr())
-
- -- 防封群分享
- if not app.config.ModuleConfig.IsSupportZhanJiUrl then
- self.ui.Items.Layout_preventShare:setVisible(false)
- self.ui.Items.Layout_Buttons:requestDoLayout()
- self.ui.Items.Layout_Buttons:doLayout()
- else
- -- 获取分享网页战绩用的连接
- self:initShareUrl();
- end
-
- if isReviewVersion() then
- self.ui.Items.Layout_Share:setVisible(false)
- self.ui.Items.Layout_preventShare:setVisible(false)
- self.ui.Items.Layout_Buttons:requestDoLayout()
- self.ui.Items.Layout_Buttons:doLayout()
- end
-
- --更新玩家信息
- self:updatePlayer(data)
- end
-
- function RoomDaJuView:updatePlayer(data)
- --隐藏所有玩家
- for i = 1, 4 do
- local player = self.ui.Items["Layout_Player_" .. i]
- if player then
- player:setVisible(false)
- end
- end
-
- local maxScore = 0
- for _,v in pairs(data.memberList) do
- v.nTotalScore = tonumber(v.nTotalScore)
- if v.nTotalScore > maxScore then
- maxScore = v.nTotalScore
- end
- end
-
- --更新玩家数据
- for k,v in pairs(data.memberList) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- local player = self.ui.Items["Layout_Player_" .. viewId]
- local userInfo = json.decode(v.userInfo)
- if player then
- v.nTotalScore = tonumber(v.nTotalScore)
- --显示玩家信息
- player:setVisible(true)
- --更新头像
- local head = self.ui.Items["Image_Head_" .. viewId]
- if head then
- setPlayerHeadImage(v.nUserId, userInfo.headimgurl, head)
- end
- --名字
- local name = self.ui.Items["Text_Name_" .. viewId]
- if name then
- name:setText("" .. userInfo.nickname)
- end
- --玩家id
- local userId = self.ui.Items["Text_UserId_" .. viewId]
- if userId then
- userId:setText("" .. v.nUserId)
-
- --显示隐藏游戏内选手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
- userId:setVisible(true)
- else
- userId:setVisible(false)
- end
- end
- end
- end
- if v.nUserId == tonumber(app.user.loginInfo.uid) then
- userId:setVisible(true)
- end
- -- end
-
- end
- --分数
- local score = self.ui.Items["Text_Score_" .. viewId]
- if score then
- if v.nTotalScore > 0 then
- score:setText("+" .. v.nTotalScore)
- else
- score:setText("" .. v.nTotalScore)
- end
- end
- --更新背景
- local bg = self.ui.Items["Image_Bg_" .. viewId]
- if bg then
- if v.nTotalScore >= 0 then
- bg:loadTexture("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_daju/doudizhu_daju_winbg.png")
- else
- bg:loadTexture("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_daju/doudizhu_daju_losebg.png")
- end
- end
- --大赢家
- local banker = self.ui.Items["Image_MaxWin_" .. viewId]
- if banker then
- banker:setVisible(maxScore > 0 and maxScore <= v.nTotalScore)
- end
- end
- end
- self.ui.Items.Layout_Players:requestDoLayout()
- self.ui.Items.Layout_Players:doLayout()
- end
-
- -- 分享
- function RoomDaJuView:onClickShare()
- playBtnEffect()
- function callbackEx(ret, fileName)
- if tonumber(ret) == 1 then
- local info = {}
- info.contentType = "image"
- info.image = fileName
- info.imageWidth = 800
-
- local gamerule = nil
- local roomInfo = app.room.roomInfo
- if roomInfo.strGameInfo then
- local jsonInfo = json.decode(roomInfo.strGameInfo)
- if jsonInfo then
- gamerule = jsonInfo.gamerule
- end
- end
-
- local rulename = ""
- if gamerule then
- rulename = " - " .. getSubGameRuleName(app.gameId, gamerule)
- end
-
- local gameName = getSubGameName(app.gameId) .. rulename
-
- info.copyData = {
- type = 1,
- gameName = gameName or "",
- tableId = app.room.roomInfo.nShowTableId,
- userInfos = {},
- }
-
- info.isShareZhanjiUrl = true
-
- for nUserId,totalData in pairsByKeys(self.response.memberList) do
- local userInfo = app.room:getUserInfo(nUserId)
- --昵称
- local nickname = userInfo.nickname or ""
- local totalScore = totalData.nTotalScore
- table.insert(info.copyData.userInfos, { nickname = nickname, totalScore = totalScore })
- end
-
- local view = import("luaScript.Views.Main.ShareView"):new(info)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- else
- showTooltip("截图保存失败")
- end
- end
-
- if isWin32Platform() then
- callbackEx(1, "testName")
- else
- local fileNameEx = cc.FileUtils:getInstance():getWritablePath() .. tostring(app.room.roomInfo.nShowTableId) .. "_screen.jpg"
- cc.FileUtils:getInstance():screenToFile(fileNameEx, function(retEx)
- callbackEx(retEx, fileNameEx)
- end)
- end
- end
-
- -- 确认
- function RoomDaJuView:onClickOver()
- playBtnEffect()
- app.room:dispatchEvent({name = "onGameOverResponse"})
- self:removeFromParent()
- app:gotoView(import("luaScript.Views.Main.MainView"):new(app.gameId, app.room.roomInfo.nShowTableId))
- end
-
- function RoomDaJuView:initShareUrl()
- app.php:initShareZhanJiToUrl(function(url)
- self.zhanjiUrl = url
- end)
- end
-
- function RoomDaJuView:onClickShareZhanJiUrl( sender )
- playBtnEffect()
- local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
- local gameName = getSubGameName(28) 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 = app.room.roomInfo.nShowTableId,
- userInfos = {},
- }
- local content = nil;
- local memberList = self.response.memberList
-
- for k,v in pairs(memberList) do
- local userInfo = json.decode(v.userInfo) or {}
- local nickname = userInfo.nickname or ""
- local totalScore = v.nTotalScore
- local userId = v.nUserId
- table.insert(info.copyData.userInfos,{nickname=nickname,totalScore=totalScore,nUserId = userId})
-
- 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",
- self.zhanjiUrl,
- app.user.loginInfo.uid,
- 28,
- getAppId(),
- app.room.roomInfo.nShowTableId,
- self.response.ntime 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)
-
- end
- ---
- -- 初始化大结算再来一局
- -- @return
- --
- function RoomDaJuView: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 = Functions.getRuleStrByClubInvite()
- 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_Buttons then
- self.ui.Items.Layout_Buttons:requestDoLayout()
- self.ui.Items.Layout_Buttons:doLayout()
- self.ui.Items.Layout_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("RoomDaJuView:initPlayGameAgain", "不在亲友圈或桌子id为空,不能进行再来一局操作")
- if self.ui.Items.Layout_Button_PlayAgain then
- self.ui.Items.Layout_Button_PlayAgain:setVisible(false)
- end
- if self.ui.Items.Layout_Buttons then
- self.ui.Items.Layout_Buttons:requestDoLayout()
- self.ui.Items.Layout_Buttons:doLayout()
- self.ui.Items.Layout_Buttons:setPositionX(cc.Director:getInstance():getVisibleSize().width / 2)
- end
- end
- end
- ---
- -- 监听亲友圈邀请信息
- -- @param event
- -- @return
- --
- function RoomDaJuView:onClubInviteEvent(event)
- dd.IPlayGameAgain.showClubInviteDialog(event, nil, nil)
- end
-
- return RoomDaJuView
|