|
- 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 changpaiRoomOperationView = class("changpaiRoomOperationView", cc.UIView)
-
- function changpaiRoomOperationView:ctor()
- changpaiRoomOperationView.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 changpaiRoomOperationView:onEnter()
- changpaiRoomOperationView.super.onEnter(self)
-
- self:bindEvent(app.room,"onHideOpreationView",handler(self,self.onHideOpreationView))
- local ui = loadUI("zp_changpai/res/ui/ui_fangjian/changpai_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]
- 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 card = self.operationCardlist[operateCode][1]
- self:sendOperationCode(operateCode,card)
- --直接隐藏界面
- 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]
- 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 card = self.operationCardlist[self.baOperate][1]
- self:sendOperationCode(operateCode,card)
- --直接隐藏界面
- 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 card = self.operationCardlist[self.touOperate][1]
- self:sendOperationCode(operateCode,card)
- --直接隐藏界面
- 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("changpaiRoomOperationView:baojiao"..table.tostring(request))
- self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
- logE("changpaiRoomOperationView 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("changpaiRoomOperationView:baojiao"..table.tostring(request))
- self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
- logE("changpaiRoomOperationView baojiao response = ", table.tostring(response))
- end)
- self:showBaoPaiOpView(false)
- end)
-
- self:hideSelf()
- end
-
-
- function changpaiRoomOperationView:onHideOpreationView()
- self.tishi = false
- self:setOperatorPanelView(false)
- end
-
- --是否需要展示操作界面
- function changpaiRoomOperationView:IsshowOpView(op)
- local cardlist = {}
- if op then
- cardlist = self.operationCardlist[op]
- end
-
- if #cardlist > 1 then
- return true
- end
-
- return false
- end
-
-
- function changpaiRoomOperationView: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_changpai/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_changpai/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_changpai/res/ui/zy_fangjian/opeate_chi.png")
- end
-
- end
-
- --如果有多张牌时,展示操作界面
- function changpaiRoomOperationView: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 k,v in ipairs(cardlist) do
- local uiTemplate = self.ui.Items.Layout_opCard
- local uiItem = uiTemplate:getCopied()
- uiItem.Items = getUIItems(uiItem)
- local fileName = ZPFuc.getZPCardImgByValue(v,ZPDef.CardType.CARD_TYPE_GROUP,self.colorType)
- uiItem.Items.ImageView_card:loadTextureFromPlist(fileName)
- uiItem.Items.ImageView_card:registerClick(function()
- local operateCode = 0
- operateCode = op
- local card = v
- self:sendOperationCode(operateCode,card)
- --直接隐藏界面
- self:hideSelf()
- end)
- self.ui.Items.Layout_12:addChild(uiItem)
- 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 changpaiRoomOperationView: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 changpaiRoomOperationView:hidePengBtn()
-
- end
-
- function changpaiRoomOperationView:showOperation(mainOpCode,card,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 = card
- --是否是起手操作
- 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))
-
- --胡牌优先规则
- 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 changpaiRoomOperationView: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 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)
- 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 changpaiRoomOperationView: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 changpaiRoomOperationView: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 changpaiRoomOperationView: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 changpaiRoomOperationView:hideSelf()
- self.ui.Items.Layout_operatorPanel:setVisible(false)
- self.ui.Items.Layout_Group:setVisible(false)
- end
-
- function changpaiRoomOperationView:sendOperationCode(operationCode,opCard)
- if app.room:isLittleFamily() then return end
- local opCard = opCard or 0
- if self.isQiShou then
- local request = ZPMessage.GameQiShouSendOperateCodeResponse: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
-
- app:dispatchEvent({name = "onClickOpBtn"});
- end
-
- function changpaiRoomOperationView: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_changpai.luaScript.Views.Room.changpaiRoomBaoPei"):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 changpaiRoomOperationView:setEatCardView(bVisible)
- self.ui.Items.Layout_Group:setVisible(bVisible)
- self.ui.Items.Layout_12:removeAllChildren()
- end
-
- --隐藏比牌界面
- function changpaiRoomOperationView:setEatCardBiView(bVisible)
- end
-
- --隐藏比牌界面
- function changpaiRoomOperationView:setEatCardSanBiView(bVisible)
- end
-
- function changpaiRoomOperationView:setAllEatView(bVisible)
- end
-
- --吃牌点击
- function changpaiRoomOperationView:touchEatOneCardCallBack()
-
- end
- --点击吃牌组合牌一回调
- function changpaiRoomOperationView:touchEatTwoCardCallBack(operateCode,weaveCardList)
- end
-
-
- --点击吃牌组合牌一回调
- function changpaiRoomOperationView:touchEatSanCardCallBack(operateCode1,weaveCardList1,operateCode2,weaveCardList2)
-
- end
-
- --判断能否吃牌
- --[[
- operateCode:吃牌操作码
- list : 吃牌组合,key为操作码,value为三张牌组合
- index :list的有效大小
- ]]
- function changpaiRoomOperationView:getEatLeaveWeave(handCardValueLocalTemp)
-
- end
-
- --判断能否吃牌
- --[[
- weaveCard:要吃的那组牌
- handCardValueLocalTemp:剩下的手牌(已经假定删掉吃过的牌)
- ]]
- function changpaiRoomOperationView:eatCardLogic(weaveCard,handCardValueLocalTemp)
-
- end
-
-
-
- --多维数组转 一维数组
- function changpaiRoomOperationView: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 changpaiRoomOperationView:RankChiPai(weaveCardList,listCode)
-
- end
-
- --游戏场景传一些参数过来 出的牌,手牌数据
- function changpaiRoomOperationView:setSameParame(outCard,handCardList)
- self.outCard = outCard
- self.handCardValueLocal = handCardList
- end
-
- return changpaiRoomOperationView;
|