OperateWeaveCtrl.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. aniName = ["gang_loop"];
  114. break;
  115. }
  116. case GameDef.WIK_GANG_BU:
  117. {
  118. this.m_tipGangBu.active = true;
  119. aniNode = this.m_tipGangBu.getComponent("SpineAnimationCtrl");
  120. aniName = ["gang_loop"];
  121. break;
  122. }
  123. case GameDef.WIK_HAI_DI:
  124. {
  125. this.m_tipHaiDi.active = true;
  126. WeaveCardStatus = false;
  127. break;
  128. }
  129. case GameDef.WIK_JIA_HU:
  130. case GameDef.WIK_CHI_HU:
  131. {
  132. this.m_tipHu.active = true;
  133. WeaveCardStatus = false;
  134. aniNode = this.m_tipHu.getComponent("SpineAnimationCtrl");
  135. aniName = ["hu_in", "hu_loop"];
  136. break;
  137. }
  138. case GameDef.WIK_MEN_HU:
  139. {
  140. this.m_tipMenHu.active = true;
  141. WeaveCardStatus = false;
  142. break;
  143. }
  144. case GameDef.WIK_LISTEN:
  145. {
  146. this.m_tipTing.active = true;
  147. WeaveCardStatus = false;
  148. break;
  149. }
  150. }
  151. if (!!aniNode && !!aniName) {
  152. if (1 == aniName.length) {
  153. aniNode.playAnimation(aniName[0], true);
  154. } else {
  155. aniNode.playAnimation(aniName[0], false, false, aniName[1], true);
  156. }
  157. }
  158. if (typeof (WeaveInfo) != 'number') {
  159. for (var i = 0; i < 4; i++) {
  160. WeaveInfo.cbCardData[i] = (WeaveInfo.cbCardCount > i) ? WeaveInfo.cbCardData[i] : 0;
  161. this.cbWeaveCardData[i] = WeaveInfo.cbCardData[i];
  162. if (WeaveInfo.cbExtraCount != null)
  163. this.cbExtraCount[i] = WeaveInfo.cbExtraCount[i];
  164. }
  165. this.WeaveCard.SetWeaveData(WeaveInfo.cbCardData, WeaveInfo.cbCardCount, INVALID_CHAIR, true);
  166. this.WeaveCard.SetWeaveState(WeaveInfo);
  167. this.WeaveCard.SetWeaveNumber(WeaveInfo.cbExtraCount);
  168. WeaveCardStatus = false;
  169. }
  170. else {
  171. WeaveCardStatus = false;
  172. }
  173. this.WeaveCard.node.active = WeaveCardStatus;
  174. this.onWeaveCardResize(WeaveCardStatus);
  175. },
  176. subClickBtn: function () {
  177. if (this.wOperateCode == GameDef.WIK_GANG_XI) {
  178. for (var i = 0; i < 4; i++) {
  179. if (this.cbExtraCount[i] > 0) {
  180. this.cbWeaveCardData[3] = 0x35 + i;
  181. break;
  182. }
  183. }
  184. this.cbCardCont = 4;
  185. }
  186. if (this.isChi == false) {
  187. this.pCtrl.subClickBtn(this.wOperateCode, this.cbWeaveCardData, this.cbCardCont);
  188. } else {
  189. if (this.WeaveCard.node.active) {
  190. this.pCtrl.subClickBtn(this.wOperateCode, this.cbWeaveCardData, this.cbCardCont);
  191. } else {
  192. for (var i = 0; i < this.pCtrl.WeaveCtrl.length; ++i) {
  193. this.pCtrl.WeaveCtrl[i].node.active = false;
  194. }
  195. for (let index = 0; index < this.pCtrl.chiCount; index++) {
  196. this.pCtrl.WeaveChies[index].node.active = true;
  197. this.pCtrl.WeaveChies[index].WeaveCard.node.active = true;
  198. this.pCtrl.WeaveChies[index].onWeaveCardResize(true);
  199. this.pCtrl.WeaveChies[index].m_tipChi.active = true;
  200. this.pCtrl.WeaveChies[index].m_bgChi.active = true;
  201. }
  202. }
  203. }
  204. },
  205. // called every frame, uncomment this function to activate update callback
  206. // update: function (dt) {
  207. // },
  208. onWeaveCardResize(status) {
  209. this.node.width = status ? WeaveWidth : WeaveSingleWidth;
  210. this.m_bgChi.width = status ? WeaveWidth : WeaveSingleWidth;
  211. },
  212. });