12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- var {GameNotificationKey} = require('../utils/GameEnum');
- var Item = require("UserInsertCardItem");
- cc.Class({
- extends: cc.Component,
- properties: {
- cardLayout: cc.Layout,
- cardPrefab: cc.Prefab,
- cardsArray: [Item],
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- for (var i = 0; i < 3; i++) {
- let item = cc.instantiate(this.cardPrefab);
- item = item.getComponent('UserInsertCardItem');
- this.cardsArray.push(item);
- this.cardLayout.node.addChild(item.node);
- }
- let width = this.cardLayout.node._contentSize.width;
- let gap = (width - 3*190) / 2;
- this.cardLayout.spacingX = gap;
- this.setEventListener();
- },
- setEventListener() {
- GameEvent.on(GameNotificationKey.InsertCardToUser, this, (cardInfo) => {
- this.insertCardToUser(cardInfo);
- });
- },
- start () {
- },
- init(list, uid) {
- this.uid = uid;
- if (list != undefined) {
- this.list = list;
- for (var i = 0; i < list.length; i++) {
- let itemModel = list[i];
- let itemMng = this.cardsArray[i];
- itemMng.configCardInfo(itemModel, uid);
- }
- }
- },
- onDisable() {
- this.cardsArray.forEach(item => {
- if (item.isHasCard == true) {
- item.isHasCard = false;
- }
- });
- },
- // update (dt) {},
- closeAction() {
- this.node.active = false;
- },
- insertCardToUser(cardInfo) {
- for(var index in this.cardsArray) {
- let item = this.cardsArray[index];
- if (item.isHasCard == false) {
- item.configCardInfo(cardInfo,this.uid);
- break;
- }
- }
- },
- });
|