local RoomView_ERDouDiZhu = class("RoomView_ERDouDiZhu", cc.UIView) local Functions = require("pk_erdoudizhu.luaScript.Functions_ERDouDiZhu") local defs = require("pk_erdoudizhu.luaScript.Def_ERDouDiZhu") local Messages = require("pk_erdoudizhu.luaScript.Protocol.ProtocolMessage_ERDouDiZhu") local PokerUtil = require('pk_erdoudizhu.luaScript.Views.Room.newPokerUtil') local DDZ_New_Effect_Helper = require("pk_erdoudizhu.luaScript.Views.Room.DDZNewEffectHelper"):new() local TuoGuanView = require('pk_erdoudizhu.luaScript.Views.Room.RoomTuoGuanView') local Card_Move_Up_Down_Time = 0.1 -- 手牌抬起下放动画时间 local Card_Out_Down_Time = 0.15 -- 出牌下放动画时间 local Card_Out_Down_Offset_Y = -5 -- 出牌下放位置 function RoomView_ERDouDiZhu:ctor() RoomView_ERDouDiZhu.super.ctor(self) self._pokerUtil = nil self._isCanClickBg = true end function RoomView_ERDouDiZhu:initData() --事件队列 self.callbackQueue = {} --手牌间距(越大越密集,越小越稀疏) self.handCardDif = 110 --默认闹钟时间 self.clockTime = 15 --上家出的牌数据 self.lastData = {} self:setLastData() end function RoomView_ERDouDiZhu:onEnter() RoomView_ERDouDiZhu.super.onEnter(self) --ui load local ui = loadUI("pk_erdoudizhu/res/ui/ui_fangjian/doudizhu_ui_fangjian.ui") self:addChild(ui) self.ui = ui -- 添加合图缓存 self:addloadSpriteFrame() -- 添加扑克牌型提示文件 self:initPokerUtil() --初始化属性数据 self:initData() --初始化所有的玩家节点 self:initPlayerNodes() --初始化工具层 self:initToolLayer() -- 初始化GPS组件 self:initGpsComponent() -- 初始化电量和信号 self:initSingleComponent() -- 初始化扑克牌 self:initPoker() --监听事件 self:bindAllEvent() --显示桌面信息 self:initDeskInfo() --初始游戏中按钮 self:initGameButtons() --初始化玩法 self:initGameRule() --播放音乐 Functions.playMusic() --先收到8009再初始化的房间(房间还未监听8009事件),所以这里调用重连 self:onGameReconnection() --恢复协议 self:startGame() --测试 --self.weaveCardList = self:getTip(self.handCards["" .. self:getMeViewId()]) self:initPlayGameAgain() end function RoomView_ERDouDiZhu:addloadSpriteFrame() loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cards/doudizhu_pokerCards.plist") -- 动画相关 loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_shunzi/zy_ddz_CardFX_ShunZi_Sheet1.plist") loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_shunzi/zy_ddz_CardFX_ShunZi_Sheet2.plist") loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_bomb/zy_ddz_CardFX_ZhaDan_Sheet1.plist") loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_liandui/zy_ddz_CardFX_LianDui_Sprite_1.plist") loadSpriteFrameFile("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_player/zy_game_jingbao/ddz_Ani_BJ.plist") loadSpriteFrameFile('pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_kingbomb/doudizhu_Ani_KingBomb.plist') end function RoomView_ERDouDiZhu:initPokerUtil() self._pokerUtil = PokerUtil:new() end function RoomView_ERDouDiZhu:initPoker() local changePoker = tonumber(loadUserInfo("ddz_setting_poker")) or defs.Default_Poker_Choose self:onNormalChangePoker({idx=changePoker}) end function RoomView_ERDouDiZhu:onClickButtonDismiss( sender ) playBtnEffect() local function onClickOk() app.room:requestDismissRoom(1)--发起解散 end local function onClickCancel() end showConfirmDialog("确定要申请解散房间吗?", onClickOk, onClickCancel) end function RoomView_ERDouDiZhu:hideXiangQing(hideAction) self.xiangQingView.Items.Layout_XiangQing:setVisible(false) self.xiangQingView.Items.Layout_XQ_content:stopAllActions() self.xiangQingView.Items.ListView_Xq:setVisible(false) if hideAction == true then self.xiangQingView.Items.Layout_XQ_content:setPosition(self.xiangQingViewHidePos) self.xiangQingView.Items.Button_XiangQing:setVisible(true) else self.xiangQingView.Items.Layout_XQ_content:runAction( cc.Sequence:create( cc.MoveTo:create(0.35 , self.xiangQingViewHidePos), cc.CallFunc:create(function() self.xiangQingView.Items.Button_XiangQing:setVisible(true) end) ) ) end end function RoomView_ERDouDiZhu:initGameRule() self.xiangQingView = loadUI("pk_erdoudizhu/res/ui/ui_fangjian/doudizhu_ui_wanfa.ui") self.ui.Items.Layout_RuleView:addChild(self.xiangQingView) self.xiangQingView.Items.Button_XiangQing:setVisible(false) self.xiangQingView.Items.Layout_XiangQing:setVisible(true) local offsetX = 20 self.xiangQingView.Items.Button_XiangQing:setPositionX(self.xiangQingView.Items.Button_XiangQing:getPositionX() + offsetX) self.xiangQingView.Items.Layout_XQ_content:setPositionX(self.xiangQingView.Items.Layout_XQ_content:getPositionX() + offsetX) local size = self.xiangQingView.Items.Layout_XQ_content:getContentSize() self.xiangQingViewShowPos = self.xiangQingView.Items.Layout_XQ_content:getPosition() self.xiangQingViewHidePos = cc.vec3(self.xiangQingViewShowPos.x,self.xiangQingViewShowPos.y + size.height,self.xiangQingViewShowPos.z) self.xiangQingView.Items.Button_XiangQing_Back:registerClick(handler(self , self.hideXiangQing)) self.xiangQingView.Items.Layout_XiangQing:registerClick(handler(self , self.hideXiangQing)) self.xiangQingView.Items.Layout_XQ_content:registerClick(handler(self , self.hideXiangQing)) self.xiangQingView.Items.Button_XiangQing:registerClick(function() playBtnEffect() self.xiangQingView.Items.Button_XiangQing:setVisible(false) self.xiangQingView.Items.Layout_XQ_content:stopAllActions() self.xiangQingView.Items.Layout_XQ_content:runAction( cc.Sequence:create( cc.MoveTo:create(0.35 , self.xiangQingViewShowPos), cc.CallFunc:create(function() self.xiangQingView.Items.ListView_Xq:setVisible(true) self.xiangQingView.Items.Layout_XiangQing:setVisible(true) end) ) ) end) self.xiangQingView.Items.ListView_Xq:getVBar():setVisible(false) local roomInfo = app.room.roomInfo local ruleAll = Functions.getRuleStr() local wanfaList = string.split(ruleAll," ") local listviewSize = self.xiangQingView.Items.ListView_Xq:getContentSize() for i,v in pairs(wanfaList) do if v ~= "" and v ~= " " then local layout=cc.Layout:create() local wanfaText = cc.Text:createNode() wanfaText:setDefaults() local config = wanfaText:getFontConfig() config.fontSize = 24 config.texColor = cc.c4b(255,192,101,255) wanfaText:setFontConfig(config) layout:setSize(cc.size(listviewSize.width,35)) layout:addChild(wanfaText) wanfaText:setPosition(cc.p(listviewSize.width/2,15)) wanfaText:setString(v) self.xiangQingView.Items.ListView_Xq:pushBackCustomItem(layout) end end if app.room.roomInfo.nGameStartCount > 0 then self:hideXiangQing(true) else self:runAction(cc.Sequence:create( cc.DelayTime:create(2), cc.CallFunc:create(self.hideXiangQing) )) end end function RoomView_ERDouDiZhu:defaultState() --队列初始化 self.callbackQueue = {} self.callbackRunning = false --刷新按钮 self:updateButtons() --刷新用户信息 self:refreshPlayer(true) --隐藏地主底牌、炸弹等信息 self:setBankerCardsVisible(false) -- 隐藏桌面信息 self:isShowMiddleTips(false) self:isShowMiddleTipsForAll(false) -- 小结算 if self.XiaoJuView then self.XiaoJuView:setVisible(false) end --是否开局 if app.room.roomInfo.nGameStartCount > 0 then --隐藏加倍界面 self:setAskBeiVisible(false) --隐藏叫分界面 self:setAskLoardVisible(false) -- 隐藏让界面 self:setRangVisible(false) -- 隐藏抢界面 self:setQiangVisible(false) --隐藏玩家出牌操作信息 self:hideAllOutCardOperation() --隐藏界面 for _,v in pairs(app.room.roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) --隐藏桌面加倍标识 -- self.PlayerView:setTipsVisible("tips_jiabei", false, viewId) --隐藏桌面叫分标识 -- self.PlayerView:setTipsVisible("tips_jiaofen", false, viewId) self.PlayerView:setTipsVisibleExcept({}, viewId) --隐藏手牌 local handLayout = self.ui.Items["Layout_Hand_" .. viewId] if handLayout then handLayout:removeAllChildren() if self.handCards then local handCards = self.handCards["" .. viewId] if handCards then self.handCards["" .. viewId] = nil end end end end end end function RoomView_ERDouDiZhu:onUserExitResponseRoom(data) local function runUserExitResponseRoom(onEnd) local response = data.response --房间号 local roomid = app.room.roomInfo.nShowTableId app.room.roomInfo.tableOverFlag = response.tableOverFlag local tableOverFlag = response.tableOverFlag local nGameStartCount = app.room.roomInfo.nGameStartCount --长时间未开始强制退出,否则不退出 if tableOverFlag ~= defs.TABLE_OVER_FLAG.TABLE_OVER_LONG_TIME_NO_START and nGameStartCount ~= 0 then response.logoutFlag = 0 else response.logoutFlag = 1 end if tableOverFlag == defs.TABLE_OVER_FLAG.TABLE_OVER_LONG_TIME_NO_START and nGameStartCount > 0 then -- 如果已经有牌局了,则显示结算界面,不踢到大厅 response.logoutFlag = 0 end --如果是自己点离开必须退出 if app.room.roomInfo.bQuitRoom then response.logoutFlag = 1 end --正常结束不提示,其他都要提示 if tableOverFlag >= defs.TABLE_OVER_FLAG.TABLE_OVER_GROUP_DISBAND then showTooltip(defs.TABLE_OVER_FLAG_TEXT[tableOverFlag]) end -- 0: 不退出, 1: 退出 if response.logoutFlag == 1 then app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.LiuZhou, roomid)) end app.room:dispatchEvent({name = "onUserExitResponseHall"}) if onEnd then onEnd() end end self:addCallBack(runUserExitResponseRoom) end function RoomView_ERDouDiZhu:showProp(data) local response = data.response logE("RoomView_ERDouDiZhu:showProp response = "..table.tostring(response)) --ui表现开始 local uidStarId = response.uidStarId local uidEndId = response.uidEndId local propId = response.propId local isQunFa = response.isQunFa local beginViewId = app.room:getViewIdByUserId(uidStarId) local endViewId = app.room:getViewIdByUserId(uidEndId) if not self.allNodes[beginViewId] or not self.allNodes[endViewId] or not self.allNodes[endViewId].head or not self.allNodes[beginViewId].head then logE("场景还没初始化完成就收到道具消息果断return!") return end --播放动画 if isQunFa == 1 then local onLineList = app.room.roomInfo.memberList for nUserId,v in pairs(onLineList) do local endViewId = app.room:getViewIdByUserId(nUserId) if endViewId ~= beginViewId then self.PropAniManager:playAnimation(self.allNodes[beginViewId].head,self.allNodes[endViewId].head,propId) end end else self.PropAniManager:playAnimation(self.allNodes[beginViewId].head,self.allNodes[endViewId].head,propId) end end function RoomView_ERDouDiZhu:initPlayerNodes() self.PlayerView = import("pk_erdoudizhu.luaScript.Views.Room.RoomPlayerView_ERDouDiZhu"):new() self.ui.Items.Layout_Player:addChild(self.PlayerView) end function RoomView_ERDouDiZhu:refreshPlayer(bVisible, viewId, playerInfo) if bVisible then self.PlayerView:updatePlayer(playerInfo, viewId) else self.PlayerView:hidePlayer(viewId) end local uids = {} for k,v in pairs(app.room.roomInfo.memberList) do uids[v.nUserId] = true end if self.messageView then self.messageView:setPlayerUids(uids) end end function RoomView_ERDouDiZhu:initToolLayer() --加载工具层 self.toolView = import("pk_erdoudizhu.luaScript.Views.Room.RoomToolView_ERDouDiZhu"):new() self.ui.Items.Layout_Tool:addChild(self.toolView) --ChatView self.messageView = require("luaScript.Views.Room.ChatView"):new({chatList = defs.GAME_CHAT_TXT}, self.PlayerView:getChatViewPos(), true) self.toolView.ui.Items.Layout_ChatView:addChild(self.messageView) --设置语言 self.messageView:setLanguage(Functions.getCurLanguage() == defs.LANGUAGE_TYPE.PU_TONG_HUA) --互动表情,语音 self.messageView:setBtnFace(defs.FACE_POS) self.messageView:setBtnVoice(defs.VOICE_POS) self.messageView.ui.Items.Button_Face:loadTextureNormal("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_kjy.png") self.messageView.ui.Items.Button_Face:loadTexturePressed("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_kjy.png") self.messageView.ui.Items.Button_Face:loadTextureDisabled("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_kjy.png") self.messageView.ui.Items.Button_Voice:loadTextureNormal("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_yuyin.png") self.messageView.ui.Items.Button_Voice:loadTexturePressed("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_yuyin.png") self.messageView.ui.Items.Button_Voice:loadTextureDisabled("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_yuyin.png") --是否屏蔽互动表情 self.messageView:setPropEnabled((tonumber(loadUserInfo("HuDongBiaoQingKG" .. app.gameId)) or 1) == 1)--0关 1开 --是否屏蔽屏蔽语音 self.messageView:setVoiceEnabled((tonumber(loadUserInfo("PingBiYuYinKG" .. app.gameId)) or 1) == 1)--0关 1开 --道具播放管理器 self.PropAniManager = import("luaScript.Tools.PropAniPlayer"):new(self.ui.Items.Layout_Touch) -- if Functions.getIsForbidVoiceAndProp() then -- self.messageView:hideBtns() -- self.messageView:setPropEnabled(false) -- self.messageView:setVoiceEnabled(false) -- end if Functions.getIsForbidFace() then self.messageView:hideFace() self.messageView:setPropEnabled(false) end if Functions.getIsForbidVoice() then self.messageView:hideVoice() self.messageView:setVoiceEnabled(false) end end function RoomView_ERDouDiZhu:initGpsComponent() local versionCode = getAppVersionCode() versionCode = tonumber(versionCode) or 0 logD("RoomView_ERDouDiZhu:initGpsComponent() versionCode = ", versionCode) if isReviewVersion() then self.toolView.ui.Items.Button_GPS:registerClick(handler(self, self.showGpsView)) self.toolView.ui.Items.Button_GPS:setVisible(false) return end -- 创建 gps 组件 self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponent"):new() -- GPS 按钮 self.toolView.ui.Items.Button_GPS:registerClick(handler(self, self.showGpsView)) -- 我的GPS数据发生变化时检测是否需要通知服务器 self:bindEvent(app, "onGpsInoChanged", handler(self, self.checkMyGpsNeedUpdate)) -- 进入时检测一遍我的GPS数据是否需要更新 self:checkMyGpsNeedUpdate() end -- 初始化电量和信号 function RoomView_ERDouDiZhu:initSingleComponent() self.singleComponent = import("luaScript.Views.Room.RoomSinglePowerComponent"):new(self.ui.Items.ImageView_Single, self.ui.Items.LoadingBar_Power); end -- 注销电量、网络信号 function RoomView_ERDouDiZhu:deInitSingleComponent() if self.singleComponent then self.singleComponent:exit() end end function RoomView_ERDouDiZhu:bindAllEvent() --用户状态(包括准备,其他玩家进入或者离开通知,离线等) self:bindUserStatedMessage() --私人场消息(包括解散等) self:bindPrivateMessage() --游戏消息 self:bindGameMessage() --游戏场景消息 self:bindGameSceneMessage() --绑定更换桌布事件 self:bindEvent(app , "onChangeTable" , handler(self , self.onChangeTable)) --发送道具 self:bindEvent(app.room,"showProp" , handler(self , self.showProp)) --绑定更换语言种类 self:bindEvent(app , "onChangeLanguage" , handler(self , self.onChangeLanguage)) --设置互动表情开关事件 self:bindEvent(app.room,"ontSetPropEnabled" , handler(self , self.ontSetPropEnabled)) --设置语音开关事件 self:bindEvent(app.room,"onSetVoiceEnabled" , handler(self , self.onSetVoiceEnabled)) -- 游戏设置里更换扑克 self:bindEvent(app.room, "ddzNormalEvent_changePoker" , handler(self , self.onNormalChangePoker)) -- 小结算内通知解散 self:bindEvent(app.room, 'onResultInformDisMiss', handler(self, self.onClickButtonDismiss)) -- 托管回复 self:bindEvent(app.room , 'onHostingResponse', handler(self, self.onHostingResponse)) end function RoomView_ERDouDiZhu:initDeskInfo() --设置房间号 self.ui.Items.Text_roomNum:setText("房间号: " .. app.room.roomInfo.nShowTableId) -- 更新当前局数 self:updateGameNums() --系统时间 if not app.room.roomInfo.isRecord then self.ui.Items.Text_systemTime:stopAllActions() self.ui.Items.Text_systemTime:runActions( cc.RepeatForever:create( cc.Sequence:create( cc.CallFunc:create(function() self.ui.Items.Text_systemTime:setText(string.format("%s", os.date("%H:%M:%S", os.time()))) end), cc.DelayTime:create(0.5) ) ) ) end --刷新桌面背景和Logo self:setTableImg(Functions.getDefaultBg()) end function RoomView_ERDouDiZhu:startGame() --起飞 app.net:onMsgResume() end function RoomView_ERDouDiZhu:updateGameNums() -- 更新当前局数 local roomInfo = app.room.roomInfo local curCount = roomInfo.nGameStartCount or 0 local str = string.format("%02d / %02d", curCount, roomInfo.nTotalGameNum) self.ui.Items.Text_JuShu:setText(str) end function RoomView_ERDouDiZhu:onExit() RoomView_ERDouDiZhu.super.onExit(self) self:deInitSingleComponent() app.room:dispatchEvent({name = "onGameOverResponse"}) stopBGMusic() self:cleanCache() -- jxtd 记得验证是否要删除 end -- 清理缓存,用于测试 function RoomView_ERDouDiZhu:cleanCache() local preload = package.loaded for k, v in pairs(package.loaded or {}) do local res1 = string.find( k, "pk_erdoudizhu.luaScript") or 0 if res1 > 0 then package.loaded[k] = nil end end end -- 其他玩家坐下成功 function RoomView_ERDouDiZhu:onOtherSitDownResponse(data) local viewId = app.room:getViewIdByUserId(data.response.nUserId) self:checkGpsDistance(data.response.nUserId) self:refreshPlayer(true, viewId, app.room.roomInfo.memberList[data.response.nUserId]) self:updateButtons() if not tolua.isnull(self.quickStartView) then self.quickStartView:removeView() self.quickStartView = nil end end function RoomView_ERDouDiZhu:updateButtons() local nGameStartCount = app.room.roomInfo.nGameStartCount or 0 if nGameStartCount > 0 then -- 准备按钮 self.toolView:setReadyVisible(false) -- 是否显示邀请好友 self.toolView:setInviteVisible(false) -- 离开按钮 self.toolView:setLeaveEnabled(false) -- 解散按钮 self.toolView:setDissmissEnabled(true) -- 显示是否可以解散 self.toolView:checkCanDismiss() else local myUserId = app.room:getMyUserId() -- 是否显示邀请好友 if isReviewVersion() then self.toolView:setInviteVisible(false) else self.toolView:setInviteVisible(table.nums(app.room.roomInfo.memberList) < app.room.roomInfo.nMaxPlayCount) end -- 准备按钮 local readyState = app.room.roomInfo.memberList[myUserId].nPlayerFlag or 0 self.toolView:setReadyVisible(readyState == 0) -- 离开按钮 self.toolView:setLeaveEnabled(true) -- 解散按钮 local nRoomOwnedUid = app.room.roomInfo.nRoomOwnedUid or 0 self.toolView:setDissmissEnabled(nRoomOwnedUid == app.room:getMyUserId() and (not app.club_php.clubID or (app.club_php.clubID and app.club_php.clubID == 0))) end end function RoomView_ERDouDiZhu:onOtherDroppedResponse(data) if not data.response then return end self:setPlayerOffLine(data.response.nOnlineStatus == 0, app.room:getViewIdByUserId(data.response.nUserId)) end function RoomView_ERDouDiZhu:setPlayerOffLine(bVisible, viewId, times) --离线 self.PlayerView:setOffLineVisible(bVisible, viewId) --[[ if bVisible then local startTime = os.time() self.allNodes[viewId].offLine:stopAllActions() self.allNodes[viewId].offLine:runAction( cc.RepeatForever:create( cc.Sequence:create( cc.CallFunc:create(function() local endTime = os.time() local difTime = endTime - startTime + (times or 0) local timeStr = string.format("%02d : %02d", difTime / 60, difTime % 60) self.allNodes[viewId].offLineTime:setText(timeStr) end), cc.DelayTime:create(1.0) ) ) ) end --]] end function RoomView_ERDouDiZhu:onOtherLogoutResponse(data) self:refreshPlayer(false, data.response.viewId) self:updateButtons() end function RoomView_ERDouDiZhu:onUserReadyResponse(data) --自己准备 if app.room:getMyUserId() == data.response.nUserId then --重置桌面 self:defaultState() --更新按钮状态 self:updateButtons() end --显示准备 self.PlayerView:setReadyVisible(true, app.room:getViewIdByUserId(data.response.nUserId)) end --用户状态消息 function RoomView_ERDouDiZhu:bindUserStatedMessage() --默认状态 self:bindEvent(app.room , "defaultState", handler(self , self.defaultState)) -- 玩家准备 self:bindEvent(app.room , "onUserReadyResponse", handler(self , self.onUserReadyResponse)) -- 其他玩家进入房间 self:bindEvent(app.room , "onOtherSitDownResponse", handler(self , self.onOtherSitDownResponse)) -- 其他玩家退出房間 self:bindEvent(app.room , "onOtherLogoutResponse", handler(self , self.onOtherLogoutResponse)) -- 其他玩家掉线 self:bindEvent(app.room , "onOtherDroppedResponse", handler(self , self.onOtherDroppedResponse)) -- 用户T出 self:bindEvent(app.room , "onUserExitResponseRoom", handler(self , self.onUserExitResponseRoom)) -- 玩家的GPS信息发生变化 self:bindEvent(app.room , "onGpsChangeResponse", handler(self , self.onGpsChangeResponse)) end --私人场消息 function RoomView_ERDouDiZhu:bindPrivateMessage() -- 玩家收到解散房间的请求 self:bindEvent(app.room , "onDismissResponse", handler(self , self.onDismissResponse)) end --场景恢复 function RoomView_ERDouDiZhu:bindGameSceneMessage() app.hall:addEventListener("onEnterRoomSuccess", handler(self , self.onEnterRoomSuccess)) end function RoomView_ERDouDiZhu:onEnterRoomSuccess() if tolua.isnull(self.ui) then logE("self.is null") return end self:stopAllActions() self:onGameReconnection() self:startGame() end function RoomView_ERDouDiZhu:onGameReconnection() --默认状态 self:defaultState() --是否开局 if app.room.roomInfo.nGameStartCount > 0 then --显示剩余手牌 for _,v in pairs(app.room.roomInfo.memberList) do self.PlayerView:setLeftNumVisible(true, app.room:getViewIdByUserId(v.nUserId), table.nums(v.handCards)) -- 恢复手牌 self:initHandCards(v.handCards, app.room:getViewIdByUserId(v.nUserId)) end --恢复手牌 -- self:initHandCards(app.room.roomInfo.memberList[app.room:getMyUserId()].handCards, self:getMeViewId()) --叫地主阶段 if app.room.roomInfo.nStatus == defs.GAME_STATUS.ASK_LOARD then --当前操作位置 self.curViewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId) --显示方位 self.PlayerView:setClockVisibel(true, self.curViewId, app.room.roomInfo.currentLeftTime) --显示叫分/叫地主 local tips = '' local gameMode = Functions.getGameMode() if gameMode == 1 then tips = 'tips_jiaodizhu' else tips = 'tips_jiaofen' end for k,v in pairs(app.room.roomInfo.memberList) do if v.bAskLoard == 1 then self.PlayerView:setTipsVisible(tips, true, app.room:getViewIdByUserId(v.nUserId), { askLoard = v.askLoard }) end end --是否显示叫分 if self.curViewId == self:getMeViewId() then self:setAskLoardVisible(true, app.room.roomInfo.opType == 1, gameMode) end -- 显示中间提示内容 self:isShowMiddleTipsForAll(true) -- 抢地主阶段 elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.QIANG_LOARD then --当前操作位置 self.curViewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId) --显示方位 self.PlayerView:setClockVisibel(true, self.curViewId, app.room.roomInfo.currentLeftTime) for _, v in pairs(app.room.roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) if viewId ~= self.curViewId then if tonumber(v.bAskQiang) == 1 then self.PlayerView:setTipsVisible('tips_qiangdizhu', true, viewId, { opType = 1 }) elseif tonumber(v.bAskLoard) == 1 then local tips = '' local gameMode = Functions.getGameMode() if gameMode == 1 then tips = 'tips_jiaodizhu' else tips = 'tips_jiaofen' end self.PlayerView:setTipsVisible(tips, true, viewId, { askLoard = v.askLoard }) end end end --是否显示抢地主 if self.curViewId == self:getMeViewId() then self:setQiangVisible(true) end -- 显示中间提示内容 self:isShowMiddleTipsForAll(true, app.room.roomInfo.nRangTotalNums) --加倍阶段 elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.ASK_BEI then --显示庄家 self.PlayerView:setBankerVisible(true, app.room:getViewIdByUserId(app.room.roomInfo.nBankerId)) --显示加倍状态 for k,v in pairs(app.room.roomInfo.memberList) do if v.bAskBei == 1 then self.PlayerView:setTipsVisible("tips_jiabei", true, app.room:getViewIdByUserId(v.nUserId), { askBei = v.askBei }) else self.PlayerView:setClockVisibel(true, app.room:getViewIdByUserId(v.nUserId), 0) end end --是否显示加倍 local myMemberInfo = app.room.roomInfo.memberList[app.room:getMyUserId()] if myMemberInfo.bAskBei == 0 then self:setAskBeiVisible(true) end -- 显示中间提示内容 self:isShowMiddleTipsForAll(true, app.room.roomInfo.nRangTotalNums) -- 让牌阶段 elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.ASK_RANG then --当前操作位置 self.curViewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId) --显示方位 self.PlayerView:setClockVisibel(true, self.curViewId, app.room.roomInfo.currentLeftTime) --是否显示让 if self.curViewId == self:getMeViewId() then -- local rangCount = Functions.getRangCount() -- if rangCount > 0 then self:setRangVisible(true, rangCount) -- end end -- 显示中间提示内容 self:isShowMiddleTipsForAll(true, app.room.roomInfo.nRangTotalNums) --打牌阶段 elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.PLAYING then --当前操作位置 self.curViewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId) --显示方位 self.PlayerView:setClockVisibel(true, self.curViewId, app.room.roomInfo.currentLeftTime) --显示庄家 self.PlayerView:setBankerVisible(true, app.room:getViewIdByUserId(app.room.roomInfo.nBankerId)) --最后一手手牌 if app.room:checkUserIDIsInTable(app.room.roomInfo.lastUserId) then local lastViewId = app.room:getViewIdByUserId(app.room.roomInfo.lastUserId) self:setOutCardsVisible(true, lastViewId, { cards = app.room.roomInfo.lastCards, opType = app.room.roomInfo.lastCardType }) end -- 玩家过数据 for k,v in pairs(app.room.roomInfo.memberList) do -- 显示过 if v.nGuo and v.nGuo == 1 then self.PlayerView:setTipsVisible("tips_yaobuqi", true, app.room:getViewIdByUserId(v.nUserId)) end end --是否显示操作 if self.curViewId == self:getMeViewId() then self:setOperationVisible(true, app.room.roomInfo.opType) end if app.room.roomInfo.nBankerId == app.room:getMyUserId() then local rangCount = Functions.getRangCount() -- if rangCount > 0 then local myMemberInfo = app.room.roomInfo.memberList[app.room:getMyUserId()] local otherHandCards = 0 local otherViewId = 0 -- 对方玩家的牌长度,因为只有2人,所以直接取非自己的即可。 for _,v in pairs(app.room.roomInfo.memberList) do if v.nUserId ~= app.room:getMyUserId() then otherHandCards = table.nums(v.handCards) otherViewId = app.room:getViewIdByUserId(v.nUserId) end end self:isShowMiddleTips(true, app.room.roomInfo.nRangTotalNums) -- 因为删手牌是正序,所以这里使用逆序,避免删除掉 for i = 1, tonumber(app.room.roomInfo.nRangTotalNums) do -- handCards[i]:setColor(cc.c3b(0xb3, 0xaa, 0xaa))--DOWN_COLOR self.handCards[''..otherViewId][i].isGrey = true self.handCards[''..otherViewId][i]:setGreyEnabled(true) end -- else -- self:isShowMiddleTips(false) -- end end --小局结算阶段 elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.ROUND_OVER then --服务器会推送一个结算消息 --恢复最后一手出牌 local myMemberInfo = app.room.roomInfo.memberList[app.room:getMyUserId()] if myMemberInfo.nPlayerFlag == 0 then self:setOutCardsVisible(true, app.room:getViewIdByUserId(app.room.roomInfo.lastUserId), { cards = app.room.roomInfo.lastCards, opType = app.room.roomInfo.lastCardType }) end end --显示底牌和底分炸弹情况 if app.room:checkUserIDIsInTable(app.room.roomInfo.nBankerId) and table.nums(app.room.roomInfo.bankerCards) > 0 then self:setBankerCardsVisible(true, app.room.roomInfo.bankerCards) else local bankCards = {{card = 0}, {card = 0}, {card = 0}} self:setBankerCardsVisible(true, bankCards) end --是否有人发起解散 self:judgeDissmiss() end end function RoomView_ERDouDiZhu:setXiaoJuVisible(bVisible, data) if self.XiaoJuView then --显示 self.XiaoJuView:setVisible(bVisible) end if bVisible then --显示玩家数据 for _,v in pairs(data.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) --显示剩余手牌 if v.nUserId ~= app.room:getMyUserId() and v.nUserId ~= data.nWinId then self:setOutCardsVisible(true, viewId, { cards = v.handCards, maxLen = 10 }) end --刷新分数 self.PlayerView:updateScore(viewId, v.nTotalScore) end --显示小局结算 if not self.XiaoJuView then function xiaYiJu() if app.room.roomInfo.isGameOver == 1 then -- self:goToHall() self:showDaJu(app.room.roomInfo._GameOverInfo) else self.ui:sendMsg(app.room, "callReadyRequest") end end self.XiaoJuView = import("pk_erdoudizhu.luaScript.Views.Room.RoomXiaoJuView_ERDouDiZhu"):new(xiaYiJu) self.ui.Items.Layout_XiaoJu:addChild(self.XiaoJuView) end --更新界面数据 self.XiaoJuView:updateView(data) end end function RoomView_ERDouDiZhu:judgeDissmiss() local roomInfo = app.room.roomInfo --解散状态 local uid = 0 local isDismiss = false for k,v in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(k) --记录玩家解散状态 0:初始状态, 1:发起解散 2: 同意解散 3:不同意解散 app.room.dismissInfo[k] = v.disbandStatus --有人发起解散时才显示解散界面 if v.disbandStatus == 1 then isDismiss = true uid = k end end --有人发起解散时才显示解散界面 if isDismiss then local memberList = {} for nUserId,memberInfo in pairs(roomInfo.memberList) do if app.room:checkUserIDIsInTable(nUserId) then memberList[nUserId] = memberInfo memberList[nUserId].nDisbandStatus = memberInfo.disbandStatus end end local view = import("luaScript.Views.Room.RoomDismissView"):new(uid, memberList, roomInfo.nDismissStateTime) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end end function RoomView_ERDouDiZhu:goToHall() app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.ERDouDiZhu)) end function RoomView_ERDouDiZhu:leaveRoomRequest() app.room.roomInfo.bQuitRoom = true self.ui:sendMsg(app.room, "callLeaveRequest") end -- 服务器广播玩家数据发生变化 function RoomView_ERDouDiZhu:onGpsChangeResponse(data) logD("RoomView_ERDouDiZhu:onGpsChangeResponse()") if not data or not data.nUserId then return end local nUserId = data.nUserId logD("RoomView_ERDouDiZhu:onGpsChangeResponse()", tostring(nUserId)) self:checkGpsDistance(nUserId) end -- 检查服务器记录的我的GPS数据是最新的,如果不是,则请求更新 function RoomView_ERDouDiZhu:checkMyGpsNeedUpdate() logD("RoomView_ERDouDiZhu:checkMyGpsNeedUpdate()") local nMyUserId = app.user.loginInfo.uid local myMemberInfo = app.room.roomInfo.memberList[nMyUserId] if myMemberInfo then local userInfo = json.decode(myMemberInfo.userInfo) if userInfo then local gpsInfo = userInfo.gpsInfo local isNewest = app.user:isGpsInfoNewest(gpsInfo) logD("RoomView_ERDouDiZhu:checkMyGpsNeedUpdate() gpsInfo is isNewest = ", tostring(isNewest)) if not isNewest then app.room:onGpsChangeRequest() else logD("RoomView_ERDouDiZhu:checkMyGpsNeedUpdate() gpsInfo is newest") end else logD("RoomView_ERDouDiZhu:checkMyGpsNeedUpdate() userInfo is nil") end else logD("RoomView_ERDouDiZhu:checkMyGpsNeedUpdate() myMemberInfo is nil") end end -- 更新所有玩家的信息到GPS组件 function RoomView_ERDouDiZhu:updateAllGpsInfo() local userInfoList = {} for nUserId, memberInfo in pairs(app.room.roomInfo.memberList) do local nSeatId = memberInfo.nSeatId local userInfo = memberInfo.userInfo if userInfo then userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo} end end if self.gpsComponent then self.gpsComponent:updateUserInfos(userInfoList) end end -- 检测玩家与其他玩家之间的距离 -- 如果不传参数,则检测所有玩家相互之间的距离 function RoomView_ERDouDiZhu:checkGpsDistance(curUserId) if app.room.roomInfo.nGameStartCount > 0 then return end self:updateAllGpsInfo() if self.gpsComponent then self.gpsComponent:checkGpsDistance(curUserId) end end -- 显示GPS界面 function RoomView_ERDouDiZhu:showGpsView() logD("RoomView_ERDouDiZhu:showGpsView()") local isGameStart = app.room.roomInfo.nGameStartCount > 0 local exitRoomCallback = function() self.ui:sendMsg(app.room, "callLeaveRequest") end local dismissCallback = function() app.room:requestDismissRoom(1) end self:updateAllGpsInfo() if self.gpsComponent then self.gpsComponent:showGpsView(3, isGameStart, exitRoomCallback, dismissCallback) end end -- 玩家收到解散房间的请求 function RoomView_ERDouDiZhu:onDismissResponse(event) logE("onDismissResponse() response = ", event.response) if not event or not event.response then return end local response = event.response --当前时间 app.room.roomInfo.nDismissStateTime = response.timeLeft --总的时间,服务器没发解散总时间来。那么就和一开始收到的解散剩余时间一致 app.room.roomInfo.nDismissToTalTime = response.timeLeft --显示解散(此标志会影响闹钟时间会冻住) app.room.roomInfo.nShowDismiss = true if response.operateType == 1 then local memberList = {} for nUserId,memberInfo in pairs(app.room.roomInfo.memberList) do if app.room:checkUserIDIsInTable(nUserId) then memberList[nUserId] = memberInfo end end if response.memberList ~= nil then for k,v in pairs(response.memberList) do if v.dismissState == 1 then local view = import("luaScript.Views.Room.RoomDismissView"):new(v.nUserId, memberList, app.room.roomInfo.nDismissStateTime) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) return end end else local view = import("luaScript.Views.Room.RoomDismissView"):new(response.nUserId, memberList, app.room.roomInfo.nDismissStateTime) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end else local memberStatus={} if response.memberList ~= nil then for k,v in pairs(response.memberList) do table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState}) end else table.insert(memberStatus,{userId = response.nUserId, status = response.operateType}) end app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus}) end end function RoomView_ERDouDiZhu:addCallBack(callback) table.insert(self.callbackQueue, callback) logE(" #self.callbackQueue:".. #self.callbackQueue) --高延迟情况下,执行快速播放,15条是没有标准,根据实际调整的 --if #self.callbackQueue >= 15 then --cc.Director:getInstance():getScheduler():setTimeScale(5.0) --else cc.Director:getInstance():getScheduler():setTimeScale(1.0) --end local function runFunc() log("2000000000 - runNextFunc() size = ", #self.callbackQueue ) if #self.callbackQueue <= 0 then self.callbackRunning = false return end local func = self.callbackQueue[1] table.remove(self.callbackQueue,1) self.callbackRunning = true func(function() self.callbackRunning = false runFunc() end) end log("self.callbackRunning:",self.callbackRunning) if not self.callbackRunning then runFunc() end end function RoomView_ERDouDiZhu:onChangeTable(data) self:setTableImg(data.idx) end function RoomView_ERDouDiZhu:onChangeLanguage(data) local idx = data.idx if self.messageView then self.messageView:setLanguage(idx == defs.LANGUAGE_TYPE.PU_TONG_HUA) end end function RoomView_ERDouDiZhu:setTableImg(idx) --桌布 self.ui.Items.ImageView_bg:loadTexture(defs.BG_Img[idx] and defs.BG_Img[idx] or defs.BG_Img[1]) self:initLogo() end function RoomView_ERDouDiZhu:initLogo() if tolua.isnull(self.ui.Items.ImageView_Logo) then return end if not (type(getSubGameRoomLogo) == 'function') then self.ui.Items.ImageView_Logo:setVisible(false) return end local roomInfo = app.room.roomInfo local gameInfo = json.decode(roomInfo.strGameInfo or "") local gamerule = tonumber(gameInfo.gamerule or 1) roomInfo.gameId = roomInfo.gameId or app.gameId or 0 local logofile = getSubGameRoomLogo(roomInfo.gameId, gamerule) if logofile then self.ui.Items.ImageView_Logo:loadTexture(logofile) self.ui.Items.ImageView_Logo:setVisible(true); else self.ui.Items.ImageView_Logo:setVisible(false); end --self.ui.Items.ImageView_Logo:setVisible(false) end function RoomView_ERDouDiZhu:ontSetPropEnabled(event) if self.messageView then self.messageView:setPropEnabled(event.value == 1) end end function RoomView_ERDouDiZhu:onSetVoiceEnabled(event) if self.messageView then self.messageView:setVoiceEnabled(event.value == 1) end end function RoomView_ERDouDiZhu:onNormalChangePoker(data) if data.idx > 2 and data.idx < 1 then return end local temp = { "pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cards/doudizhu_pokerCards_old.plist", "pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cards/doudizhu_pokerCards.plist", } -- 删除缓存重新添加缓存 for i, v in ipairs(temp) do cc.SpriteFrameCache:getInstance():removeSpriteFramesFromFile(v) end loadSpriteFrameFile(temp[data.idx]) -- 刷新当前手牌 if self.handCards then for _, v in pairs(app.room.roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) local handCardLayout = self.handCards["" .. viewId] if handCardLayout then for i, v in ipairs(handCardLayout) do if v.refreshCard then v:refreshCard() end end self:rankHandCards(viewId, false) end end end -- 刷新当前出的牌 for _, v in pairs(app.room.roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) local outCardLayout = self.ui.Items["Layout_Out_" .. viewId] if outCardLayout then for _, card in ipairs(outCardLayout:getChildren()) do if card.refreshCard then card:refreshCard() end end end end end --自己的视图ID function RoomView_ERDouDiZhu:getMeViewId() return defs.VIEW_ID.MY_VIEW_ID end function RoomView_ERDouDiZhu:cmd_0x8104_Resp(data) function cmd_0x8104_RespEx(onEnd) playVoice("pk_erdoudizhu/res/sound/doudizhu_common_began.ogg") self.PlayerView:setLeftNumVisible(true, -1, 17) self:setXiaoJuVisible(false, nil) --更新局数 self:updateGameNums() --更新按钮状态 self:updateButtons() --隐藏所有准备 self:setAllReadyVisible(false) -- 玩家托管状态还原 self:refreshPlayerAIStatus() -- 显示左边内容 local bankCards = {{card = 0}, {card = 0}, {card = 0}} self:setBankerCardsVisible(true, bankCards) if onEnd then onEnd() end end self:addCallBack(cmd_0x8104_RespEx) end --显隐所有准备 function RoomView_ERDouDiZhu:setAllReadyVisible(bVisible) for k,v in pairs(app.room.roomInfo.memberList) do self.PlayerView:setReadyVisible(bVisible, app.room:getViewIdByUserId(v.nUserId)) end end function RoomView_ERDouDiZhu:cmd_0x8105_Resp(data) function cmd_0x8105_RespEx(onEnd) --加倍阶段,隐藏叫分相关界面 if data.response.nStatus == defs.GAME_STATUS.ASK_BEI then self:setAskLoardVisible(false) for _,v in pairs(app.room.roomInfo.memberList) do self.PlayerView:setTipsVisibleExcept({'tips_jiaofen'}, app.room:getViewIdByUserId(v.nUserId)) end -- 让牌阶段 elseif data.response.nStatus == defs.GAME_STATUS.ASK_RANG then self:setAskLoardVisible(false) for _,v in pairs(app.room.roomInfo.memberList) do self.PlayerView:setTipsVisibleExcept({}, app.room:getViewIdByUserId(v.nUserId)) end --打牌阶段,隐藏加倍相关界面 elseif data.response.nStatus == defs.GAME_STATUS.PLAYING then self:setAskBeiVisible(false) for _,v in pairs(app.room.roomInfo.memberList) do -- self.PlayerView:setTipsVisible("tips_jiabei", false, app.room:getViewIdByUserId(v.nUserId)) self.PlayerView:setTipsVisibleExcept({}, app.room:getViewIdByUserId(v.nUserId)) end -- 若处理打牌中,并且有让牌值,则置灰 if not app.room.roomInfo.isRecord then for _, v in pairs(app.room.roomInfo.memberList) do if v.nUserId ~= app.room:getMyUserId() and v.nUserId ~= app.room.roomInfo.nBankerId then local vId = app.room:getViewIdByUserId(v.nUserId) local handCards = self.handCards["" .. vId] local cardNums = table.nums(handCards) for i = 1, tonumber(app.room.roomInfo.nRang) do -- handCards[i]:setColor(cc.c3b(0xb3, 0xaa, 0xaa))--DOWN_COLOR handCards[i].isGrey = true handCards[i]:setGreyEnabled(true) end end end end end if data.response.nStatus == defs.GAME_STATUS.SENDCARDS then self.PlayerView:setLeftNumVisible(true, -1, 17) end -- 显示中间庄家让x 所有人 if app.room.roomInfo.nStatus then if app.room.roomInfo.nStatus >= defs.GAME_STATUS.ASK_LOARD and app.room.roomInfo.nStatus <= defs.GAME_STATUS.ASK_RANG then self:isShowMiddleTipsForAll(true, app.room.roomInfo.nRang or 0) elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.PLAYING and app.room.roomInfo.nBankerId == app.room:getMyUserId() then self:isShowMiddleTips(true, app.room.roomInfo.nRang) else self:isShowMiddleTipsForAll(false) end end if onEnd then onEnd() end end self:addCallBack(cmd_0x8105_RespEx) end function RoomView_ERDouDiZhu:getCardType(card) return self._pokerUtil:getCardType(card) end function RoomView_ERDouDiZhu:getCardValue(card) return self._pokerUtil:getCardValue(card) end function RoomView_ERDouDiZhu:setCardUp(card) card.isUp = true self.selectCards["" .. card.cardNum] = card -- card:setPosition(cc.pAdd(card.tarPos, cc.p(0, 35))) -- 抬起动画 card:stopAllActions() local moveTo = cc.MoveTo:create(Card_Move_Up_Down_Time, cc.pAdd(card.tarPos, cc.p(0, 28))) card:runAction(moveTo) end function RoomView_ERDouDiZhu:setCardDown(card) card.isUp = false -- card:setPosition(card.tarPos) -- 下放动画 card:stopAllActions() local moveTo = cc.MoveTo:create(Card_Move_Up_Down_Time, card.tarPos) card:runAction(moveTo) end function RoomView_ERDouDiZhu:handCardItemRegisterTouchEvent(handCard) local nomalColor = cc.c3b(255,255,255) local selectColor = cc.c3b(200,200,200) function onTouchBegan(touch, event) local target = event:getCurrentTarget() local locationInNode = target:convertToNodeSpace(touch:getLocation()) local s = target:getContentSize() local rect = cc.rect(0, 0, s.width, s.height) if cc.rectContainsPoint(rect, locationInNode) then self.touchBeganPos = touch:getLocation() target:setColor(selectColor) target.isHit = true return true else return false end end function onTouchMoved(touch, event) local touchMovePos = touch:getLocation() local direction = touchMovePos.x - self.touchBeganPos.x local handCards = self.handCards["" .. self:getMeViewId()] --灵敏度 if math.abs(direction) < 5 then return end if handCards then for k,v in ipairs(handCards) do local needContain = true if v.isHit then local locationInWorld = v:getParent():convertToWorldSpace(v:getPosition()) if direction > 0 then if touchMovePos.x > locationInWorld.x - v:getContentSize().width / 2 + (v:getContentSize().width - self.handCardDif) then needContain = false end else if touchMovePos.x < locationInWorld.x - v:getContentSize().width / 2 then needContain = false end end end if needContain then local cardSize = v:getContentSize() local locationInNode = v:convertToNodeSpace(touch:getLocation()) local rectEx = cc.rect(0, 0, cardSize.width - self.handCardDif, cardSize.height) if cc.rectContainsPoint(rectEx, locationInNode) then v:setColor(selectColor) v.isHit = true else v:setColor(nomalColor) v.isHit = false end end end end end function onTouchEnded(touch, event) local handCards = self.handCards["" .. self:getMeViewId()] if handCards then -- for k,v in ipairs(handCards) do -- if v.isHit then -- if v.isUp then -- self:setCardDown(v) -- else -- self:setCardUp(v) -- end -- end -- v:setColor(nomalColor) -- v.isHit = false -- end local isAllNormal = true for _,card in pairs(handCards) do if card then if card.isUp then isAllNormal = false break end end end local selectCards = {} for k,card in ipairs(handCards) do if card.isHit then table.insert(selectCards, card.cardNum) end end -- 过滤选择的牌(主动出牌) if isAllNormal then if #self.lastData.cards <= 0 then if self._pokerUtil and self._pokerUtil.getCardInSelectCard then selectCards = self._pokerUtil:getCardInSelectCard(selectCards) end end end for i, v in ipairs(selectCards) do local node = self:getCardNodeByCardValue(v) if node then if node.isUp then self:setCardDown(node) else self:setCardUp(node) end node:setColor(nomalColor) node.isHit = false end end for i, card in ipairs(handCards) do if card.isHit then card:setColor(nomalColor) card.isHit = false end end end end -- 创建一个事件监听器 local listener = cc.EventListenerTouchOneByOne:create() --设置穿透属性 listener:setSwallowTouches(true) --添加事件和回调 listener:registerScriptHandler(onTouchBegan, cc.Handler.EVENT_TOUCH_BEGAN) listener:registerScriptHandler(onTouchMoved, cc.Handler.EVENT_TOUCH_MOVED) listener:registerScriptHandler(onTouchEnded, cc.Handler.EVENT_TOUCH_ENDED) -- 得到事件派发器 local eventDispatcher = self:getEventDispatcher() -- 将监听器注册到派发器中 eventDispatcher:addEventListenerWithSceneGraphPriority(listener, handCard) end function RoomView_ERDouDiZhu:initHandCardItem(card, viewId) local switchEx = {} local cardType = self:getCardType(card) local cardValue = self:getCardValue(card) local scaleEx = 0.35 local frameName = 'ddz_cards_%d_%d.png' if card == 0 then frameName = 'ddz_cards_0.png' end switchEx["1"] = function() -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源 local card = cc.Sprite:createWithSpriteFrameName(string.format(frameName, cardType, cardValue)) -- 新资源 card:setAnchorPoint(cc.p(1, 1)) card:setScale(scaleEx) return card end switchEx["2"] = function() -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源 -- local card = cc.Sprite:createWithSpriteFrameName(string.format(frameName, cardType, cardValue)) -- 新资源 -- 使用iamgeview,使得可以置灰 local card = cc.ImageView:create() card:loadTexture(string.format(frameName, cardType, cardValue), 1) -- card:setAnchorPoint(cc.p(1, 1)) card:setScale(scaleEx) return card end switchEx["3"] = function() -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源 local card = cc.Sprite:createWithSpriteFrameName(string.format(frameName, cardType, cardValue)) -- 新资源 card:setAnchorPoint(cc.p(0, 1)) card:setScale(scaleEx) return card end switchEx["4"] = function() -- return cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源 return cc.Sprite:createWithSpriteFrameName(string.format(frameName, cardType, cardValue)) -- 新资源 -- local card = cc.Sprite:createWithSpriteFrameName(string.format("ddz_cards_%d_%d.png", cardType, cardValue)) -- 新资源 -- card:setScale(scaleEx) -- return card end local initFunc = switchEx["" .. viewId] if initFunc then local imageCard = nil local imageCard = initFunc() if imageCard then imageCard.cardValue = cardValue -- 牌具体值1~13 imageCard.cardType = cardType -- 牌类型 imageCard.cardNum = card -- 牌的标准值 imageCard.refreshCard = function() -- 刷新卡牌 -- if card > 0 then -- local cardPng = string.format("ddz_cards_%d_%d.png", cardType, cardValue) local cardPng = string.format(frameName, cardType, cardValue) if imageCard.setSpriteFrame then imageCard:setSpriteFrame(cardPng) elseif imageCard.loadTexture then imageCard:loadTexture(string.format(frameName, cardType, cardValue), 1) end if imageCard.bankerMark then local size = imageCard:getContentSize() local offsetX, offsetY = self:getBankTagOffset() imageCard.bankerMark:setPosition(cc.p(size.width * 0.72 + offsetX, size.height * 0.78 + offsetY)) end -- end end if viewId == self:getMeViewId() then self:handCardItemRegisterTouchEvent(imageCard) end -- 设置为庄家牌 if self:checkIsBankCard(imageCard.cardNum, viewId) then imageCard.isBankCard = true end end logE("initHandCardItem viewId " .. viewId .. "imageCard " .. imageCard.cardNum) return imageCard end end function RoomView_ERDouDiZhu:rankHandCards(viewId, ani) local childs = self.handCards["" .. viewId] if childs then local isBanker = app.room.roomInfo.nBankerId and app.room.roomInfo.nBankerId > 0 and app.room:getViewIdByUserId(app.room.roomInfo.nBankerId) == viewId local childsNum = table.nums(childs) local xDiff = -30 --x轴调整 local getPokerChoose = tonumber(loadUserInfo("ddz_setting_poker")) or defs.Default_Poker_Choose local cardDif = (getPokerChoose == 1) and 96 or 110 if childsNum > 17 then -- 使得扑克超过17张的话,让扑克牌组挤一点 self.handCardDif = cardDif + 3 * (childsNum - 17) else self.handCardDif = cardDif end for k,v in ipairs(childs) do local maxLen = 20 local kEx = tonumber(k) local floor = math.floor(kEx / maxLen) local mod = kEx % maxLen + (kEx >= maxLen and 1 or 0) local childScale = v:getScale() local childSize = v:getContentSize() if viewId == defs.VIEW_ID.MY_VIEW_ID then v.tarPos = cc.p(xDiff + (kEx - childsNum / 2) * (childSize.width - self.handCardDif) * childScale.x, childSize.height / 2 * childScale.y) elseif viewId == defs.VIEW_ID.TOP_VIEW_ID then --设置zOder -- v:setLocalZOrder(maxLen * floor - kEx) -- v.tarPos = cc.p((-1) * mod * (childSize.width - self.handCardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5 * floor) v.tarPos = cc.p(xDiff + (kEx - childsNum / 2 + 1) * (childSize.width - cardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5) elseif viewId == defs.VIEW_ID.LEFT_VIEW_ID then v.tarPos = cc.p(mod * (childSize.width - self.handCardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5 * floor) elseif viewId == defs.VIEW_ID.RIGHT_VIEW_ID then v:setLocalZOrder(maxLen * floor - kEx) v.tarPos = cc.p((-1) * mod * (childSize.width - self.handCardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5 * floor) end --庄家标识 if isBanker then if v.isBankCard then if v.cardNum ~= 0 then if v.bankerMark then v.bankerMark:setVisible(true) else v.bankerMark = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_bankerCardMark.png")) local offsetX, offsetY = self:getBankTagOffset() if app.room.roomInfo.isRecord then if viewId ~= self:getMeViewId() then offsetY = offsetY - 1.5 end end v.bankerMark:setPosition(cc.p(childSize.width * 0.72 + offsetX, childSize.height * 0.78 + offsetY)) v:addChild(v.bankerMark) end end end end if ani then v:stopAllActions() v:runAction(cc.MoveTo:create(0.15, v.tarPos)) else v:setPosition(v.tarPos) end end end end function RoomView_ERDouDiZhu:initHandCards(handCards, viewId) local handLayout = self.ui.Items["Layout_Hand_" .. viewId] --手牌 self.handCards = self.handCards or {} --选中的牌 self.selectCards = self.selectCards or {} if handLayout then handLayout:removeAllChildren() --排序手牌 table.sort(handCards.Datas, function(a, b) local cardValueA = self:getCardValue(a.card) local cardValueB = self:getCardValue(b.card) return cardValueA > cardValueB or cardValueA == cardValueB and self:getCardType(a.card) > self:getCardType(b.card) end) for k,v in ipairs(handCards.Datas) do local imageCard = self:initHandCardItem(v.card, viewId) if imageCard then handLayout:addChild(imageCard) end end self.handCards["" .. viewId] = handLayout:getChildren() end self:rankHandCards(viewId) end function RoomView_ERDouDiZhu:fapaiAni(onEnd) self._isCanClickBg = false local handCards = self.handCards["" .. self:getMeViewId()] if not handCards then logE("RoomView_ERDouDiZhu fapaiAni error") if onEnd then onEnd() end end for k,v in ipairs(handCards) do v:setPosition(cc.pAdd(v.tarPos, cc.p(1280, 0))) v:runAction( cc.Sequence:create( cc.DelayTime:create(0.03 * tonumber(k)), cc.MoveTo:create(0, v.tarPos), cc.CallFunc:create(function() --playVoice("pk_erdoudizhu/res/sound/doudizhu_common_fapai.ogg") if tonumber(k) == table.nums(handCards) then self._isCanClickBg = true if onEnd then onEnd() end end end) ) ) end end function RoomView_ERDouDiZhu:cmd_0x8106_Resp(data) function cmd_0x8106_Resp(onEnd) local handCards = app.room.roomInfo.memberList[data.response.nUserId].handCards -- self:initHandCards(handCards, self:getMeViewId()) self:initHandCards(handCards, app.room:getViewIdByUserId(data.response.nUserId)) if data.response.nUserId == app.room:getMyUserId() then if table.nums(handCards) == 20 then local bankerCards = {} for _,v in ipairs(app.room.roomInfo.bankerCards) do table.insert(bankerCards, v.card) end --从手牌中上升地主牌 self:setHandCardsUp(self:getMeViewId(), bankerCards) if onEnd then onEnd() end else self:fapaiAni(onEnd) end else if onEnd then onEnd() end end end self:addCallBack(cmd_0x8106_Resp) end -- 叫分界面/叫地主界面 function RoomView_ERDouDiZhu:setAskLoardVisible(bVisible, biJiao, nPlayMode) -- 叫分模式 self.ui.Items.Layout_Ask_Loard_Mode_Score:setVisible(false) self.ui.Items.Layout_Ask_Loard_Mode_DiZhu:setVisible(false) if bVisible then if nPlayMode == 1 then -- 叫地主 self.ui.Items.Layout_Ask_Loard_Mode_DiZhu:setVisible(true) local curAskLoard = app.room.roomInfo.curAskLoard or 0 for i = 0, 1 do local askLoardBtn = self.ui.Items["Button_Ask_Loard_D_" .. i] if askLoardBtn then if biJiao then askLoardBtn:setEnabled(i == 1) end end end self.ui.Items.Layout_Ask_Loard_Mode_DiZhu_Buttons:requestDoLayout() self.ui.Items.Layout_Ask_Loard_Mode_DiZhu_Buttons:doLayout() elseif nPlayMode == 2 then -- 叫分 self.ui.Items.Layout_Ask_Loard_Mode_Score:setVisible(true) local curAskLoard = app.room.roomInfo.curAskLoard or 0 for i = 0, 3 do local askLoardBtn = self.ui.Items["Button_Ask_Loard_F_" .. i] if askLoardBtn then if biJiao then askLoardBtn:setEnabled(i == 3) else askLoardBtn:setEnabled(not (i ~= 0 and i <= curAskLoard)) end end end self.ui.Items.Layout_Ask_Loard_Mode_Score_Buttons:requestDoLayout() self.ui.Items.Layout_Ask_Loard_Mode_Score_Buttons:doLayout() end end end -- 抢地主界面 function RoomView_ERDouDiZhu:setQiangVisible(bVisible) self.ui.Items.Layout_Qiang:setVisible(bVisible) end -- 让牌界面 function RoomView_ERDouDiZhu:setRangVisible(bVisible, rangMaxCount) self.ui.Items.Layout_Rang:setVisible(bVisible) if bVisible then for i = 0, 4 do if i ~= 1 then local rangLayout = self.ui.Items["Layout_Rang_" .. i] if rangLayout then rangLayout:setVisible(i <= rangMaxCount) end end end self.ui.Items.Layout_Rang_Buttons:requestDoLayout() self.ui.Items.Layout_Rang_Buttons:doLayout() end end function RoomView_ERDouDiZhu:setAskBeiVisible(bVisible) self.ui.Items.Layout_Ask_Bei:setVisible(bVisible) end function RoomView_ERDouDiZhu:setOperationVisible(bVisible, opType) self.ui.Items.Layout_Operation:setVisible(bVisible) if bVisible then -- opType: 0要不起(没有可压牌), 1可要可不要, 2必须出(轮到自己了) if opType == 1 then -- 这种风格是,全程没有变灰的按钮,直接就隐藏掉 self.ui.Items.Layout_Operation_BuChu:setVisible(bVisible) self.ui.Items.Layout_Operation_TiShi:setVisible(bVisible) self.ui.Items.Layout_Operation_ChuPai:setVisible(bVisible) self.ui.Items.Layout_Operation_YaoBuQi:setVisible(not bVisible) -- 这种风格是,有变灰的按钮,不可点击,下面同理 --[[ self.ui.Items.Button_Operation_BuChu:setEnabled(bVisible) self.ui.Items.Button_Operation_TiShi:setEnabled(bVisible) self.ui.Items.Button_Operation_ChuPai:setEnabled(bVisible) self.ui.Items.Layout_Operation_YaoBuQi:setVisible(false) ]] elseif opType == 2 then self:setLastData() self.ui.Items.Layout_Operation_BuChu:setVisible(not bVisible) self.ui.Items.Layout_Operation_TiShi:setVisible(not bVisible) -- 轮到自己回合,提示按钮隐藏 self.ui.Items.Layout_Operation_ChuPai:setVisible(bVisible) self.ui.Items.Layout_Operation_YaoBuQi:setVisible(not bVisible) --[[ self.ui.Items.Button_Operation_BuChu:setEnabled(not bVisible) self.ui.Items.Button_Operation_TiShi:setEnabled(bVisible) self.ui.Items.Button_Operation_ChuPai:setEnabled(bVisible) self.ui.Items.Layout_Operation_YaoBuQi:setVisible(false) ]] else self.ui.Items.Layout_Operation_BuChu:setVisible(not bVisible) self.ui.Items.Layout_Operation_TiShi:setVisible(not bVisible) self.ui.Items.Layout_Operation_ChuPai:setVisible(not bVisible) self.ui.Items.Layout_Operation_YaoBuQi:setVisible(bVisible) --[[ self.ui.Items.Button_Operation_BuChu:setEnabled(bVisible) self.ui.Items.Button_Operation_TiShi:setEnabled(not bVisible) self.ui.Items.Button_Operation_ChuPai:setEnabled(not bVisible) self.ui.Items.Layout_Operation_YaoBuQi:setVisible(false) ]] end self.ui.Items.Layout_Operation_Buttons:requestDoLayout() self.ui.Items.Layout_Operation_Buttons:doLayout() --检测提示 self.tiShiCount = 1 local handCards = self.handCards["" .. self:getMeViewId()] local handCardsValueTable = {} -- 玩家手牌值表 local lastDataValueTable = {} -- 上个牌数据值表 for i, v in pairs(handCards) do table.insert(handCardsValueTable, v.cardNum) end for i, v in pairs(self.lastData.cards) do table.insert(lastDataValueTable, v.cardNum) end -- 判断是否可以一手出完牌 if self._pokerUtil:checkIsCanOneOutCard(handCardsValueTable, lastDataValueTable) then --self:setOperationVisible(false) self:runAction( cc.Sequence:create( cc.DelayTime:create(0.5), cc.CallFunc:create(function () self:setHandCardsUp(self:getMeViewId(), handCardsValueTable) self:chuPai() end) ) ) end -- 牌型提示 if self.ui.Items.Layout_Operation_TiShi:isVisible() then self.weaveCardList = self:getTip(handCardsValueTable, lastDataValueTable) end end end function RoomView_ERDouDiZhu:setHandCardsUp(viewId, cards) --下降所有牌 self:setAllHandCardDown(self:getMeViewId()) --上升指定牌 if self.handCards and cards then local handCards = self.handCards["" .. viewId] if handCards then for k,v in ipairs(cards) do for _,v2 in ipairs(handCards) do if v == v2.cardNum then self:setCardUp(v2) end end end end end end function RoomView_ERDouDiZhu:setAllHandCardDown(viewId) if self.handCards then local handCards = self.handCards["" .. viewId] if handCards then for _,v in ipairs(handCards) do self:setCardDown(v) end end end end function RoomView_ERDouDiZhu:initGameButtons() --桌面 self.ui.Items.ImageView_bg:registerClick(function() --测试 --self:chuPai() --self:tiShi() --self:fapaiAni() if not self._isCanClickBg then return end --下降所有牌 self:setAllHandCardDown(self:getMeViewId()) end) --叫分 self.ui.Items.Layout_Ask_Loard_Mode_Score:setVisible(false) for i = 0, 3 do local button = self.ui.Items["Button_Ask_Loard_F_" .. i] if button then button:registerClick(function() playBtnEffect() app.room:sendAskLoard(i) end) end end -- 叫地主按钮 self.ui.Items.Layout_Ask_Loard_Mode_DiZhu:setVisible(false) for i = 0, 1 do local button = self.ui.Items["Button_Ask_Loard_D_" .. i] if button then button:registerClick(function() playBtnEffect() app.room:sendAskLoard(i) end) end end -- 抢地主按钮 self.ui.Items.Layout_Qiang:setVisible(false) for i = 0, 1 do local button = self.ui.Items["Button_Qiang_" .. i] if button then button:registerClick(function() playBtnEffect() app.room:sendQiang(i) end) end end -- 让牌按钮 self.ui.Items.Layout_Rang:setVisible(false) for i = 0, 4 do if i ~= 1 then local button = self.ui.Items["Button_Rang_" .. i] if button then button:registerClick(function() playBtnEffect() app.room:sendRang(i) end) end end end --加倍 self.ui.Items.Layout_Ask_Bei:setVisible(false) for i = 0, 1 do local button = self.ui.Items["Button_Ask_Bei_" .. i] if button then button:registerClick(function() playBtnEffect() app.room:sendAskBei(i) end) end end --要不起,不出,提示,出牌 self.ui.Items.Layout_Operation:setVisible(false) self.ui.Items.Button_Operation_YaoBuQi:registerClick(function() playBtnEffect() app.room:sendOperation({opType = 0, cards = {}}) end) self.ui.Items.Button_Operation_BuChu:registerClick(function() playBtnEffect() app.room:sendOperation({opType = 0, cards = {}}) end) self.ui.Items.Button_Operation_TiShi:registerClick(handler(self, self.tiShi)) self.ui.Items.Button_Operation_ChuPai:registerClick(handler(self, self.chuPai)) end function RoomView_ERDouDiZhu:getCardsType(cards) return self._pokerUtil:getCardsType(cards) end function RoomView_ERDouDiZhu:getTip(cards, lastData) if cards and cards[1] and type(cards[1]) == 'userdata' then logD('亲!现在调用getTip,cards数据是要传牌值,不是card节点啦!!!') return end return self._pokerUtil:getTip(cards, lastData) end function RoomView_ERDouDiZhu:tiShi() playBtnEffect() if self.weaveCardList and table.nums(self.weaveCardList) > 0 then function tiShiEx() local weaveList = self.weaveCardList[self.tiShiCount] if weaveList then self:setHandCardsUp(self:getMeViewId(), weaveList) self.tiShiCount = self.tiShiCount + 1 else self.tiShiCount = 1 tiShiEx() end end tiShiEx() else app.room:sendOperation({opType = 0, cards = {}}) end end function RoomView_ERDouDiZhu:chuPai() playBtnEffect() local handCards = self.handCards["" .. self:getMeViewId()] if not handCards then logE("RoomView_ERDouDiZhu chuPai error handCards is null") end --获取点中的牌 local cards = {} local cardsEx = {} for k,v in ipairs(handCards) do if v:isVisible() and v.isUp then table.insert(cards, v.cardNum) table.insert(cardsEx, v) end end --local typeEx = self:getCardsType(cardsEx) --logE("RoomView_ERDouDiZhu chuPai type : " .. table.tostring(cardsEx)) logE("RoomView_ERDouDiZhu chuPai type : " .. table.tostring(cards)) app.room:sendOperation({opType = 1, cards = cards}) end function RoomView_ERDouDiZhu:cmd_0x8108_Resp(data) function cmd_0x8108_RespEx(onEnd) --当前操作玩家 self.curViewId = app.room:getViewIdByUserId(data.response.nUserId) --显示闹钟 self.PlayerView:setClockVisibel(true, self.curViewId, data.response.leftTime) --显示叫分 if self.curViewId == self:getMeViewId() then self:setAskLoardVisible(true, data.response.mustBanker == 1, data.response.nPlayMode) end if onEnd then onEnd() end end self:addCallBack(cmd_0x8108_RespEx) end function RoomView_ERDouDiZhu:cmd_0x8109_Resp(data) function cmd_0x8109_RespEx(onEnd) local viewId = app.room:getViewIdByUserId(data.response.nUserId) --隐藏叫分界面 self:setAskLoardVisible(false) --隐藏闹钟 self.PlayerView:setClockVisibel(false, viewId) --显示叫分/叫地主 local tips = '' local soundTips = '' if data.response.nPlayMode == 1 then tips = 'tips_jiaodizhu' soundTips = 'jiaodizhu' else tips = 'tips_jiaofen' soundTips = 'jiaofen' end self.PlayerView:setTipsVisible(tips, true, viewId, {askLoard = data.response.askLoard}) --播放音效 Functions.playVoice(soundTips, data.response.askLoard, self.PlayerView:getPlayerData("sex", viewId)) if onEnd then onEnd() end end self:addCallBack(cmd_0x8109_RespEx) end function RoomView_ERDouDiZhu:setBankerAskLoard() -- 隐藏叫分 do self.ui.Items.Image_Score_Title:setVisible(false) return end self.ui.Items.Text_AskLoard:setText(app.room.roomInfo.curAskLoard or 0) end function RoomView_ERDouDiZhu:setCurZhaDanNum() -- 隐藏炸弹数 do self.ui.Items.Image_Bomb_Title:setVisible(false) return end self.ui.Items.Text_ZhaDan:setText(app.room.roomInfo.nBombs or 0) end function RoomView_ERDouDiZhu:setCurMultiple() self.ui.Items.Text_BeiShu:setText(app.room.roomInfo.nMult or 0) self.ui.Items.Layout_BeiShu_Info:setVisible(true) end function RoomView_ERDouDiZhu:setCurRang() -- if Functions.getRangCount() <= 0 then -- self.ui.Items.Layout_Rang_Info:setVisible(false) -- return -- end self.ui.Items.Text_Rang:setText(app.room.roomInfo.nRang or 0) self.ui.Items.Layout_Rang_Info:setVisible(true) end function RoomView_ERDouDiZhu:setCurDiPaiTypeAndMult() local diType = app.room.roomInfo.diType or 0 local imgPath = 'pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/dipai_type/%s.png' local imgMultPath = 'pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/dipai_type/doudizhu_mult_%s.png' if diType > 0 then if diType ~= defs.DI_TYPE.TYPE_TONGHUASHUN then -- 同花顺单独特殊处理 self.ui.Items.Layout_DiPai_Type_2:setVisible(false) self.ui.Items.Layout_DiPai_Type_1:setVisible(true) self.ui.Items.ImageView_DIPai_Type_1:loadTexture(string.format(imgPath, defs.DI_TYPE_IMAGE_PATH[diType])) self.ui.Items.ImageView_DIPai_Type_Mult_1:loadTexture(string.format(imgMultPath, defs.DI_TYPE_MULT[diType])) else self.ui.Items.Layout_DiPai_Type_2:setVisible(true) self.ui.Items.Layout_DiPai_Type_1:setVisible(true) self.ui.Items.ImageView_DIPai_Type_1:loadTexture(string.format(imgPath, defs.DI_TYPE_IMAGE_PATH[defs.DI_TYPE.TYPE_TONGHUA])) self.ui.Items.ImageView_DIPai_Type_Mult_1:loadTexture(string.format(imgMultPath, defs.DI_TYPE_MULT[defs.DI_TYPE.TYPE_TONGHUA])) self.ui.Items.ImageView_DIPai_Type_2:loadTexture(string.format(imgPath, defs.DI_TYPE_IMAGE_PATH[defs.DI_TYPE.TYPE_SHUNZI])) self.ui.Items.ImageView_DIPai_Type_Mult_2:loadTexture(string.format(imgMultPath, defs.DI_TYPE_MULT[defs.DI_TYPE.TYPE_SHUNZI])) end else self.ui.Items.Layout_DiPai_Type_2:setVisible(false) self.ui.Items.Layout_DiPai_Type_1:setVisible(false) end self.ui.Items.Layout_BankerInfo_1:requestDoLayout() self.ui.Items.Layout_BankerInfo_1:doLayout() end function RoomView_ERDouDiZhu:setBankerCardsVisible(bVisible, bankerCards) self.ui.Items.Layout_BankerInfo:setVisible(bVisible) self.ui.Items.Layout_BankCard:setVisible(bVisible) if bVisible then for k,v in ipairs(bankerCards) do local card = self.ui.Items["Image_BankerCard_" .. k] if card then -- card:loadTexture(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))) -- 旧资源 if v.card > 0 then card:loadTexture(string.format("ddz_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card)), 1) -- 新资源 elseif v.card == 0 then card:loadTexture(string.format("ddz_cards_0.png"), 1) -- 新资源 end end end self:setCurZhaDanNum() self:setBankerAskLoard() self:setCurMultiple() self:setCurRang() self:setCurDiPaiTypeAndMult() end self.ui.Items.Layout_BankerInfo_1:requestDoLayout() self.ui.Items.Layout_BankerInfo_1:doLayout() end function RoomView_ERDouDiZhu:cmd_0x810a_Resp(data) function cmd_0x810a_RespEx(onEnd) self:runAction( cc.Sequence:create( cc.DelayTime:create(1.0), cc.CallFunc:create(function() local viewId = app.room:getViewIdByUserId(data.response.nBankerId) --显示剩余手牌 self.PlayerView:setLeftNumVisible(true, viewId, 20) --显示庄家 self.PlayerView:setBankerVisible(true, viewId) --显示底牌和底分炸弹情况 self:setBankerCardsVisible(true, data.response.bankerCards) -- 底牌显示的时候,即叫分结束,此时把叫分分数隐藏 self:setAllTipsVisible() if onEnd then onEnd() end end) ) ) end self:addCallBack(cmd_0x810a_RespEx) end function RoomView_ERDouDiZhu:setAllTipsVisible(bVisible) for k,v in pairs(app.room.roomInfo.memberList) do self.PlayerView:setTipsVisible("tips_jiaofen", false, app.room:getViewIdByUserId(v.nUserId)) end end function RoomView_ERDouDiZhu:cmd_0x810c_Resp(data) function cmd_0x810c_RespEx(onEnd) --显示加倍 self:setAskBeiVisible(true) local function endCallback(viewId) if Functions.getIsAutoAskBeiAfterTimeout() then if viewId == self:getMeViewId() then app.room:sendAskBei(0) end end end --显示闹钟 for k,v in pairs(app.room.roomInfo.memberList) do self.PlayerView:setClockVisibel(true, app.room:getViewIdByUserId(v.nUserId), data.response.leftTime, endCallback) end if onEnd then onEnd() end end self:addCallBack(cmd_0x810c_RespEx) end function RoomView_ERDouDiZhu:cmd_0x810d_Resp(data) function cmd_0x810d_RespEx(onEnd) local viewId = app.room:getViewIdByUserId(data.response.nUserId) --隐藏加倍操作界面 if viewId == self:getMeViewId() then self:setAskBeiVisible(false) self:setAllHandCardDown(viewId) end --隐藏闹钟 self.PlayerView:setClockVisibel(false, viewId) --显示加倍状态 self.PlayerView:setTipsVisible("tips_jiabei", true, viewId, { askBei = data.response.askBei }) --播放音效 Functions.playVoice("jiabei", data.response.askBei, self.PlayerView:getPlayerData("sex", viewId)) self:runAction( cc.Sequence:create( cc.DelayTime:create(0.5), cc.CallFunc:create(function() if onEnd then onEnd() end end) ) ) end self:addCallBack(cmd_0x810d_RespEx) end function RoomView_ERDouDiZhu:hideAllOutCardOperation() --隐藏玩家出牌操作信息 for _,v in pairs(app.room.roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) --隐藏玩家的出牌 self:setOutCardsVisible(false, viewId) --隐藏玩家的操作 self.PlayerView:setTipsVisible("tips_yaobuqi", false, viewId) end end function RoomView_ERDouDiZhu:cmd_0x810e_Resp(data) function cmd_0x810e_RespEx(onEnd) --当前操作玩家 self.curViewId = app.room:getViewIdByUserId(data.response.nUserId) local delayTime = 0 if data.response.opType == 2 then -- 如果是所有玩家都操作不要,即本家必须出牌 delayTime = 0.4 end self:runAction(cc.Sequence:create( cc.DelayTime:create(delayTime), cc.CallFunc:create(function() --隐藏玩家出牌操作信息 if data.response.opType == 2 then self:hideAllOutCardOperation() else --隐藏玩家的出牌 self:setOutCardsVisible(false, self.curViewId) --隐藏玩家的操作 self.PlayerView:setTipsVisible("tips_yaobuqi", false, self.curViewId) end --显示闹钟 self.PlayerView:setClockVisibel(true, self.curViewId, self.clockTime) --显示操作 if self.curViewId == self:getMeViewId() then self:setOperationVisible(true, data.response.opType) end if onEnd then onEnd() end end) )) end self:addCallBack(cmd_0x810e_RespEx) end function RoomView_ERDouDiZhu:cmd_0x810f_Resp(data) function cmd_0x810f_RespEx(onEnd) local errorMessage = { [1] = "轮次错误", [2] = "牌型错误", [3] = "出牌错误", } --下降所有手牌 self:setAllHandCardDown(self.getMeViewId()) --显示错误信息 showTooltip(errorMessage[data.response.errorType] or "出牌错误") if onEnd then onEnd() end end self:addCallBack(cmd_0x810f_RespEx) end function RoomView_ERDouDiZhu:setLastData(viewId, data) if viewId and data then local cardsEx = {} local cardsValueTable = {} for k,v in ipairs(data.cards) do table.insert(cardsEx, { cardNum = v.card, cardValue = self:getCardValue(v.card), cardType = self:getCardType(v.card) }) table.insert(cardsValueTable, v.card) end local lastDataEx = self:getCardsType(cardsValueTable) if lastDataEx then for k,v in pairs(lastDataEx) do self.lastData[k] = v end end self.lastData.cards = cardsEx self.lastData.viewId = viewId --播放音效 Functions.playVoice("chupai", self.lastData, self.PlayerView:getPlayerData("sex", viewId)) else self.lastData = { min = 0, cards = {}, viewId = 0, cardType = 0, } end end function RoomView_ERDouDiZhu:setOutCardsVisible(bVisible, viewId, data) logE("RoomView_ERDouDiZhu setOutCardsVisible data : ".. table.toString(data)) local outCardsLayout = self.ui.Items["Layout_Out_" .. viewId] if outCardsLayout then outCardsLayout:setVisible(bVisible) if bVisible then outCardsLayout:removeAllChildren() if data.opType == 0 then self.PlayerView:setTipsVisible("tips_yaobuqi", true, viewId) --播放音效 Functions.playVoice("buyao", 0, self.PlayerView:getPlayerData("sex", viewId)) else if not data.maxLen then self:setLastData(viewId, data) end self:initOutCardItem(outCardsLayout, viewId, data) end end end end function RoomView_ERDouDiZhu:initOutCardItem(outCardsLayout, viewId, data) local cardScale = 0.5 local cardsLen = table.nums(data.cards) local isBanker = app.room.roomInfo.nBankerId > 0 and app.room:getViewIdByUserId(app.room.roomInfo.nBankerId) == viewId for k,v in ipairs(data.cards) do -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))) -- 旧资源 local card = cc.Sprite:createWithSpriteFrameName(string.format("ddz_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))) -- 新资源 if card then -- 设置为庄家牌 if self:checkIsBankCard(v.card, viewId) then card.isBankCard = true end local kEx = tonumber(k) card:setScale(cardScale) outCardsLayout:addChild(card) local cardSize = card:getContentSize() if viewId == 1 then --左对齐 if data.maxLen then local floor = math.floor(kEx / data.maxLen) local mod = kEx % data.maxLen + (kEx >= data.maxLen and 1 or 0) --设置zOder card:setLocalZOrder(data.maxLen * floor - kEx) card:setPosition(cc.p((-1) * mod * (cardSize.width - self.handCardDif) * cardScale, (-1) * cardSize.height * cardScale * 0.5 * floor)) else --设置zOder card:setLocalZOrder(cardsLen - kEx) card:setPosition(cc.p((-1) * kEx * (cardSize.width - self.handCardDif) * cardScale, 0)) end elseif viewId == 3 then --右对齐 if data.maxLen then local floor = math.floor(kEx / data.maxLen) local mod = kEx % data.maxLen + (kEx >= data.maxLen and 1 or 0) card:setPosition(cc.p(mod * (cardSize.width - self.handCardDif) * cardScale, (-1) * cardSize.height * cardScale * 0.5 * floor)) else card:setPosition(cc.p(kEx * (cardSize.width - self.handCardDif) * cardScale, 0)) end else --居中 card:setPosition(cc.p((kEx - cardsLen / 2) * (cardSize.width - self.handCardDif) * cardScale, 0)) end --庄家标识 if isBanker then if card.isBankCard then if card.bankerMark then card.bankerMark:setVisible(true) else card.bankerMark = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_bankerCardMark.png")) local offsetX, offsetY = self:getBankTagOffset() card.bankerMark:setPosition(cc.p(cardSize.width * 0.72 + offsetX, cardSize.height * 0.7835 + offsetY)) card:addChild(card.bankerMark) end end end card:stopAllActions() local moveTo = cc.MoveBy:create(Card_Out_Down_Time, cc.p(0, Card_Out_Down_Offset_Y)) card:runAction(moveTo) -- 添加刷新牌的方法 card.refreshCard = function() -- 刷新卡牌 if v.card > 0 then local cardPng = string.format("ddz_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card)) card:setSpriteFrame(cardPng) if card.bankerMark then local size = card:getContentSize() local offsetX, offsetY = self:getBankTagOffset() card.bankerMark:setPosition(cc.p(size.width * 0.72 + offsetX, size.height * 0.7835 + offsetY)) end end end else logE("RoomView_ERDouDiZhu initOutCardItem error".. table.toString(v)) end end --播放动画 if #self.lastData.cards > 0 then local cardsEx = outCardsLayout:getChildren() if #cardsEx > 0 then local effect = nil if self.lastData.cardType == defs.CARD_TYPE.SHUNZI then --顺子 -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_shunzi.plist", "shunzi%d.png", 1, 17, -1) effect = DDZ_New_Effect_Helper:getShunziNew() elseif self.lastData.cardType == defs.CARD_TYPE.SHUANGSHUN then --连对 -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_liandui.plist", "liandui%d.png", 1, 8, -1) effect = DDZ_New_Effect_Helper:getLianduiNew() elseif self.lastData.cardType == defs.CARD_TYPE.SANSHUN then --飞机 -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_feiji.plist", "feiji%d.png", 1, 16, -1) effect = DDZ_New_Effect_Helper:getPlanNew() elseif self.lastData.cardType == defs.CARD_TYPE.AIRPLANE_SINGLE then --飞机 -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_feiji.plist", "feiji%d.png", 1, 16, -1) effect = DDZ_New_Effect_Helper:getPlanNew() elseif self.lastData.cardType == defs.CARD_TYPE.AIRPLANE_DUAD then --飞机 -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_feiji.plist", "feiji%d.png", 1, 16, -1) effect = DDZ_New_Effect_Helper:getPlanNew() elseif self.lastData.cardType == defs.CARD_TYPE.BOMB then --炸弹 -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_zhadan.plist", "zhadan%d.png", 1, 17, -1) effect = DDZ_New_Effect_Helper:getBombNew() elseif self.lastData.cardType == defs.CARD_TYPE.BOMB_KING then --王炸 -- effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_zhadan.plist", "zhadan%d.png", 1, 17, -1) effect = DDZ_New_Effect_Helper:getKingBombNew() end if effect then effect:setScale(0.7) effect:setPosition(cardsEx[toint(#cardsEx / 2)]:getPosition()) outCardsLayout:addChild(effect, 100) if effect.onEnter and type(effect.onEnter)=='function' then effect:onEnter() end end end end end function RoomView_ERDouDiZhu:deleteHandCards(viewId, cards, doAni) local handCards = self.handCards["" .. viewId] if handCards then for k,v in ipairs(cards) do logE("handCards v.card " .. v.card) for k2,v2 in ipairs(handCards) do logE("handCards v2.cardNum " .. v2.cardNum) if v2.cardNum == v.card and not v2.isGrey then v2:removeFromParent() table.remove(handCards, k2) break end end end self:rankHandCards(viewId, doAni) end end -- 根据牌的标准值获取手牌节点 function RoomView_ERDouDiZhu:getCardNodeByCardValue(cardValue) if self.handCards and cardValue then local handCards = self.handCards["" .. self:getMeViewId()] if handCards then for _,cardNode in ipairs(handCards) do if cardValue == cardNode.cardNum then return cardNode end end end end end -- 判断是否是庄家牌 function RoomView_ERDouDiZhu:checkIsBankCard(card, viewId) if not app.room.roomInfo.bankerCards then return false end -- 只要是庄家,庄家的牌都显示为地主 local isBanker = app.room.roomInfo.nBankerId and app.room.roomInfo.nBankerId > 0 and app.room:getViewIdByUserId(app.room.roomInfo.nBankerId) == viewId return isBanker -- 只有3张底牌显示 -- local temp = {} -- for _,v in ipairs(app.room.roomInfo.bankerCards) do -- table.insert(temp, v.card) -- end -- for i, v in ipairs(temp) do -- if card == v then -- return true -- end -- end -- return false end -- 获得庄家标记偏移值 function RoomView_ERDouDiZhu:getBankTagOffset() local getPokerChoose = tonumber(loadUserInfo("ddz_setting_poker")) or defs.Default_Poker_Choose local offsetX = (getPokerChoose == 1) and 0 or 3 local offsetY = (getPokerChoose == 1) and 1 or -1.2 return offsetX, offsetY end function RoomView_ERDouDiZhu:cmd_0x8110_Resp(data) function cmd_0x8110_RespEx(onEnd) --隐藏玩家信息 if data.response.opType == 1 then self:hideAllOutCardOperation() end --操作位置 local opViewId = app.room:getViewIdByUserId(data.response.nUserId) --显示剩余手牌 self.PlayerView:setLeftNumVisible(true, opViewId, data.response.leftNum) --隐藏操作 self:setOperationVisible(false) --隐藏闹钟 self.PlayerView:setClockVisibel(false, opViewId) --显示出牌 self:setOutCardsVisible(true, opViewId, {cards = data.response.cards, opType = data.response.opType}) --删除手牌 if opViewId == self:getMeViewId() then self:deleteHandCards(opViewId, data.response.cards, true) else local nums = table.nums(data.response.cards) local cards = {} for i = 1, nums do table.insert(cards, {card = 0}) end self:deleteHandCards(opViewId, cards, true) end -- 改变中间提示 -- local rangCount = Functions.getRangCount() -- if rangCount > 0 then if app.room.roomInfo.nBankerId == app.room:getMyUserId() then if opViewId ~= self:getMeViewId() then local rang = app.room.roomInfo.memberList[app.room:getMyUserId()].askRangNum local rangTotalCount = app.room.roomInfo.nRang local otherHandCardCount = table.nums(self.handCards['' .. opViewId]) self:isShowMiddleTips(true, rangTotalCount) end end -- end if onEnd then onEnd() end end self:addCallBack(cmd_0x8110_RespEx) end function RoomView_ERDouDiZhu:cmd_0x8111_Resp(data) function cmd_0x8111_RespEx(onEnd) --设置底分 self:setBankerAskLoard() --设置炸弹数 self:setCurZhaDanNum() -- 设置倍数 self:setCurMultiple() -- 设置让牌数 self:setCurRang() -- 显示中间庄家让x 所有人 if app.room.roomInfo.nStatus then if app.room.roomInfo.nStatus >= defs.GAME_STATUS.ASK_LOARD and app.room.roomInfo.nStatus <= defs.GAME_STATUS.ASK_RANG then self:isShowMiddleTipsForAll(true, app.room.roomInfo.nRang or 0) end end if onEnd then onEnd() end end self:addCallBack(cmd_0x8111_RespEx) end function RoomView_ERDouDiZhu:cmd_0x8112_Resp(data) function cmd_0x8112_RespEx(onEnd) --显示春天动画 -- 去除春天动画 -- if data.response.nSpring == 1 then -- local effect = createAnimationByPlist("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_spring.plist", "spring%d.png", 1, 22, -1) -- if effect then -- playVoice("pk_erdoudizhu/res/sound/doudizhu_common_spring.ogg") -- effect:setPosition(cc.p(640, 360)) -- self:addChild(effect) -- end -- end self:runAction( cc.Sequence:create( -- cc.DelayTime:create(1.0), cc.DelayTime:create(0.5), cc.CallFunc:create(function() --隐藏界面 local winViewId = app.room:getViewIdByUserId(data.response.nWinId) for _,v in pairs(app.room.roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) if viewId ~= winViewId then --出牌界面 self:setOutCardsVisible(false, viewId) end --闹钟界面 self.PlayerView:setClockVisibel(false, viewId) end --显示小局结算 self:setXiaoJuVisible(true, data.response) if onEnd then onEnd() end end) ) ) end self:addCallBack(cmd_0x8112_RespEx) end function RoomView_ERDouDiZhu:showDaJu(data) if not self.daJuView then self.daJuView = import("pk_erdoudizhu.luaScript.Views.Room.RoomDaJuView_ERDouDiZhu"):new(data) -- self.ui.Items.Layout_DaJu:addChild(self.daJuView) self.daJuView:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(self.daJuView); end --更新界面 self.daJuView:updateView(data) self:showGameOverAward() end function RoomView_ERDouDiZhu:cmd_0x8113_Resp(data) function cmd_0x8113_RespEx(onEnd) if self.tuoguanView then self:showTuoGuan(false) end local isShow_XiaoJu = (self.XiaoJuView and self.XiaoJuView:isVisible()) or false -- 如果之前没显示过小结算,或者是解散导致的结束,直接显示大结算 if not isShow_XiaoJu or app.room.roomInfo._stopFlag == 9 then --隐藏小局结算 self:setXiaoJuVisible(false) --显示总结算 self:showDaJu(data.response) end --关闭结算界面 app.room:dispatchEvent({ name = GAME_EVENT.DISSMISS_CLOSE }) if onEnd then onEnd() end end self:addCallBack(cmd_0x8113_RespEx) end function RoomView_ERDouDiZhu:cmd_0x8114_Resp(data) function cmd_0x8114_RespEx(onEnd) --重置桌面 self:defaultState() if onEnd then onEnd() end end self:addCallBack(cmd_0x8114_RespEx) end --- -- 初始化大结算再来一局 -- @return -- function RoomView_ERDouDiZhu:initPlayGameAgain() local strGameInfo = app.room.roomInfo.strGameInfo local isInClub = app.club_php.clubID and app.club_php.clubID ~= 0 if not isInClub then logD("RoomView_ERDouDiZhu.initPlayGameAgain", "当前玩家不在亲友圈内,不能再来一局"); return end local clubGameInfo = json.decode(strGameInfo) or {} if not clubGameInfo.ruleid then logD("RoomView_ERDouDiZhu.initPlayGameAgain", "游戏包间id不存在,不能再来一局"); return end dd.IPlayGameAgain.setAgainGameBaoJianId(clubGameInfo.ruleid) end -- 托管通知 function RoomView_ERDouDiZhu:onHostingResponse( data ) local function onHostingResponseEx(onEnd) local response = data.response -- 如果是我,则显示托管layout界面 if response.nUserId == app.room:getMyUserId() then if response.status == 1 then --托管状态 self:showTuoGuan(true) elseif response.status == 0 then--取消托管状态 self:showTuoGuan(false) end end local isTuoGuan = response.status == 1 local viewId = app.room:getViewIdByUserId(response.nUserId) self.PlayerView:showTuoGuanByViewId(viewId, isTuoGuan) if onEnd then onEnd() end end self:addCallBack(onHostingResponseEx) end --显示隐藏托管 function RoomView_ERDouDiZhu:showTuoGuan(isShow) if not self.tuoguanView then self.tuoguanView = TuoGuanView:new() self:addChild(self.tuoguanView) self.tuoguanView:setVisible(false) end self.tuoguanView:setVisible(isShow) end function RoomView_ERDouDiZhu:refreshPlayerAIStatus() for _,v in pairs(app.room.roomInfo.memberList) do local isTuoGuan = v.AIStatus == 1 print('RoomView_ERDouDiZhu:refreshPlayerAIStatus', v.nUserId, isTuoGuan) self.PlayerView:showTuoGuanByViewId(app.room:getViewIdByUserId(v.nUserId), isTuoGuan) end end --游戏消息 function RoomView_ERDouDiZhu:bindGameMessage() self:bindEvent(app.room, "cmd_0x8104_Resp", handler(self, self.cmd_0x8104_Resp)) self:bindEvent(app.room, "cmd_0x8105_Resp", handler(self, self.cmd_0x8105_Resp)) self:bindEvent(app.room, "cmd_0x8106_Resp", handler(self, self.cmd_0x8106_Resp)) self:bindEvent(app.room, "cmd_0x8108_Resp", handler(self, self.cmd_0x8108_Resp)) self:bindEvent(app.room, "cmd_0x8109_Resp", handler(self, self.cmd_0x8109_Resp)) self:bindEvent(app.room, "cmd_0x810a_Resp", handler(self, self.cmd_0x810a_Resp)) self:bindEvent(app.room, "cmd_0x810c_Resp", handler(self, self.cmd_0x810c_Resp)) self:bindEvent(app.room, "cmd_0x810d_Resp", handler(self, self.cmd_0x810d_Resp)) self:bindEvent(app.room, "cmd_0x810e_Resp", handler(self, self.cmd_0x810e_Resp)) self:bindEvent(app.room, "cmd_0x810f_Resp", handler(self, self.cmd_0x810f_Resp)) self:bindEvent(app.room, "cmd_0x8110_Resp", handler(self, self.cmd_0x8110_Resp)) self:bindEvent(app.room, "cmd_0x8111_Resp", handler(self, self.cmd_0x8111_Resp)) self:bindEvent(app.room, "cmd_0x8112_Resp", handler(self, self.cmd_0x8112_Resp)) self:bindEvent(app.room, "cmd_0x8113_Resp", handler(self, self.cmd_0x8113_Resp)) self:bindEvent(app.room, "cmd_0x8114_Resp", handler(self, self.cmd_0x8114_Resp)) self:bindEvent(app.room, 'cmd_0x8123_Resp', handler(self, self.cmd_0x8123_Resp)) -- 通知抢地主 self:bindEvent(app.room, 'cmd_0x8124_Resp', handler(self, self.cmd_0x8124_Resp)) -- 抢地主结果 self:bindEvent(app.room, 'cmd_0x8121_Resp', handler(self, self.cmd_0x8121_Resp)) -- 通知让牌 self:bindEvent(app.room, 'cmd_0x8122_Resp', handler(self, self.cmd_0x8122_Resp)) -- 让牌结果 end --- -- 显示抽奖界面 -- function RoomView_ERDouDiZhu:showGameOverAward() if not (dd and dd.IGameOverAward) then return end self:runDelay(0.1, function ( ) -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息 dd.IGameOverAward.showAwardView(); end) end -- 通知抢地主 function RoomView_ERDouDiZhu:cmd_0x8123_Resp(data) function cmd_0x8123_RespEx(onEnd) --当前操作玩家 self.curViewId = app.room:getViewIdByUserId(data.response.nUserId) --显示闹钟 self.PlayerView:setClockVisibel(true, self.curViewId, data.response.leftTime) -- 隐藏之前的提示内容 self.PlayerView:setTipsVisibleExcept({}, self.curViewId) --显示抢地主 if self.curViewId == self:getMeViewId() then self:setQiangVisible(true) end if onEnd then onEnd() end end self:addCallBack(cmd_0x8123_RespEx) end -- 抢地主结果 function RoomView_ERDouDiZhu:cmd_0x8124_Resp(data) function cmd_0x8124_RespEx(onEnd) local viewId = app.room:getViewIdByUserId(data.response.nUserId) --隐藏抢地主界面 self:setQiangVisible(false) --隐藏闹钟 self.PlayerView:setClockVisibel(false, viewId) -- 隐藏之前的叫地主 self.PlayerView:setTipsVisibleExcept({}, viewId) --显示叫分 self.PlayerView:setTipsVisible("tips_qiangdizhu", true, viewId, {opType = data.response.opType}) --播放音效 Functions.playVoice("qiangdizhu", data.response.opType, self.PlayerView:getPlayerData("sex", viewId)) if onEnd then onEnd() end end self:addCallBack(cmd_0x8124_RespEx) end -- 通知让牌 function RoomView_ERDouDiZhu:cmd_0x8121_Resp(data) function cmd_0x8121_RespEx(onEnd) --当前操作玩家 self.curViewId = app.room:getViewIdByUserId(data.response.nUserId) --显示闹钟 self.PlayerView:setClockVisibel(true, self.curViewId, data.response.leftTime) --显示让牌 if self.curViewId == self:getMeViewId() then self:setRangVisible(true, data.response.nRangPai) end if onEnd then onEnd() end end self:addCallBack(cmd_0x8121_RespEx) end -- 让牌结果 function RoomView_ERDouDiZhu:cmd_0x8122_Resp(data) function cmd_0x8122_RespEx(onEnd) local viewId = app.room:getViewIdByUserId(data.response.nUserId) --隐藏抢地主界面 self:setRangVisible(false) --隐藏闹钟 self.PlayerView:setClockVisibel(false, viewId) -- todo 显示和音效 --显示叫分 -- self.PlayerView:setTipsVisible("tips_jiaofen", true, viewId, {askLoard = data.response.askLoard}) --播放音效 -- Functions.playVoice("jiaofen", data.response.askLoard, self.PlayerView:getPlayerData("sex", viewId)) if onEnd then onEnd() end end self:addCallBack(cmd_0x8122_RespEx) end -- 中间提示内容(地主让x,对家出x,只有庄家可看) function RoomView_ERDouDiZhu:isShowMiddleTips(isVisible, tip1, tip2) self.ui.Items.Layout_Middle_Tips:setVisible(isVisible) if not isVisible then return end self.ui.Items.Layout_Middle_Tips_1:setVisible(false) -- 与另一个中间提示内容互斥 -- 增加对家显示不小于0 -- tip2 = (tonumber(tip2) > 0 and tip2 or 0) self.ui.Items.Text_Tips_Rang_1:setText(tip1) -- 计算对家牌 local otherHandCardCount = 0 for _, v in pairs(app.room.roomInfo.memberList) do if v.nUserId ~= app.room:getMyUserId() then local viewId = app.room:getViewIdByUserId(v.nUserId) local otherHandCards = self.handCards["" .. viewId] if otherHandCards and next(otherHandCards) then otherHandCardCount = table.nums(otherHandCards) end end end local txtRang2 = otherHandCardCount - tonumber(tip1) txtRang2 = (txtRang2 > 0) and txtRang2 or 0 self.ui.Items.Text_Tips_Rang_2:setText(txtRang2) end -- 中间提示内容(地主让x,两人都可看) function RoomView_ERDouDiZhu:isShowMiddleTipsForAll(isVisible, tip) self.ui.Items.Layout_Middle_Tips_1:setVisible(isVisible) if not isVisible then return end -- 叫分没有抢,所以不需要显示 if Functions.getGameMode() == 2 then self.ui.Items.Layout_Middle_Tips_1:setVisible(false) return end self.ui.Items.Layout_Middle_Tips:setVisible(false) -- 与另一个中间提示内容互斥 tip = tip or 0 self.ui.Items.Text_Tips_DiZhuRang_1:setText(tip) end return RoomView_ERDouDiZhu