Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

628 wiersze
17 KiB

  1. local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
  2. local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
  3. local ZPSound = ZPFramework.ZPImport("zp_base.luaScript.ZPSound")
  4. local ZPMessage = ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage")
  5. local ErWuRoomOperationView = class("ErWuRoomOperationView", cc.UIView)
  6. function ErWuRoomOperationView:ctor()
  7. ErWuRoomOperationView.super.ctor(self);
  8. self.baOperate = nil
  9. self.touOperate = nil
  10. self.operationCardlist = {}
  11. self.isQiShou = false
  12. self.tishi = false
  13. self.colorType = ZPDef.ColorType.White
  14. self.outCard = 0 --点过的时候发过去的牌值
  15. end
  16. function ErWuRoomOperationView:onEnter()
  17. ErWuRoomOperationView.super.onEnter(self)
  18. self:bindEvent(app.room,"onHideOpreationView",handler(self,self.onHideOpreationView))
  19. local ui = loadUI("zp_erwu/res/ui/ui_fangjian/erwu_ui_operation.ui");
  20. self.ui = ui;
  21. self:addChild(ui);
  22. self.ui.Items.Button_Close:registerClick(function()
  23. self.ui.Items.Layout_operatorPanel:setVisible(true)
  24. self.ui.Items.Layout_Group:setVisible(false)
  25. end)
  26. --1吃 2碰 3过 4胡 5巴 6偷
  27. --吃牌只能拿自己手里的一张牌跟别人打出的牌或者摸到牌做组合
  28. --ui排序:吃碰胡过
  29. self.ui.Items.Button_1:registerClick(nil,function ()
  30. local function chi()
  31. local code = ZPDef.OpCode.OP_CHI
  32. if self:IsshowOpView(code) then
  33. self:showOperateView(code)
  34. else
  35. local card = self.operationCardlist[code][1].cards
  36. self:sendOperationCode(code,card)
  37. --直接隐藏界面
  38. self:setOperatorPanelView(false)
  39. end
  40. end
  41. local isHu = self:getIsHaveHuOp()
  42. if isHu == true then
  43. local content = string.format("确定放弃胡牌吗?")
  44. local okCallBack = function ()
  45. chi()
  46. end
  47. local cancelCallBack = function ()
  48. end
  49. showConfirmDialog(content,okCallBack,cancelCallBack)
  50. else
  51. chi()
  52. end
  53. end)
  54. self.ui.Items.Button_2:registerClick(function ()
  55. local function peng()
  56. local operateCode = ZPDef.OpCode.OP_PENG
  57. if self:IsshowOpView(operateCode) then
  58. self:showOperateView(operateCode)
  59. else
  60. local cards = self.operationCardlist[operateCode][1].cards
  61. for k, v in ipairs(cards) do
  62. if v == 0x52 then
  63. operateCode = ZPDef.OpCode.OP_PENG_LAIZI
  64. break
  65. end
  66. end
  67. self:sendOperationCode(operateCode,cards)
  68. --直接隐藏界面
  69. self:setOperatorPanelView(false)
  70. end
  71. end
  72. local isHu = self:getIsHaveHuOp()
  73. if isHu == true then
  74. local content = string.format("确定放弃胡牌吗?")
  75. local okCallBack = function ()
  76. peng()
  77. end
  78. local cancelCallBack = function ()
  79. end
  80. showConfirmDialog(content,okCallBack,cancelCallBack)
  81. else
  82. peng()
  83. end
  84. end)
  85. --self:hidePengBtn()
  86. self.ui.Items.Button_3:registerClick(function ()
  87. if app.room:isLittleFamily() then return end
  88. local isHu = self:getIsHaveHuOp()
  89. if isHu == true then
  90. local content = string.format("确定放弃胡牌吗?")
  91. local okCallBack = function ()
  92. self:onClickGuo()
  93. end
  94. local cancelCallBack = function ()
  95. end
  96. showConfirmDialog(content,okCallBack,cancelCallBack)
  97. else
  98. self:onClickGuo()
  99. end
  100. end)
  101. self.ui.Items.Button_4:registerClick(function ()
  102. local operateCode = 0
  103. operateCode = ZPDef.OpCode.OP_HU
  104. local card = 0
  105. if not self.isQiShou then
  106. card = self.operationCardlist[ZPDef.OpCode.OP_HU][1].cards
  107. end
  108. self:sendOperationCode(operateCode,card)
  109. self:setOperatorPanelView(false)
  110. end)
  111. --巴牌
  112. self.ui.Items.Button_5:registerClick(function ()
  113. local function ba()
  114. if self:IsshowOpView(self.baOperate) then
  115. self:showOperateView(self.baOperate)
  116. else
  117. local operateCode = 0
  118. operateCode = self.baOperate
  119. local data = self.operationCardlist[self.baOperate][1]
  120. self:sendOperationCode(operateCode, data.cards)
  121. --直接隐藏界面
  122. self:setOperatorPanelView(false)
  123. end
  124. end
  125. local isHu = self:getIsHaveHuOp()
  126. if isHu == true then
  127. local content = string.format("确定放弃胡牌吗?")
  128. local okCallBack = function ()
  129. ba()
  130. end
  131. local cancelCallBack = function ()
  132. end
  133. showConfirmDialog(content,okCallBack,cancelCallBack)
  134. else
  135. ba()
  136. end
  137. end)
  138. --偷牌
  139. self.ui.Items.Button_6:registerClick(function ()
  140. local function tou()
  141. if self:IsshowOpView(self.touOperate) then
  142. self:showOperateView(self.touOperate)
  143. else
  144. local operateCode = 0
  145. operateCode = self.touOperate
  146. local data = self.operationCardlist[self.touOperate][1]
  147. self:sendOperationCode(operateCode, data.cards)
  148. --直接隐藏界面
  149. self:setOperatorPanelView(false)
  150. end
  151. end
  152. local isHu = self:getIsHaveHuOp()
  153. if isHu == true then
  154. local content = string.format("确定放弃胡牌吗?")
  155. local okCallBack = function ()
  156. tou()
  157. end
  158. local cancelCallBack = function ()
  159. end
  160. showConfirmDialog(content,okCallBack,cancelCallBack)
  161. else
  162. tou()
  163. end
  164. end)
  165. self.ui.Items.Button_7:registerClick(function ()
  166. if app.room:isLittleFamily() then return end
  167. local request = ZPMessage.BaoPai:new()
  168. request.optType = 1
  169. logE("ErWuRoomOperationView:baojiao"..table.tostring(request))
  170. self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
  171. logE("ErWuRoomOperationView baojiao response = ", table.tostring(response))
  172. end)
  173. self:showBaoPaiOpView(false)
  174. end)
  175. self.ui.Items.Button_8:registerClick(function ()
  176. if app.room:isLittleFamily() then return end
  177. local request = ZPMessage.BaoPai:new()
  178. request.optType = 0
  179. logE("ErWuRoomOperationView:baojiao"..table.tostring(request))
  180. self.ui:sendMsg(app.room, "BaoPai", request, function(status, response)
  181. logE("ErWuRoomOperationView baojiao response = ", table.tostring(response))
  182. end)
  183. self:showBaoPaiOpView(false)
  184. end)
  185. self:hideSelf()
  186. end
  187. function ErWuRoomOperationView:onHideOpreationView()
  188. self.tishi = false
  189. self:setOperatorPanelView(false)
  190. end
  191. --是否需要展示操作界面
  192. function ErWuRoomOperationView:IsshowOpView(op)
  193. local cardlist = {}
  194. if op then
  195. cardlist = self.operationCardlist[op]
  196. end
  197. if #cardlist > 1 then
  198. return true
  199. end
  200. return false
  201. end
  202. function ErWuRoomOperationView:loadImageType(op)
  203. local retBa1 = bit32.band(op,ZPDef.OpCode.OP_BA_QI_SHOU)
  204. local retBa2 = bit32.band(op,ZPDef.OpCode.OP_BA_ZHUA)
  205. local retBa3 = bit32.band(op,ZPDef.OpCode.OP_BA_FAN)
  206. if retBa3 > 0 or retBa1 > 0 or retBa2 > 0 then
  207. self.ui.Items.ImageView_Op:loadTexture("zp_erwu/res/ui/zy_fangjian/opeate_ba.png")
  208. end
  209. local retTou4 = bit32.band(op,ZPDef.OpCode.OP_TOU_QI_SHOU)
  210. local retTou5 = bit32.band(op,ZPDef.OpCode.OP_TOU_ZHUA)
  211. if retTou4 > 0 or retTou5 > 0 then
  212. self.ui.Items.ImageView_Op:loadTexture("zp_erwu/res/ui/zy_fangjian/opeate_tou.png")
  213. end
  214. local retChi = bit32.band(op,ZPDef.OpCode.OP_CHI)
  215. if retChi > 0 then
  216. self.ui.Items.ImageView_Op:loadTexture("zp_erwu/res/ui/zy_fangjian/opeate_chi.png")
  217. end
  218. local retPengLaiZi = bit32.band(op, ZPDef.OpCode.OP_PENG_LAIZI)
  219. local retPeng = bit32.band(op, ZPDef.OpCode.OP_PENG)
  220. if retPengLaiZi > 0 or retPeng > 0 then
  221. self.ui.Items.ImageView_Op:loadTexture("zp_erwu/res/ui/zy_fangjian/opeate_peng.png")
  222. end
  223. end
  224. function ErWuRoomOperationView:createOperationCardView (operateCode, cards)
  225. local width, height = 129, 207
  226. local layout = cc.Layout:create()
  227. layout:setAnchorPoint(cc.p(0, 0))
  228. layout:setSize(cc.size(width, height))
  229. -- layout:setTouchEnabled(true)
  230. for k, v in ipairs(cards) do
  231. local img = cc.ImageView:create()
  232. local fileName = ZPFuc.getZPCardImgByValue(v,ZPDef.CardType.CARD_TYPE_GROUP,self.colorType)
  233. img:loadTextureFromPlist(fileName)
  234. img:registerClick(function()
  235. if operateCode == ZPDef.OpCode.OP_PENG then
  236. for k, v in ipairs(cards) do
  237. if v == 0x52 then
  238. operateCode = ZPDef.OpCode.OP_PENG_LAIZI
  239. break
  240. end
  241. end
  242. end
  243. self:sendOperationCode(operateCode, cards)
  244. --直接隐藏界面
  245. self:hideSelf()
  246. end)
  247. local offsetY = (#cards == 3) and (#cards * 46) or (#cards == 2 and (#cards * 60) or (#cards * 100))
  248. img:setLocalZOrder(1 - table.nums(cards) + 5)
  249. img:setPositionY(-(k - 1) * 40 + offsetY)
  250. img:setPositionX(width / 2)
  251. layout:addChild(img)
  252. end
  253. return layout
  254. end
  255. --如果有多张牌时,展示操作界面
  256. function ErWuRoomOperationView:showOperateView(op)
  257. self.ui.Items.Layout_operatorPanel:setVisible(false)
  258. self.ui.Items.Layout_Group:setVisible(true)
  259. self.ui.Items.Layout_12:removeAllChildren()
  260. self:loadImageType(op)
  261. local cardlist = self.operationCardlist[op]
  262. for _, item in ipairs(cardlist) do
  263. local cardView = self:createOperationCardView(op, item.cards)
  264. self.ui.Items.Layout_12:addChild(cardView)
  265. end
  266. self.ui.Items.Layout_12:requestDoLayout()
  267. self.ui.Items.Layout_12:doLayout();
  268. self.ui.Items.Layout_Group:requestDoLayout()
  269. self.ui.Items.Layout_Group:doLayout()
  270. end
  271. --获取是否有胡操作
  272. function ErWuRoomOperationView:getIsHaveHuOp()
  273. if not self.operationLocalCode then return false end
  274. local beginList = {}
  275. beginList = ZPFuc.getZPOperationType(self.operationLocalCode,true)
  276. local isHu = false
  277. for k,opType in pairs(beginList) do
  278. if opType == ZPDef.OpType.OP_TYPE_HU then
  279. isHu = true
  280. break
  281. end
  282. end
  283. return isHu
  284. end
  285. --泸州大贰自动碰,所以隐藏碰按钮
  286. function ErWuRoomOperationView:hidePengBtn()
  287. end
  288. function ErWuRoomOperationView:showOperation(mainOpCode, operationCardlist, isQiShou, hasGuo, isTishi, colorType)
  289. if app.room:isLittleFamily() then return end
  290. --操作码
  291. self.operationLocalCode = mainOpCode
  292. --获取偷巴操作
  293. self.touOperate = self:getTouOperate(self.operationLocalCode)
  294. self.baOperate = self:getBaOperate(self.operationLocalCode)
  295. --可以操作的牌
  296. self.operationCardlist = operationCardlist
  297. --是否是起手操作
  298. self.isQiShou = isQiShou
  299. logE("RoomView:showOperation(mainOpCode) 1:"..mainOpCode)
  300. --操作牌颜色
  301. self.colorType = colorType or ZPDef.ColorType.White
  302. self.tishi = isTishi
  303. --操作类型
  304. local beginList = {}
  305. beginList = ZPFuc.getZPOperationType(mainOpCode,hasGuo)--,self.playerZhao[1] > 0
  306. logE("RoomView:showOperation isCheckMustOperation before (beginList)1 :"..table.tostring(beginList))
  307. logD("ErWuRoomOperationView:showOperation", "operationCardlist", table.tostring(operationCardlist))
  308. --胡牌优先规则
  309. local isHu = false
  310. for k,opType in pairs(beginList) do
  311. if opType == ZPDef.OpType.OP_TYPE_HU then
  312. isHu = true
  313. break
  314. end
  315. end
  316. --如果没有胡,扫,提,跑,等自动操作,则显示吃碰过操作
  317. self:setOperatorPanelView(true, beginList)
  318. end
  319. --隐藏行为操作层
  320. function ErWuRoomOperationView:setOperatorPanelView(bVisible, operations)
  321. self:setVisible(bVisible)
  322. self.ui.Items.Layout_operatorPanel:setVisible(bVisible)
  323. --置灰所有 ui排序:吃碰过
  324. for i = 1 ,8 do
  325. local name = string.format("Button_%d",i)
  326. if self.ui.Items[name] then
  327. self.ui.Items[name]:setVisible(false)
  328. end
  329. end
  330. local index = 1
  331. local guoPosx = self.ui.Items.Layout_3:getPositionX()
  332. --显示操作序列
  333. if operations then
  334. for k,v in pairs(operations) do
  335. local name = string.format("Button_%d",v)
  336. local layout = string.format("Layout_%d",v)
  337. --偷和巴做特殊判断
  338. if v == 12 or v == 15 then
  339. name = string.format("Button_%d",5)
  340. layout = string.format("Layout_%d",5)
  341. elseif v == 13 then
  342. name = string.format("Button_%d",6)
  343. layout = string.format("Layout_%d",6)
  344. elseif v == 14 then
  345. name = string.format("Button_%d",2)
  346. layout = string.format("Layout_%d",2)
  347. end
  348. if self.ui.Items[name] then
  349. self.ui.Items[name]:setEnabled(true)
  350. self.ui.Items[name]:setVisible(true)
  351. if v ~= 3 then
  352. self.ui.Items[layout]:setPositionX(guoPosx - index*161)
  353. index = index + 1
  354. end
  355. end
  356. end
  357. end
  358. end
  359. function ErWuRoomOperationView:getTouOperate(op)
  360. local opreate = nil
  361. local ret1 = bit32.band(op,ZPDef.OpCode.OP_TOU_QI_SHOU)
  362. if ret1 > 0 then
  363. return ZPDef.OpCode.OP_TOU_QI_SHOU
  364. end
  365. local ret2 = bit32.band(op,ZPDef.OpCode.OP_TOU_ZHUA)
  366. if ret2 > 0 then
  367. return ZPDef.OpCode.OP_TOU_ZHUA
  368. end
  369. return opreate
  370. end
  371. function ErWuRoomOperationView:getBaOperate(op)
  372. local opreate = nil
  373. local ret1 = bit32.band(op,ZPDef.OpCode.OP_BA_QI_SHOU)
  374. if ret1 > 0 then
  375. return ZPDef.OpCode.OP_BA_QI_SHOU
  376. end
  377. local ret2 = bit32.band(op,ZPDef.OpCode.OP_BA_ZHUA)
  378. if ret2 > 0 then
  379. return ZPDef.OpCode.OP_BA_ZHUA
  380. end
  381. local ret3 = bit32.band(op,ZPDef.OpCode.OP_BA_FAN)
  382. if ret3 > 0 then
  383. return ZPDef.OpCode.OP_BA_FAN
  384. end
  385. return opreate
  386. end
  387. --显示爆牌操作
  388. function ErWuRoomOperationView:showBaoPaiOpView(isshow)
  389. if app.room:isLittleFamily() then return end
  390. self:setVisible(isshow)
  391. if true == isshow then
  392. local operations = {}
  393. table.insert(operations,8)
  394. table.insert(operations,7)
  395. self:setOperatorPanelView(isshow,operations)
  396. else
  397. self:setOperatorPanelView(false)
  398. end
  399. end
  400. --隐藏自身
  401. function ErWuRoomOperationView:hideSelf()
  402. self.ui.Items.Layout_operatorPanel:setVisible(false)
  403. self.ui.Items.Layout_Group:setVisible(false)
  404. end
  405. function ErWuRoomOperationView:sendOperationCode(operationCode,opCards)
  406. if type(opCards) == "number" then
  407. opCards = {opCards}
  408. end
  409. if app.room:isLittleFamily() then return end
  410. local opCards = opCards or {0}
  411. -- if self.isQiShou then
  412. -- local request = ZPMessage.GameSendOperateCodeRequest:new()
  413. -- request.operateCode = operationCode
  414. -- request.opCard= tonumber(opCard)
  415. -- logE("sendQiShouOperate:"..table.tostring(request))
  416. -- self.ui:sendMsg(app.room, "sendQiShouOperate", request, function(status, response)
  417. -- logE("RoomView sendQiShouOperate() response = ", table.tostring(response))
  418. -- end)
  419. -- else
  420. -- local request = ZPMessage.GameSendOpCodeResponse:new()
  421. -- --发送操作码
  422. -- request.operateCode = operationCode
  423. -- request.opCard= tonumber(opCard)
  424. -- logE("sendOperationCode:"..table.tostring(request))
  425. -- self.ui:sendMsg(app.room, "sendOperationCode", request, function(status, response)
  426. -- logE("RoomView sendOperationCode() response = ", table.tostring(response))
  427. -- end)
  428. -- end
  429. local eventName = self.isQiShou and "sendQiShouOperate" or "sendOperationCode"
  430. local request = ZPMessage.GameSendOpCodeResponse:new()
  431. request.operateCode = operationCode
  432. for k, v in ipairs(opCards) do
  433. table.insert(request.opCard.Datas, v)
  434. end
  435. logE("ErWuRoomOperationView:sendOperationCode:"..table.tostring(request))
  436. self.ui:sendMsg(app.room, eventName, request, function(status, response)
  437. logE("ErWuRoomOperationView:sendOperationCode response = ", table.tostring(response))
  438. end)
  439. app:dispatchEvent({name = "onClickOpBtn"});
  440. end
  441. function ErWuRoomOperationView:onClickGuo()
  442. --算法保留,现在是强制胡牌,如果是非强制胡牌的规则,这里就起作用了
  443. --操作类型
  444. local beginList = {}
  445. beginList = ZPFuc.getZPOperationType(self.operationLocalCode,true)--,self.playerZhao[1] > 0
  446. local isHu = false
  447. for k,opType in pairs(beginList) do
  448. if opType == ZPDef.OpType.OP_TYPE_HU then
  449. isHu = true
  450. break
  451. end
  452. end
  453. if self.tishi then
  454. local view = import("zp_erwu.luaScript.Views.Room.ErWuRoomBaoPei"):new(nil,1)
  455. view:setAnchorPoint(cc.p(0.5, 0.5))
  456. app:showWaitDialog(view)
  457. else
  458. local operateCode = 0
  459. operateCode = ZPDef.OpCode.OP_CANCEL
  460. self:sendOperationCode(operateCode,self.outCard)
  461. --直接隐藏界面
  462. self:setOperatorPanelView(false)
  463. --如果有吃的界面则隐藏
  464. self:setEatCardView(false)
  465. local nUserID = app.room:getUserIdByViewId(1)
  466. end
  467. --playVoiceOperation(ZPDef.OpType.OP_TYPE_CANCEL,nUserID)
  468. end
  469. --隐藏吃牌界面
  470. function ErWuRoomOperationView:setEatCardView(bVisible)
  471. self.ui.Items.Layout_Group:setVisible(bVisible)
  472. self.ui.Items.Layout_12:removeAllChildren()
  473. end
  474. --隐藏比牌界面
  475. function ErWuRoomOperationView:setEatCardBiView(bVisible)
  476. end
  477. --隐藏比牌界面
  478. function ErWuRoomOperationView:setEatCardSanBiView(bVisible)
  479. end
  480. function ErWuRoomOperationView:setAllEatView(bVisible)
  481. end
  482. --吃牌点击
  483. function ErWuRoomOperationView:touchEatOneCardCallBack()
  484. end
  485. --点击吃牌组合牌一回调
  486. function ErWuRoomOperationView:touchEatTwoCardCallBack(operateCode,weaveCardList)
  487. end
  488. --点击吃牌组合牌一回调
  489. function ErWuRoomOperationView:touchEatSanCardCallBack(operateCode1,weaveCardList1,operateCode2,weaveCardList2)
  490. end
  491. --判断能否吃牌
  492. --[[
  493. operateCode:吃牌操作码
  494. list : 吃牌组合,key为操作码,value为三张牌组合
  495. index :list的有效大小
  496. ]]
  497. function ErWuRoomOperationView:getEatLeaveWeave(handCardValueLocalTemp)
  498. end
  499. --判断能否吃牌
  500. --[[
  501. weaveCard:要吃的那组牌
  502. handCardValueLocalTemp:剩下的手牌(已经假定删掉吃过的牌)
  503. ]]
  504. function ErWuRoomOperationView:eatCardLogic(weaveCard,handCardValueLocalTemp)
  505. end
  506. --多维数组转 一维数组
  507. function ErWuRoomOperationView:ChangeDataToVector(data)
  508. local tt = {}
  509. for i = 1, self.lieShuMax do
  510. for j = 1, self.hangShuMax do
  511. if data[i][j] then
  512. table.insert(tt,data[i][j])
  513. end
  514. end
  515. end
  516. return tt
  517. end
  518. --[[
  519. 吃牌优化:优先显示油数的组合
  520. ]]
  521. function ErWuRoomOperationView:RankChiPai(weaveCardList,listCode)
  522. end
  523. --游戏场景传一些参数过来 出的牌,手牌数据
  524. function ErWuRoomOperationView:setSameParame(outCard,handCardList)
  525. self.outCard = outCard
  526. self.handCardValueLocal = handCardList
  527. end
  528. return ErWuRoomOperationView;