UserInsertCard.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var {GameNotificationKey} = require('../utils/GameEnum');
  2. var Item = require("UserInsertCardItem");
  3. const GameModule = require('../utils/GameModule');
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. cardLayout: cc.Layout,
  8. cardPrefab: cc.Prefab,
  9. cardsArray: [Item],
  10. },
  11. // LIFE-CYCLE CALLBACKS:
  12. onLoad () {
  13. for (var i = 0; i < 3; i++) {
  14. let item = cc.instantiate(this.cardPrefab);
  15. item = item.getComponent('UserInsertCardItem');
  16. this.cardsArray.push(item);
  17. this.cardLayout.node.addChild(item.node);
  18. }
  19. let width = this.cardLayout.node._contentSize.width;
  20. let gap = (width - 3*190) / 2;
  21. this.cardLayout.spacingX = gap;
  22. this.setEventListener();
  23. },
  24. setEventListener() {
  25. GameEvent.on(GameNotificationKey.InsertCardToUser, this, (cardInfo) => {
  26. this.insertCardToUser(cardInfo);
  27. });
  28. GameModule.homeGuide.on('Fire_state32', this.openPack, this);
  29. },
  30. start () {
  31. GameModule.homeGuide.getComponent('HomeGuide').handleState('state32')
  32. },
  33. init(list, uid) {
  34. this.uid = uid;
  35. if (list != undefined) {
  36. this.list = list;
  37. for (var i = 0; i < list.length; i++) {
  38. let itemModel = list[i];
  39. let itemMng = this.cardsArray[i];
  40. itemMng.configCardInfo(itemModel, uid);
  41. }
  42. }
  43. },
  44. onDisable() {
  45. this.cardsArray.forEach(item => {
  46. if (item.isHasCard == true) {
  47. item.isHasCard = false;
  48. }
  49. });
  50. },
  51. // update (dt) {},
  52. closeAction() {
  53. this.node.active = false;
  54. },
  55. openPack() {
  56. GameEvent.fire(GameNotificationKey.OpenPack,false);
  57. },
  58. insertCardToUser(cardInfo) {
  59. for(var index in this.cardsArray) {
  60. let item = this.cardsArray[index];
  61. if (item.isHasCard == false) {
  62. item.configCardInfo(cardInfo,this.uid);
  63. break;
  64. }
  65. }
  66. },
  67. });