|
- -- 房间设置界面
- local MJRoomSettingView = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomSettingView")
- local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
- local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
- local MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction")
- local MJMessage = import("mj.luaScript.Protocol.MJMessage")
- local MJRoomToolView = class("MJRoomToolView", cc.UIView)
-
- -- require("LiuHuQiangDef")
-
- function MJRoomToolView:ctor()
- MJRoomToolView.super.ctor(self);
- self:loadUI()
- --是否是该场景点了准备
- self.isTouchCurScene = false
- end
-
- function MJRoomToolView:loadUI()
- local ui = loadUI("mj/res/ui/ui_fangjian/mj_ui_tool.ui");
- -- local ui = loadUI("mj/res/ui/ui_fangjian/mj_ui_new_tool.ui");
- self.ui = ui;
- self:addChild(ui);
- end
-
- function MJRoomToolView:onEnter()
- MJRoomToolView.super.onEnter(self)
-
- self:initEvents()
-
- --测试开关
- self.ui.Items.Layout_Test:setVisible(false)
-
- --播放队列
- self.ui.Items.Button_Play:registerClick(function ()
- app.net:onMsgResume()
- end)
-
- --停止队列
- self.ui.Items.Button_Stop:registerClick(function ()
- app.net:onMsgPause()
- end)
-
- self:initButton()
- self:updateButtonPosition()
-
-
-
- --上传日记
- --[[ local day = os.date("%Y-%m-%d")
- local key = string.format("dingdinglog-%s",day)
- local isShow = cc.UserDefault:getInstance():getBoolForKey(key,false)
- if isShow or isReviewVersion() then
- -- self.ui.Items.Button_updateLog:setVisible(false)
- end
-
- if isDebug() or cc.Application:getInstance():getTargetPlatform() == 0 then
- self.ui.Items.Button_Upload:setVisible(true)
- end
- --]]
-
- -- 详情
- -- self.ui.Items.Button_ruleIntro:registerClick(handler(self , self.onClickRule))
-
- -- self.ui.Items.ImageView_Rule_bg:setVisible(false)
-
- end
-
- function MJRoomToolView:onExit( )
- logD("MJRoomToolView:onExit")
- end
- ---
- -- 初始化事件
- -- @return
- --
- function MJRoomToolView:initEvents()
- self:bindEvent(app.room , MJDefine.MJEvent.GameStartResponse, handler(self , self.onGameStartResponse));
- end
-
- function MJRoomToolView:initButton()
- if self.ui.Items.Button_Invite then
- self.ui.Items.Button_Invite:registerClick(handler(self,self.onClickInvite))
- end
- if self.ui.Items.Button_Ready then
- self.ui.Items.Button_Ready:registerClick(handler(self,self.onClickReady))
- end
- if self.ui.Items.Button_Invite_Club then
- self.ui.Items.Button_Invite_Club:registerClick(handler(self,self.onClickInviteClub))
- end
- if self.ui.Items.Button_FastStart then
- self.ui.Items.Button_FastStart:registerClick(handler(self,self.onClickQuickStart))
- end
-
- if self.ui.Items.Button_Copy then
- self.ui.Items.Button_Copy:registerClick(handler(self,self.onClickCopy))
- end
-
- -- self.ui.Items.Button_Voice:registerClick(handler(self,self.onClickVoice))
- if self.ui.Items.Button_Voice then
- self.ui.Items.Button_Voice:setVisible(not MJFunction:isVoiceFobided())
- end
-
- if self.ui.Items.Button_Face then
- self.ui.Items.Button_Face:registerClick(handler(self,self.onClickFace))
- self.ui.Items.Button_Face:setVisible(not MJFunction:isPropFobided())
- end
-
- -- 菜单按钮
- if self.ui.Items.Button_Menu then
- self.ui.Items.Button_Menu:registerClick(handler(self , self.onClickMenu))
- end
- --菜单背景layout,注册时间防止穿透点到下面的头像
- if self.ui.Items.Layout_Menu then
- self.ui.Items.Layout_Menu:registerClick(handler(self , self.onClickLayoutMenu))
- end
- if self.ui.Items.Button_Leave then
- self.ui.Items.Button_Leave:registerClick(handler(self , self.onClickLeave))
- end
- if self.ui.Items.Button_Dismiss then
- self.ui.Items.Button_Dismiss:registerClick(handler(self , self.onClickDismiss))
- end
- if self.ui.Items.Button_Set then
- self.ui.Items.Button_Set:registerClick(handler(self , self.onClickSet))
- end
- if self.ui.Items.Button_Rule then
- self.ui.Items.Button_Rule:registerClick(handler(self , self.onClickRule))
- self.ui.Items.Button_Rule:setVisible(false)
- end
-
- if self.ui.Items.Layout_tuoguan then
- self.ui.Items.Button_guoguan:registerClick(handler(self , self.onClickQXTuoGuan))
- self.ui.Items.Layout_tuoguan:setTouchEnabled(true)
- self.ui.Items.Layout_tuoguan:setLocalZOrder(1000)
- self:showTuoGuan(false)
- end
-
- ---self.ui.Items.Layout_Touch:registerClick(handler(self , self.onClickBlank))
-
- self:initVoiceComponent()
- self:initButtonBaoJian()
-
- self:setMenuVisible(false, true)
- -- self.ui.Items.Layout_Rule:setVisible(false)
-
- if self.ui.Items.Layout_Rule then
- self.ui.Items.Layout_Rule:runAction(cc.Sequence:create(
- cc.DelayTime:create(2),
- cc.CallFunc:create(function()
- self:hideRule()
- end)))
- end
- end
-
- function MJRoomToolView:initVoiceComponent()
- local voiceComponentView = import("luaScript.Views.Room.RoomVoiceComponentView"):new(self.ui.Items.Button_Voice)
- self:addChild(voiceComponentView)
- end
-
- function MJRoomToolView:onClickRule()
- self.ui.Items.Layout_Rule:setVisible(true)
- self.ui.Items.Button_Rule:setVisible(false)
- end
-
- function MJRoomToolView:hideRule()
- if self.ui.Items.Layout_Rule then
- self.ui.Items.Layout_Rule:stopAllActions()
- self.ui.Items.Layout_Rule:setVisible(false)
- end
- if self.ui.Items.Button_Rule then
- self.ui.Items.Button_Rule:setVisible(true)
- end
- end
-
- function MJRoomToolView:updateRule()
- if not self.ui.Items.Text_Rule then
- return
- end
- --房间规则不会中途变化,不用多次更新
- if not self.isHadupdateRule then
- self.isHadupdateRule = true
- else
- return
- end
- local roomInfo = app.room.roomInfo;
- self.ui.Items.Text_Rule:setVisible(false)
- -- self.ui.Items.Layout_Rule:setVisible(false)
- self.ui.Items.ListView:removeAllChildren()
- self.ui.Items.ListView:setAutoSize(true)
- local rules = MJWanFa.getWanFaInfoTab(roomInfo.strGameInfo, app.room.roomInfo.nTotalGameNum)
- for k,v in pairs(rules) do
- local text = self.ui.Items.Text_Rule:getCopied()
- text:setVisible(true)
- text:setString(v)
- self.ui.Items.ListView:addChild(text)
- end
- end
-
-
- --隐藏微信按钮
- function MJRoomToolView:setWetChatVisible(bVisible)
- if self.ui.Items.Button_Invite then
- self.ui.Items.Button_Invite:getParent():setVisible(bVisible)
- --self:updateButtonPosition()
-
- --审核或者开局后都默认隐藏
- if isReviewVersion() then
- logD("MJRoomToolView:setWetChatVisible isReviewVersion()")
- self.ui.Items.Button_Invite:getParent():setVisible(false)
- end
- end
- self:setInviteClubVisible(bVisible)
- end
-
- --按钮位置调整
- function MJRoomToolView:updateButtonPosition()
- if not self.ui.Items.Layout_Button then return end
-
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- else
- -- local readyPosX = self.ui.Items.Button_Ready:getPositionX()
- -- self.ui.Items.Button_Ready:setPositionX(readyPosX+90)
- -- local posX = self.ui.Items.Button_Invite:getPositionX()
- -- self.ui.Items.Button_Invite:setPositionX(posX+90)
- end
-
- if self.ui.Items.Layout_Button then
- self.ui.Items.Layout_Button:requestDoLayout()
- self.ui.Items.Layout_Button:doLayout()
- end
- end
-
- function MJRoomToolView:updateButton(isMove)
- local roomInfo = app.room.roomInfo
-
- local curMemberNum = table.nums(roomInfo.memberList)
- --没有坐满
- local isNotSitFull = curMemberNum < roomInfo.nMaxPlayCount
- --更新邀请按钮
- self:setWetChatVisible(isNotSitFull)
-
- --更新快速开局 没有坐满并且当前人数大于2显示
- local info = json.decode(roomInfo.strGameInfo or "") or {}
- if self.ui.Items.Button_FastStart then
- self.ui.Items.Button_FastStart:setVisible(isNotSitFull and curMemberNum>=2 and info.isfaststart == 1)
- end
-
-
- local nUserId = app.room:getMyUserId()
- local memberInfo = roomInfo.memberList[nUserId]
- --更新准备按钮状态
- if self.ui.Items.Button_Ready then
- self.ui.Items.Button_Ready:getParent():setVisible(memberInfo.nPlayerFlag == 0)
- end
-
- --更新解散按钮状态
- if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then
- self.ui.Items.Button_Dismiss:setEnabled(false)
- else
- self.ui.Items.Button_Dismiss:setEnabled(true)
- end
-
- --已经开局
- if roomInfo.nGameStartCount>0 then
- if self.ui.Items.Button_Leave then
- self.ui.Items.Button_Leave:setEnabled(false)
- end
-
- self:setWetChatVisible(false)
- -- self.ui.Items.Button_Invite:getParent():setVisible(false)
- if self.ui.Items.Button_FastStart then
- self.ui.Items.Button_FastStart:setVisible(false)
- end
- if self.ui.Items.Button_Ready then
- self.ui.Items.Button_Ready:getParent():setVisible(false)
- end
- end
-
- self:updateButtonPosition()
- self:checkCanDismiss()
- end
-
- function MJRoomToolView:onClickReady()
- self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest)
- playVoice("res/sound/room/sit.ogg")
- end
-
- --初始包间按钮
- function MJRoomToolView:initButtonBaoJian()
- if not self.ui.Items.Button_BaoJian then
- return
- end
- self.ui.Items.Button_BaoJian:registerClick(handler(self , self.onClickBaoJian))
- --包间
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- self.ui.Items.Button_BaoJian:setVisible(true)
- else
- self.ui.Items.Button_BaoJian:setVisible(false)
- end
- end
-
-
- --点击日记
- function MJRoomToolView:onClickLog()
- playBtnEffect()
- print("=========================DingDingLog===============================")
- local uiTechnialView
- uiTechnialView = import("luaScript.Views.Room.UplogView"):new()
- self:addChild(uiTechnialView)
- end
-
- function MJRoomToolView:getInviteData()
- local tt =
- {
- [0] = "零缺四",
- [1] = "一缺三",
- [2] = "二缺二",
- [3] = "三缺一",
- [4] = "满座",
- }
-
- if app.room:getMaxPlayerCount()==3 then
- tt =
- {
- [0] = "零缺三",
- [1] = "一缺二",
- [2] = "二缺一",
- [3] = "满座",
- }
- end
-
- if app.room:getMaxPlayerCount()==2 then
- tt =
- {
- [0] = "零缺二",
- [1] = "一缺一",
- [2] = "满座",
- }
- end
- local num = table.nums(app.room.roomInfo.memberList)
- local strNum = tt[num]
- --根据游戏类型分享
- local roomInfo = app.room.roomInfo;
- local jsonInfo = json.decode(roomInfo.strGameInfo)
-
- local mjName=getSubGameConfig(app.room.roomInfo.gameId).gameName or "麻将"
-
- local title = string.format("%s 房号[%s] %s", mjName,app.room.roomInfo.nShowTableId,strNum)
-
- --添加俱乐部ID
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- title = string.format("%s %sID[%d]", title,PLN.CLUB_NAME, tonumber(app.club_php.clubID))
- end
-
- local strGameNum = string.format("%s局", app.room.roomInfo.nTotalGameNum)
-
- local strGameMode = MJWanFa.getWanFaInfo(app.room.roomInfo.strGameInfo)--getLHQRuleStr()
-
- local strNames = ""
- local index = 0
- for k,v in pairs(app.room.roomInfo.memberList) do
- index = index + 1
- local userInfo = json.decode(v.userInfo)
- local name = getSubStringNickname(userInfo.nickname)
- strNames = strNames..name
- if index < num then
- strNames = strNames..","
- end
- end
- local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames)
- print(desc)
-
- return title,desc
- end
-
- -- 邀请好友
- function MJRoomToolView:onClickInvite()
- playBtnEffect()
-
- local title,desc = self:getInviteData()
- local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
-
- local info = {}
- info.title = title
- info.description = desc
- info.copyData={type=2}
-
- local view = import("luaScript.Views.Main.ShareView"):new(info)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- --app.plugin:shareGame(info)
- end
-
- --点击亲友圈邀请
- function MJRoomToolView:onClickInviteClub()
- playBtnEffect()
-
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- local roomInfo = app.room.roomInfo;
- --local gameInfo = roomInfo.nGameInfo
- if roomInfo and roomInfo.nShowTableId then
- local strInvite = MJFunction.getClubInviteWanFa(app.gameId, roomInfo)
- local view = import("luaScript.Views.Club.ClubInvite"):new(roomInfo.nShowTableId, strInvite)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- end
- end
- end
-
- --设置邀请亲友圈成员显示
- function MJRoomToolView:setInviteClubVisible(bVisible)
- if self.ui.Items.Button_Invite_Club then
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- self.ui.Items.Button_Invite_Club:getParent():setVisible(bVisible)
- else
- self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
- end
-
- local roomInfo = app.room.roomInfo or {}
- local gameId = roomInfo.gameId or app.gameId
- local gameConfig = getSubGameConfig(gameId)
- if gameConfig.isOpenClubInvite == false then
- self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
- end
-
- --审核或者开局后都默认隐藏
- if isReviewVersion() then
- logD("MJRoomToolView:setInviteClubVisible isReviewVersion()")
- self.ui.Items.Button_Invite_Club:setVisible(false)
- end
- end
- end
-
- function MJRoomToolView:onClickQuickStart()
- playBtnEffect()
- local request = MJMessage.FastStartRequest:new()
- request.tp = 1
-
- self.ui:sendMsg(app.room,MJDefine.MJEvent.RequestFastsStart, request)
- end
-
- --菜单按钮 (通过动画实现)
- function MJRoomToolView:onClickMenu()
- playBtnEffect()
- self:setMenuVisible(not self.ui.Items.Layout_Menu:isVisible())
- end
- function MJRoomToolView:onClickLayoutMenu()
- end
-
- --设置按钮菜单
- function MJRoomToolView:setMenuVisible(bVisible,flag)
- if flag then
- self.ui.Items.Layout_Menu:setVisible(bVisible)
- return
- end
- if bVisible then
- self.ui.Items.Layout_Menu:setVisible(bVisible)
- else
- self.ui.Items.Layout_Menu:setVisible(bVisible)
- end
- end
-
- --离开按钮
- function MJRoomToolView:onClickLeave()
- playBtnEffect()
- if app.room then
- self.ui:sendMsg(app.room, "callLeaveRequest")
- end
- end
-
- --解散按钮
- function MJRoomToolView:onClickDismiss()
- playBtnEffect()
-
- local function onClickOk()
- if app.room and app.room.requestDismissRoom then
- app.room:requestDismissRoom(1)
- end
- end
- local function onClickCancel()
-
- end
- showConfirmDialog("确认发起解散?", onClickOk,onClickCancel)
-
- self:setMenuVisible(false)
- --self.ui.Items.Button_Dismiss:setEnabled(false)
- end
-
- --设置按钮
- function MJRoomToolView:onClickSet()
- playBtnEffect()
- local view = MJRoomSettingView:new();
- view:setAnchorPoint(cc.p(0.5, 0.5));
- app:showWaitDialog(view,100);
- --[[if self.setCallBack then
- self.setCallBack()
- end--]]
-
- end
-
- --上传按钮
- function MJRoomToolView:onClickUpload()
- local uiTechnialView = import("luaScript.Views.Room.UplogView"):new()
- self:addChild(uiTechnialView)
- end
-
- --包间按钮
- function MJRoomToolView:onClickBaoJian()
- playBtnEffect()
- if IS_USER_NEW_CLUB then
- openClub()
- else
- local clubList = app.club_php.clubList
- if clubList and table.nums(clubList) > 0 then
- --房间号
- local roomInfo = app.room.roomInfo
- if roomInfo then
- --创建房间时传入的桌子下标
- local strGameInfo = roomInfo.strGameInfo
- local ttGameInfo = json.decode(strGameInfo)
- local tableIdx = tonumber(ttGameInfo.tableIdx)
-
- self.clubView = import("luaScript.Views.Club.ClubTable"):new(clubList[app.club_php.clubID], tableIdx)
- self.clubView:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(self.clubView)
- end
- else
- --未找到俱乐部列表数据时,请求俱乐部列表(可能是断线重连)
- app.club_php:getClubList();
- end
- end
- end
-
-
- --[[--点击空白地方
- function MJRoomToolView:onClickBlank()
- --关闭菜单
- self:setMenuVisible(false,true)
- end--]]
-
- --隐藏俱乐部
- function MJRoomToolView:hideClub()
- --self.ui.Items.Button_BaoJian:setVisible(false)
- if self.clubView and not tolua.isnull(self.clubView) then
- self.clubView:removeFromParent()
- self.clubView=nil
- end
- end
-
- function MJRoomToolView:onClickCopy()
- playBtnEffect()
- local title,desc = self:getInviteData()
- local clubData = ""
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- local clubName = ""
- local clubList = app.club_php.clubList
- if clubList and table.nums(clubList) > 0 then
- clubName = clubList[tonumber(app.club_php.clubID)].clubName;
- end
- clubData = string.format(PLN.CLUB_NAME.."名:%s \n", clubName)
- end
- local tishi = "复制信息打开游戏将自动入座\n<仅供娱乐,严禁赌博>"
- copyData = string.format("%s%s\n%s\n%s",clubData,title,desc,tishi)
- logD(copyData)
-
- copyStringToClipboard(copyData)
-
-
- app.plugin:gotoWeiXin()
- end
-
- -- function MJRoomToolView:onClickVoice()
-
- -- end
-
- function MJRoomToolView:onClickFace()
- local chatView = import("luaScript.Views.Room.RoomChatView"):new(MJDefine.MJChatTxt,MJDefine.MJFaceConfig)
- chatView:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(chatView,0,true)
- end
-
- function MJRoomToolView:onClickQXTuoGuan( sender )
- playBtnEffect()
- --
- local request = MJMessage.HostingRequest:new()
- request.nUserId = 0
- request.status = 0 --1托管 0取消托管
- self.ui:sendMsg(app.room, MJDefine.MJEvent.HostingRequest, request)
- end
-
- function MJRoomToolView:showTuoGuan( is )
- self.ui.Items.Layout_tuoguan:setVisible(is==true)
- end
-
- function MJRoomToolView:onGameStartResponse()
- self:checkCanDismiss()
- end
- ---
- -- 检测是否可以解散房间
- -- @param
- -- @return
- --
- function MJRoomToolView:checkCanDismiss( )
- local onCanDismissCallback = function (info)
- local nUserId = app.room:getMyUserId()
- local roomInfo = app.room.roomInfo or {}
- local canDismiss = (tonumber(info.canDismiss or 1) == 1) or roomInfo.nRoomOwnedUid == nUserId or dd.IClub.isAdmin()
- if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then
- canDismiss = false
- end
- self:onCanDismissCallback(canDismiss)
- end
-
- if dd.IClub.getCanDismiss then
- local canDismiss = dd.IClub.getCanDismiss(onCanDismissCallback)
- if canDismiss then
- onCanDismissCallback({canDismiss = canDismiss})
- end
- end
- end
-
- function MJRoomToolView:onCanDismissCallback(canDismiss)
- if not tolua.isnull(self.ui.Items.Button_Dismiss) then
- self.ui.Items.Button_Dismiss:setEnabled(canDismiss)
- end
- end
-
- return MJRoomToolView;
|