OperateWeaveCtrl.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. const WeaveWidth = 320;
  2. const WeaveSingleWidth = 140;
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. m_tipChi: cc.Node,
  7. m_tipPeng: cc.Node,
  8. m_tipGang: cc.Node,
  9. m_tipGangBu: cc.Node,
  10. m_tipHaiDi: cc.Node,
  11. m_tipHu: cc.Node,
  12. m_tipMenHu: cc.Node,
  13. m_tipTing: cc.Node,
  14. m_tipGuo: cc.Node,
  15. m_WeaveCardPrefab: cc.Node,
  16. m_WeaveCardItem: cc.Prefab,
  17. m_bgChi : cc.Node,
  18. },
  19. // use this for initialization
  20. onLoad: function () {
  21. if (this.bLoad == false) {
  22. this.m_tipChi.active = false;
  23. this.m_tipPeng.active = false;
  24. this.m_tipGang.active = false;
  25. this.m_tipGangBu.active = false;
  26. this.m_tipHaiDi.active = false;
  27. this.m_tipHu.active = false;
  28. this.m_tipMenHu.active = false;
  29. this.m_tipTing.active = false;
  30. // this.m_tipDanHu.active = false;
  31. this.m_tipGuo.active = false;
  32. this.WeaveCard = this.m_WeaveCardPrefab.getComponent('WeaveItem');
  33. this.WeaveCard.BuildCard(GameDef.HAND_BOTTOM, this.m_WeaveCardItem);
  34. this.WeaveCard.SetCardItemColor();
  35. this.WeaveCard.m_bSelfCard = true;
  36. this.WeaveCard.m_bDisplayItem = true;
  37. this.bLoad = true;
  38. this.node.width = WeaveSingleWidth;
  39. this.node.height = 120;
  40. }
  41. },
  42. ctor: function () {
  43. //this.WeaveCard = null;
  44. this.bLoad = false;
  45. this.wOperateCode = 0;
  46. this.cbWeaveCardData = new Array();
  47. this.cbExtraCount = new Array();
  48. this.isChi = false;
  49. //this.m_bgChi.active =false;
  50. },
  51. SetWeaveInfo: function (pCtrl, WeaveInfo) {
  52. this.pCtrl = pCtrl;
  53. this.isChi = false;
  54. GameDef.g_GameEngine.m_GameClientView.m_CardView.ChangeCardBack(this.node, GameDef.g_GameEngine.m_CardBack);
  55. this.cbCardCont = WeaveInfo.cbCardCount;
  56. this.wOperateCode = WeaveInfo.wWeaveKind;
  57. if (this.bLoad == false) this.onLoad();
  58. this.m_bgChi.active = false;
  59. this.m_tipChi.active = false;
  60. this.m_tipPeng.active = false;
  61. this.m_tipGang.active = false;
  62. this.m_tipGangBu.active = false;
  63. this.m_tipHaiDi.active = false;
  64. this.m_tipHu.active = false;
  65. this.m_tipMenHu.active = false;
  66. this.m_tipTing.active = false;
  67. // this.m_tipDanHu.active = false;
  68. this.m_tipGuo.active = false;
  69. let WeaveCardStatus = true;
  70. let aniNode = null;
  71. let aniName = null;
  72. switch (this.wOperateCode) {
  73. case GameDef.WIK_NULL:
  74. {
  75. this.m_tipGuo.active = true;
  76. WeaveCardStatus = false;
  77. aniNode = this.m_tipChi.getComponent("SpineAnimationCtrl");
  78. aniName = ["qi_loop"];
  79. this.node.width = 100;
  80. this.node.height = 120;
  81. break;
  82. }
  83. case GameDef.WIK_LEFT:
  84. case GameDef.WIK_CENTER:
  85. case GameDef.WIK_RIGHT:
  86. case GameDef.WIK_CAI_ZFB:
  87. {
  88. if (this.pCtrl.chiCount < 1) {
  89. this.m_tipChi.active = true;
  90. } else {
  91. this.node.active = false;
  92. }
  93. this.pCtrl.WeaveChies[this.pCtrl.chiCount] = this;
  94. this.pCtrl.chiCount++;
  95. this.isChi = true;
  96. aniNode = this.m_tipChi.getComponent("SpineAnimationCtrl");
  97. aniName = ["chi_in", "chi_loop"];
  98. break;
  99. }
  100. case GameDef.WIK_PENG:
  101. {
  102. this.m_tipPeng.active = true;
  103. aniNode = this.m_tipPeng.getComponent("SpineAnimationCtrl");
  104. aniName = ["peng_in", "peng_loop"];
  105. break;
  106. }
  107. case GameDef.WIK_GANG:
  108. case GameDef.WIK_GANG_XI:
  109. case GameDef.WIK_ADD_ZFB:
  110. {
  111. this.m_tipGang.active = true;
  112. aniNode = this.m_tipGang.getComponent("SpineAnimationCtrl");
  113. show2Effect = false;
  114. aniName = ["gang_loop"];
  115. break;
  116. }
  117. case GameDef.WIK_GANG_BU:
  118. {
  119. this.m_tipGangBu.active = true;
  120. aniNode = this.m_tipGangBu.getComponent("SpineAnimationCtrl");
  121. show2Effect = false;
  122. aniName = ["gang_loop"];
  123. break;
  124. }
  125. case GameDef.WIK_HAI_DI:
  126. {
  127. this.m_tipHaiDi.active = true;
  128. WeaveCardStatus = false;
  129. break;
  130. }
  131. case GameDef.WIK_JIA_HU:
  132. case GameDef.WIK_CHI_HU:
  133. {
  134. this.m_tipHu.active = true;
  135. WeaveCardStatus = false;
  136. aniNode = this.m_tipHu.getComponent("SpineAnimationCtrl");
  137. aniName = ["hu_in", "hu_loop"];
  138. break;
  139. }
  140. case GameDef.WIK_MEN_HU:
  141. {
  142. this.m_tipMenHu.active = true;
  143. WeaveCardStatus = false;
  144. break;
  145. }
  146. case GameDef.WIK_LISTEN:
  147. {
  148. this.m_tipTing.active = true;
  149. WeaveCardStatus = false;
  150. break;
  151. }
  152. }
  153. if (!!aniNode && !!aniName) {
  154. if (1 == aniName.length) {
  155. aniNode.playAnimation(aniName[0], true);
  156. } else {
  157. aniNode.playAnimation(aniName[0], false, false, aniName[1], true);
  158. }
  159. }
  160. if (typeof (WeaveInfo) != 'number') {
  161. for (var i = 0; i < 4; i++) {
  162. WeaveInfo.cbCardData[i] = (WeaveInfo.cbCardCount > i) ? WeaveInfo.cbCardData[i] : 0;
  163. this.cbWeaveCardData[i] = WeaveInfo.cbCardData[i];
  164. if (WeaveInfo.cbExtraCount != null)
  165. this.cbExtraCount[i] = WeaveInfo.cbExtraCount[i];
  166. }
  167. this.WeaveCard.SetWeaveData(WeaveInfo.cbCardData, WeaveInfo.cbCardCount, INVALID_CHAIR, true);
  168. this.WeaveCard.SetWeaveState(WeaveInfo);
  169. this.WeaveCard.SetWeaveNumber(WeaveInfo.cbExtraCount);
  170. WeaveCardStatus = false;
  171. }
  172. else {
  173. WeaveCardStatus = false;
  174. }
  175. this.WeaveCard.node.active = WeaveCardStatus;
  176. this.onWeaveCardResize(WeaveCardStatus);
  177. },
  178. subClickBtn: function () {
  179. if (this.wOperateCode == GameDef.WIK_GANG_XI) {
  180. for (var i = 0; i < 4; i++) {
  181. if (this.cbExtraCount[i] > 0) {
  182. this.cbWeaveCardData[3] = 0x35 + i;
  183. break;
  184. }
  185. }
  186. this.cbCardCont = 4;
  187. }
  188. if (this.isChi == false) {
  189. this.pCtrl.subClickBtn(this.wOperateCode, this.cbWeaveCardData, this.cbCardCont);
  190. } else {
  191. if (this.WeaveCard.node.active) {
  192. this.pCtrl.subClickBtn(this.wOperateCode, this.cbWeaveCardData, this.cbCardCont);
  193. } else {
  194. for (var i = 0; i < this.pCtrl.WeaveCtrl.length; ++i) {
  195. this.pCtrl.WeaveCtrl[i].node.active = false;
  196. }
  197. for (let index = 0; index < this.pCtrl.chiCount; index++) {
  198. this.pCtrl.WeaveChies[index].node.active = true;
  199. this.pCtrl.WeaveChies[index].WeaveCard.node.active = true;
  200. this.pCtrl.WeaveChies[index].onWeaveCardResize(true);
  201. this.pCtrl.WeaveChies[index].m_tipChi.active = true;
  202. this.pCtrl.WeaveChies[index].m_bgChi.active = true;
  203. }
  204. }
  205. }
  206. },
  207. // called every frame, uncomment this function to activate update callback
  208. // update: function (dt) {
  209. // },
  210. onWeaveCardResize(status) {
  211. this.node.width = status ? WeaveWidth : WeaveSingleWidth;
  212. this.m_bgChi.width = status ? WeaveWidth : WeaveSingleWidth;
  213. },
  214. });