CardItem.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. properties: {
  4. m_Card: [cc.Sprite],
  5. m_Atlas: cc.SpriteAtlas,
  6. m_HandShow: [cc.Node],
  7. m_HandState: cc.Integer,
  8. m_labNumber: cc.Label,
  9. m_HunPaiTip: [cc.Node],
  10. m_ProvideUser: cc.Node,
  11. m_CardItemBack: [cc.Sprite],
  12. m_TingTip: cc.Node,
  13. m_JiPaiTip: [cc.Node],
  14. m_Mash: cc.Node,
  15. },
  16. // LIFE-CYCLE CALLBACKS:
  17. ctor: function () {
  18. this.bShoot = false;
  19. this.m_LastClickTime = 0;
  20. this.m_Click = false;
  21. this.m_MoveIng = false;
  22. this.m_Provide = 0;
  23. this.m_bCanOut = true;
  24. this.m_State = 0;
  25. this.m_colorArr = new Array(new cc.color(255, 255, 255), new cc.color(226, 255, 200));
  26. },
  27. onLoad() {
  28. this.SetState(GameDef.HAND_STATE_STAND);
  29. this.SetHunPai(false);
  30. this.SetJiPai(false);
  31. this.m_BasePos = this.node.getPosition();
  32. if (this.m_ProvideUser != null)
  33. this.m_ProvideUser.active = false;
  34. GameDef.m_AllCardItem.push(this);
  35. },
  36. start: function () {
  37. },
  38. SetProvideType(type) {
  39. this.m_Provide = type;
  40. },
  41. SetState: function (state) {
  42. this.m_State = state;
  43. if (this.m_HandShow == null) return;
  44. for (var i = 0; i < this.m_HandShow.length; i++) {
  45. this.m_HandShow[i].active = false;
  46. }
  47. if (this.m_HandShow[state] != null) {
  48. this.m_HandShow[state].active = true;
  49. }
  50. },
  51. ChangeColor: function (bChange) {
  52. if (this.m_State == GameDef.HAND_STATE_STAND && this.m_HandState != GameDef.HAND_BOTTOM || this.m_State == GameDef.HAND_STATE_SHOW_BACK) return;
  53. if (bChange) {
  54. this.SetColor(cc.color(210, 255, 165));
  55. // this.SetColor(cc.color(160,210,100));
  56. //this.node.opacity = 100;
  57. }
  58. else {
  59. this.SetColor(cc.color(255, 255, 255));
  60. this.node.opacity = 255;
  61. }
  62. },
  63. //投影显示不显示
  64. SetShadowShow: function (bShow) {
  65. if (this.m_HandShow == null) return;
  66. // console.log("Exist_Res--", cc.gPreLoader.Exist_Res('PublicMJ_2', 'Image_GameMJTiles_5'));
  67. for (var i = 0; i < this.m_HandShow.length; i++) {
  68. if (bShow) {
  69. this.m_HandShow[i].getComponent(cc.Sprite).spriteFrame = this.m_Atlas.getSpriteFrame('Shadow');
  70. // cc.gPreLoader.LoadRes('Image_GameMJTiles_Shadow', 'PublicMJ_2', function(sf, Param){
  71. // console.log("show---",this.m_HandShow,this.m_HandShow.length,Param.Index,)
  72. // this.m_HandShow[ Param.Index].getComponent(cc.Sprite).spriteFrame = sf;
  73. // }.bind(this), {Index: i});
  74. }
  75. else {
  76. this.m_HandShow[i].getComponent(cc.Sprite).spriteFrame = null;
  77. }
  78. }
  79. },
  80. SetColor: function (color) {
  81. if (this.m_CardItemBack == null) return;
  82. for (var i = 0; i < this.m_CardItemBack.length; i++) {
  83. if (this.m_CardItemBack[i] == null) {
  84. continue;
  85. }
  86. if (this.m_CardItemBack[i].node != null) {
  87. this.m_CardItemBack[i].node.color = color;
  88. }
  89. }
  90. },
  91. SetCardData: function (cbCardData, bLookOnMode) {
  92. this.SetColor(this.m_colorArr[0]);
  93. if (cbCardData == 0) {
  94. for (var i = 0; i < this.m_Card.length; i++) {
  95. this.m_Card[i].spriteFrame = null;
  96. }
  97. this.SetState(GameDef.HAND_STATE_STAND);
  98. this.SetHunPai(false);
  99. this.SetJiPai(false);
  100. return;
  101. }
  102. if (bLookOnMode) {
  103. this.SetState(GameDef.HAND_STATE_SHOW_BACK);
  104. }
  105. // console.log("SetLiangCardData--",cbCardData);
  106. // console.log("Exist_Res--", cc.gPreLoader.Exist_Res('PublicMJ_2', 'Image_GameMJTiles_5'));
  107. for (var i = 0; i < this.m_Card.length; i++) {
  108. // console.log("cbCardData--",cbCardData,i,this.m_Card)
  109. this.m_Card[i].spriteFrame = this.m_Atlas.getSpriteFrame('' + cbCardData);
  110. // cc.gPreLoader.LoadRes('Image_GameMJTiles_'+i, 'PublicMJ_2', function(sf, Param){
  111. // console.log("cbCardData---",this.m_Card,Param.Index,this.m_Card.length,sf)
  112. // this.m_Card[Param.Index].spriteFrame = sf;
  113. // }.bind(this), {Index: i});
  114. }
  115. this.cbCardData = cbCardData;
  116. this.SetShoot(false);
  117. this.SetNumber(0);
  118. var bShowHun = false;
  119. bShowHun = GameDef.m_cbMagicData != 0 && GameDef.m_cbMagicData == cbCardData;
  120. this.SetHunPai(bShowHun);
  121. var bJiPai = GameDef.IsJiPai(cbCardData);
  122. this.SetJiPai(bJiPai);
  123. //手里有定缺的花色
  124. if (GameDef.m_bHasQue == true && this.m_HandState == GameDef.HAND_BOTTOM && this.m_State == GameDef.HAND_STATE_STAND) {
  125. var cbColor = cbCardData & GameDef.MASK_COLOR;
  126. if (cbColor == GameDef.g_GameEngine.m_cbQueColor[0] || cbColor == GameDef.g_GameEngine.m_cbQueColor[1]) {
  127. this.SetMash(false);
  128. }
  129. else {
  130. this.SetMash(true);
  131. }
  132. }
  133. else {
  134. this.SetMash(false);
  135. }
  136. this.node.setPosition(this.m_BasePos);
  137. if (this.m_ProvideUser) this.m_ProvideUser.active = false;
  138. },
  139. SetLiangCardData: function (cbCardData) {
  140. this.SetColor(this.m_colorArr[0]);
  141. if (cbCardData == 0) {
  142. for (var i = 0; i < this.m_Card.length; i++) {
  143. this.m_Card[i].spriteFrame = null;
  144. }
  145. this.SetState(GameDef.HAND_STATE_STAND);
  146. this.SetHunPai(false);
  147. return;
  148. }
  149. // console.log("Exist_Res--", cc.gPreLoader.Exist_Res('PublicMJ_2', 'Image_GameMJTiles_5'));
  150. for (var i = 0; i < this.m_Card.length; i++) {
  151. // console.log("cbCardData--",cbCardData,i,this.m_Card.length,this.m_Card)
  152. this.m_Card[i].spriteFrame = this.m_Atlas.getSpriteFrame('' + cbCardData);
  153. // cc.gPreLoader.LoadRes('Image_GameMJTiles_'+cbCardData, 'PublicMJ_2', function(sf, Param){
  154. // console.log("cbCardData---",this.m_Card,Param.Index,this.m_Card.length,sf)
  155. // this.m_Card[Param.Index].spriteFrame = sf;
  156. // }.bind(this), {Index: i});
  157. }
  158. this.cbCardData = cbCardData;
  159. this.SetState(GameDef.HAND_STATE_SHOW);
  160. this.SetShoot(false);
  161. this.SetNumber(0);
  162. var bShowHun = false;
  163. bShowHun = GameDef.m_cbMagicData != 0 && GameDef.m_cbMagicData == cbCardData;
  164. this.SetHunPai(bShowHun);
  165. this.node.setPosition(this.m_BasePos);
  166. if (this.m_ProvideUser) this.m_ProvideUser.active = false;
  167. },
  168. SetBasePos: function () {
  169. this.node.stopAllActions();
  170. this.node.setPosition(this.m_BasePos);
  171. var sql = cc.moveTo(0.1, cc.v2(this.node.x, this.m_BasePos.y));
  172. this.node.runAction(sql);
  173. this.bShoot = false;
  174. },
  175. SetProvide: function (provide) {
  176. if (this.m_ProvideUser == null) return;
  177. if (this.m_Provide == GameDef.ITEM_PROVIDE_DIR) {
  178. this.m_ProvideUser.active = true;
  179. // this.m_ProvideUser.angle = 270 - provide * 90;
  180. this.m_ProvideUser.angle = -270 + provide * 90;
  181. } else {
  182. //this.SetColor(this.m_colorArr[1]);
  183. this.node.opacity = 140;
  184. }
  185. //0[90] 1[180] 2[270] 3[0]
  186. },
  187. SetShow: function (show) {
  188. this.node.active = show;
  189. },
  190. GetCardData: function () {
  191. return this.cbCardData;
  192. },
  193. SetShoot: function (bShoot, anim) {
  194. this.bShoot = bShoot;
  195. if (anim != null && anim) {
  196. var sql;
  197. this.node.stopAllActions();
  198. if (this.bShoot) {
  199. sql = cc.moveTo(0.1, cc.v2(this.node.x, this.m_BasePos.y + 24));
  200. } else {
  201. sql = cc.moveTo(0.1, cc.v2(this.node.x, this.m_BasePos.y));
  202. }
  203. this.node.runAction(sql);
  204. } else {
  205. if (this.bShoot) {
  206. this.node.y = 24;
  207. } else {
  208. this.node.y = 0;
  209. }
  210. }
  211. },
  212. GetShoot: function () {
  213. return this.bShoot;
  214. },
  215. SetCardID: function (CardID) {
  216. this.m_CardID = CardID;
  217. },
  218. // 注册触摸
  219. RegisterTouchOn: function (ResponseObj, cbCardID) {
  220. },
  221. // 开始
  222. OnTouch: function (event) {
  223. },
  224. SetNumber: function (count) {
  225. if (this.m_labNumber == null) return;
  226. this.m_labNumber.string = '';
  227. if (count > 0) {
  228. this.m_labNumber.node.active = true;
  229. this.m_labNumber.string = 'x' + count;
  230. }
  231. },
  232. update: function (dt) {
  233. },
  234. SetHunPai: function (bShow) {
  235. if (this.m_HunPaiTip == null) return;
  236. for (var i = 0; i < this.m_HunPaiTip.length; i++) {
  237. this.m_HunPaiTip[i].active = false;//bShow; todo
  238. }
  239. },
  240. SetJiPai: function (bShow) {
  241. if (this.m_JiPaiTip == null) return;
  242. for (var i = 0; i < this.m_JiPaiTip.length; i++) {
  243. this.m_JiPaiTip[i].active = false;// bShow; todo
  244. }
  245. },
  246. SetTingTip: function (bShow) {
  247. if (GameDef.g_GameEngine && GameDef.g_GameEngine.m_ReplayMode) return;
  248. if (this.m_TingTip != null) {
  249. this.m_TingTip.active = bShow;
  250. }
  251. },
  252. SetLockTips: function (bShow) {
  253. if (this.m_LockTips != null) {
  254. this.m_LockTips.active = bShow;
  255. this.SetCanOut(!bShow);
  256. }
  257. },
  258. SetCanOut: function (bCanOut) {
  259. this.m_bCanOut = bCanOut;
  260. },
  261. GetCanOut: function () {
  262. if (this.m_Mash != null) {
  263. return this.m_bCanOut && this.m_Mash.active == false;
  264. }
  265. else {
  266. return this.m_bCanOut;
  267. }
  268. },
  269. SetMash: function (bShow) {
  270. if (this.m_Mash != null) this.m_Mash.active = bShow;
  271. },
  272. SetTingMask: function (Active) {
  273. if (this.m_TingMask) this.m_TingMask.active = Active;
  274. },
  275. });