local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef") local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions") local ZPSound = ZPFramework.ZPImport("zp_base.luaScript.ZPSound") local ZPMessage = ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage") local ZPRoomOperationView = ZPFramework.ZPFrameworkClassImprot("zp_base.luaScript.Views.Room.ZPRoomOperationView") local xichongRoomOperationView = class("xichongRoomOperationView", ZPRoomOperationView) local tempCardVlue ={ [17] = 20, --11 [18] = 30, --12 [49] = 40, --31 [34] = 41, --22 [20] = 50, --14 [50] = 51, --32 [21] = 60, --15 [36] = 61, --24 [51] = 62, --33 [22] = 70, --16 [52] = 71, --34 [82] = 72, --52 [68] = 80, --44 [38] = 81, --26 [53] = 82, --35 [84] = 90, --54 [54] = 91, --36 [70] = 100, --46 [85] = 101, --55 [86] = 110, --56 [102] = 120, --66 } function xichongRoomOperationView:ctor() xichongRoomOperationView.super.ctor(self); self.chiList = {} self.baoTypeList = {} self.anThreeZ = nil self.anThourZ = nil self.baoType = 0 self.opCard = 0 self.selectBaType = 0 end function xichongRoomOperationView:onEnter() xichongRoomOperationView.super.onEnter(self) --self:bindEvent(app.room,"onHideOpreationView",handler(self,self.onHideOpreationView)) local ui = loadUI("zp_xichong/res/ui/ui_fangjian/xichong_ui_operation.ui"); self.ui = ui; self:addChild(ui); self.ui.Items.ImageView_BaoType:setVisible(false) self.ui.Items.Layout_BaoJiao:registerClick(handler(self,self.onClickBaoBg)) --ui排序:吃碰胡过 self.ui.Items.Button_1:registerClick(nil,function () local function chi() local operateCode = ZPDef.OpCode.OP_CHI if table.nums(self.chiList) >= 1 then self:showChiOpList() end end local isHu = self:getIsHaveHuOp() if isHu == true then local content = string.format("确定放弃胡牌吗?") local okCallBack = function () chi() end local cancelCallBack = function () end showConfirmDialog(content,okCallBack,cancelCallBack) else chi() end end) self.ui.Items.Button_2:registerClick(function () local function peng() local operateCode = ZPDef.OpCode.OP_PENG self:sendOperationCode(operateCode,self.opCard) --直接隐藏界面 self:setOperatorPanelView(false) end local isHu = self:getIsHaveHuOp() if isHu == true then local content = string.format("确定放弃胡牌吗?") local okCallBack = function () peng() end local cancelCallBack = function () end showConfirmDialog(content,okCallBack,cancelCallBack) else peng() end end) --self:hidePengBtn() self.ui.Items.Button_3:registerClick(function () if app.room:isLittleFamily() then return end local isHu = self:getIsHaveHuOp() if isHu == true then local content = string.format("确定放弃胡牌吗?") local okCallBack = function () self:onClickGuo() end local cancelCallBack = function () end showConfirmDialog(content,okCallBack,cancelCallBack) else self:onClickGuo() end end) --暗 self.ui.Items.Button_5:registerClick(function () local function An() if self.anThreeZ and self.anThourZ then self:showAnOpList() else local operateCode = 0 if self.anThreeZ then operateCode = self.anThreeZ end if self.anThourZ then operateCode = self.anThourZ end self:sendOperationCode(operateCode,self.opCard) --直接隐藏界面 self:setOperatorPanelView(false) end end local isHu = self:getIsHaveHuOp() if isHu == true then local content = string.format("确定放弃胡牌吗?") local okCallBack = function () An() end local cancelCallBack = function () end showConfirmDialog(content,okCallBack,cancelCallBack) else An() end end) --跨 self.ui.Items.Button_9:registerClick(function () local function Kua() local operateCode = ZPDef.OpCode.OP_KUA self:sendOperationCode(operateCode,self.opCard) --直接隐藏界面 self:setOperatorPanelView(false) end local isHu = self:getIsHaveHuOp() if isHu == true then local content = string.format("确定放弃胡牌吗?") local okCallBack = function () Kua() end local cancelCallBack = function () end showConfirmDialog(content,okCallBack,cancelCallBack) else Kua() end end) self.ui.Items.Button_4:registerClick(function () local operateCode = 0 --判断是否有胡 local retHu = bit32.band(self.operationLocalCode,ZPDef.OpCode.OP_HU) if retHu > 0 then operateCode = ZPDef.OpCode.OP_HU end local retHu1 = bit32.band(self.operationLocalCode,ZPDef.OpCode.OP_TIAN_HU) if retHu1 > 0 then operateCode = ZPDef.OpCode.OP_TIAN_HU end self:sendOperationCode(operateCode,self.opCard) self:setOperatorPanelView(false) end) --不爆牌 self.ui.Items.Button_8:registerClick(function () if app.room:isLittleFamily() then return end local request = ZPMessage.GameBaoSendOperateCode:new() request.operateCode = 0 logE("xichongRoomOperationView:baopai"..table.tostring(request)) self.ui:sendMsg(app.room, "sendBaoOperate", request, function(status, response) logE("xichongRoomOperationView baopai response = ", table.tostring(response)) end) self:showBaoPaiOpView(false) end) --爆牌 self.ui.Items.Button_7:registerClick(function () if app.room:isLittleFamily() then return end local num = self:getBaoTypeNum(self.baoType) if num > 1 then self:showBaoPaiOpList() else local request = ZPMessage.GameBaoSendOperateCode:new() request.operateCode = self.baoType logE("xichongRoomOperationView:baopai"..table.tostring(request)) self.ui:sendMsg(app.room, "sendBaoOperate", request, function(status, response) logE("xichongRoomOperationView baopai response = ", table.tostring(response)) end) self:showBaoPaiOpView(false) end end) self:initUI() self:hideSelf() end function xichongRoomOperationView:onClickBaoBg() end function xichongRoomOperationView:initUI() ---注册点击事件 for i = 1, 3 do if i == 3 then i = i+1 end local paixing = string.format("Layout_paixing_%d",i) local selectImage = string.format("ImageView_select_%d",i) local selectImageNode = self.ui.Items[selectImage] selectImageNode:setVisible(true) self.ui.Items[paixing]:registerClick(function() local selectImage = string.format("ImageView_select_%d",i) local selectImageNode = self.ui.Items[selectImage] local selectImage1 = string.format("ImageView_BaoType_sel_%d",i) local selectImageNode1 = self.ui.Items[selectImage1] selectImageNode:setVisible(not selectImageNode:isVisible()) selectImageNode1:setVisible(not selectImageNode1:isVisible()) self.selectBaType = 0 if self.ui.Items.ImageView_select_1:isVisible() then self.selectBaType = getNumOr(self.selectBaType,ZPDef.BaoOpCode.BAO_ZHAO_CHI) end if self.ui.Items.ImageView_select_2:isVisible() then self.selectBaType = getNumOr(self.selectBaType,ZPDef.BaoOpCode.BAO_TUI) end if self.ui.Items.ImageView_select_4:isVisible() then self.selectBaType = getNumOr(self.selectBaType,ZPDef.BaoOpCode.BAO_HOU_DUI) end if self.selectBaType == 0 then self.ui.Items.Button_QD:setEnabled(false) else self.ui.Items.Button_QD:setEnabled(true) end end) end self.ui.Items.Button_QD:registerClick(function() local request = ZPMessage.GameBaoSendOperateCode:new() request.operateCode = self.selectBaType logE("xichongRoomOperationView:baopai"..table.tostring(request)) self.ui:sendMsg(app.room, "sendBaoOperate", request, function(status, response) logE("xichongRoomOperationView baopai response = ", table.tostring(response)) end) self:showBaoPaiOpView(false) end) end function xichongRoomOperationView:showChiOpList() local laySize = self.ui.Items.Layout_1:getContentSize() local worldPos = self.ui.Items.Layout_1:getWorldPosition() local nodePos = worldPos self.ui.Items.Layout_EatPanle:setPositionX(nodePos.x + laySize.width/2) self.ui.Items.ImageView_jiantou:setPositionX(nodePos.x + laySize.width/2) if self.ui.Items.Layout_Eat:isVisible() then self.ui.Items.Layout_Eat:setVisible(false) return else self.ui.Items.Layout_Eat:setVisible(true) end self.ui.Items.Layout_EatPanle:removeAllChildren() local list = self.chiList --按点数从小到大排序 table.sort(list,function(a,b) local numA = tempCardVlue[tonumber(a)] local numB = tempCardVlue[tonumber(b)] if (numA ~= nil) and (numB ~= nil) then return numA < numB end return false end) for k,v in ipairs(list) do local tempList = {} table.insert(tempList,v) table.insert(tempList,self.opCard) local eatCardUI = loadUI("zp_xichong/res/ui/ui_fangjian/xichong_ui_chiGroup.ui") self.ui.Items.Layout_EatPanle:addChild(eatCardUI) for i = 1, 2 do local cardShow = tempList[i] local fileName = ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE) local eatCardName = string.format("ImageView_Card_%d",i) logE("创建吃牌单个:.."..fileName) eatCardUI.Items[eatCardName]:loadTextureFromPlist(fileName) --eatCardUI.Items[eatCardName]:setTouchEnabled(true) if eatCardUI.Items[eatCardName]:isTouchEnabled() then logE("吃牌设置触摸成功") end end eatCardUI.Items.Layout_Group:registerClick(function() local card = v self:sendOperationCode(ZPDef.OpCode.OP_CHI,card) --直接隐藏界面 self:setOperatorPanelView(false) end) end --self.ui.Items.Layout_EatPanle:requestDoLayout() --self.ui.Items.Layout_EatPanle:doLayout(); end function xichongRoomOperationView:showAnOpList() local laySize = self.ui.Items.Layout_5:getContentSize() local worldPos = self.ui.Items.Layout_5:getWorldPosition() local nodePos = worldPos self.ui.Items.Layout_AnPanle:setPositionX(nodePos.x + laySize.width/2) self.ui.Items.ImageView_jiantou_2:setPositionX(nodePos.x + laySize.width/2) if self.ui.Items.Layout_An:isVisible() then self.ui.Items.Layout_An:setVisible(false) return else self.ui.Items.Layout_An:setVisible(true) end self.ui.Items.Layout_AnPanle:removeAllChildren() local eatCardUI = loadUI("zp_xichong/res/ui/ui_fangjian/xichong_ui_anGroup.ui") self.ui.Items.Layout_AnPanle:addChild(eatCardUI) for i = 1, 4 do local eatCardName = string.format("ImageView_Card_%d",i) eatCardUI.Items[eatCardName]:setVisible(false) end for i = 1, 3 do local cardShow = self.opCard local fileName = ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE) local eatCardName = string.format("ImageView_Card_%d",i) logE("创建吃牌单个:.."..fileName) eatCardUI.Items[eatCardName]:setVisible(true) eatCardUI.Items[eatCardName]:loadTextureFromPlist(fileName) if eatCardUI.Items[eatCardName]:isTouchEnabled() then logE("吃牌设置触摸成功") end end eatCardUI.Items.Layout_Group:registerClick(function() local card = self.opCard self:sendOperationCode(self.anThreeZ,card) --直接隐藏界面 self:setOperatorPanelView(false) end) local eatCardUI1 = loadUI("zp_xichong/res/ui/ui_fangjian/xichong_ui_anGroup.ui") self.ui.Items.Layout_AnPanle:addChild(eatCardUI1) for i = 1, 4 do local eatCardName = string.format("ImageView_Card_%d",i) eatCardUI1.Items[eatCardName]:setVisible(false) end for i = 1, 4 do local cardShow = self.opCard local fileName = ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE) local eatCardName = string.format("ImageView_Card_%d",i) logE("创建吃牌单个:.."..fileName) eatCardUI1.Items[eatCardName]:setVisible(true) eatCardUI1.Items[eatCardName]:loadTextureFromPlist(fileName) if eatCardUI1.Items[eatCardName]:isTouchEnabled() then logE("吃牌设置触摸成功") end end eatCardUI1.Items.Layout_Group:registerClick(function() local card = self.opCard self:sendOperationCode(self.anThourZ,card) --直接隐藏界面 self:setOperatorPanelView(false) end) self.ui.Items.Layout_AnPanle:requestDoLayout() self.ui.Items.Layout_AnPanle:doLayout(); end function xichongRoomOperationView:showBaoPaiOpList() local laySize = self.ui.Items.Layout_7:getContentSize() local worldPos = self.ui.Items.Layout_7:getWorldPosition() local nodePos = worldPos self.ui.Items.Layout_BaoJiao:setPositionX(nodePos.x + laySize.width/2) if self.ui.Items.Layout_BaoJiao:isVisible() then self.ui.Items.Layout_BaoJiao:setVisible(false) return else self.ui.Items.Layout_BaoJiao:setVisible(true) end local num = self:getBaoTypeNum(self.baoType) for i = 1, 3 do if i == 3 then i = i+1 end local paixing = string.format("Layout_paixing_%d",i) self.ui.Items[paixing]:setVisible(false) local selectType = string.format("ImageView_select_%d",i) self.ui.Items[selectType]:setVisible(false) end for k,v in pairs(self.baoTypeList) do local paixing = string.format("Layout_paixing_%d",v) self.ui.Items[paixing]:setVisible(true) local selectType = string.format("ImageView_select_%d",v) self.ui.Items[selectType]:setVisible(true) local selectImage = string.format("ImageView_BaoType_sel_%d",v) self.ui.Items[selectImage]:setVisible(true) end self.ui.Items.Layout_leixing:requestDoLayout() self.ui.Items.Layout_leixing:doLayout(); end function xichongRoomOperationView:getBaoTypeNum(baoType) local num = 0 self.baoTypeList = {} local ret1 = bit32.band(baoType,ZPDef.BaoOpCode.BAO_ZHAO_CHI) if ret1 > 0 then num = num + 1 table.insert(self.baoTypeList,ZPDef.BaoOpCode.BAO_ZHAO_CHI) end local ret2 = bit32.band(baoType,ZPDef.BaoOpCode.BAO_TUI) if ret2 > 0 then num = num + 1 table.insert(self.baoTypeList,ZPDef.BaoOpCode.BAO_TUI) end local ret3 = bit32.band(baoType,ZPDef.BaoOpCode.BAO_HOU_DUI) if ret3 > 0 then num = num + 1 table.insert(self.baoTypeList,ZPDef.BaoOpCode.BAO_HOU_DUI) end return num end --获取是否有胡操作 function xichongRoomOperationView:getIsHaveHuOp() if not self.operationLocalCode then return false end local beginList = {} beginList = ZPFuc.getZPOperationType(self.operationLocalCode,true) local isHu = false for k,opType in pairs(beginList) do if opType == ZPDef.OpType.OP_TYPE_HU then isHu = true break end end return isHu end --泸州大贰自动碰,所以隐藏碰按钮 function xichongRoomOperationView:hidePengBtn() end function xichongRoomOperationView:showOpeation(mainOpCode,card,chilist,hasGuo) if app.room:isLittleFamily() then return end --操作码 self.operationLocalCode = mainOpCode --可以操作的牌 self.opCard = card --吃牌列表 self.chiList = chilist logE("RoomView:showOpeation(mainOpCode) 1:"..mainOpCode) --获取偷巴操作 self.anThreeZ = self:getTouOperate(self.operationLocalCode) self.anThourZ = self:getBaOperate(self.operationLocalCode) --操作类型 local beginList = {} beginList = ZPFuc.getZPOperationType(mainOpCode,hasGuo)--,self.playerZhao[1] > 0 logE("RoomView:showOpeation isCheckMustOperation before (beginList)1 :"..table.tostring(beginList)) --胡牌优先规则 local isHu = false for k,opType in pairs(beginList) do if opType == ZPDef.OpType.OP_TYPE_HU then isHu = true break end end --如果没有胡,扫,提,跑,等自动操作,则显示吃碰过操作 self:setOperatorPanelView(true,beginList) end --暗三张 function xichongRoomOperationView:getTouOperate(op) local opreate = nil local ret2 = bit32.band(op,ZPDef.OpCode.OP_TOU_ZHUA) if ret2 > 0 then return ZPDef.OpCode.OP_TOU_ZHUA end return opreate end --暗四张 function xichongRoomOperationView:getBaOperate(op) local opreate = nil local ret2 = bit32.band(op,ZPDef.OpCode.OP_BA_ZHUA) if ret2 > 0 then return ZPDef.OpCode.OP_BA_ZHUA end return opreate end --隐藏行为操作层 function xichongRoomOperationView:setOperatorPanelView(bVisible,operations) self:setVisible(bVisible) self.ui.Items.Layout_operatorPanel:setVisible(bVisible) self.ui.Items.Layout_An:setVisible(false) self.ui.Items.Layout_BaoJiao:setVisible(false) self.ui.Items.Layout_Eat:setVisible(false) --置灰所有 ui排序:吃碰过 for i = 1 ,9 do local name = string.format("Button_%d",i) local layout = string.format("Layout_%d",i) if self.ui.Items[name] then self.ui.Items[layout]:setVisible(false) self.ui.Items[name]:setVisible(false) end end local index = 1 --local guoPosx = self.ui.Items.Layout_3:getPositionX() --显示操作序列 if operations then for k,v in pairs(operations) do local name = string.format("Button_%d",v) local layout = string.format("Layout_%d",v) --偷和巴做特殊判断 if v == 12 or v== 13 then name = string.format("Button_%d",5) layout = string.format("Layout_%d",5) end if v == 14 then name = string.format("Button_%d",9) layout = string.format("Layout_%d",9) end if self.ui.Items[name] and not self.ui.Items[name]:isVisible() then self.ui.Items[layout]:setVisible(true) self.ui.Items[name]:setEnabled(true) self.ui.Items[name]:setVisible(true) end end self.ui.Items.Layout_Operate:requestDoLayout() self.ui.Items.Layout_Operate:doLayout() end end --显示爆牌操作 function xichongRoomOperationView:showBaoPaiOpView(isshow,baoType) if app.room:isLittleFamily() then return end self:setVisible(isshow) self.selectBaType = baoType self.baoType = baoType if true == isshow then local num = self:getBaoTypeNum(baoType) logD("xichongRoomOperationView showBaoPaiOpView",baoType) if num == 1 then if baoType == ZPDef.BaoOpCode.BAO_TUI then self.ui.Items.ImageView_BaoType:loadTexture(ZPDef.PaiXingFile.BAOTUI) elseif baoType == ZPDef.BaoOpCode.BAO_ZHAO_CHI then self.ui.Items.ImageView_BaoType:loadTexture(ZPDef.PaiXingFile.ZHAOCHI) elseif baoType == ZPDef.BaoOpCode.BAO_HOU_DUI then self.ui.Items.ImageView_BaoType:loadTexture(ZPDef.PaiXingFile.HOUDUI) end self.ui.Items.ImageView_BaoType:setVisible(true) else self.ui.Items.ImageView_BaoType:setVisible(false) end local operations = {} table.insert(operations,8) table.insert(operations,7) self:setOperatorPanelView(isshow,operations) else self:setOperatorPanelView(false) self.ui.Items.ImageView_BaoType:setVisible(false) end end --隐藏自身 function xichongRoomOperationView:hideSelf() self.ui.Items.Layout_operatorPanel:setVisible(false) end function xichongRoomOperationView:sendOperationCode(operationCode,opCard) if app.room:isLittleFamily() then return end local opCard = opCard or 0 local request = ZPMessage.GameSendOpCodeResponse:new() --发送操作码 request.operateCode = operationCode request.opCard= tonumber(opCard) logE("sendOperationCode:"..table.tostring(request)) self.ui:sendMsg(app.room, "sendOperationCode", request, function(status, response) logE("RoomView sendOperationCode() response = ", table.tostring(response)) end) app:dispatchEvent({name = "onClickOpBtn"}); end function xichongRoomOperationView:onClickGuo() --算法保留,现在是强制胡牌,如果是非强制胡牌的规则,这里就起作用了 --操作类型 local beginList = {} beginList = ZPFuc.getZPOperationType(self.operationLocalCode,true)--,self.playerZhao[1] > 0 local isHu = false for k,opType in pairs(beginList) do if opType == ZPDef.OpType.OP_TYPE_HU then isHu = true break end end local operateCode = 0 operateCode = ZPDef.OpCode.OP_CANCEL local card = self.outCard or 0 self:sendOperationCode(operateCode,card) --直接隐藏界面 self:setOperatorPanelView(false) --如果有吃的界面则隐藏 --self:setEatCardView(false) local nUserID = app.room:getUserIdByViewId(1) --playVoiceOperation(ZPDef.OpType.OP_TYPE_CANCEL,nUserID) end --隐藏吃牌界面 function xichongRoomOperationView:setEatCardView(bVisible) end --隐藏比牌界面 function xichongRoomOperationView:setEatCardBiView(bVisible) end --隐藏比牌界面 function xichongRoomOperationView:setEatCardSanBiView(bVisible) end function xichongRoomOperationView:setAllEatView(bVisible) end --吃牌点击 function xichongRoomOperationView:touchEatOneCardCallBack() end --点击吃牌组合牌一回调 function xichongRoomOperationView:touchEatTwoCardCallBack(operateCode,weaveCardList) end --点击吃牌组合牌一回调 function xichongRoomOperationView:touchEatSanCardCallBack(operateCode1,weaveCardList1,operateCode2,weaveCardList2) end --判断能否吃牌 --[[ operateCode:吃牌操作码 list : 吃牌组合,key为操作码,value为三张牌组合 index :list的有效大小 ]] function xichongRoomOperationView:getEatLeaveWeave(handCardValueLocalTemp) end --判断能否吃牌 --[[ weaveCard:要吃的那组牌 handCardValueLocalTemp:剩下的手牌(已经假定删掉吃过的牌) ]] function xichongRoomOperationView:eatCardLogic(weaveCard,handCardValueLocalTemp) end --多维数组转 一维数组 function xichongRoomOperationView:ChangeDataToVector(data) local tt = {} for i = 1, self.lieShuMax do for j = 1, self.hangShuMax do if data[i][j] then table.insert(tt,data[i][j]) end end end return tt end --[[ 吃牌优化:优先显示油数的组合 ]] function xichongRoomOperationView:RankChiPai(weaveCardList,listCode) end --游戏场景传一些参数过来 出的牌,手牌数据 function xichongRoomOperationView:setSameParame(outCard,handCardList) self.outCard = outCard self.handCardValueLocal = handCardList end return xichongRoomOperationView;