|
- 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 ErWuRoomOperationView = class("ErWuRoomOperationView", cc.UIView)
-
- function ErWuRoomOperationView:ctor()
- ErWuRoomOperationView.super.ctor(self);
-
- self.baOperate = nil
- self.touOperate = nil
-
- self.operationCardlist = {}
-
- self.isQiShou = false
-
- self.tishi = false
-
- self.colorType = ZPDef.ColorType.White
-
- self.outCard = 0 --点过的时候发过去的牌值
- end
-
- function ErWuRoomOperationView:onEnter()
- ErWuRoomOperationView.super.onEnter(self)
-
- self:bindEvent(app.room,"onHideOpreationView",handler(self,self.onHideOpreationView))
- local ui = loadUI("zp_erwu/res/ui/ui_fangjian/erwu_ui_operation.ui");
- self.ui = ui;
- self:addChild(ui);
-
-
- self.ui.Items.Button_Close:registerClick(function()
- self.ui.Items.Layout_operatorPanel:setVisible(true)
- self.ui.Items.Layout_Group:setVisible(false)
- end)
-
- --1吃 2碰 3过 4胡 5巴 6偷
- --吃牌只能拿自己手里的一张牌跟别人打出的牌或者摸到牌做组合
- --ui排序:吃碰胡过
- self.ui.Items.Button_1:registerClick(nil,function ()
- local function chi()
- local code = ZPDef.OpCode.OP_CHI
- if self:IsshowOpView(code) then
- self:showOperateView(code)
- else
- local card = self.operationCardlist[code][1].cards
- self:sendOperationCode(code,card)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- 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
- if self:IsshowOpView(operateCode) then
- self:showOperateView(operateCode)
- else
- local cards = self.operationCardlist[operateCode][1].cards
- for k, v in ipairs(cards) do
- if v == 0x52 then
- operateCode = ZPDef.OpCode.OP_PENG_LAIZI
- break
- end
- end
- self:sendOperationCode(operateCode,cards)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- end
- 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_4:registerClick(function ()
- local operateCode = 0
- operateCode = ZPDef.OpCode.OP_HU
- local card = 0
- if not self.isQiShou then
- card = self.operationCardlist[ZPDef.OpCode.OP_HU][1].cards
- end
- self:sendOperationCode(operateCode,card)
- self:setOperatorPanelView(false)
- end)
-
- --巴牌
- self.ui.Items.Button_5:registerClick(function ()
- local function ba()
- if self:IsshowOpView(self.baOperate) then
- self:showOperateView(self.baOperate)
- else
- local operateCode = 0
- operateCode = self.baOperate
- local data = self.operationCardlist[self.baOperate][1]
- self:sendOperationCode(operateCode, data.cards)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- end
- end
- local isHu = self:getIsHaveHuOp()
- if isHu == true then
- local content = string.format("确定放弃胡牌吗?")
- local okCallBack = function ()
- ba()
- end
- local cancelCallBack = function ()
-
- end
- showConfirmDialog(content,okCallBack,cancelCallBack)
- else
- ba()
- end
- end)
-
- --偷牌
- self.ui.Items.Button_6:registerClick(function ()
- local function tou()
- if self:IsshowOpView(self.touOperate) then
- self:showOperateView(self.touOperate)
- else
- local operateCode = 0
- operateCode = self.touOperate
- local data = self.operationCardlist[self.touOperate][1]
- self:sendOperationCode(operateCode, data.cards)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- end
- end
- local isHu = self:getIsHaveHuOp()
- if isHu == true then
- local content = string.format("确定放弃胡牌吗?")
- local okCallBack = function ()
- tou()
- end
- local cancelCallBack = function ()
-
- end
- showConfirmDialog(content,okCallBack,cancelCallBack)
- else
- tou()
- end
- end)
-
- self.ui.Items.Button_7:registerClick(function ()
- if app.room:isLittleFamily() then return end
- local request = ZPMessage.BaoPai:new()
- request.optType = 1
- logE("ErWuRoomOperationView:baojiao"..table.tostring(request))
- self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
- logE("ErWuRoomOperationView baojiao response = ", table.tostring(response))
- end)
- self:showBaoPaiOpView(false)
- end)
-
- self.ui.Items.Button_8:registerClick(function ()
- if app.room:isLittleFamily() then return end
- local request = ZPMessage.BaoPai:new()
- request.optType = 0
- logE("ErWuRoomOperationView:baojiao"..table.tostring(request))
- self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
- logE("ErWuRoomOperationView baojiao response = ", table.tostring(response))
- end)
- self:showBaoPaiOpView(false)
- end)
-
- self:hideSelf()
- end
-
-
- function ErWuRoomOperationView:onHideOpreationView()
- self.tishi = false
- self:setOperatorPanelView(false)
- end
-
- --是否需要展示操作界面
- function ErWuRoomOperationView:IsshowOpView(op)
- local cardlist = {}
- if op then
- cardlist = self.operationCardlist[op]
- end
-
- if #cardlist > 1 then
- return true
- end
-
- return false
- end
-
-
- function ErWuRoomOperationView:loadImageType(op)
- local retBa1 = bit32.band(op,ZPDef.OpCode.OP_BA_QI_SHOU)
- local retBa2 = bit32.band(op,ZPDef.OpCode.OP_BA_ZHUA)
- local retBa3 = bit32.band(op,ZPDef.OpCode.OP_BA_FAN)
- if retBa3 > 0 or retBa1 > 0 or retBa2 > 0 then
- self.ui.Items.ImageView_Op:loadTexture("zp_erwu/res/ui/zy_fangjian/opeate_ba.png")
- end
-
- local retTou4 = bit32.band(op,ZPDef.OpCode.OP_TOU_QI_SHOU)
- local retTou5 = bit32.band(op,ZPDef.OpCode.OP_TOU_ZHUA)
- if retTou4 > 0 or retTou5 > 0 then
- self.ui.Items.ImageView_Op:loadTexture("zp_erwu/res/ui/zy_fangjian/opeate_tou.png")
- end
-
-
- local retChi = bit32.band(op,ZPDef.OpCode.OP_CHI)
- if retChi > 0 then
- self.ui.Items.ImageView_Op:loadTexture("zp_erwu/res/ui/zy_fangjian/opeate_chi.png")
- end
-
- local retPengLaiZi = bit32.band(op, ZPDef.OpCode.OP_PENG_LAIZI)
- local retPeng = bit32.band(op, ZPDef.OpCode.OP_PENG)
- if retPengLaiZi > 0 or retPeng > 0 then
- self.ui.Items.ImageView_Op:loadTexture("zp_erwu/res/ui/zy_fangjian/opeate_peng.png")
- end
- end
-
- function ErWuRoomOperationView:createOperationCardView (operateCode, cards)
- local width, height = 129, 207
- local layout = cc.Layout:create()
- layout:setAnchorPoint(cc.p(0, 0))
- layout:setSize(cc.size(width, height))
- -- layout:setTouchEnabled(true)
- for k, v in ipairs(cards) do
- local img = cc.ImageView:create()
- local fileName = ZPFuc.getZPCardImgByValue(v,ZPDef.CardType.CARD_TYPE_GROUP,self.colorType)
- img:loadTextureFromPlist(fileName)
- img:registerClick(function()
- if operateCode == ZPDef.OpCode.OP_PENG then
- for k, v in ipairs(cards) do
- if v == 0x52 then
- operateCode = ZPDef.OpCode.OP_PENG_LAIZI
- break
- end
- end
- end
- self:sendOperationCode(operateCode, cards)
- --直接隐藏界面
- self:hideSelf()
- end)
- local offsetY = (#cards == 3) and (#cards * 46) or (#cards == 2 and (#cards * 60) or (#cards * 100))
- img:setLocalZOrder(1 - table.nums(cards) + 5)
- img:setPositionY(-(k - 1) * 40 + offsetY)
- img:setPositionX(width / 2)
- layout:addChild(img)
- end
- return layout
- end
-
- --如果有多张牌时,展示操作界面
- function ErWuRoomOperationView:showOperateView(op)
- self.ui.Items.Layout_operatorPanel:setVisible(false)
- self.ui.Items.Layout_Group:setVisible(true)
- self.ui.Items.Layout_12:removeAllChildren()
- self:loadImageType(op)
- local cardlist = self.operationCardlist[op]
-
- for _, item in ipairs(cardlist) do
- local cardView = self:createOperationCardView(op, item.cards)
- self.ui.Items.Layout_12:addChild(cardView)
- end
-
- self.ui.Items.Layout_12:requestDoLayout()
- self.ui.Items.Layout_12:doLayout();
-
- self.ui.Items.Layout_Group:requestDoLayout()
- self.ui.Items.Layout_Group:doLayout()
-
- end
-
- --获取是否有胡操作
- function ErWuRoomOperationView: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 ErWuRoomOperationView:hidePengBtn()
-
- end
-
- function ErWuRoomOperationView:showOperation(mainOpCode, operationCardlist, isQiShou, hasGuo, isTishi, colorType)
- if app.room:isLittleFamily() then return end
- --操作码
- self.operationLocalCode = mainOpCode
- --获取偷巴操作
- self.touOperate = self:getTouOperate(self.operationLocalCode)
- self.baOperate = self:getBaOperate(self.operationLocalCode)
- --可以操作的牌
- self.operationCardlist = operationCardlist
- --是否是起手操作
- self.isQiShou = isQiShou
- logE("RoomView:showOperation(mainOpCode) 1:"..mainOpCode)
-
- --操作牌颜色
- self.colorType = colorType or ZPDef.ColorType.White
-
- self.tishi = isTishi
- --操作类型
- local beginList = {}
-
- beginList = ZPFuc.getZPOperationType(mainOpCode,hasGuo)--,self.playerZhao[1] > 0
- logE("RoomView:showOperation isCheckMustOperation before (beginList)1 :"..table.tostring(beginList))
- logD("ErWuRoomOperationView:showOperation", "operationCardlist", table.tostring(operationCardlist))
-
- --胡牌优先规则
- 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 ErWuRoomOperationView:setOperatorPanelView(bVisible, operations)
- self:setVisible(bVisible)
- self.ui.Items.Layout_operatorPanel:setVisible(bVisible)
-
- --置灰所有 ui排序:吃碰过
- for i = 1 ,8 do
- local name = string.format("Button_%d",i)
- if self.ui.Items[name] then
- 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 == 15 then
- name = string.format("Button_%d",5)
- layout = string.format("Layout_%d",5)
- elseif v == 13 then
- name = string.format("Button_%d",6)
- layout = string.format("Layout_%d",6)
- elseif v == 14 then
- name = string.format("Button_%d",2)
- layout = string.format("Layout_%d",2)
- end
-
- if self.ui.Items[name] then
- self.ui.Items[name]:setEnabled(true)
- self.ui.Items[name]:setVisible(true)
- if v ~= 3 then
- self.ui.Items[layout]:setPositionX(guoPosx - index*161)
- index = index + 1
- end
- end
- end
- end
- end
-
-
- function ErWuRoomOperationView:getTouOperate(op)
- local opreate = nil
-
- local ret1 = bit32.band(op,ZPDef.OpCode.OP_TOU_QI_SHOU)
- if ret1 > 0 then
- return ZPDef.OpCode.OP_TOU_QI_SHOU
- end
-
- 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 ErWuRoomOperationView:getBaOperate(op)
- local opreate = nil
-
- local ret1 = bit32.band(op,ZPDef.OpCode.OP_BA_QI_SHOU)
- if ret1 > 0 then
- return ZPDef.OpCode.OP_BA_QI_SHOU
- end
-
- local ret2 = bit32.band(op,ZPDef.OpCode.OP_BA_ZHUA)
- if ret2 > 0 then
- return ZPDef.OpCode.OP_BA_ZHUA
- end
-
- local ret3 = bit32.band(op,ZPDef.OpCode.OP_BA_FAN)
- if ret3 > 0 then
- return ZPDef.OpCode.OP_BA_FAN
- end
-
- return opreate
- end
-
- --显示爆牌操作
- function ErWuRoomOperationView:showBaoPaiOpView(isshow)
- if app.room:isLittleFamily() then return end
- self:setVisible(isshow)
- if true == isshow then
- local operations = {}
- table.insert(operations,8)
- table.insert(operations,7)
- self:setOperatorPanelView(isshow,operations)
- else
- self:setOperatorPanelView(false)
- end
- end
-
- --隐藏自身
- function ErWuRoomOperationView:hideSelf()
- self.ui.Items.Layout_operatorPanel:setVisible(false)
- self.ui.Items.Layout_Group:setVisible(false)
- end
-
- function ErWuRoomOperationView:sendOperationCode(operationCode,opCards)
- if type(opCards) == "number" then
- opCards = {opCards}
- end
- if app.room:isLittleFamily() then return end
- local opCards = opCards or {0}
- -- if self.isQiShou then
- -- local request = ZPMessage.GameSendOperateCodeRequest:new()
- -- request.operateCode = operationCode
- -- request.opCard= tonumber(opCard)
- -- logE("sendQiShouOperate:"..table.tostring(request))
- -- self.ui:sendMsg(app.room, "sendQiShouOperate", request, function(status, response)
- -- logE("RoomView sendQiShouOperate() response = ", table.tostring(response))
- -- end)
- -- else
- -- 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)
- -- end
-
-
- local eventName = self.isQiShou and "sendQiShouOperate" or "sendOperationCode"
- local request = ZPMessage.GameSendOpCodeResponse:new()
- request.operateCode = operationCode
-
- for k, v in ipairs(opCards) do
- table.insert(request.opCard.Datas, v)
- end
-
- logE("ErWuRoomOperationView:sendOperationCode:"..table.tostring(request))
- self.ui:sendMsg(app.room, eventName, request, function(status, response)
- logE("ErWuRoomOperationView:sendOperationCode response = ", table.tostring(response))
- end)
-
- app:dispatchEvent({name = "onClickOpBtn"});
- end
-
- function ErWuRoomOperationView: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
-
- if self.tishi then
- local view = import("zp_erwu.luaScript.Views.Room.ErWuRoomBaoPei"):new(nil,1)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- else
- local operateCode = 0
- operateCode = ZPDef.OpCode.OP_CANCEL
- self:sendOperationCode(operateCode,self.outCard)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- --如果有吃的界面则隐藏
- self:setEatCardView(false)
- local nUserID = app.room:getUserIdByViewId(1)
- end
-
-
- --playVoiceOperation(ZPDef.OpType.OP_TYPE_CANCEL,nUserID)
- end
-
- --隐藏吃牌界面
- function ErWuRoomOperationView:setEatCardView(bVisible)
- self.ui.Items.Layout_Group:setVisible(bVisible)
- self.ui.Items.Layout_12:removeAllChildren()
- end
-
- --隐藏比牌界面
- function ErWuRoomOperationView:setEatCardBiView(bVisible)
- end
-
- --隐藏比牌界面
- function ErWuRoomOperationView:setEatCardSanBiView(bVisible)
- end
-
- function ErWuRoomOperationView:setAllEatView(bVisible)
- end
-
- --吃牌点击
- function ErWuRoomOperationView:touchEatOneCardCallBack()
-
- end
- --点击吃牌组合牌一回调
- function ErWuRoomOperationView:touchEatTwoCardCallBack(operateCode,weaveCardList)
- end
-
-
- --点击吃牌组合牌一回调
- function ErWuRoomOperationView:touchEatSanCardCallBack(operateCode1,weaveCardList1,operateCode2,weaveCardList2)
-
- end
-
- --判断能否吃牌
- --[[
- operateCode:吃牌操作码
- list : 吃牌组合,key为操作码,value为三张牌组合
- index :list的有效大小
- ]]
- function ErWuRoomOperationView:getEatLeaveWeave(handCardValueLocalTemp)
-
- end
-
- --判断能否吃牌
- --[[
- weaveCard:要吃的那组牌
- handCardValueLocalTemp:剩下的手牌(已经假定删掉吃过的牌)
- ]]
- function ErWuRoomOperationView:eatCardLogic(weaveCard,handCardValueLocalTemp)
-
- end
-
-
-
- --多维数组转 一维数组
- function ErWuRoomOperationView: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 ErWuRoomOperationView:RankChiPai(weaveCardList,listCode)
-
- end
-
- --游戏场景传一些参数过来 出的牌,手牌数据
- function ErWuRoomOperationView:setSameParame(outCard,handCardList)
- self.outCard = outCard
- self.handCardValueLocal = handCardList
- end
-
- return ErWuRoomOperationView;
|