1
0

UserInsertCard.js 1.8 KB

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