Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

327 linhas
10 KiB

  1. local PKDef = PKFramework.PKImport("pk_base.luaScript.PKDef")
  2. local PKFuc = PKFramework.PKImport("pk_base.luaScript.PKFunctions")
  3. local PKSound = PKFramework.PKImport("pk_base.luaScript.PKSound")
  4. local PKMessage = PKFramework.PKImport("pk_base.luaScript.Protocol.PKMessage")
  5. local PKRoomOperationView = class("PKRoomOperationView", cc.UIView)
  6. function PKRoomOperationView:ctor(parent)
  7. PKRoomOperationView.super.ctor(self);
  8. self.parent = parent
  9. end
  10. function PKRoomOperationView:onEnter()
  11. PKRoomOperationView.super.onEnter(self)
  12. local ui = loadUI("pk_base/res/ui/ui_fangjian/pk_ui_operation.ui");
  13. self.ui = ui;
  14. self:addChild(ui);
  15. self.ui.Items.Button_Choice:registerClick(nil,function ()
  16. playBtnEffect()
  17. if self.selectCard == 0 then
  18. showTooltip("请选择一张牌")
  19. else
  20. app.room:requestCallCard(self.selectCard)
  21. end
  22. end)
  23. self.ui.Items.Button_Choice_Sure:registerClick(nil,function ()
  24. playBtnEffect()
  25. if table.nums(self.cardList) <= 0 then
  26. showTooltip("请选择一组牌")
  27. else
  28. logD("list:",table.tostring(self.cardList))
  29. logD("srcList:",table.tostring(self.srcCardList))
  30. self:setChoiceCardView(false)
  31. app.room:requestSendOutCard(1,self.srcCardList,self.cardList)
  32. local tpCardInfo = PKFuc.getCardType(self.cardList)
  33. self.parent:createOutCard(PKDef.MyViewID, self.cardList, tpCardInfo[1].cardType, false, self.srcCardList);
  34. end
  35. end)
  36. --包牌
  37. self.ui.Items.Button_BaoPai:registerClick(nil,function ()
  38. playBtnEffect()
  39. local content = string.format("是否确认包牌吗?")
  40. local okCallBack = function ()
  41. if self.parent:getTuoGuanState() == true then
  42. self:hideSelf()
  43. return
  44. end
  45. app.room:requestBaoPai(PKDef.BaoPai.BAOPAI)
  46. self:hideSelf()
  47. end
  48. local cancelCallBack = function ()
  49. end
  50. showConfirmDialog(content,okCallBack,cancelCallBack)
  51. end)
  52. --不包
  53. self.ui.Items.Button_BuBao:registerClick(function ()
  54. playBtnEffect()
  55. self:hideSelf()
  56. app.room:requestBaoPai(PKDef.BaoPai.BUBAO)
  57. end)
  58. --反包
  59. self.ui.Items.Button_FanBao:registerClick(nil,function ()
  60. playBtnEffect()
  61. local content = string.format("是否确认反包?")
  62. local okCallBack = function ()
  63. app.room:requestBaoPai(PKDef.BaoPai.FANBAO)
  64. self:hideSelf()
  65. end
  66. local cancelCallBack = function ()
  67. end
  68. showConfirmDialog(content,okCallBack,cancelCallBack)
  69. end)
  70. --不反
  71. self.ui.Items.Button_BuFan:registerClick(function ()
  72. playBtnEffect()
  73. self:hideSelf()
  74. app.room:requestBaoPai(PKDef.BaoPai.BUFAN)
  75. end)
  76. --出牌
  77. self.ui.Items.Button_OutCard:registerClick(function ()
  78. playBtnEffect()
  79. self.parent:sendOutCard()
  80. end)
  81. --提示
  82. self.ui.Items.Button_Tip:registerClick(function ()
  83. playBtnEffect()
  84. self.parent:onTiShiClick()
  85. end)
  86. --不出
  87. self.ui.Items.Button_NoOut:registerClick(function ()
  88. playBtnEffect()
  89. self.parent:sendNoOutCard()
  90. end)
  91. self.srcWidth = self.ui.Items.Layout_ChoiceCardType:getContentSize().width
  92. self.srcHeight = self.ui.Items.Layout_ChoiceCardType:getContentSize().height
  93. self:hideSelf(true)
  94. end
  95. function PKRoomOperationView:setLayoutBaoPaiView(bVisible)
  96. self:hideSelf()
  97. self.ui.Items.Layout_BaoPai:setVisible(bVisible)
  98. end
  99. function PKRoomOperationView:setLayoutFanPaoView(bVisible)
  100. self:hideSelf()
  101. self.ui.Items.Layout_FanBao:setVisible(bVisible)
  102. end
  103. function PKRoomOperationView:setOperatorPanelView(bVisible,opType)
  104. self:hideSelf()
  105. self.ui.Items.Layout_operatorPanel:setVisible(bVisible)
  106. --0-只能pass 1-可以选择出也可以不出 2-必须出牌
  107. if opType == 0 then
  108. self.ui.Items.Layout_NoOut:setVisible(true)
  109. self.ui.Items.Layout_Tip:setVisible(false)
  110. self.ui.Items.Layout_OutCard:setVisible(false)
  111. elseif opType == 1 then
  112. self.ui.Items.Layout_NoOut:setVisible(true)
  113. self.ui.Items.Layout_Tip:setVisible(true)
  114. self.ui.Items.Layout_OutCard:setVisible(true)
  115. elseif opType == 2 then
  116. self.ui.Items.Layout_NoOut:setVisible(false)
  117. self.ui.Items.Layout_Tip:setVisible(true)
  118. self.ui.Items.Layout_OutCard:setVisible(true)
  119. end
  120. self.ui.Items.Layout_operatorPanel:requestDoLayout()
  121. self.ui.Items.Layout_operatorPanel:doLayout()
  122. end
  123. function PKRoomOperationView:setPlayerView(view)
  124. self.playerView = view
  125. end
  126. function PKRoomOperationView:setCallCardView(bVisible,cardList,callCard,isNotShowAni)
  127. self.ui.Items.Layout_CallCard:setVisible(bVisible)
  128. self.ui.Items.Layout_Card:setVisible(false)
  129. self.ui.Items.Layout_Banker:setVisible(false)
  130. self.ui.Items.ImageView_CallCardBg:setVisible(false)
  131. self.ui.Items.ImageView_WaitBanker:setVisible(false)
  132. self.ui.Items.Layout_JiaoPai:removeAllChildren()
  133. self.selectCard = 0
  134. if not bVisible then
  135. return
  136. end
  137. if callCard then
  138. self.ui.Items.ImageView_CallCardBg:setVisible(true)
  139. local file = PKFuc.getPKCardImgByValue(callCard)
  140. self.ui.Items.ImageView_ChoiceCard:loadTextureFromPlist(file)
  141. if not isNotShowAni then
  142. self.ui.Items.ImageView_ChoiceCard:setScale(0)
  143. local viewId = app.room:getViewIdByUserId(app.room.roomInfo.nBankerUserId)
  144. local srcPos = self.ui.Items.ImageView_ChoiceCard:getPosition()
  145. local pos = cc.p(self.playerView.allNodes[viewId].head:getContentSize().width/2 ,
  146. self.playerView.allNodes[viewId].head:getContentSize().height/2)
  147. local worldPos = self.playerView.allNodes[viewId].head:convertToWorldSpace(pos)
  148. local posInPlayer = self.ui.Items.ImageView_ChoiceCard:getParent():convertToNodeSpace(worldPos)
  149. local cententPos = self.ui.Items.ImageView_ChoiceCard:getParent():convertToNodeSpace(cc.p(getWinSize().width/2,getWinSize().height/2))
  150. self.ui.Items.ImageView_ChoiceCard:setPosition(posInPlayer)
  151. local spawn = cc.Spawn:create(cc.MoveTo:create(0.3,cententPos),cc.ScaleTo:create(0.3,3))
  152. local spawn2 = cc.Spawn:create(cc.MoveTo:create(0.5,srcPos),cc.ScaleTo:create(0.5,1))
  153. local seq = cc.Sequence:create(spawn,cc.DelayTime:create(1.0),spawn2)
  154. self.ui.Items.ImageView_ChoiceCard:runAction(seq)
  155. end
  156. return
  157. end
  158. if app.room.roomInfo.nBankerUserId == app.room:getMyRecordUserId() then
  159. self.ui.Items.Layout_Banker:setVisible(true)
  160. self.callCallList = {}
  161. for k,v in ipairs(cardList) do
  162. local card = self.ui.Items.Layout_Card:getCopied()
  163. card.Items = getUIItems(card)
  164. card:setVisible(true)
  165. local cardValue = 0xff
  166. if PKFuc.getIsMingJiao() then
  167. cardValue = v.card
  168. end
  169. local file = PKFuc.getPKCardImgByValue(cardValue)
  170. card.Items.ImageView_Card:loadTextureFromPlist(file)
  171. self.ui.Items.Layout_JiaoPai:addChild(card)
  172. self.ui.Items.Layout_JiaoPai:requestDoLayout()
  173. self.ui.Items.Layout_JiaoPai:doLayout()
  174. table.insert(self.callCallList,card)
  175. local srcPosY = card.Items.ImageView_Card:getPositionY()
  176. card:registerClick(function ()
  177. for _,ui in ipairs(self.callCallList) do
  178. ui.Items.ImageView_Card:setPositionY(srcPosY)
  179. end
  180. card.Items.ImageView_Card:setPositionY(srcPosY + 20)
  181. self.selectCard = v.card
  182. log("选择的牌:")
  183. PKFuc.logCard(v.card)
  184. end)
  185. end
  186. else
  187. self.ui.Items.ImageView_WaitBanker:setVisible(true)
  188. end
  189. end
  190. function PKRoomOperationView:setChoiceCardView(bVisible,srcList,weaveCardList)
  191. self.ui.Items.Layout_ChoiceCard:setVisible(bVisible)
  192. if bVisible then
  193. self.ui.Items.Layout_ChoiceCardType:removeAllChildren()
  194. self.ui.Items.Layout_CardItem:setVisible(false)
  195. self.ui.Items.Layout_CardItemParent:setVisible(false)
  196. self.ui.Items.Layout_Item:setVisible(false)
  197. logD("weaveCardList:",table.tostring(weaveCardList))
  198. self.selectCallList = {}
  199. --最大组合数
  200. local maxWeaveNum = table.nums(weaveCardList)
  201. local tpLineCount = math.ceil(maxWeaveNum / 2)
  202. local tpHeightCount = 2
  203. self.ui.Items.Layout_ChoiceCardType:setSize(cc.size(self.srcWidth,self.srcHeight))
  204. local width = tpLineCount * self.srcWidth
  205. local height = tpHeightCount * self.srcHeight
  206. --根据组合设置我变化后的宽高
  207. self.ui.Items.Layout_ChoiceCardType:setSize(cc.size(width,height))
  208. --title
  209. self.ui.Items.ImageView_Title_CardType:setPositionY(self.ui.Items.Layout_ChoiceCardType:getPositionY() + height / 2 + 15)
  210. local newWidth = self.ui.Items.Layout_ChoiceCardType:getContentSize().width
  211. local newHeight = self.ui.Items.Layout_ChoiceCardType:getContentSize().height
  212. local isdefault = false
  213. local topLayout = self.ui.Items.Layout_Item:getCopied()
  214. self.ui.Items.Layout_ChoiceCardType:addChild(topLayout)
  215. topLayout:setPosition(cc.p(newWidth/2,newHeight * 0.75))
  216. local bottomLayout = self.ui.Items.Layout_Item:getCopied()
  217. self.ui.Items.Layout_ChoiceCardType:addChild(bottomLayout)
  218. bottomLayout:setPosition(cc.p(newWidth/2,newHeight * 0.25))
  219. local cardWidth = 0
  220. for k1,list in ipairs(weaveCardList) do
  221. local nodeLayout = self.ui.Items.Layout_CardItemParent:getCopied()
  222. for _k,cardvalue in ipairs(list) do
  223. local card = self.ui.Items.Layout_CardItem:getCopied()
  224. card.Items = getUIItems(card)
  225. local file = PKFuc.getPKCardImgByValue(cardvalue)
  226. card.Items.ImageView_CardItem:loadTextureFromPlist(file)
  227. cardWidth = card.Items.ImageView_CardItem:getContentSize().width
  228. nodeLayout:addChild(card)
  229. end
  230. nodeLayout:setColor(cc.c3b(125,125,125))
  231. if not isdefault then
  232. isdefault = true
  233. nodeLayout:setColor(cc.c3b(255,255,255))
  234. self.cardList = app.room:getTableList(list)
  235. self.srcCardList = app.room:getTableList(srcList)
  236. end
  237. table.insert(self.selectCallList,nodeLayout)
  238. nodeLayout:requestDoLayout()
  239. nodeLayout:doLayout()
  240. local mid = math.floor(maxWeaveNum/2)
  241. local leftBlock = maxWeaveNum - mid
  242. if k1 <= mid then
  243. topLayout:addChild(nodeLayout)
  244. else
  245. local nWidth = nodeLayout:getChildrenCount() * self.ui.Items.Layout_CardItem:getContentSize().width + cardWidth * 0.5
  246. --nodeLayout:setContentSize(cc.size(nWidth,nodeLayout:getContentSize().height))
  247. local sss = nodeLayout:getContentSize()
  248. bottomLayout:addChild(nodeLayout)
  249. end
  250. nodeLayout:registerClick(function ()
  251. for _,ui in ipairs(self.selectCallList) do
  252. ui:setColor(cc.c3b(125,125,125))
  253. end
  254. nodeLayout:setColor(cc.c3b(255,255,255))
  255. self.cardList = app.room:getTableList(list)
  256. self.srcCardList = app.room:getTableList(srcList)
  257. end)
  258. end
  259. bottomLayout:requestDoLayout()
  260. bottomLayout:doLayout()
  261. topLayout:requestDoLayout()
  262. topLayout:doLayout()
  263. end
  264. end
  265. --隐藏自身
  266. function PKRoomOperationView:hideSelf(isHideAll)
  267. self.ui.Items.Layout_operatorPanel:setVisible(false)
  268. self.ui.Items.Layout_BaoPai:setVisible(false)
  269. self.ui.Items.Layout_FanBao:setVisible(false)
  270. if isHideAll then
  271. self.ui.Items.Layout_CallCard:setVisible(false)
  272. end
  273. self.ui.Items.Layout_ChoiceCard:setVisible(false)
  274. end
  275. function PKRoomOperationView:ChoiceViewIsVisible()
  276. return self.ui.Items.Layout_ChoiceCard:isVisible()
  277. end
  278. return PKRoomOperationView;