Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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