OperateWeaveCtrl.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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._resetOperateData();
  46. this.cbExtraCount = new Array();
  47. this.isChi = false;
  48. //this.m_bgChi.active =false;
  49. },
  50. _resetOperateData() {
  51. this.wOperateCode = 0;
  52. this.cbWeaveCardData = [];
  53. },
  54. SetWeaveInfo: function (pCtrl, WeaveInfo, index) {
  55. this._resetOperateData();
  56. this.pCtrl = pCtrl;
  57. this.isChi = false;
  58. GameDef.g_GameEngine.m_GameClientView.m_CardView.ChangeCardBack(this.node, GameDef.g_GameEngine.m_CardBack);
  59. this.cbCardCont = WeaveInfo.cbCardCount;
  60. cc.error("SetWeaveInfo ", WeaveInfo, index, this.wOperateCode, this.cbWeaveCardData);
  61. this.wOperateCode = WeaveInfo.wWeaveKind;
  62. if (this.bLoad == false) this.onLoad();
  63. this.m_bgChi.active = false;
  64. this.m_tipChi.active = false;
  65. this.m_tipPeng.active = false;
  66. this.m_tipGang.active = false;
  67. this.m_tipGangBu.active = false;
  68. this.m_tipHaiDi.active = false;
  69. this.m_tipHu.active = false;
  70. this.m_tipMenHu.active = false;
  71. this.m_tipTing.active = false;
  72. // this.m_tipDanHu.active = false;
  73. this.m_tipGuo.active = false;
  74. let WeaveCardStatus = true;
  75. let aniNode = null;
  76. let aniName = null;
  77. switch (this.wOperateCode) {
  78. case GameDef.WIK_NULL:
  79. {
  80. this.m_tipGuo.active = true;
  81. WeaveCardStatus = false;
  82. aniNode = this.m_tipChi.getComponent("SpineAnimationCtrl");
  83. aniName = ["qi_loop"];
  84. this.node.width = 100;
  85. this.node.height = 120;
  86. break;
  87. }
  88. case GameDef.WIK_LEFT:
  89. case GameDef.WIK_CENTER:
  90. case GameDef.WIK_RIGHT:
  91. case GameDef.WIK_CAI_ZFB:
  92. {
  93. // if (this.pCtrl.chiCount < 1) {
  94. // this.m_tipChi.active = true;
  95. // } else {
  96. // this.node.active = false;
  97. // }
  98. this.m_tipChi.active = true;
  99. this.pCtrl.WeaveChies[this.pCtrl.chiCount] = this;
  100. this.pCtrl.chiCount++;
  101. this.isChi = true;
  102. aniNode = this.m_tipChi.getComponent("SpineAnimationCtrl");
  103. aniName = ["chi_in", "chi_loop"];
  104. break;
  105. }
  106. case GameDef.WIK_PENG:
  107. {
  108. this.m_tipPeng.active = true;
  109. aniNode = this.m_tipPeng.getComponent("SpineAnimationCtrl");
  110. aniName = ["peng_in", "peng_loop"];
  111. break;
  112. }
  113. case GameDef.WIK_GANG:
  114. case GameDef.WIK_GANG_XI:
  115. case GameDef.WIK_ADD_ZFB:
  116. {
  117. this.m_tipGang.active = true;
  118. aniNode = this.m_tipGang.getComponent("SpineAnimationCtrl");
  119. aniName = ["gang_loop"];
  120. break;
  121. }
  122. case GameDef.WIK_GANG_BU:
  123. {
  124. this.m_tipGangBu.active = true;
  125. aniNode = this.m_tipGangBu.getComponent("SpineAnimationCtrl");
  126. aniName = ["gang_loop"];
  127. break;
  128. }
  129. case GameDef.WIK_HAI_DI:
  130. {
  131. this.m_tipHaiDi.active = true;
  132. WeaveCardStatus = false;
  133. break;
  134. }
  135. case GameDef.WIK_JIA_HU:
  136. case GameDef.WIK_CHI_HU:
  137. {
  138. this.m_tipHu.active = true;
  139. WeaveCardStatus = false;
  140. aniNode = this.m_tipHu.getComponent("SpineAnimationCtrl");
  141. aniName = ["hu_in", "hu_loop"];
  142. break;
  143. }
  144. case GameDef.WIK_MEN_HU:
  145. {
  146. this.m_tipMenHu.active = true;
  147. WeaveCardStatus = false;
  148. break;
  149. }
  150. case GameDef.WIK_LISTEN:
  151. {
  152. this.m_tipTing.active = true;
  153. WeaveCardStatus = false;
  154. break;
  155. }
  156. }
  157. if (!!aniNode && !!aniName) {
  158. if (1 == aniName.length) {
  159. aniNode.playAnimation(aniName[0], true);
  160. } else {
  161. aniNode.playAnimation(aniName[0], false, false, aniName[1], true);
  162. }
  163. }
  164. let isPengGang = this.wOperateCode == GameDef.WIK_GANG && 1 == WeaveInfo.cbCardCount;
  165. if (typeof (WeaveInfo) != 'number') {
  166. for (var i = 0; i < 4; i++) {
  167. WeaveInfo.cbCardData[i] = WeaveInfo.cbCardCount > i ? WeaveInfo.cbCardData[i] : 0;
  168. this.cbWeaveCardData[i] = WeaveInfo.cbCardData[i];
  169. if (isPengGang) {
  170. WeaveInfo.cbCardData[i] = WeaveInfo.cbCardData[0];
  171. WeaveInfo.cbCardCount = 4;
  172. }
  173. if (WeaveInfo.cbExtraCount != null)
  174. this.cbExtraCount[i] = WeaveInfo.cbExtraCount[i];
  175. }
  176. this.WeaveCard.SetWeaveData(WeaveInfo.cbCardData, WeaveInfo.cbCardCount, INVALID_CHAIR, true);
  177. this.WeaveCard.SetWeaveState(WeaveInfo);
  178. this.WeaveCard.SetWeaveNumber(WeaveInfo.cbExtraCount);
  179. // WeaveCardStatus = false;
  180. }
  181. else {
  182. WeaveCardStatus = false;
  183. }
  184. this.WeaveCard.node.active = WeaveCardStatus;
  185. this.onWeaveCardResize(WeaveCardStatus);
  186. },
  187. subClickBtn: function () {
  188. if (this.wOperateCode == GameDef.WIK_GANG_XI) {
  189. for (var i = 0; i < 4; i++) {
  190. if (this.cbExtraCount[i] > 0) {
  191. this.cbWeaveCardData[3] = 0x35 + i;
  192. break;
  193. }
  194. }
  195. this.cbCardCont = 4;
  196. }
  197. if (this.isChi == false) {
  198. this.pCtrl.subClickBtn(this.wOperateCode, this.cbWeaveCardData, this.cbCardCont);
  199. } else {
  200. if (this.WeaveCard.node.active) {
  201. this.pCtrl.subClickBtn(this.wOperateCode, this.cbWeaveCardData, this.cbCardCont);
  202. } else {
  203. for (var i = 0; i < this.pCtrl.WeaveCtrl.length; ++i) {
  204. this.pCtrl.WeaveCtrl[i].node.active = false;
  205. }
  206. for (let index = 0; index < this.pCtrl.chiCount; index++) {
  207. this.pCtrl.WeaveChies[index].node.active = true;
  208. this.pCtrl.WeaveChies[index].WeaveCard.node.active = true;
  209. this.pCtrl.WeaveChies[index].onWeaveCardResize(true);
  210. this.pCtrl.WeaveChies[index].m_tipChi.active = true;
  211. this.pCtrl.WeaveChies[index].m_bgChi.active = true;
  212. }
  213. }
  214. }
  215. this._resetOperateData();
  216. },
  217. // called every frame, uncomment this function to activate update callback
  218. // update: function (dt) {
  219. // },
  220. onWeaveCardResize(status) {
  221. this.node.width = status ? WeaveWidth : WeaveSingleWidth;
  222. this.m_bgChi.width = status ? WeaveWidth : WeaveSingleWidth;
  223. },
  224. });