|
- 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 PokerUtil = require("zp_doushisi.luaScript.Views.Room.doushisiPokerUtil")
-
- local doushisiRoomOperationView = class("doushisiRoomOperationView", cc.UIView)
-
- function doushisiRoomOperationView:ctor()
- doushisiRoomOperationView.super.ctor(self);
-
- self.baOperate = nil
- self.touOperate = nil
-
- self.operationCardlist = {}
-
- self.isQiShou = false
-
- self.tishi = false
-
- self.outCard = 0 --点过的时候发过去的牌值
- end
-
- function doushisiRoomOperationView:onEnter()
- doushisiRoomOperationView.super.onEnter(self)
-
- self:bindEvent(app.room,"onHideOpreationView",handler(self,self.onHideOpreationView))
- local ui = loadUI("zp_doushisi/res/ui/ui_fangjian/doushisi_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]
- local oplist = {}
- table.insert(oplist,card)
- self:sendOperationCode(code,oplist)
- --直接隐藏界面
- 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:showMoreCardOperateView(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.ui.Items.Button_9:registerClick(function ()
- local function peng()
- local operateCode = ZPDef.OpCode.OP_PENG_LAIZI
- if self:IsshowOpView(operateCode) then
- self:showMoreCardOperateView(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 retHu = bit32.band(self.operationLocalCode,ZPDef.OpCode.OP_HU)
- if retHu > 0 then
- operateCode = ZPDef.OpCode.OP_HU
- else
- operateCode = ZPDef.OpCode.OP_TIAN_HU
- end
- local card = 0
- if not self.isQiShou then
- card = self.operationCardlist[ZPDef.OpCode.OP_HU][1]
- end
- local oplist = {}
- table.insert(oplist,card)
- self:sendOperationCode(operateCode,oplist)
- 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]
- local oplist = {}
- table.insert(oplist,card)
- self:sendOperationCode(operateCode,oplist)
- --直接隐藏界面
- 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:showMoreCardOperateView(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("doushisiRoomOperationView:baojiao"..table.tostring(request))
- self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
- logE("doushisiRoomOperationView 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("doushisiRoomOperationView:baojiao"..table.tostring(request))
- self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
- logE("doushisiRoomOperationView baojiao response = ", table.tostring(response))
- end)
- self:showBaoPaiOpView(false)
- end)
-
- self:hideSelf()
- end
-
-
- function doushisiRoomOperationView:onHideOpreationView()
- self.tishi = false
- self:setOperatorPanelView(false)
- end
-
- --是否需要展示操作界面
- function doushisiRoomOperationView:IsshowOpView(op)
- local cardlist = {}
- if op then
- cardlist = self.operationCardlist[op]
- end
-
- if #cardlist > 1 then
- return true
- end
-
- return false
- end
-
-
- function doushisiRoomOperationView: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_doushisi/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_doushisi/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_doushisi/res/ui/zy_fangjian/opeate_chi.png")
- end
-
-
- local retPeng = bit32.band(op,ZPDef.OpCode.OP_PENG)
- if retPeng > 0 then
- self.ui.Items.ImageView_Op:loadTexture("zp_doushisi/res/ui/zy_fangjian/opeate_peng.png")
- end
-
-
- end
-
- --如果有多张牌时,展示操作界面 --吃的时候发一张牌
- function doushisiRoomOperationView: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 = PokerUtil.pokerPng(v,ZPDef.CardType.CARD_TYPE_GROUP_OUT)
- for i = 1, 3 do
- local imageNode = string.format("ImageView_card_%d",i)
- uiItem.Items[imageNode]:setVisible(false)
- end
- uiItem.Items.ImageView_card_2:setVisible(true)
- uiItem.Items.ImageView_card_2:loadTextureFromPlist(fileName)
- uiItem.Items.Layout_opCard:registerClick(function()
- local operateCode = 0
- operateCode = op
- local card = v
- local oplist = {}
- table.insert(oplist,card)
- self:sendOperationCode(operateCode,oplist)
- --直接隐藏界面
- 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 doushisiRoomOperationView:showMoreCardOperateView(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]
-
- local resultGroupList = {}
- for k,cards in pairs(cardlist) do
- local list = PokerUtil.pokerSortDssCards(cards)
- table.insert(resultGroupList,list)
- end
-
- table.sort(resultGroupList, function (a, b)
- if a[1].val == b[1].val then
- return a[1].tp < b[1].tp
- else
- return a[1].val < b[1].val
- end
- end)
-
-
- local tempCarlist = {}
- local cardData = {}
- for i = 1,#resultGroupList do
- local list = resultGroupList[i]
- cardData = {}
- for i = 1, #list do
- local card = list[i].cid
- table.insert(cardData,card)
- end
- table.insert(tempCarlist,cardData)
- end
-
- for k,v in ipairs(tempCarlist) do
- local uiTemplate = self.ui.Items.Layout_opCard
- local uiItem = uiTemplate:getCopied()
- uiItem.Items = getUIItems(uiItem)
- for i = 1, 3 do
- local imageNode = string.format("ImageView_card_%d",i)
- uiItem.Items[imageNode]:setVisible(false)
- end
- local oplist = {}
-
- for _,val in pairs(v or {}) do
- table.insert(oplist,val)
- end
-
- table.sort(oplist,function(a,b)
- return a > b
- end)
-
- local lens = table.nums(oplist)
-
- for i = 1,lens do
- local imageNode = string.format("ImageView_card_%d",i)
- uiItem.Items[imageNode]:setVisible(true)
- local fileName = PokerUtil.pokerPng(oplist[i],ZPDef.CardType.CARD_TYPE_GROUP_OUT)
- uiItem.Items[imageNode]:loadTextureFromPlist(fileName)
- end
-
- uiItem.Items.Layout_opCard:registerClick(function()
- local operateCode = 0
- operateCode = op
- local card = v
- local oplist = {}
- for _,val in pairs(card or {}) do
- table.insert(oplist,val)
- end
- self:sendOperationCode(operateCode,oplist)
- --直接隐藏界面
- 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 doushisiRoomOperationView: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 doushisiRoomOperationView:hidePengBtn()
-
- end
-
- function doushisiRoomOperationView:showOperation(mainOpCode,card,isQiShou,hasGuo,isTishi)
- 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.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 doushisiRoomOperationView: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)
- 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 doushisiRoomOperationView: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 doushisiRoomOperationView: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 doushisiRoomOperationView: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 doushisiRoomOperationView:hideSelf()
- self.ui.Items.Layout_operatorPanel:setVisible(false)
- self.ui.Items.Layout_Group:setVisible(false)
- end
-
- function doushisiRoomOperationView:sendOperationCode(operationCode,oplist)
- if app.room:isLittleFamily() then return end
- local oplist = oplist or {}
- local ishasLaizi = false
-
- for _,v in pairs(oplist) do
- if v > 0x50 then
- ishasLaizi = true
- break
- end
- end
-
- if ishasLaizi and operationCode == ZPDef.OpCode.OP_PENG then
- operationCode = ZPDef.OpCode.OP_PENG_LAIZI
- end
-
- if self.isQiShou then
- local request = ZPMessage.GameQiShouSendOperateCodeResponse:new()
- request.operateCode = operationCode
- for _,v in pairs(oplist) do
- table.insert(request.opCard.Datas, v)
- end
- 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
- for _,v in pairs(oplist) do
- table.insert(request.opCard.Datas, v)
- end
- 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 doushisiRoomOperationView: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_doushisi.luaScript.Views.Room.doushisiRoomBaoPei"):new(nil,1)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- else
- local operateCode = 0
- operateCode = ZPDef.OpCode.OP_CANCEL
- local oplist = {}
- table.insert(oplist,self.outCard)
- self:sendOperationCode(operateCode,oplist)
- --直接隐藏界面
- self:setOperatorPanelView(false)
- --如果有吃的界面则隐藏
- self:setEatCardView(false)
- local nUserID = app.room:getUserIdByViewId(1)
- end
-
-
- --playVoiceOperation(ZPDef.OpType.OP_TYPE_CANCEL,nUserID)
- end
-
- --隐藏吃牌界面
- function doushisiRoomOperationView:setEatCardView(bVisible)
- self.ui.Items.Layout_Group:setVisible(bVisible)
- self.ui.Items.Layout_12:removeAllChildren()
- end
-
- --隐藏比牌界面
- function doushisiRoomOperationView:setEatCardBiView(bVisible)
- end
-
- --隐藏比牌界面
- function doushisiRoomOperationView:setEatCardSanBiView(bVisible)
- end
-
- function doushisiRoomOperationView:setAllEatView(bVisible)
- end
-
- --吃牌点击
- function doushisiRoomOperationView:touchEatOneCardCallBack()
-
- end
- --点击吃牌组合牌一回调
- function doushisiRoomOperationView:touchEatTwoCardCallBack(operateCode,weaveCardList)
- end
-
-
- --点击吃牌组合牌一回调
- function doushisiRoomOperationView:touchEatSanCardCallBack(operateCode1,weaveCardList1,operateCode2,weaveCardList2)
-
- end
-
- --判断能否吃牌
- --[[
- operateCode:吃牌操作码
- list : 吃牌组合,key为操作码,value为三张牌组合
- index :list的有效大小
- ]]
- function doushisiRoomOperationView:getEatLeaveWeave(handCardValueLocalTemp)
-
- end
-
- --判断能否吃牌
- --[[
- weaveCard:要吃的那组牌
- handCardValueLocalTemp:剩下的手牌(已经假定删掉吃过的牌)
- ]]
- function doushisiRoomOperationView:eatCardLogic(weaveCard,handCardValueLocalTemp)
-
- end
-
-
-
- --多维数组转 一维数组
- function doushisiRoomOperationView: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 doushisiRoomOperationView:RankChiPai(weaveCardList,listCode)
-
- end
-
- --游戏场景传一些参数过来 出的牌,手牌数据
- function doushisiRoomOperationView:setSameParame(outCard,handCardList)
- self.outCard = outCard
- self.handCardValueLocal = handCardList
- end
-
- return doushisiRoomOperationView;
|