--游戏公用 （设置）
local CreatUI 				--创建UI
local CleanUp 				--清空
local Close 				--关闭
local Init 					--初始化数据
local PushBackCB 			--返回回调
local PushTalkCB 			--聊天回调

local PushGuiZeCB           --规则回调
local TuoGuanBackCB 		--托管参数回调
--local GetMenuDate 			--得到按钮状态
local RegisterEventListen		-- 注册事件监听
local UnRegisterEventListen		-- 取消事件监听
local CloseGameCB 					--关闭游戏回调函数

local PushBackAgainDelFunc 		--点击了返回后再次点击的处理函数
--local CheckJiangQuanFunc
--local SetLobbyShowWorldTalkLab
local CreSysTime				-- 创建系统时间显示

local m_IsPushBackTimer 			--是否点击back定时器
local m_CurrGameID 				--此时的游戏ID
local m_GameState = 0				--游戏的状态
--local m_IsTuoGuan = 0			--是否托管

local m_BaseLayer = nil			--主Layer
local m_RuleBtn = nil			--规则按钮
local m_RenwuBtn = nil           --任务按钮
local m_FriendInviteBtn = nil    --好友邀请
---local m_WorldChangeLabShowTimer1 = nil
--local m_OnlineRewardsBtn = nil	--在线奖励按钮
--local m_OnlineRewardsBtnCanTouch = false --能否点击
--local m_OnlineRewardsBtnShineSp = nil --按钮闪光
--local m_PdownSetMenu = nil 		--设置下拉菜单
--local m_PupSetMenu = nil			--设置上拉菜单
local m_RoomDateNode = nil		--显示房间信息的Node
local m_BtnListBg    = nil      --按钮背景
local m_BackBtn = nil			--返回按钮
local m_TalkBtn = nil			--说话按钮
--local m_YuYinBtn = nil          --语音按钮
local m_SetBtn = nil				--设置按钮
--local m_TuoGuanBtn = nil			--托管按钮
--local m_SetBg = nil				--设置背景
--local m_MenuBg = nil		--按钮背景
local m_IsGuanZhan = false			--是否是观战
--local m_OnlineTimeNode = nil				--在线奖励时间层
--local m_VoiceBtn = nil			--音乐按钮
--local m_EffectBtn = nil			--音效按钮
--local m_WaitShowStrTb = {} 		--世界聊天显示
local m_SysTimeSec = 0 			-- 系统时间秒数
local m_SysTimeSp = nil 		-- 系统时间显示
--local m_CreInviteListTimer = nil --好友邀请list
--local m_LobbyShowWorldTalkLab = nil

local BASENODTAG = 100 		--主节点TAG
--local RULEBTNTAG = 101		--规则TAG
--local RULEBTNTAGSP = 201		--规则TAG
--local ONLINETAG  = 102 		--在线奖励Tag -> 主节点
local MEAN_BACKTAG = 104 	--按钮返回TAG -> 主节点
local MEAN_TALKTAG = 105 	--按钮聊天TAG
local MEAN_SETTAG = 106 	--设置tag -> 主节点
--local NODE_SETTAG 	= 108 	--设置bg -> 设置Layer -> 主节点
--local CANCLEMASKTAG = 109 	--退出遮罩Tag -> 主节点
--local TASKTAG = 111		--任务TAG
--local m_SetMenuIsVisible = false   --按钮背景是否能看见
--local m_TableIDLab = nil			--桌号lab
local m_CurrTbaleInfo = {}
--local m_OnlineReward_CutdownTime = 0  --剩余倒计时间
--local m_SetNode = nil
local m_InviteNode = nil
local m_ParentNode = nil
local m_GoOutExplain = nil
local m_GoOutUncondition = false
local m_IsPushBack = false
local M_WatcherTalk = {} 
--local m_Mode3GameEndTime = nil
local M_GameBtn = {}
--local BISAIENDACTIONTAG = 114


local m_RoomTipsNode    =nil         ---房间提示层
local DelroomTipsFun                ---清除房间提示
local CreSccussRoomTipsFun         ---房间成功提示
local CreShenQingCloseRoomTipsFun   --申请解散房间
local CreGuiZeTipsFun                 --规则内容
local CreJuJueCloseRoonTipsFun        --拒绝解散房间
local CreTongIpTipsFun                -- 同一ip
local CreJieSanFun                   --解散房间
local CrePushBackUI                  --返回UI
local SendShengQingCloseRoom         --申请结算房间
local CreDuanXianUI
local CreLocationTipsFun

local m_guizeMsgTb         =  {}       --g规则内容
local m_DianLiangSp        =  nil     --电池电量
local Dl_progressBar       =  nil     --百分比
local m_WifiSp             =  nil     --WiFi
local m_KoulingSp          =  nil   -- 口令
local m_koulingBg          =  nil
local m_IsBigHostJieSuan   =  false  --是否是打结算
local m_JieSanTime         =  0
--local CreJixuTipsUIFun           --继续游戏提示
local m_failreasnValue            --s失败结果


local m_selfQuit = true
local m_showLocationTip = false
local m_locationPlayerTable = {}

function pt_m_gamepublic_getSelfQuit()
	return m_selfQuit
end

function pt_m_gamepublic_setSelfQuit(b)
	if(b)then
		CCLOG("pt_m_gamepublic_setSelfQuit = true")
	else
		CCLOG("pt_m_gamepublic_setSelfQuit = false")
	end
	
	m_selfQuit = b
end

M_GameBtn.__index = M_GameBtn

--服务器要求玩家踢出去
local FwqYaoqiuplayerQuit  =false
function M_GameBtn:CleanUp()
	self.backbtn 	= nil
	self.onlinebtn 	= nil
	self.chatbtn 	= nil
	self.setbtn 	= nil
	self.renwubtn 	= nil
    self.btnListbg  = nil
    self.guizetn    =nil
    self.yuyinbtn   =nil
    self.diadLiang  =nil
    self.wifi       =nil
	self.SetContentTB = {}
	self.koulingName  =nil
end 
function M_public_SetsetState( _iscreste )
	-- if _iscreste == true then    
	-- 	-- CreSetUI() 	--显示按钮
	-- else
	-- 	-- DelCreSetUI() --显示底分
	-- end 
end
Init = function (  )
	m_GoOutExplain = nil
	m_GoOutUncondition = true
	--FwqYaoqiuplayerQuit  =false
end

RegisterEventListen = function (  )
		--设置游戏状态
	local  function S_setgamestate( key,s )
		CCLOG("Pt_Events.CC_ROOM_SET_STATE 设置游戏状态")
		m_GameState = s["roomstate"]
		if s["roomstate"] == emRoomState_Wait   then
			Init()
			Pt_M_ShowBackBtn(true)
	    elseif s["roomstate"] == emRoomState_JSWait   then
			Init()
			--Pt_M_ShowBackBtn(true)
		elseif s["roomstate"] == emRoomState_Game then
            Pt_M_ShowBackBtn(false)
		end 
	end
	Pt_EventMgr:register( Pt_Events.CC_ROOM_SET_STATE, "M_Public_Game", S_setgamestate )
		--同意强退
	local  function S_agreequit( key,s )
		CCLOG("Pt_Events.SC_XC_PLAYER_AGREE_QUIT 同意强退")
	 	Close()
	end
	Pt_EventMgr:register( Pt_Events.SC_XC_PLAYER_AGREE_QUIT, "M_Public_Game", S_agreequit )
		--不同意强退
	local  function S_disagreequit( key,s )
		CCLOG("Pt_Events.SC_XC_PLAYER_DISAGREE_QUIT 不同意强退")
	 	tips.creUpTimeBgTips("游戏中，无法退出")
	end
	Pt_EventMgr:register( Pt_Events.SC_XC_PLAYER_DISAGREE_QUIT, "M_Public_Game", S_disagreequit )
	--同意观看者强退
	local  function S_agreewatchquit( key,s )
		CCLOG("Pt_Events.SC_AGREE_QUIT_WATCH 同意观看者强退")
		Close()
	end
	Pt_EventMgr:register( Pt_Events.SC_AGREE_QUIT_WATCH, "M_Public_Game", S_agreewatchquit )
	--玩家准备超时踢出房间,发送给此玩家
	local  function S_timeout( key,s )
		CCLOG("Pt_Events.SC_ROOM_PREPARE_TIMEOUT 玩家准备超时踢出房间,发送给此玩家")
		-- PushBackCB()
		Close()
	end
	Pt_EventMgr:register( Pt_Events.SC_ROOM_PREPARE_TIMEOUT, "M_Public_Game", S_timeout )
	--玩家房间条件不够被踢出房间,发送给此玩家
	local  function S_del_player( key,s )
		CCLOG("Pt_Events.SC_ROOM_DEL_PLAYER 玩家房间条件不够被踢出房间,发送给此玩家")
		m_IsPushBack = true
		LockMsg2()
		local decStr = "你的金币不足,不能继续游戏!"
		if Pt_Get_SelectGameMode() == emMode_3 then
			decStr = "你的积分不足,不能继续比赛!"
		end
		tips.creMOKMaskTips(decStr,nil,nil,true,nil,function (  )
																				Close(false)
																			end)
		local array = {}
		array[1] = cc.DelayTime:create(5)
		array[2] = cc.CallFunc:create(function (  )
			-- PushBackCB()
			Close(false)
		end)
		m_BaseLayer:runAction(cc.Sequence:create(array))
		-- tips.creUpTimeBgTips("啊！没钱了！！先撤")
	end
	Pt_EventMgr:register( Pt_Events.SC_ROOM_DEL_PLAYER, "M_Public_Game", S_del_player )
	local function S_room_del( key, s )
		CCLOG("S_room_del 退出游戏房间")		
		m_selfQuit = true
		Close()

	end
	Pt_EventMgr:register( Pt_Events.SC_ROOM_DEL, "M_Public_Game", S_room_del )
  
    local function S_Vip_delRoom( key,s )
    	CCLOG("S_Vip_delRoom----------1")
    	Close()
    	Pt_Add_GameBackToLobbyCallFunc(function ( )
			local tipsStr = "房主离开,不能继续游戏!"
			CCLOG("S_Vip_delRoom----------2")
			tips.creMOKMaskTips(tipsStr,nil,nil,true,nil,function (  )
																	Pt_Clean_GameBackToLobbyCallFunc()	
																	CCLOG("S_Vip_delRoom----------3")		
 																	end)
		end,s)
    end 
    Pt_EventMgr:register( Pt_Events.SC_ROOM_VIP_DEL, "M_Public_Game", S_Vip_delRoom )


	local function S_room_zanli( key, s )
		CCLOG("S_room_zanli 暂离游戏房间")
		Close()
	end
	Pt_EventMgr:register( Pt_Events.SC_ROOM_ZANLI_SUCCESS, "M_Public_Game", S_room_zanli )

	local function S_mode1_quit( key, s )
		CCLOG("S_mode1_quit mode1退出游戏房间")
		Close()
	end
	Pt_EventMgr:register( Pt_Events.SC_MODE1_QUIT_PIPEI_SUCCESS, "M_Public_Game", S_mode1_quit )
	local function s_SC_DEL_GAMELIST( key, s )
		CCLOG("游戏中游戏服务器关闭")
		tips.creUpTimeBgTips("游戏服务器关闭,即将退出")
		local array = {}
		array[1] = cc.DelayTime:create(2)
		array[2] = cc.CallFunc:create(function (  )
			Close()
		end)
		m_BaseLayer:runAction(cc.Sequence:create(array))
	end
	Pt_EventMgr:register( Pt_Events.SC_DEL_GAMELIST, "M_Public_Game", s_SC_DEL_GAMELIST )
	Pt_EventMgr:register( Pt_Events.SC_ROOM_INFO, "M_Public_Game", function (key,s )
		CCLOG("SC_ROOM_INFO   M_Public_Game")
		m_CurrTbaleInfo = s

		if s.deskcode  then
		   if m_KoulingSp  then
               m_KoulingSp:setString(s.deskcode)
		   end
		end
        Pt_M_SetFanZhuFail(0)
       -- CreDuanXianUI(s)


       	--如果是房主，将其他人加入聊天房间
		local myplayerid =Pt_GetPlayerInfo().playerid
		if(m_CurrTbaleInfo.hostid == myplayerid)then
			for i = 1, #m_CurrTbaleInfo.playerlist do
				if(m_CurrTbaleInfo.playerlist[i].playerid ~= myplayerid)then
					local groupID = Pt_JMessageGetCurGroupID()
    				Pt_JMessageJoinGroup(groupID, m_CurrTbaleInfo.playerlist[i].playerid)
				end
			end
		end

	end )

    --IP相同玩家通知
	local  function fun_SC_IP_SAME_INFO( key,s )
        CCLOG("fun_SC_IP_SAME_INFO")
        SHOW(s)
      CreTongIpTipsFun(s)
    
	end
	Pt_EventMgr:register( Pt_Events.SC_IP_SAME_INFO, "M_Public_Game", fun_SC_IP_SAME_INFO )

    --解散桌子
	local  function fun_SC_DISMISS_DESK( key,s )
        CCLOG("fun_SC_DISMISS_DESK")
        SHOW(s)
        
        CreJieSanFun(s)
	end
	Pt_EventMgr:register( Pt_Events.SC_DISMISS_DESK, "M_Public_Game", fun_SC_DISMISS_DESK )


	-- -房主付费房间中房主离开房间拆桌
	local  function fun_SC_ROOM_HOST_DEL( key,s )
        CCLOG("fun_SC_ROOM_HOST_DEL",m_GameState)
        SHOW(s)  

        Pt_M_SetIsBigHost(false)
        if m_GameState ==emRoomState_Wait  then       
            Close()
        elseif   m_GameState ==emRoomState_JSWait  then
           -- Close()
            Pt_M_SetIsBigHost(true)
            CCLOG("m_IsBigHostJieSuan",Pt_M_GetIsBigHost())
        else
       	    Close()      
        end
	end
	Pt_EventMgr:register( Pt_Events.SC_ROOM_HOST_DEL, "M_Public_Game", fun_SC_ROOM_HOST_DEL )

	-- --通知客户端无法继续游戏原因（大结算阶段）
 --    local  function S_SC_CONTINUE_FAIL( key,s )
 --       CCLOG("通知客户端无法继续游戏原因（大结算阶段")
 --       m_failreasnValue= s.failreason 
 --       if s.failreason and s.failreason~=0 then
 --           Pt_M_CreJixuTipsUIFun(s.failreason,true)
 --           --Pt_M_SetIsBigHost(true)
 --       	end
	-- end
	-- Pt_EventMgr:register( Pt_Events.SC_CONTINUE_FAIL, "M_Public_Game", S_SC_CONTINUE_FAIL )



	--有玩家进入房间
	local function _PlayerEnterRoom(key,s)
		local hostid =Pt_M_GetFangZhuPlayerId()
    	local myplayerid =Pt_GetPlayerInfo().playerid
    	if(hostid ~= nil and (hostid == myplayerid) )then
    		local groupID = Pt_JMessageGetCurGroupID()
    		Pt_JMessageJoinGroup(groupID, s.playerid)
    	end
	end
	Pt_EventMgr:register( Pt_Events.SC_ROOM_PLAYER_ENTER, "M_Public_Game", _PlayerEnterRoom)

	--通知玩家桌上各玩家坐标与IP
	local function _PlayerLocationAndIP(key,s)
		CCLOG("_PlayerLocationAndIP")
		SHOW(s)

		CreLocationTipsFun(s)
	end
	Pt_EventMgr:register( Pt_Events.SC_GPS_POSITION, "M_Public_Game", _PlayerLocationAndIP)

	--有玩家退出房间
	local function _roomPlayerQuit(key, s)
		if(m_showLocationTip == true)then
			DelroomTipsFun()
		end
	end
	Pt_EventMgr:register( Pt_Events.SC_ROOM_PLAYER_QUIT, "M_Public_Game", _roomPlayerQuit)

	--玩家准备
	local function _playerstateChange(key, s)
		if(m_showLocationTip == true)then
			if(m_locationPlayerTable[tostring(s.playerid)] ~= nil)then
				local readySp = m_locationPlayerTable[tostring(s.playerid)]:getChildByTag(1)
				if(readySp ~= nil)then
					readySp:removeFromParent()
				end
				if(s.playerstate == emPlayerState_Prepare)then
					local rdSp = xui.addSprite(m_locationPlayerTable[tostring(s.playerid)], "xx_zb", 20, 60)
					rdSp:setTag(1)
					rdSp:setLocalZOrder(2)
				end
			end
		end
	end
	Pt_EventMgr:register( Pt_Events.SC_ROOM_SET_PLAYER_STATE, "M_Public_Game", _playerstateChange)

end
function Pt_M_GetFanZhuFail(  )
	CCLOG("failreasnValue",m_failreasnValue)
	return m_failreasnValue
end
function Pt_M_SetFanZhuFail( value )
	CCLOG("Pt_M_SetFanZhuFail",value)
     m_failreasnValue=value
end
function  Pt_M_CreJixuTipsUIFun( tage,can )
	-- CCLOG("Pt_M_CreJixuTipsUIFun",tage) 
	-- ---if not m_BaseNode  then  CCLOG("tage si nil ")  return end
	-- local  strtips = nil
	-- if tage ==emPlayerStateFailReason_RoomCard then
 --       strtips="你的房卡不足，不能继续游戏！"
 --        if  CHECK_VER_FLAG_CONTROL ~=nil  then 
 --            strtips="无法继续游戏！"
 --        end
	-- end
	-- if tage ==emPlayerStateFailReason_HostRoomCard then
 --       strtips="房主房卡不足，不能继续游戏！"
	-- end
	-- if tage ==emPlayerStateFailReason_HostLeave then
 --       strtips="房主离开，不能继续游戏！"
	-- end
	-- if tage ==emPlayerStateFailReason_Dismiss then
 --       strtips="房间解散，不能继续游戏！"
	-- end
	-- if tage ==emPlayerStateFailReason_WaitDismiss then
 --        strtips="房主解散，返回大厅！"
 --        local hostid =Pt_M_GetFangZhuPlayerId()
	--     local myplayerid =Pt_GetPlayerInfo().playerid
	--     if hostid~=myplayerid then 
 --       		Pt_SaveJieSanRoom(true)
 --       	end
 --        if can and can==true then
 --       	   CCLOG("在游戏中")
 --           return 
 --       	end
	-- end

	-- if  strtips then 
 --        local size={width=570,height=350}

 --        local sDirector = CCDirector:getInstance()
 --        local currScene = sDirector:getRunningScene()
	-- 	local backNode = cc.Node:create()
	-- 	currScene:addChild(backNode,4000)
   
	-- 	local function CloseBackUI(  )
	-- 		if backNode then
	-- 			backNode:removeFromParent(true)
	-- 		end
	-- 		Pt_SaveJieSanRoom(false)
	-- 	end
	--     local mask = xui.creMaskLy( backNode, nil, nil, nil, function (  )
 --            -- CloseBackUI()
	-- 	end )
	--     local tipsBg = xui.addSpr9(backNode,"xxqp_bg_0",570, 350, sys.center.x, sys.center.y)
	-- 	----关闭
	-- 	local closeBtn = MyBtnClass:new("xxqp_cancel_zc","xxqp_cancel_dj","xxqp_cancel_dj",
	-- 						function ( )
	-- 							CloseBackUI()
	-- 						end)
	-- 	tipsBg:addChild(closeBtn.btnLy,4)
	-- 	closeBtn.btnLy:setPosition(tipsBg:getContentSize().width-50, tipsBg:getContentSize().height-50)
	-- 	local lable =xui.addLabel(backNode,strtips,sys.colors.white,28,sys.center.x,sys.center.y,sys.ap.center)
	--     CCLOG("Pt_M_CreJixuTipsUIFun  is end")
	-- end
end
-- SetLobbyShowWorldTalkLab = function( str )
-- 	if m_LobbyShowWorldTalkLab then
-- 		-- m_LobbyShowWorldTalkLab.label:removeFromParent()
-- 		m_LobbyShowWorldTalkLab:removeFromParent()
-- 		m_LobbyShowWorldTalkLab = nil
-- 	end
-- 	if str and str ~= "" then
-- 		if string.utf8len(str) > 15 then
-- 			str = string.utf8sub(str,1,15).."…"
-- 		end
-- 		m_LobbyShowWorldTalkLab = xui.addLabel(m_BaseLayer,str,sys.colors.white,26,sys.center.x,sys.center.y)
-- 		local spwidth = 400
-- 		if m_LobbyShowWorldTalkLab:getContentSize().width + 40 > 400 then
-- 			spwidth = m_LobbyShowWorldTalkLab:getContentSize().width + 40
-- 		end
-- 		local ly =  xui.addSpr9(m_LobbyShowWorldTalkLab,"pt_gy_ggk",spwidth,46,m_LobbyShowWorldTalkLab:getContentSize().width/2,m_LobbyShowWorldTalkLab:getContentSize().height/2)
-- 		ly:setLocalZOrder(-1)	

-- 	end
-- end
UnRegisterEventListen = function (  )
	Pt_EventMgr:unregisterByKey( "M_Public_Game" )
end
function M_public_CreMenu( p,cb,gameid,fensnod ,tuoguancb)--主节点 回调函数 游戏ID 房间信息 托管回调
	CleanUp()
	M_GameBtn:CleanUp()
	M_WatcherTalk:CleanUp()
	CloseGameCB = cb
	--TuoGuanBackCB = tuoguancb
	m_CurrGameID = gameid
	m_RoomDateNode = fensnod
	m_BaseLayer = cc.Layer:create()

	local sDirector = CCDirector:getInstance()
	local currScene = sDirector:getRunningScene()

	m_ParentNode = p
	m_ParentNode:addChild(m_BaseLayer,PT_GAME_PUBLIC_ZORDER)
	m_BaseLayer:setTag(BASENODTAG)

	m_InviteNode = cc.Node:create()
	m_BaseLayer:addChild(m_InviteNode,100)

	m_RoomTipsNode=cc.Node:create()
	m_ParentNode:addChild(m_RoomTipsNode,11000)

	CreatUI()
	M_WatcherTalk:Create( )
	RegisterEventListen()
	return M_GameBtn
end
CleanUp = function (  )
	Send_relief = true
	m_IsPushBackTimer = false
	m_IsPushBack = false
	m_GoOutExplain = nil
	m_GoOutUncondition = false
	FwqYaoqiuplayerQuit  =false	
	m_ParentNode = nil
	m_InviteNode = nil
	--m_SetNode = nil
	--m_TableIDLab 	= nil
 	--m_OnlineRewardsBtnShineSp = nil
	--m_OnlineRewardsBtnCanTouch = false
	--m_OnlineTimeNode = nil
	--m_IsTuoGuan = 0
	m_IsGuanZhan = false
	m_BaseLayer = nil
	--m_SetMenuIsVisible = false
	m_GameState = 0
	m_RoomDateNode = nil
	--m_LobbyShowWorldTalkLab = nil
	m_RuleBtn = nil
	--m_OnlineRewardsBtn = nil	--在线奖励按钮
	--m_PdownSetMenu = nil 		--设置下拉菜单
	--m_PupSetMenu = nil			--设置上拉菜单
	m_BackBtn = nil			    --返回按钮
	m_TalkBtn = nil			    --说话按钮
	m_RenwuBtn = nil            --任务
	m_FriendInviteBtn = nil 	--好友邀请
	m_SetBtn = nil				--设置按钮
	--m_TuoGuanBtn = nil			--托管按钮
	--m_SetBg = nil				--设置背景
	--m_MenuBg = nil		        --按钮背景
	--m_VoiceBtn = nil			--音乐按钮
	--m_EffectBtn = nil			--音效按钮
   	m_CurrTbaleInfo = {}
    m_SysTimeSec = 0
	m_SysTimeSp = nil
	--m_Mode3GameEndTime = nil
	---m_WorldChangeLabShowTimer1 = nil
	m_BtnListBg  =nil
	--m_YuYinBtn   =nil
	m_RoomTipsNode =nil
	m_guizeMsgTb={}
	 m_DianLiangSp        =  nil     --电池电量
	 Dl_progressBar       =  nil     --百分比
	 m_WifiSp             =  nil     --WiFi
	 m_KoulingSp          =   nil   -- 口令
	 m_koulingBg          =  nil 
	 m_IsBigHostJieSuan   =false
	 m_JieSanTime         =0
	 m_failreasnValue     =0

end


CreatUI = function ( )
	CCLOG("创建设置UI")
	--返回
	local istop=nil
	local isZhanji= Pt_M_GetIsVideoFun()
	local backres1,backres2,backres3 = "xxqp_zj_fh_zc","xxqp_zj_fh_dj","xxqp_zj_fh_zc"
	if isZhanji==true then 
		istop=true 
		backres1,backres2,backres3 = "yxgy_fanhui_zc","yxgy_fanhui_dj","yxgy_fanhui_zc"
	end
	m_BackBtn = MyBtnClass:new(backres1,backres2,backres3 ,function (  )
		 Pt_M_PushbackFun()
	end,nil,true,istop)
	m_BackBtn.btnLy:setPosition(10 , sys.height-m_BackBtn.btnLy:getContentSize().height)
	m_BaseLayer:addChild(m_BackBtn.btnLy)
	m_BackBtn.btnLy:setTag(MEAN_BACKTAG)

	if isZhanji ==true then
		m_BackBtn.btnLy:setPosition(sys.center.x+320,sys.center.y-200)
	end
	M_GameBtn.backbtn = m_BackBtn
    m_koulingBg = xui.addSprite(m_RoomDateNode,"xxqp_yxjs_db",140,sys.height-40,sys.ap.leftCenter)
	--m_KoulingSp=xui.addLabel(kouingSp,"口令：",sys.colors.white,28,300, sys.height-40,sys.ap.center)
	local koulingName = xui.addSprite(m_koulingBg,"xxqp_yxjs_kl",10,m_koulingBg:getContentSize().height/2,sys.ap.leftCenter)
     m_KoulingSp = xui.addLabel( m_koulingBg, "", sys.creColor3( 248,220,110 ), 32, koulingName:getContentSize().width+30, m_koulingBg:getContentSize().height/2, sys.ap.leftCenter)
    m_KoulingSp:setTag(11)
    M_GameBtn.koulingName = m_koulingBg
	local offy = 95
	local offx = 70
	local startx = sys.width - 80
	local starty = sys.height - 80
	--设置
	m_SetBtn = MyBtnClass:new("xxqp_sz_zcn","xxqp_sz_djn","xxqp_sz_zcn",function (  )
     -- test模拟断线重连
	 -- if 1 then
	 -- 	   SMALLTOBIGUNDELLCLIENT = true
	 --        Pt_EventMgr:fire(Pt_Events.RECONNECT_INFO)
	 --        local timer = nil
	 --        timer = CCDirector:getInstance():getScheduler():scheduleScriptFunc( function (  )
	 --                CS_REQUEST_ROOM()
	 --                CCDirector:getInstance():getScheduler():unscheduleScriptEntry( timer )
	 --                timer = nil
	 --            end,1,false)
	 --        return
	 --    end
	Pt_Public_SetVoiAndEffe()
	end,nil,true,nil,{width = 79,height = 77})
	m_SetBtn.btnLy:setPosition(startx, starty )
	m_BaseLayer:addChild(m_SetBtn.btnLy)
	m_SetBtn.btnLy:setTag(MEAN_SETTAG)
    M_GameBtn.setbtn = m_SetBtn
    if isZhanji ==true then
       m_SetBtn.SetMyBtnTouchEnableState(false)
    end

    startx = sys.width - 40
    starty = sys.height - 40
    --WiFi
    m_WifiSp =xui.addSprite(m_BaseLayer,"wifi_1",startx-offx,starty)
    M_GameBtn.wifi =m_WifiSp
    if(PT_VER_CONTROL ~= "local")then
	    Pt_M_UpdateSpWifi()
	    Pt_M_UpdateWifi()
	end
    --电量
    m_DianLiangSp=xui.addSprite(m_BaseLayer,"xxqp_dc",startx-2*offx,starty)
    M_GameBtn.diadLiang =m_DianLiangSp
    Dl_progressBar = xui.addProgressH(m_DianLiangSp, "xxqp_dc_man", m_DianLiangSp:getContentSize().width/2-2, m_DianLiangSp:getContentSize().height/2)
    Dl_progressBar:setTag(1)
    Dl_progressBar:setPercentage(50)
    if(PT_VER_CONTROL ~= "local")then
	    local  precent= sys.getBatteryPercent()
		if precent and  type(precent)=="number"  then
		    if Dl_progressBar then
		        Dl_progressBar:setPercentage(precent)
		    end
		end
	   Pt_M_UpdateDianLian()
	end
    local isCre = Pt_M_CreateRecorderUI(sys.width-70+7,sys.center.y-2*80+10)
    Pt_RegisterRecvRecordCallBack(function ( playerID,duration )
        Pt_M_ReCvRecordFun(playerID,duration)
    end)
    local offY = 80
    local offX = 7
    local size = {width=70,height=180}   --250
    CCLOG("isCre",isCre)
    if isCre then
        size = {width=70,height=250}
    end
    local starty = size.height-80
    m_BtnListBg= xui.addSpr9(m_BaseLayer,"xxqp_dt_fxb_zc",size.width,size.height,sys.width-size.width/2,sys.center.y-30)--xui.addSprite(m_BaseLayer,"xxqp_dt_fxb_zc",sys.width-30,sys.center.y)
    M_GameBtn.btnListbg =m_BtnListBg

    --规则
	m_RuleBtn = MyBtnClass:new("xxqp_bz_zcn","xxqp_bz_djn","xxqp_bz_zcn",function (  )
		-- Pt_EventMgr:fire(Pt_Events.CC_GUIZE)
        PushGuiZeCB()

	end,nil,true,nil,{width = 55,height = 60})
	
	m_BtnListBg:addChild(m_RuleBtn.btnLy)
	m_RuleBtn.btnLy:setTag(RULEBTNTAG)
	m_RuleBtn.btnLy:setPosition(offX, starty)
	M_GameBtn.guizetn =m_RuleBtn
	if isZhanji ==true then
       m_RuleBtn.SetMyBtnTouchEnableState(false)
    end


    --if 1 then return end
	m_TalkBtn = MyBtnClass:new("xxqp_xx_zcn","xxqp_xx_djn","xxqp_xx_zcn",function (  )
		 PushTalkCB()
	end,nil,true,nil)
	
	m_BaseLayer:addChild(m_TalkBtn.btnLy)
	m_TalkBtn.btnLy:setTag(MEAN_TALKTAG)
	m_TalkBtn.btnLy:setPosition(sys.width-size.width+10,sys.center.y-65)
	M_GameBtn.chatbtn =m_TalkBtn
    if isZhanji ==true then
       m_TalkBtn.SetMyBtnTouchEnableState(false)
    end
    --m_TalkBtn.SetMyBtnVisible(false)
	-- m_YuYinBtn = MyBtnClass:new("xxqp_yy_zc","xxqp_yy_dj","xxqp_yy_zc",function (  )
	-- 	  if Pt_M_GetIsVideoFun() ==true then return end
		
	-- end,nil,true,nil,{width = 55,height = 60})
	
	-- m_BtnListBg:addChild(m_YuYinBtn.btnLy)
	-- m_YuYinBtn.btnLy:setTag(RULEBTNTAG)
	-- m_YuYinBtn.btnLy:setPosition(offX, starty-2*offY)
	-- M_GameBtn.yuyinbtn =m_YuYinBtn
	-- m_YuYinBtn.SetMyBtnVisible(false)
	-- if isZhanji ==true then
 --       m_YuYinBtn.SetMyBtnTouchEnableState(false)
 --    end

	-- 系统时间
	if isZhanji ==false then
	   CreSysTime()
	end
    --房主离开房间
	Pt_SaveJieSanRoom(false)
end

--接到语音
function Pt_M_ReCvRecordFun(playerID,duration)
    CCLOG("Pt_M_ReCvRecordFun",playerID,duration)
    local m_TouXiangLayerTB = {}
    if m_CurrGameID  ==emGame_LuZhouMaJiang then
     	m_TouXiangLayerTB=Lzmj_M_GetTouXiangLayer()
    end
    if m_CurrGameID  ==emGame_MaJiang then
     	m_TouXiangLayerTB=Majo_M_GetTouXiangLayer()
    end
    if m_CurrGameID  ==emGame_YiBinMaJiang then
     	m_TouXiangLayerTB=YbMj_M_GetTouXiangLayer()
    end
    if m_CurrGameID  ==emGame_NeiJiangMaJiang or m_CurrGameID  ==emGame_NeiJiang3RenMaJiang  then
     	m_TouXiangLayerTB=Njmj_M_GetTouXiangLayer()
    end
    if m_CurrGameID  ==emGame_ZiGongMaJiang then
     	m_TouXiangLayerTB=Zgmj_M_GetTouXiangLayer()
    end
    if m_CurrGameID  ==emGame_YBYaoDiRen then
     	m_TouXiangLayerTB=YbYdr_M_GetTouXiangLayer()
    end
    if (m_CurrGameID  ==emGame_DaEr) or (m_CurrGameID ==emGame_HeJiangDaEr)  or (m_CurrGameID ==emGame_XuYongDaEr)  or (m_CurrGameID ==emGame_GuLinDaEr) then
     	m_TouXiangLayerTB=YbDaer_M_GetTouXiangLayer()
    end
    if m_CurrGameID  ==emGame_PuChengMaJiang then
     	m_TouXiangLayerTB=Pcmj_M_GetTouXiangLayer()
    end
    if m_CurrGameID == emGame_YBDouDiZhu then
    	m_TouXiangLayerTB =Ybddz_M_PlayerInfoCallBack() 
    end
    for k,v in pairs(m_TouXiangLayerTB or {}) do
         if v.playerinfo and v.playerinfo.playerid ==playerID then
            v:ShowYuYinFun(duration)
         end
     end
end
PushGuiZeCB=function (  )
    CCLOG("PushGuiZeCB",m_CurrGameID)
    if not m_CurrTbaleInfo.deskparam  then CCLOG("deskparam")  return end  	
    local  guizeStrTb = {}
    for k,v in pairs(m_CurrTbaleInfo.deskparam.rule or {}) do
    	if v.name then
           table.insert(guizeStrTb,v.name)
        end
        if v.seeds then 
            for k1,v1 in pairs(v.seeds or {}) do
            	if v1.name then
                   table.insert(guizeStrTb,v1.name)
            	end
            end
        end
    end
    if m_CurrTbaleInfo.deskparam.type  then
        table.insert(guizeStrTb,m_CurrTbaleInfo.deskparam.type.name)
        if m_CurrTbaleInfo.deskparam.type.seeds  then
            for k,v in pairs(m_CurrTbaleInfo.deskparam.type.seeds or {}) do
          	   table.insert(guizeStrTb,v.name)
            end
        end
    end
    if m_CurrTbaleInfo.deskparam.type2  then
        table.insert(guizeStrTb,m_CurrTbaleInfo.deskparam.type2.name)
        if m_CurrTbaleInfo.deskparam.type2.seeds  then
            for k,v in pairs(m_CurrTbaleInfo.deskparam.type2.seeds or {}) do
          	   table.insert(guizeStrTb,v.name)
            end
        end
    end
    local ruleCount = sys.getTBCount(guizeStrTb)
    CCLOG("guizeStrTb",ruleCount)
    local str_x =30
    local off_y =25
    local size={width=260,height=240}
    local startx,starty =sys.width-200, sys.center.y-30
    if ruleCount >0 then
       local sortCount =0
       for k,v in pairs(guizeStrTb) do
       	    if string.utf8len(v)>4 then
                size.height=size.height+off_y
                sortCount=0
            else
                sortCount=sortCount+1
                if sortCount ==1 then
                    size.height=size.height+off_y
                end
                if sortCount>1 then sortCount=0 end
       	    end
       end
    end
   	local sDirector = CCDirector:getInstance()
    local currScene = sDirector:getRunningScene()

	local backNode = cc.Node:create()
	m_BaseLayer:addChild(backNode,300)
	backNode:setPositionX(300)
    local isMoveClicek = false
    local  array={}
    array[1]=cc.MoveTo:create(0.15,{x=0,y=0})
	array[2]=cc.CallFunc:create(function (  )
	  	isMoveClicek=true
	end)
    backNode:runAction(cc.Sequence:create(array))

	local function CloseBackUI(  )
		if backNode then
			local array1={}
			array1[1]=cc.MoveTo:create(0.1,{x=300,y=0})
			array1[2]=cc.CallFunc:create(function (  )
				backNode:removeFromParent(true)
				backNode=nil
				isMoveClicek=false
			end)
		    backNode:runAction(cc.Sequence:create(array1))
		end
	end
    local mask = xui.creMaskLy( backNode, nil, nil, nil, function (  )
         CloseBackUI()
	end )
    local tipsBg = xui.addSpr9(backNode,"yxgy_yxgz_bg",size.width, size.height, startx,starty)
    local namelableStr=""
    local lableStr=""
    if m_CurrTbaleInfo.deskparam.cname then 
         namelableStr=m_CurrTbaleInfo.deskparam.cname 
    end
    starty=starty+size.height/2-30
    --名字
    local namaLabel  =xui.addLabel(backNode,namelableStr,cc.c3b(93,58,0),26,startx,starty)
    starty  =starty-40
    local guzenameBg=xui.addSprite(backNode,"yxgy_yxgz_gztxt",startx,starty+4)
    local count  =0
    for k,v in pairs(guizeStrTb) do
    	if v~=nil then
            local add_x = 0
            if string.utf8len(v)>4 then
                 starty =starty-off_y 
                 count=0
            else
                count=count+1
                if count ==1 then
                    starty =starty-off_y 
                end
                if count==2 then add_x=100  count=0 end
            end

            local guinamaLabel  =xui.addLabel(backNode,v,cc.c3b(93,58,0),22,startx-size.width/2+str_x+add_x,starty,sys.ap.leftCenter)
    	end
    end
    starty  =starty-30
    local fansuBg =xui.addSprite(backNode,"yxgy_yxgz_jushu",startx,starty)
    starty  =starty-30
    local maxjuStr = "本轮最大"
    local maxHouZhuiStr ="番"
    if m_CurrTbaleInfo.deskparam.multi ~=0 then
    	if m_CurrGameID  == emGame_LuZhouMaJiang or m_CurrGameID  == emGame_DaEr   then
	       maxjuStr="最大颗数"
	       maxHouZhuiStr="颗"
	    end
	    if m_CurrGameID  == emGame_YBDouDiZhu   then
	       maxjuStr="最大炸数"
	       maxHouZhuiStr="炸"
	    end
        maxjuStr=maxjuStr..m_CurrTbaleInfo.deskparam.multi..maxHouZhuiStr
    else
    	maxHouZhuiStr="不限番"
    	if m_CurrGameID  == emGame_LuZhouMaJiang or m_CurrGameID  == emGame_DaEr   then
	       maxHouZhuiStr="不限颗数"
	    end
	    if m_CurrGameID  == emGame_YBDouDiZhu then
	       maxHouZhuiStr="不限炸"
	    end
    	maxjuStr=maxjuStr..maxHouZhuiStr
    end
    CCLOG("maxjuStr",maxjuStr)
    local maxJushu =xui.addLabel(backNode,maxjuStr,cc.c3b(93,58,0),22,startx-size.width/2+str_x,starty,sys.ap.leftCenter)
    starty  =starty-off_y
    local jushustr="本轮游戏为"
    if m_CurrTbaleInfo.deskparam.turn ~=0 then
       jushustr=jushustr..m_CurrTbaleInfo.deskparam.turn.."局"
    end
    --局数
    local chocseJushu =xui.addLabel(backNode,jushustr,cc.c3b(93,58,0),22,startx-size.width/2+str_x,starty,sys.ap.leftCenter)
    starty  =starty-40
    local winRes ="yxgy_yxgz_dyj"
    if  m_CurrTbaleInfo.costtype  and  m_CurrTbaleInfo.costtype==emRoomCostType_Host    then 
         winRes ="yxgy_yxgz_fangzhu"
    end
    local dayingBg =xui.addSprite(backNode,winRes,startx,starty)
end
--更新电量
function Pt_M_UpdateDianLian( )
	local time = 10
	if Dl_progressBar  then
		local timeArray = {}
		timeArray[1] = CCDelayTime:create(time)
		timeArray[2] = CCCallFunc:create(function (  )
            CCLOG("Pt_M_UpdateDianLian")
            local  precent= sys.getBatteryPercent()
            if  precent and  type(precent)=="number"  then
                if Dl_progressBar then
                    Dl_progressBar:setPercentage(precent)
                end
            end
		end)
		local seq = CCSequence:create(timeArray)
		local repeatAni = CCRepeatForever:create(seq)
		m_BaseLayer:runAction(repeatAni)
	end
end
--跟新WiFi
function Pt_M_UpdateWifi( )
	local time = 10
	if m_WifiSp  then
		local timeArray = {}
		timeArray[1] = CCDelayTime:create(time)
		timeArray[2] = CCCallFunc:create(function (  )
                                                Pt_M_UpdateSpWifi()
											end)
		local seq = CCSequence:create(timeArray)
		local repeatAni = CCRepeatForever:create(seq)
		m_BaseLayer:runAction(repeatAni)
	end
end
--UpdateWifi Sp

function Pt_M_UpdateSpWifi(  )
	local wifiState=sys.getWebState()
	local wifiRes="wifi_1"
    if   wifiState and wifiState ==2  then
       local wifipersent=sys.getWifiState()
       if wifipersent and  type(wifipersent) and wifipersent>0 and wifipersent<=100  then
            if  wifipersent> 0 and wifipersent<=25 then
                wifiRes="wifi_2"
           	elseif  wifipersent> 25 and wifipersent<=50 then
                wifiRes="wifi_3"
           	elseif  wifipersent> 50 and wifipersent<=75 then
                wifiRes="wifi_4"
           	else
                wifiRes="wifi_5"
           	end
        end
    elseif  wifiState and wifiState ==1  then
        wifiRes="xxqp_yxgy_yidong"
    elseif  wifiState and wifiState ==3  then
    	wifiRes="xxqp_yxgy_yidong"
    elseif  wifiState and wifiState ==4  then
    	wifiRes="xxqp_yxgy_yidong"
    elseif  wifiState and wifiState ==5  then
    	wifiRes="xxqp_yxgy_yidong"
    else
    	wifiRes="wifi_1"
    end
    CCLOG("Pt_M_UpdateSpWifi",wifiState,wifiRes)
    if m_WifiSp and wifiRes then
        m_WifiSp:setSpriteFrame(wifiRes)
    end
end
--跟新返回按钮
function Pt_M_ShowBackBtn( isShow )
	if m_BackBtn  then
        m_BackBtn.SetMyBtnVisible(isShow)
	end
	if m_koulingBg  then
       m_koulingBg:setVisible(isShow)
	end
end
DelroomTipsFun= function ( ... )
	if m_RoomTipsNode ~=nil then
	   m_RoomTipsNode:stopAllActions()
       m_RoomTipsNode:removeAllChildren(true)
       CCLOG("DelroomTipsFun")
	end

	m_showLocationTip = false
	m_locationPlayerTable = {}
end
--返回关闭
CrePushBackUI =function ( isType )
	if m_ParentNode ~=nil then
		CCLOG("isType",isType)
		local size={width=570,height=350}
		local backNode = cc.Node:create()
		m_ParentNode:addChild(backNode,PT_GAME_PUBLIC_ZORDER+200)

		local scaleNode = xui.addNode(backNode)
		scaleNode:setPosition(sys.center.x, sys.center.y)
		Pt_M_UIAni_ScaleOut(scaleNode)
		scaleNode:setLocalZOrder(2)

   
		local function CloseBackUI(  )
			local function _callfunc()
				if backNode then
					backNode:removeFromParent(true)
				end
			end
			Pt_M_UIAni_ScaleIn(scaleNode, _callfunc)
			
		end
	    local mask = xui.creMaskLy( backNode, nil, nil, nil, function (  )
            -- CloseBackUI()
		end )
	    local tipsBg = xui.addSpr9(scaleNode,"xxqp_bg_0",570, 350, 0, 0)
		-- ---关闭
		local closeBtn = MyBtnClass:new("xxqp_cancel_zc","xxqp_cancel_dj","xxqp_cancel_dj",
							function ( )
								CloseBackUI()
							end)
		tipsBg:addChild(closeBtn.btnLy,4)
		closeBtn.btnLy:setPosition(tipsBg:getContentSize().width-50, tipsBg:getContentSize().height-50)
	         
        if  isType ==2 then
            local lableStr = "提示"
            local lable =xui.addLabel(scaleNode,lableStr,sys.colors.white,28,0,0+size.height/2-55,sys.ap.center)
            local lableStr = "退回大厅就退出房间啦！"
            local lable =xui.addLabel(scaleNode,lableStr,sys.colors.white,28,0,0+50,sys.ap.center)
            local lableStr = "确定要退出吗？"
            local lable =xui.addLabel(scaleNode,lableStr,sys.colors.white,28,0,0,sys.ap.center)
        else
            local lableStr = "解散房间"
        	local lable =xui.addLabel(scaleNode,lableStr,sys.colors.white,28,0,0+size.height/2-55,sys.ap.center)
        	local lableStr = "游戏未开始，确定退出房间吗？"
        	--审核 iOS
            if  CHECK_VER_FLAG_CONTROL ==nil  then 
                lableStr = "游戏未开始，解散房间不会扣除房卡！"
            end
            local lable =xui.addLabel(scaleNode,lableStr,sys.colors.white,28,0,0+30,sys.ap.center)
        end

	    local tongyiBtn = MyBtnClass:new("xxqp_xzdq_qd_zc","xxqp_xzdq_qd_dj","xxqp_xzdq_qd_zc",function ( ... )
		    CCLOG("push 同意")
		    Pt_M_SendShengQingCloseRoom(Index)
		    CloseBackUI()
		    Pt_JMessageExitAllGroup()
	    end)
	    scaleNode:addChild(tongyiBtn.btnLy)
	    tongyiBtn.btnLy:setPosition(0-135,0-size.height/2+40)
	end
end
CreJieSanFun =function ( s )
    CCLOG("CreJieSanFun   ---1") 
	local faqiTb = {}
	local jujueTb = {} 
	local tongyiTb = {}
	local infoTb={}
	if s.waittime  then
		m_JieSanTime =s.waittime
	end
	for k,v in pairs(s) do
		if v and type(v) =="table"  then
           -- infoTb=v
           -- break
           table.insert(infoTb,v)
		end
	end
	--SHOW(infoTb)
	for k,v in pairs(infoTb) do
		if v.agree and v.agree ==emAgreeType_Refuse  then
	        table.insert(jujueTb,v)
		end
	    if v.agree and v.agree ==emAgreeType_Agree  then
	        table.insert(tongyiTb,v)
		end
	    if v.agree and v.agree ==emAgreeType_Hand  then
	        table.insert(faqiTb,v)
		end
	end
	if sys.getTBCount(jujueTb)==0 then
		CreShenQingCloseRoomTipsFun(faqiTb,tongyiTb,infoTb)
	else
		CreJuJueCloseRoonTipsFun(faqiTb,jujueTb)
	end
end
CreSccussRoomTipsFun=function ( s )
    DelroomTipsFun()
    local mask = xui.creMaskLy( m_RoomTipsNode, nil, nil, nil, function (  )

	end )
	local tipsBg = xui.addSpr9(m_RoomTipsNode,"xxqp_bg_0",570, 350, sys.center.x, sys.center.y)

	---关闭
	local closeBtn = MyBtnClass:new("xxqp_cancel_zc","xxqp_cancel_dj","xxqp_cancel_dj",
						function ( )
							DelroomTipsFun()
						end)
	tipsBg:addChild(closeBtn.btnLy,4)
	closeBtn.btnLy:setPosition(tipsBg:getContentSize().width-50, tipsBg:getContentSize().height-50)
    
    local lableStr = "玩家".."XXXXX".."成功开房"

    local lable =xui.addLabel(m_RoomTipsNode,lableStr,sys.colors.white,28,sys.center.x,sys.center.y,sys.ap.center)
end

CreShenQingCloseRoomTipsFun = function (faqiTb,tongyiTb,infoTb)
	DelroomTipsFun()
	CCLOG("CreShenQingCloseRoomTipsFun m_JieSanTime", m_JieSanTime)
	local size={width=570,height=350}
    local mask = xui.creMaskLy( m_RoomTipsNode, nil, nil, nil, function (  )

	end )
	local tipsBg = xui.addSpr9(m_RoomTipsNode,"xxqp_bg_0",size.width, size.height, sys.center.x, sys.center.y)
    local fangzhuName = faqiTb[1].nickname
    if  fangzhuName ~= nil and string.utf8len(fangzhuName) > 9 then
        fangzhuName = string.utf8sub(fangzhuName,1,8).."…"
    end
    local lableStr = fangzhuName.."申请解散房间"
    local lable =xui.addLabel(m_RoomTipsNode,lableStr,sys.colors.white,28,sys.center.x,sys.center.y+size.height/2-50,sys.ap.center)
    local testTb =tongyiTb 
    local startx=sys.center.x
    local starty=sys.center.y+size.height/2-110
    local count = 0
    local offy = 40
    local canClick = false
    for k,v in pairs(tongyiTb) do
    	--SHOW(v)
    	if v~=nil and v.nickname then
    		local playName = v.nickname
		    if  playName ~= nil and string.utf8len(playName) > 9 then
		        playName = string.utf8sub(playName,1,8).."…"
		    end
    		local strlab =playName.."已同意"
            local namelab = xui.addLabel(m_RoomTipsNode,strlab,sys.colors.white,24,startx,starty-offy*count,sys.ap.center)
            count=count+1
    	end
    end
    local playerid=faqiTb[1].playerid  or 0
    for k,v in pairs(infoTb) do
    	if v and v.playerid and v.playerid ==Pt_GetPlayerInfo().playerid  then
            if v.agree ==emAgreeType_Agree then
               canClick=true
               CCLOG("canClick")
            end
    	end
    end
    CCLOG("canClick ----",canClick)
    local tongyiBtn = MyBtnClass:new("yxgy_btn_tongyi_zc","yxgy_btn_tongyi_dj","yxgy_btn_tongyi_zc",function ( ... )
	    CCLOG("push 同意",canClick)
	    if canClick==false then
		    local info ={}
		    info.agree =emAgreeType_Agree
		    CS_DISMISS_DESK(info)
		else
            tips.creUpTimeBgTips("已经同意了")
		end
    end)
    m_RoomTipsNode:addChild(tongyiBtn.btnLy)
    tongyiBtn.btnLy:setPosition(sys.center.x-size.width/2+40,sys.center.y-size.height/2+40)
   
    local jujueBtn = MyBtnClass:new("yxgy_btn_jujue_zc","yxgy_btn_jujue_dj","yxgy_btn_jujue_zc",function ( ... )
    	-- body
    	 if canClick==false then
		    CCLOG("push 拒绝")
		    local info ={}
		    info.agree =emAgreeType_Refuse
		    CS_DISMISS_DESK(info)
		else
           tips.creUpTimeBgTips("已经同意了")
		end
    end)
    m_RoomTipsNode:addChild(jujueBtn.btnLy)
    jujueBtn.btnLy:setPosition(sys.center.x-size.width/2+320,sys.center.y-size.height/2+40)
    local off_x = sys.center.x+size.width/2-120
    local a = sys.ap.leftCenter
    if playerid ==Pt_GetPlayerInfo().playerid  or canClick==true then
    	CCLOG("发起者Ui")
    	tongyiBtn.SetMyBtnVisible(false)  	
    	jujueBtn.SetMyBtnVisible(false)  
    	off_x=sys.center.x
    	a=sys.ap.center
    end
    CCLOG("m_JieSanTime----1")
    if m_JieSanTime and m_JieSanTime>0 then
    	CCLOG("m_JieSanTime----2")
        local m_timelable =xui.addLabel(m_RoomTipsNode,"("..m_JieSanTime..")",sys.colors.white,28,off_x,sys.center.y-size.height/2+82,a)
        m_timelable:setLocalZOrder(1000)
        CCLOG("m_JieSanTime----3")
        local array = {}
        array[1]=cc.DelayTime:create(1)
        array[2]=CCCallFunc:create(function ( ... )
        	m_JieSanTime=m_JieSanTime-1
        	--CCLOG("m_JieSanTime",m_JieSanTime)
        	if m_JieSanTime<0 then m_JieSanTime=0 end
        	if m_timelable  then
               m_timelable:setString("("..m_JieSanTime..")")
        	end
        	CCLOG("m_JieSanTime----4")
        	if m_JieSanTime==0 then
	            DelroomTipsFun()
        	end
        end)

        local repeatAni = CCRepeatForever:create(CCSequence:create(array))
        m_RoomTipsNode:runAction(repeatAni)
        CCLOG("m_JieSanTime----5")
    end
end
CreJuJueCloseRoonTipsFun =function (faqiTb,jujueTb)
   DelroomTipsFun()
   CCLOG("CreJuJueCloseRoonTipsFun m_JieSanTime", m_JieSanTime)
	local size={width=570,height=350}
    local mask = xui.creMaskLy( m_RoomTipsNode, nil, nil, nil, function (  )

	end )
	local tipsBg = xui.addSpr9(m_RoomTipsNode,"xxqp_bg_0",size.width, size.height, sys.center.x, sys.center.y)
    local fangzhuName = faqiTb[1].nickname
    if  fangzhuName ~= nil and string.utf8len(fangzhuName) > 9 then
        fangzhuName = string.utf8sub(fangzhuName,1,8).."…"
    end
    local lableStr =fangzhuName.."申请解散房间"
    local lable =xui.addLabel(m_RoomTipsNode,lableStr,sys.colors.white,28,sys.center.x,sys.center.y+size.height/2-50,sys.ap.center)
    local startx=sys.center.x
    local starty=sys.center.y+40 
    local count = 0
    local offy = 40
    for k,v in pairs(jujueTb) do
    	if v~=nil and v.nickname then
    		local playName = v.nickname
		    if  playName ~= nil and string.utf8len(playName) > 9 then
		        playName = string.utf8sub(playName,1,8).."…"
		    end
    		local strlab =playName.."已拒绝"
           local namelab = xui.addLabel(m_RoomTipsNode,strlab,sys.colors.white,24,startx,starty-offy*count,sys.ap.center)
           count=count+1
    	end
    end
    local guanbiBtn = MyBtnClass:new("yxgy_btn_guanbi_zc","yxgy_btn_guanbi_dj","yxgy_btn_guanbi_zc",function ( ... )
    	 DelroomTipsFun()
    end)
    m_RoomTipsNode:addChild(guanbiBtn.btnLy)
    guanbiBtn.btnLy:setPosition(sys.center.x-110,sys.center.y-size.height/2+60)

end
--游戏调用
function Pt_M_GameJieSanTips(  )
	CCLOG("Pt_M_GameJieSanTips")
	DelroomTipsFun()
end

---游戏调用
function Pt_M_CreJisTips(  s)
	CreDuanXianUI(s)
end
CreDuanXianUI  =function ( s )
	if s.dismisstime  then
		if s.dismisstime ~=0 then
             local  shengqingStr =""
             local  shenqingId  =0
             local  haveJujie = false
             m_JieSanTime  = s.dismisstime
             CCLOG(" CreDuanXianUI m_JieSanTime", m_JieSanTime)
             for k,v in pairs(s.playerlist) do
             	 if v.dismissstate  and v.dismissstate==emAgreeType_Hand then
         	 	     local playName = v.nickname
				     if  playName ~= nil and string.utf8len(playName) > 9 then
				        playName = string.utf8sub(playName,1,8).."…"
				     end
                     shengqingStr=playName.."申请解散房间"
                     shenqingId=v.playerid
             	 end
             	 if v.dismissstate  and v.dismissstate==emAgreeType_Refuse then

                     haveJujie=true
             	 end
             end
            if haveJujie==true then CCLOG("有人拒绝--------1")  return end
            DelroomTipsFun()
			local size={width=570,height=350}
		    local mask = xui.creMaskLy( m_RoomTipsNode, nil, nil, nil, function (  )

			end )
			local tipsBg = xui.addSpr9(m_RoomTipsNode,"xxqp_bg_0",size.width, size.height, sys.center.x, sys.center.y)
		    local lable =xui.addLabel(m_RoomTipsNode,shengqingStr,sys.colors.white,28,sys.center.x,sys.center.y+size.height/2-50,sys.ap.center)
		    local startx=sys.center.x---size.width/2+40
		    local starty=sys.center.y+size.height/2-110
		    local count = 0
		    local offy = 40
		    local canClick = false

		    for k,v in pairs(s.playerlist) do
		    	--SHOW(v)
		    	if v.dismissstate  and v.dismissstate==emAgreeType_Agree then
			    	if v~=nil and v.nickname then
			    		local playName = v.nickname
					    if  playName ~= nil and string.utf8len(playName) > 9 then
					        playName = string.utf8sub(playName,1,8).."…"
					    end
			    		local strlab =playName.."已同意"
			            local namelab = xui.addLabel(m_RoomTipsNode,strlab,sys.colors.white,24,startx,starty-offy*count,sys.ap.center)
			            count=count+1
			    	end
			    	if v.playerid ==Pt_GetPlayerInfo().playerid  and v.dismissstate==emAgreeType_Agree   then
                        canClick = true
			    	end
			    end
		    end

		    local tongyiBtn = MyBtnClass:new("yxgy_btn_tongyi_zc","yxgy_btn_tongyi_dj","yxgy_btn_tongyi_zc",function ( ... )
			    CCLOG("push 同意",canClick)
			    if canClick==false then
				    local info ={}
				    info.agree =emAgreeType_Agree
				    CS_DISMISS_DESK(info)
				else
		            tips.creUpTimeBgTips("已经同意了")
				end
		    end)
		    m_RoomTipsNode:addChild(tongyiBtn.btnLy)
		    tongyiBtn.btnLy:setPosition(sys.center.x-size.width/2+40,sys.center.y-size.height/2+40)
	   
		    local jujueBtn = MyBtnClass:new("yxgy_btn_jujue_zc","yxgy_btn_jujue_dj","yxgy_btn_jujue_zc",function ( ... )
		    	-- body
		    	if canClick==false then
				    CCLOG("push 拒绝")
				    local info ={}
				    info.agree =emAgreeType_Refuse
				    CS_DISMISS_DESK(info)
				else
		            tips.creUpTimeBgTips("已经同意了")
				end
		    end)
		    m_RoomTipsNode:addChild(jujueBtn.btnLy)
		    jujueBtn.btnLy:setPosition(sys.center.x-size.width/2+320,sys.center.y-size.height/2+40)
            local off_x = sys.center.x+size.width/2-120
            local a=sys.ap.leftCenter
		    if shenqingId ==Pt_GetPlayerInfo().playerid or canClick==true  then
		    	tongyiBtn.SetMyBtnVisible(false)  	
		    	jujueBtn.SetMyBtnVisible(false)  
		    	off_x=sys.center.x
		    	a=sys.ap.center
		    end
		    if m_JieSanTime and m_JieSanTime>0 then
                local m_timelable =xui.addLabel(m_RoomTipsNode,"("..m_JieSanTime..")",sys.colors.white,28,off_x,sys.center.y-size.height/2+82,a)
		        m_timelable:setLocalZOrder(1000)
		        local array = {}
		        array[1]=cc.DelayTime:create(1)
                array[2]=CCCallFunc:create(function ( ... )
                	m_JieSanTime=m_JieSanTime-1
                	CCLOG("m_JieSanTime",m_JieSanTime)
                	if m_JieSanTime<0 then m_JieSanTime=0 end
                	if m_timelable  then
                       m_timelable:setString("("..m_JieSanTime..")")
                	end
                	if m_JieSanTime==0 then
			            DelroomTipsFun()
		        	end
                end)

		        local repeatAni = CCRepeatForever:create(CCSequence:create(array))
		        m_RoomTipsNode:runAction(repeatAni)
		    else
		    	CCLOG("m_JieSanTime===0")
		    end
		else
            CCLOG("断线没有结算房间")
		    return
		end
	end
end


--得到玩家位置信息tip弹窗
CreLocationTipsFun = function (s)
	DelroomTipsFun()
	m_locationPlayerTable = {}

	local tmpTbl = {}
	local playerTb = {}
	local mySeat = 0
	for i = 1, #s do
		if(s[i].playerid ~= Pt_GetPlayerInfo().playerid)then
			table.insert(tmpTbl, s[i])
		else
			mySeat = s[i].seat
		end
	end

	if(mySeat == 0 or mySeat == nil)then
		playerTb = tmpTbl
	else
		if(#s == 3)then
			for i = 1, #tmpTbl do
				if(mySeat == 1)then
					if(tmpTbl[i].seat == 2)then
						playerTb[2] = tmpTbl[i]
					else
						playerTb[1] = tmpTbl[i]
					end
				elseif(mySeat == 2)then
					if(tmpTbl[i].seat == 3)then
						playerTb[2] = tmpTbl[i]
					else
						playerTb[1] = tmpTbl[i]
					end
				elseif(mySeat == 3)then
					if(tmpTbl[i].seat == 1)then
						playerTb[2] = tmpTbl[i]
					else
						playerTb[1] = tmpTbl[i]
					end
				end
			end
		else
			for i = 1, #tmpTbl do
				if(mySeat == 1)then
					if(tmpTbl[i].seat == 3)then
						playerTb[1] = tmpTbl[i]
					elseif(tmpTbl[i].seat == 2)then
						playerTb[3] = tmpTbl[i]
					else
						playerTb[2] = tmpTbl[i]
					end
				elseif(mySeat == 2)then
					if(tmpTbl[i].seat == 4)then
						playerTb[1] = tmpTbl[i]
					elseif(tmpTbl[i].seat == 3)then
						playerTb[3] = tmpTbl[i]
					else
						playerTb[2] = tmpTbl[i]
					end
				elseif(mySeat == 3)then
					if(tmpTbl[i].seat == 1)then
						playerTb[1] = tmpTbl[i]
					elseif(tmpTbl[i].seat == 4)then
						playerTb[3] = tmpTbl[i]
					else
						playerTb[2] = tmpTbl[i]
					end
				elseif(mySeat == 4)then
					if(tmpTbl[i].seat == 2)then
						playerTb[1] = tmpTbl[i]
					elseif(tmpTbl[i].seat == 1)then
						playerTb[3] = tmpTbl[i]
					else
						playerTb[2] = tmpTbl[i]
					end
				end
			end
		end
	end

	

	local size={width=712,height=450}
    local mask = xui.creMaskLy( m_RoomTipsNode, nil, nil, nil, function (  )

	end )
	local tipsBg = xui.addSpr9(m_RoomTipsNode,"xxqp_bg_0",size.width, size.height, sys.center.x, sys.center.y)

	local titleFrameSp = xui.addSprite(m_RoomTipsNode, "xxqp_grzx_bt", sys.center.x, sys.center.y + size.height / 2 - 10)
	local titlesp =  xui.addSprite(titleFrameSp, "anquanjiance", titleFrameSp:getContentSize().width / 2, titleFrameSp:getContentSize().height / 2)
	titlesp:setScale(0.75)

	local midbg = xui.addSpr9(m_RoomTipsNode,"xxqp_lxkf_bj",616, 280, sys.center.x, sys.center.y + 40)

    
    local postable = {}
    if(#playerTb == 2)then
    	postable[1] = {x = sys.center.x - 230, y = sys.center.y + 50}
    	postable[2] = {x = sys.center.x + 230, y = sys.center.y + 50}

    	--line
    	xui.addSprite(m_RoomTipsNode, "xx_hxian", sys.center.x, sys.center.y + 50)
    else
    	postable[1] = {x = sys.center.x, y = sys.center.y + 120}
    	postable[2] = {x = sys.center.x - 230, y = sys.center.y - 10}
    	postable[3] = {x = sys.center.x + 230, y = sys.center.y - 10}

    	--line
    	xui.addSprite(m_RoomTipsNode, "xx_zxian", sys.center.x - 140, sys.center.y + 90)
    	local rLine = xui.addSprite(m_RoomTipsNode, "xx_zxian", sys.center.x + 140, sys.center.y + 90)
    	rLine:setFlipX(true)
    	xui.addSprite(m_RoomTipsNode, "xx_hxian", sys.center.x, sys.center.y - 20)
    end

	for i = 1, #playerTb do
		local Latitude =  "未知"
		local Longitude = "未知"
		if(playerTb[i].position ~= nil and tonumber(playerTb[i].position.latitude) ~= nil)then
			Latitude = tonumber(playerTb[i].position.latitude)
		end
		if(playerTb[i].position ~= nil and tonumber(playerTb[i].position.longitude) ~= nil)then
			Longitude = tonumber(playerTb[i].position.longitude)
		end

		if(postable[i] ~= nil)then
			--头像框
			local headBg = xui.addSprite(m_RoomTipsNode, "yxgy_tx_mr", postable[i].x, postable[i].y)
			m_locationPlayerTable[tostring(playerTb[i].playerid)] = headBg
			

			--头像
			local function _callf()
				local _textrue = cc.Director:getInstance():getTextureCache():getTextureForKey("MyHttpPic_" .. playerTb[i].playerid)
			    if(_textrue ~= nil)then
			        local m_headSp = cc.Sprite:createWithTexture(_textrue)
	                if m_headSp  then
	                   headBg:addChild(m_headSp)
	                   m_headSp:setScale((headBg:getContentSize().width - 4) / m_headSp:getContentSize().width)
	                   m_headSp:setPosition(headBg:getContentSize().width/2,headBg:getContentSize().height/2)
	                end
			    end
			end
			local arr = {}
			arr[1] = CCDelayTime:create(2)
			arr[2] = CCCallFunc:create(_callf)
			local seq = CCSequence:create(arr)
			headBg:runAction(seq)
			
			local idbg = xui.addSprite(headBg, "yxgy_txk_idbg", headBg:getContentSize().width / 2, 12)
			idbg:setLocalZOrder(1)

		    --id和边框
			local frame = xui.addLabel(headBg, tostring(playerTb[i].playerid), cc.c3b(211, 171, 41), 20, headBg:getContentSize().width / 2, 12)
			frame:setLocalZOrder(1)
			local txk = xui.addSprite(headBg, "yxgy_tx_txk", headBg:getContentSize().width / 2, headBg:getContentSize().height / 2)
			txk:setLocalZOrder(1)

			--是否有位置信息
			if(playerTb[i].position == nil or tonumber(playerTb[i].position.latitude) == nil or tonumber(playerTb[i].position.longitude) == nil)then
				local infolabel = xui.addSprite(headBg, "xx_weizhi", headBg:getContentSize().width / 2, -20)
				infolabel:setLocalZOrder(1)
			end

			--和别人距离
			if(i > 1)then
				for j = 1, i - 1 do
					--显示位置
					local showPos = {x = 0, y = 0}
					if(#playerTb == 2)then
						showPos.x = sys.center.x
						showPos.y = sys.center.y + 50
					else
						if(i == 2)then
							showPos.x = sys.center.x - 130
							showPos.y = sys.center.y + 134
						elseif(i == 3 and j == 1)then
							showPos.x = sys.center.x + 130
							showPos.y = sys.center.y + 134
						elseif(i == 3 and j == 2)then
							showPos.x = sys.center.x
							showPos.y = sys.center.y - 20
						end
					end

					--能得到距离
					if((playerTb[i].position ~= nil and tonumber(playerTb[i].position.latitude) ~= nil and tonumber(playerTb[i].position.longitude) ~= nil) and (playerTb[j].position ~= nil and tonumber(playerTb[j].position.latitude) ~= nil and tonumber(playerTb[j].position.longitude) ~= nil))then
						local dis = sys.LantitudeLongitudeDist(tonumber(playerTb[i].position.longitude), tonumber(playerTb[i].position.latitude), tonumber(playerTb[j].position.longitude), tonumber(playerTb[j].position.latitude))
						local disString = math.ceil(dis) .. "米"
						local disColor = cc.c3b(241, 223, 53)
						if(dis < 100)then
							disString = "<100米"
							disColor = cc.c3b(243, 35, 23)
						elseif(dis >= 100 and dis <= 1000)then
							disString = "<1000米"
							disColor = cc.c3b(241, 223, 53)
						elseif(dis > 1000)then
							disString = ">1km"
							disColor = cc.c3b(123, 203, 57)
						end

						xui.addSpr9(m_RoomTipsNode,"xx_bjs",64, 40, showPos.x, showPos.y)
						xui.addLabel(m_RoomTipsNode, disString, disColor, 22, showPos.x, showPos.y)
					end

					--IP相同提示
					if(playerTb[i].ip ~= nil and playerTb[j].ip ~= nil and playerTb[i].ip ~= "" and playerTb[j].ip ~= "" and playerTb[i].ip == playerTb[j].ip)then
						xui.addSprite(m_RoomTipsNode, "xx_jg", showPos.x - 35, showPos.y - 32)
						xui.addLabel(m_RoomTipsNode, "IP相同", cc.c3b(243, 35, 23), 22, showPos.x + 12, showPos.y - 30)
					end
				end
			end
		end
	end

	local readyBtn = MyBtnClass:new("xxqp_js_ks_zc","xxqp_js_ks_dj","xxqp_js_ks_zc",function ( ... )
    	DelroomTipsFun()
    	--发送准备消息
    	CS_ROOM_SET_PLAYER_STATE()
    end)
    m_RoomTipsNode:addChild(readyBtn.btnLy)
    readyBtn.btnLy:setPosition(sys.center.x-size.width/2+80,sys.center.y-size.height/2+30)

    --退出
    local btnres = {"xx_tc","xx_tc_dj"}
    local decStr = "确定要退出吗？"
    if(Pt_GetPlayerInfo().playerid == Pt_M_GetFangZhuPlayerId())then
    	btnres = {"yxgy_btn_jsfj_zc","yxgy_btn_jsfj_dj"}
    	decStr = "确定要解散房间吗？"
    end
    local exitBtn = MyBtnClass:new(btnres[1],btnres[2],btnres[1],function (  )
    	tips.creMOKMaskTips(decStr,nil,nil,true,true,function (  )
				Pt_M_SendShengQingCloseRoom()
				Pt_JMessageExitAllGroup()
				DelroomTipsFun()
			end)

    end)
    m_RoomTipsNode:addChild(exitBtn.btnLy)
    exitBtn.btnLy:setPosition(sys.center.x-size.width/2+420,sys.center.y-size.height/2+30)
    
    m_showLocationTip = true
end


CreTongIpTipsFun=function ( s)
    CCLOG("CreTongIpTipsFun-----1")
    local strIpTb  ={}
    for k,v in pairs(s) do
    	if v ~=nil and type(v)=="table"  then
    		local tabCount = sys.getTBCount(v)
    		if tabCount>1 then 
    			local str = "玩家"
    			local count=0
	            for k1,v1 in pairs(v) do
	            	if v1.nickname  then
	            		count=count+1
	            		if tabCount~=count  then  
                           str=str..v1.nickname.."," 
                        else
                            str=str..v1.nickname.."同一IP"
                        end       
	            	end
	            end
	            table.insert(strIpTb,str)
	        end
    	end
    end
    if sys.getTBCount(strIpTb)<=0 then
       CCLOG("ip 都不同")
       return 
    end
    SHOW(strIpTb)
	DelroomTipsFun()
	local size={width=570,height=350}
    local mask = xui.creMaskLy( m_RoomTipsNode, nil, nil, nil, function (  )

	end )
	local tipsBg = xui.addSpr9(m_RoomTipsNode,"xxqp_bg_0",size.width, size.height, sys.center.x, sys.center.y)

	---关闭
	local closeBtn = MyBtnClass:new("xxqp_cancel_zc","xxqp_cancel_dj","xxqp_cancel_dj",
						function ( )
							DelroomTipsFun()
						end)
	tipsBg:addChild(closeBtn.btnLy,4)
	closeBtn.btnLy:setPosition(tipsBg:getContentSize().width-50, tipsBg:getContentSize().height-50)
    local strCount = sys.getTBCount(strIpTb)
    local starty = 0
    if strCount>1 then strCount =40 end
    for k,v in pairs(strIpTb) do
    	if v then
	    	local lableStr  =v
		    local lable =xui.addLabel(m_RoomTipsNode,lableStr,sys.colors.white,28,sys.center.x-size.width/2+49,sys.center.y+30-(k-1)*70+strCount,sys.ap.leftCenter)
		    lable:setDimensions({width=size.width-100, height=0})
        end
    end
    local jiesanBtn = MyBtnClass:new("yxgy_btn_jsfj_zc","yxgy_btn_jsfj_dj","yxgy_btn_jsfj_zc",function ( ... )
    	 Pt_M_SendShengQingCloseRoom()
    end)
    m_RoomTipsNode:addChild(jiesanBtn.btnLy)
    jiesanBtn.btnLy:setPosition(sys.center.x-size.width/2+40,sys.center.y-size.height/2+50)
    local jixuBtn = MyBtnClass:new("yxgy_btn_jxyx_zc","yxgy_btn_jxyx_dj-34","yxgy_btn_jxyx_zc",function ( ... )
    	DelroomTipsFun()
    end)
    m_RoomTipsNode:addChild(jixuBtn.btnLy)
    jixuBtn.btnLy:setPosition(sys.center.x-size.width/2+320,sys.center.y-size.height/2+50)
end



CreGuiZeTipsFun=function ( s )
	DelroomTipsFun()
	local size={width=570,height=350}
    local mask = xui.creMaskLy( m_RoomTipsNode, nil, nil, nil, function (  )

	end )
	local tipsBg = xui.addSpr9(m_RoomTipsNode,"xxqp_bg_0",size.width, size.height, sys.center.x, sys.center.y)

	---关闭
	local closeBtn = MyBtnClass:new("xxqp_cancel_zc","xxqp_cancel_dj","xxqp_cancel_dj",
						function ( )
							DelroomTipsFun()
						end)
	tipsBg:addChild(closeBtn.btnLy,4)
	closeBtn.btnLy:setPosition(tipsBg:getContentSize().width-50, tipsBg:getContentSize().height-50)

	local nameSp = xui.addSprite(m_RoomTipsNode,"yxgy_btn_blgz",sys.center.x,sys.center.y+size.height/2-50)
end

function Pt_M_BigJieSuanPushBackCB(  )
	PushBackCB()
end

PushBackAgainDelFunc = function (  )
	CCLOG("m_IsPushBackTimer===",m_IsPushBackTimer)
	if m_IsPushBackTimer == true then
		return
	end 
	m_IsPushBackTimer = true
	local array = {}
	array[1] = cc.DelayTime:create(10)
	array[2] = cc.CallFunc:create(function ( )
		m_IsPushBack = false
		m_IsPushBackTimer = false
	end)
	m_BaseLayer:runAction(cc.Sequence:create(array))
end

PushBackCB = function (  )
	CCLOG("PushBackCB",m_IsGuanZhan,m_GameState,m_IsPushBack)
	-- if Pt_GetIsLoginIn() == false then
	-- 	CCLOG("PushBackCB Pt_GetIsLoginIn is false ")
	-- 	OK_Reconnect()
	-- 	return
	-- end
	if m_IsPushBack == true then
		PushBackAgainDelFunc()
		CCLOG("Pt_M_gamepublicFun 已经发送了，不再发送")
		return
	end 

	local quitInfo = ""
	if m_IsPushBack == true then
		quitInfo = "true"
	else
		quitInfo = "false"
	end
	CS_QUIT(quitInfo)
	m_IsPushBack = true
	m_selfQuit = true
	CCLOG("PushBackCB  ---1")

	Pt_JMessageExitAllGroup()
end

function Pt_M_SetGoOutExplain( str )
	m_GoOutExplain = str
end
function Pt_M_SetGoOutCondition( _bool )
	m_GoOutUncondition = true
end

function M_public_SetIsGuan( isguan )
	CCLOG("设置玩家是不是观战状态设置玩家是不是观战状态",isguan)
	m_IsGuanZhan = isguan
end
function M_public_SetGameState( gamestate )
	m_GameState = gamestate
end
function M_public_PushBack( )
	--删除androidquit
	tips.removeQuitMaskTips()
	PushBackCB()
end
--在线奖励断线后重启
function M_public_OnlineReward_Reconnect( )

end

--暂停计时
function M_public_OnlineReward_Time_Pause( )

end
--启动计时
function M_public_OnlineReward_Time_Restart( )

end
--更新桌号
function M_public_SetTableID( tableid,p,x,y )
	
end

Close = function ( isSend )
	m_selfQuit = true
	CCLOG("关闭游戏",m_CurrGameID)
    local   isVideo =Pt_M_GetIsVideoFun() 
	-- if m_GameState == emRoomState_Game and Pt_Get_SelectGameMode() == emMode_1  then 
	-- if Pt_Get_SelectGameMode() == emMode_1 and isVideo==false then 
	-- 	-- if isSend ~= false then
	-- 		CS_QUIT("mobile Close CS_QUIT emRoomState_Game emMode_1")
	-- 	-- end
	-- end
	M_public_CleanUpAllDATA()
	-- 阻塞消息 进入大厅后开启消息
	LockMsg2()
    CCLOG("public 关闭游戏 1--0")
	Pt_CleanALLMsgex()
	CCLOG("public 关闭游戏 1 ---2")
	UnRegisterEventListen()
	CCLOG("public 关闭游戏 1")

	CCLOG("public 关闭游戏 2",isVideo)
	if Pt_Get_SelectGameMode() == emMode_3 then
		Pt_M_DesCompetitionRankingUI()
	end
	CCLOG("public 关闭游戏 2_1")
	-- if m_CreInviteListTimer   ~= nil then
	-- 	CCDirector:getInstance():getScheduler():unscheduleScriptEntry(m_CreInviteListTimer)
	-- 	m_CreInviteListTimer = nil
	-- end
	-- if m_WorldChangeLabShowTimer1 then
	-- 	CCDirector:getInstance():getScheduler():unscheduleScriptEntry(m_WorldChangeLabShowTimer1)
	-- 	m_WorldChangeLabShowTimer1 = nil
	-- end
	CCLOG("public 关闭游戏 2_2")
	CloseGameCB()
	if m_BaseLayer then
		m_BaseLayer:removeFromParent(true)
		m_BaseLayer = nil
	end 
    CCLOG("public 关闭游戏 3")
    if isVideo then
       Pt_M_xxCreLobbyScene(nil,"replay")
    else
       Pt_M_xxCreLobbyScene(m_CurrGameID)
    end
    --设置战绩
    Pt_M_SetIsVideoFun(false)
	CCLOG("public 关闭游戏 4")
end
PushTalkCB = function ()
	CCLOG("聊天回调")
	M_Public_PlyerTalk(m_CurrGameID)
end

function Pt_M_setZhiBtnSp(isShow )

end


CreSysTime = function (  )

    --屏蔽
	m_SysTimeSec = os.time()
	local date = tostring(os.date())
	SHOW(date)
	local cutPos = string.find(date,":")
	local showTime = string.sub(date,cutPos-2,cutPos+2)
	local sysTimeSp = xui.addSprite(m_RoomDateNode,"xxqp_sj",sys.width-280, sys.height-40)
	m_SysTimeSp = xui.addLabel(m_RoomDateNode, showTime, sys.colors.white,26, sys.width-280, sys.height-40)
	--local gameID = Pt_Get_SelectGameID( )
	local timeArray = {}
	timeArray[1] = CCDelayTime:create(1)
	timeArray[2] = CCCallFunc:create(function (  )
		local date = tostring(os.date())
		local cutPos = string.find(date,":")
		local showTime = string.sub(date,cutPos-2,cutPos+2)
		if m_SysTimeSp then
			m_SysTimeSp:setString(showTime)
		end
	end)
	local seq = CCSequence:create(timeArray)
	local repeatAni = CCRepeatForever:create(seq)
	m_SysTimeSp:runAction(repeatAni)
end

function M_public_CleanUpAllDATA( )
	CCLOG("M_public_CleanUpAllDATA m1 ")
	cc.Director:getInstance():getEventDispatcher():removeAllEventListeners()
	M_Public_CleanUpPlyerTalk()
	CCLOG("M_public_CleanUpAllDATA m2 ")
	CCLOG("M_public_CleanUpAllDATA m3 ")
	CCLOG("M_public_CleanUpAllDATA m4 ")
	CleanUp()
	CCLOG("M_public_CleanUpAllDATA m5 ")
	GamePublic_TouXiangClassCleanUp()
	CCLOG("M_public_CleanUpAllDATA m6 ")
end

function Pt_M_WatcherTalk(...)
	M_WatcherTalk:InsertTalkContent(...)
end 
M_WatcherTalk.__index = M_WatcherTalk
function M_WatcherTalk:CleanUp()
	self.Node 		= nil
	self.Content 	= {}
	self.ContentSp 	= {}
	self.Pos 		= {}
	self.fs 		= 25
	self.fc 		= sys.colors.white
	self.showtime 	= 15
	self.fadetime 	= 1
	self.posytb  	= {}
end 
function M_WatcherTalk:InsertTalkContent(s,_name,_x,_y,kuaijiesoundlab )
	CCLOG("M_WatcherTalk:InsertTalkContent start")
	self.Pos = {x = _x or sys.center.x,y = _y or sys.center.y}
	local talklabel
	for k,v in pairs(s) do
		if k == "str" then
			local qianzui = "(观战)"
			if m_CurrGameID == emGame_XiaoBaiSha  or m_CurrGameID == emGame_MaJiangNiuNiu or m_CurrGameID == emGame_BaiRenNiuNiu or m_CurrGameID == emGame_DaMaoXian or m_CurrGameID == emGame_BuYuDNTG then
				qianzui = ""
			end 
			talklabel = qianzui.._name..":"..v
			table.insert( self.Content,talklabel)
			self:CreOne(talklabel)
		end
		if k=="resID" then
			if m_CurrGameID == emGame_MaJiangNiuNiu or m_CurrGameID == emGame_BaiRenNiuNiu or m_CurrGameID == emGame_DaMaoXian or m_CurrGameID == emGame_BuYuDNTG  then
	             CCLOG("biaoqing-------1")
	             talklabel=_name..":"
	             self:creMoveBiaoqian(v,talklabel)
            end
		end 
		if m_CurrGameID == emGame_MaJiangNiuNiu or m_CurrGameID == emGame_BaiRenNiuNiu or m_CurrGameID == emGame_DaMaoXian or m_CurrGameID == emGame_BuYuDNTG then
			if k=="kuaijieID"  and kuaijiesoundlab ~=nil and string.len(kuaijiesoundlab)>0 then
	            talklabel = _name..":"..kuaijiesoundlab
				table.insert( self.Content,talklabel)
				self:CreOne(talklabel)
            end  
		end
	end
	CCLOG("M_WatcherTalk:InsertTalkContent end")
end
function M_WatcherTalk:Create(  )
	CCLOG(" M_WatcherTalk:Create start ")
	if self.Node  then
		self.Node:removeFromParent(true)
		self.Node = nil
	end 
	self.Node = cc.Node:create()
	m_BaseLayer:addChild(self.Node,100)
	
	CCLOG(" M_WatcherTalk:Create end ")
end
function M_WatcherTalk:Destroy(  )
	CCLOG("M_WatcherTalk:Destroy start ")
	if self.Node  then
		self.Node:removeFromParent(true)
		self.Node = nil
	end
	self:Clean()
	CCLOG("M_WatcherTalk:Destroy end ")
end
function M_WatcherTalk:CheckPosY(  )
	CCLOG("M_WatcherTalk:CheckPosY start")
	local i = 2
	while true do
		local randomposy = math.random(sys.center.y-200,sys.center.y+200) + i
		i = i + 1
		CCLOG("i ============ ",i,randomposy)
		local iscould = true
		-- if sys.getTBCount(self.ContentSp) == 0 then
		-- 	iscould = true
		-- end 
		for k,v in pairs(self.ContentSp) do
			if (randomposy < (v.layer:getPositionY() + v.size.height) and  randomposy > (v.layer:getPositionY() - v.size.height) ) and (self.Pos.x*2 - v.layer:getPositionX()) < v.size.width then
				iscould = false
				break
			end 
		end
		if iscould == true then
			CCLOG("M_WatcherTalk:CheckPosY end")
			return randomposy
		end 
	end 
end
function M_WatcherTalk:CreOne( _str )
	CCLOG("M_WatcherTalk:CreOne start ",self.Pos.x,self.Pos.y)
	local posy = self:CheckPosY()
	local c_r = math.random(100,200)
	local c_g = math.random(100,200)
	local c_b = math.random(100,200)
	local off = 0.3
	local sp = {}
	sp.layer = cc.LayerColor:create(cc.c4b(0,0,0,175))
	self.Node:addChild(sp.layer)
	sp.label = xui.addLabel(sp.layer,_str,cc.c3b(c_r,c_g,c_b),self.fs,0,0,sys.ap.leftBottom)
	sp.size = sys.creLabel(_str, self.fc, self.fs):getContentSize()
	sp.layer:setContentSize(sp.size)
	sp.layer:setPosition({x = self.Pos.x*2,y = posy})
    local array = {}
	array[1] = cc.MoveTo:create(self.showtime,{x = -100 + (sys.DESIGW-sys.width)/2 - sp.size.width,y = posy})
	array[2] = cc.CallFunc:create(function ( )
		self:RemoveTop()
	end)
	array[3] = cc.RemoveSelf:create(true)
	sp.layer:runAction(cc.Sequence:create(array))
	table.insert(self.ContentSp,1,sp)
	CCLOG("M_WatcherTalk:CreOne end ")
end
function M_WatcherTalk:RemoveTop( )
	CCLOG("M_WatcherTalk:RemoveTop start ")
	local garbage = table.remove( self.ContentSp)
	if garbage then
		CCLOG("删除垃圾")
		garbage.layer:removeFromParent(true)
	end
	CCLOG("M_WatcherTalk:RemoveTop end ")
end
function M_WatcherTalk:refreshContentSp( )
	CCLOG("M_WatcherTalk:refreshContentSp start ")
	local offy = 5
	local startx = 0
	for k,v in pairs(self.ContentSp) do
		if k < 6 then
			v.layer:setPositionY(self.Pos.y + startx)
			startx = startx + v.size.height + offy
		else
			self:RemoveTop()
		end 
	end
	CCLOG("M_WatcherTalk:refreshContentSp end ")
end
function M_WatcherTalk:creMoveBiaoqian( resID,_str )
	CCLOG("M_WatcherTalk:creMoveBiaoqian start ",self.Pos.x,self.Pos.y)
	local posy = self:CheckPosY()
	local c_r = math.random(100,200)
	local c_g = math.random(100,200)
	local c_b = math.random(100,200)
	local off = 0.3
	local sp = {}
	sp.layer = cc.LayerColor:create(cc.c4b(0,0,0,175))
	self.Node:addChild(sp.layer)
	sp.label = xui.addLabel(sp.layer,_str,cc.c3b(c_r,c_g,c_b),self.fs,0,0,sys.ap.leftBottom)
	sp.size = sys.creLabel(_str, self.fc, self.fs):getContentSize()
    local resname,rescount = PT_PublicGetBiaoQingRes(resID)
    CCLOG("resname,resname",resname,rescount,sp.size.width)
    local biaoqingAin= xui.playAni(sp.layer,resname,rescount,0.2,sp.size.width+35,30)
	sp.layer:setContentSize(sp.size)
	sp.layer:setPosition({x = self.Pos.x*2,y = posy})
	local array = {}
	array[1] = cc.MoveTo:create(self.showtime,{x = -100 + (sys.DESIGW-sys.width)/2 - sp.size.width,y = posy})
	array[2] = cc.CallFunc:create(function ( )
		self:RemoveTop()
	end)
	array[3] = cc.RemoveSelf:create(true)
	sp.layer:runAction(cc.Sequence:create(array))
	table.insert(self.ContentSp,1,sp)
	CCLOG("M_WatcherTalk:creMoveBiaoqian end ")
end

function Pt_Public_ChoniceWXUi( )
	local size={width=570,height=300}
	local backNode = cc.Node:create()
	--m_ParentNode:addChild(backNode,1000)
    cc.Director:getInstance():getRunningScene():addChild(backNode,5000)
	local function CloseBackUI(  )
		if backNode then
			backNode:removeFromParent(true)
		end
	end
    local mask = xui.creMaskLy( backNode, nil, nil, nil, function (  )
        -- CloseBackUI()
	end )

    local tipsBg = xui.addSpr9(backNode,"xxqp_bg_0",570, size.height, sys.center.x, sys.center.y)

	-- ---关闭
	local closeBtn = MyBtnClass:new("xxqp_cancel_zc","xxqp_cancel_dj","xxqp_cancel_dj",
						function ( )
							CloseBackUI()
						end)
	tipsBg:addChild(closeBtn.btnLy,4)
	closeBtn.btnLy:setPosition(tipsBg:getContentSize().width-50, tipsBg:getContentSize().height-50)
	local lableStr ="本成绩仅限娱乐，请勿进行赌博！"
    local lable =xui.addLabel(backNode,lableStr,sys.colors.white,28,sys.center.x,sys.center.y+35,sys.ap.center)
    --好友
    local haoyoubtn = MyBtnClass:new("xxqp_fxhy_zc","xxqp_fxhy_dj","xxqp_fxhy_zc",
						function ( )
							 CCLOG("分享好友")
							 CloseBackUI()
							 sys.shareScreenShotToWX(nil,0)
						end)
	tipsBg:addChild(haoyoubtn.btnLy,4)
	haoyoubtn.btnLy:setPosition(25, 40)
    --朋友
	local pengyuanBtn = MyBtnClass:new("xxqp_fxpy_zc","xxqp_fxpy_dj","xxqp_fxpy_zc",
						function ( )
							CCLOG("分享朋友")
							CloseBackUI()
							sys.shareScreenShotToWX(nil,1)
						end)
	tipsBg:addChild(pengyuanBtn.btnLy,4)
	pengyuanBtn.btnLy:setPosition(300, 40)
 
end
function Pt_Public_SetVoiAndEffe( )
	CCLOG("设置回调")
	if not m_BaseLayer  then  CCLOG("m_BaseLayer is nil ") return end
	local m_VoiceState 			--音乐
	local m_EffectState 		--音效
	local voiceBtn_open = nil
	local voiceBtn_close = nil
	local effectBtn_open = nil
	local effectBtn_close = nil
	local voiceBtn_open_lab 	= nil
	local voiceBtn_close_lab 	= nil
	local effectBtn_open_lab 	= nil
	local effectBtn_close_lab 	= nil 
	local setlayer = cc.LayerColor:create(cc.c4b(255,255,255,0))
	m_BaseLayer:addChild(setlayer,150)
	Pt_M_UIAni_ScaleOut(setlayer)

	--删除设置
	local function DelSetLayer(  )
		if setlayer and setlayer:getParent() then
			setlayer:removeFromParent()
			setlayer = nil
		end 
	end
	-- 声音CB
	local function PushVoiceCB(  )
		if m_VoiceState == 0 then
			m_VoiceState = 1
			--CCLOG("m_VoiceState======",m_VoiceState)
			voiceBtn_open.SetMyBtnVisible(true)
			voiceBtn_close.SetMyBtnVisible(false)
		    voiceBtn_open_lab:setVisible(false)
			voiceBtn_close_lab:setVisible(true)
			sys.setMusicVolume(1)
		else
			m_VoiceState = 0
			sys.setMusicVolume(0)
			voiceBtn_open_lab:setVisible(true)
			voiceBtn_close_lab:setVisible(false)
			voiceBtn_open.SetMyBtnVisible(false)
			voiceBtn_close.SetMyBtnVisible(true)
		end
		--CCLOG("m_VoiceState======",m_VoiceState)
		Pt_SaveVoiceState(m_VoiceState)
	end
	--CCLOG("设置回调------2")
	-- 音效CB	
	local function PushEffectCB( sender, eventType )
		if m_EffectState == 0 then
			m_EffectState = 1
			effectBtn_open.SetMyBtnVisible(true)
			effectBtn_close.SetMyBtnVisible(false)
			effectBtn_open_lab:setVisible(false)
			effectBtn_close_lab:setVisible(true)
		else
			m_EffectState = 0
			effectBtn_open.SetMyBtnVisible(false)
			effectBtn_close.SetMyBtnVisible(true)
			effectBtn_open_lab:setVisible(true)
			effectBtn_close_lab:setVisible(false)
		end
		Pt_SaveEffectState(m_EffectState)
	end
	--添加遮罩
	xui.creMaskLy( setlayer, nil, nil, nil, function (  )
		--DelSetLayer()
	end )
    --CCLOG("设置回调------3")
	m_VoiceState,m_EffectState = Pt_GetSoundInfo()
    --CCLOG("设置回调------5")
    local offx =5
    local bgSp = xui.addSpr9(setlayer, "xxqp_bg_0",569, 350, sys.center.x, sys.center.y)
	local bg  =cc.Node:create()
	setlayer:addChild( bg )
    bg:setContentSize({width=bgSp:getContentSize().width,height=bgSp:getContentSize().height})
    bg:setPosition(sys.center.x-569/2,sys.center.y-350/2)
    local off_y =-40

	local size = bg:getContentSize()
    if Pt_M_GameStateFun()~=emRoomState_Wait and Pt_M_GameStateFun()~=emRoomState_JSWait then
	    local jiesanRoomBtn = MyBtnClass:new("yxgy_btn_sjjsfj_zc","yxgy_btn_sjjsfj_dj","yxgy_btn_sjjsfj_zc",function ( ... )
	    	  Pt_M_SendShengQingCloseRoom()
	          DelSetLayer()
	    end)
	    bg:addChild(jiesanRoomBtn.btnLy)
	    jiesanRoomBtn.btnLy:setPosition(size.width/2-122,20)
	    --CCLOG("设置回调------6")
	    off_y=0
	end
	---关闭
	local closeBtn = MyBtnClass:new("xxqp_cancel_zc","xxqp_cancel_dj","xxqp_cancel_dj",
		function (  )
		  Pt_M_UIAni_ScaleIn(setlayer, DelSetLayer)
		end
    )
	bg:addChild(closeBtn.btnLy,4)
	closeBtn.btnLy:setPosition(bg:getContentSize().width-50, bg:getContentSize().height-50)
	local titleFrame = xui.addSprite(bg,"xxqp_grzx_bt",size.width/2,size.height -20)
	local title = xui.addSprite(bg,"xxqp_sz_icon",size.width/2,size.height -15)

	local lablevoice = xui.addLabel(bg,"音乐：",sys.colors.white,30,size.width/2-40,size.height/2+75+off_y,sys.ap.rightCenter,nil,nil,true)
	local lableeffect = xui.addLabel(bg,"音效：",sys.colors.white,30,size.width/2-40,size.height/2-30+off_y,sys.ap.rightCenter,nil,nil,true)
   
    local anniubg = xui.addSprite(bg,"xxqp_sz_db",size.width/2+70,size.height/2+75+off_y)
    --xui.addLabel(anniubg,"开     关",cc.c3b(61,73,99),25,anniubg:getContentSize().width/2,anniubg:getContentSize().height/2)
    voiceBtn_open_lab = xui.addSprite(anniubg,"xxqp_sz_kai",45,anniubg:getContentSize().height/2)
	voiceBtn_close_lab = xui.addSprite(anniubg,"xxqp_sz_guan",anniubg:getContentSize().width-45,anniubg:getContentSize().height/2)

    voiceBtn_open = MyBtnClass:new("xxqp_sz_hn","xxqp_sz_hn","",function (  )
											PushVoiceCB()
		                                    end,nil,nil,nil,{width = 190,height = 78},nil,nil,{x = 0.3,y = 0.5},true)
	anniubg:addChild(voiceBtn_open.btnLy,2)
	voiceBtn_open.btnLy:setPosition(-5,anniubg:getContentSize().height/2 - voiceBtn_open.btnLy:getContentSize().height/2)
	--关闭按钮
	voiceBtn_close = MyBtnClass:new("xxqp_sz_hn","xxqp_sz_hn","",function (  )
										PushVoiceCB()
	                                    end,nil,nil,nil,{width = 190,height = 78},nil,nil,{x = 0.7,y = 0.5},true)
	anniubg:addChild(voiceBtn_close.btnLy,2)
	voiceBtn_close.btnLy:setPosition(anniubg:getContentSize().width - voiceBtn_close.btnLy:getContentSize().width+5,anniubg:getContentSize().height/2 - voiceBtn_open.btnLy:getContentSize().height/2)
	--CCLOG("设置回调------4")
    --设置按钮初始状态
	if m_VoiceState == 0 then
		voiceBtn_open.SetMyBtnVisible(false)
		voiceBtn_close.SetMyBtnVisible(true)
		voiceBtn_open_lab:setVisible(true)
		voiceBtn_close_lab:setVisible(false)
	else
		voiceBtn_open.SetMyBtnVisible(true)
		voiceBtn_close.SetMyBtnVisible(false)
		voiceBtn_open_lab:setVisible(false)
		voiceBtn_close_lab:setVisible(true)
	end
    local yxanniubg = xui.addSprite(bg,"xxqp_sz_db",size.width/2+70,size.height/2-30+off_y)
	--xui.addLabel(yxanniubg,"开     关",cc.c3b(61,73,99),25,yxanniubg:getContentSize().width/2,yxanniubg:getContentSize().height/2)
    effectBtn_open_lab = xui.addSprite(yxanniubg,"xxqp_sz_kai",45,yxanniubg:getContentSize().height/2)
	effectBtn_close_lab = xui.addSprite(yxanniubg,"xxqp_sz_guan",yxanniubg:getContentSize().width-45,yxanniubg:getContentSize().height/2-offx)
	--开启按钮
	effectBtn_open = MyBtnClass:new("xxqp_sz_hn","xxqp_sz_hn","",function (  )
										PushEffectCB()
	                                    end,nil,nil,nil,{width = 190,height = 78},nil,nil,{x = 0.3,y = 0.5},true)
	yxanniubg:addChild(effectBtn_open.btnLy,2)
	effectBtn_open.btnLy:setPosition(-5,yxanniubg:getContentSize().height/2 - effectBtn_open.btnLy:getContentSize().height/2)
	--关闭按钮
	effectBtn_close = MyBtnClass:new("xxqp_sz_hn","xxqp_sz_hn","",function (  )
										PushEffectCB()
	                                    end,nil,nil,nil,{width = 190,height = 78},nil,nil,{x = 0.7,y = 0.5},true)
	yxanniubg:addChild(effectBtn_close.btnLy,2)
	effectBtn_close.btnLy:setPosition(yxanniubg:getContentSize().width - effectBtn_close.btnLy:getContentSize().width+5,yxanniubg:getContentSize().height/2 - voiceBtn_open.btnLy:getContentSize().height/2)
    if  m_EffectState == 0 then
		effectBtn_open.SetMyBtnVisible(false)
		effectBtn_close.SetMyBtnVisible(true)
		effectBtn_open_lab:setVisible(true)
		effectBtn_close_lab:setVisible(false)
	else
		effectBtn_open.SetMyBtnVisible(true)
		effectBtn_close.SetMyBtnVisible(false)
		effectBtn_open_lab:setVisible(false)
		effectBtn_close_lab:setVisible(true)
	end
end

function Pt_M_GetFangZhuPlayerId(  )
	--CCLOG("Pt_M_GetFangZhuPlayerId")
	return m_CurrTbaleInfo.hostid  or 0
end

function Pt_M_SendShengQingCloseRoom( _bool )
    local hostid =Pt_M_GetFangZhuPlayerId()
    local myplayerid =Pt_GetPlayerInfo().playerid
    local  ispushBack = _bool  or false
    --CCLOG("申请解散房间 Pt_M_SendShengQingCloseRoom",hostid,myplayerid,m_GameState)
	if   m_GameState == emRoomState_Wait  or   m_GameState==emRoomState_JSWait  then
        --CCLOG("申请解散房间",hostid,myplayerid)
       -- CCLOG("游戏准备状态")
        if hostid  ==myplayerid then
    	    local info ={}
    	    info.agree =emAgreeType_Hand
    	    CS_DISMISS_DESK(info)
        else
        	Pt_M_BigJieSuanPushBackCB()
    	end
    	if ispushBack ==true then
	    	--房主离开房间
	    	--CCLOG("Pt_SaveJieSanRoom  ispushBack",ispushBack)
		    Pt_SaveJieSanRoom(false)
		end
	elseif m_GameState == emRoomState_Game then
		--CCLOG("游戏的状态1111")
        local info ={}
	    info.agree =emAgreeType_Hand
	    CS_DISMISS_DESK(info)
	else
       --CCLOG("m_GameState",m_GameState)
	end 
end

function Pt_M_PushbackFun(  )
	local isVideo = Pt_M_GetIsVideoFun()
	if isVideo==false then
	    local hostid =Pt_M_GetFangZhuPlayerId()
	    local myplayerid =Pt_GetPlayerInfo().playerid
	    --CCLOG("申请解散房间Pt_M_PushbackFun",hostid,myplayerid,m_GameState)
		if    m_GameState == emRoomState_Wait or   m_GameState==emRoomState_JSWait then
	        --CCLOG("申请解散房间",hostid,myplayerid)
	        --CCLOG("游戏准备状态")
	        if hostid  ==myplayerid then
	    	    CrePushBackUI(1)
	        else
	        	CrePushBackUI(2) 
	    	end
		elseif m_GameState == emRoomState_Game then
			--CCLOG("游戏的状态1111")
	        local info ={}
		    info.agree =emAgreeType_Hand
		    CS_DISMISS_DESK(info)
		else
	        --CCLOG("申请解散房间Pt_M_PushbackFun is other")     
		end 
	else
        Pt_M_CloseGamePublicUI()
	end
end
function Pt_M_GetRoomInfoTb(  )
	return m_CurrTbaleInfo
end

function Pt_M_GameStateFun( )
	return m_GameState
end
--callback Close
function Pt_M_CloseGamePublicUI(  )
	CCLOG("外部调用关闭游戏公共界面")
	Close()
	Pt_JMessageExitAllGroup()
end

--复制房间号callback
function Pt_M_PushCallRoomNumFun(sendStr)
	if   not m_ParentNode then  return end
	local size={width=570,height=350}
	local backNode = cc.Node:create()
	m_ParentNode:addChild(backNode,PT_GAME_PUBLIC_ZORDER+200)
    local koulinStr=""
    if m_CurrTbaleInfo and m_CurrTbaleInfo.deskcode then
       koulinStr="口令："..m_CurrTbaleInfo.deskcode
    end
    local fenxiangStr =koulinStr..sendStr.."游戏下载链接：https://xxcnqp.54.com/weixin/download（复制此消息加入对战）"
    CCLOG("fenxiangStr",fenxiangStr)
	local function CloseBackUI(  )
		if backNode then
			backNode:removeFromParent(true)
		end
	end
    local mask = xui.creMaskLy( backNode, nil, nil, nil, function (  ) end )

    local scaleNode = xui.addNode(backNode)
    scaleNode:setPosition(sys.center.x, sys.center.y)
	Pt_M_UIAni_ScaleOut(scaleNode)


    local tipsBg = xui.addSpr9(scaleNode,"xxqp_bg_0",570, 350, 0, 0)
	--关闭
	local closeBtn = MyBtnClass:new("xxqp_cancel_zc","xxqp_cancel_dj","xxqp_cancel_dj",
						function ( )
							Pt_M_UIAni_ScaleIn(scaleNode, CloseBackUI)
						end)
	tipsBg:addChild(closeBtn.btnLy,4)
	closeBtn.btnLy:setPosition(tipsBg:getContentSize().width-50, tipsBg:getContentSize().height-50)
	local lable =xui.addLabel(scaleNode,"口令已复制，选择应用长按粘贴！",sys.colors.white,28,0,0+size.height/2-90,sys.ap.center) 

	--微信btn
	local weixinBtn =MyBtnClass:new("xxqp_fxmb_weixin","xxqp_fxmb_weixin_dj","xxqp_fxmb_weixin",function (  )
		if(sys.isSupportEnableApp())then
			if(sys.isAppInstall(1))then
				sys.SetClipBoardText(fenxiangStr)
				sys.enableApp(1)
			else
				tips.creMOKMaskTips("请安装此应用", nil, nil, true)
			end
		end
	end)
	scaleNode:addChild(weixinBtn.btnLy)
	weixinBtn.btnLy:setPosition(0-size.width/2+70,0-90)
  	--支付宝btn
	local zhufuBaoBtn =MyBtnClass:new("xxqp_fxmb_zfb","xxqp_fxmb_zfb_dj","xxqp_fxmb_zfb",function (  )
		if(sys.isSupportEnableApp())then
			if(sys.isAppInstall(3))then
				sys.SetClipBoardText(fenxiangStr)
				sys.enableApp(3)
			else
				tips.creMOKMaskTips("请安装此应用", nil, nil, true)
			end
		end
	end)
	scaleNode:addChild(zhufuBaoBtn.btnLy)
	zhufuBaoBtn.btnLy:setPosition(0-40,0-90)
	--QQ btn
	local QQBtn =MyBtnClass:new("xxqp_fxmb_qq","xxqp_fxmb_qq_dj","xxqp_fxmb_qq",function (  )
		if(sys.isSupportEnableApp())then
			if(sys.isAppInstall(2))then
				sys.SetClipBoardText(fenxiangStr)
				sys.enableApp(2)
			else
				tips.creMOKMaskTips("请安装此应用", nil, nil, true)
			end
		end
	end)
	scaleNode:addChild(QQBtn.btnLy)
	QQBtn.btnLy:setPosition(0+130,0-90)
end