123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- // const GameModule = require("../utils/GameModule");
- cc.Class({
- extends: cc.Component,
- properties: {
-
- messageItem: cc.Prefab,
- /// 最大同时8条信息流
- maxCount: 8,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this._items = [];
- this._itemsData = [];
- this.updateInitData(-1);
- GameEvent.on(GameNotificationKey.GameUpdateMessageList, this, (updateCount, isTime = false) => {
- // this._updateCount =
- this.updateInitData(updateCount, isTime);
- });
- this.schedule(this.timeAction, 1);
- },
- updateInitData(updateCount, isTime) {
- let timeInformations = GameGlobal._timeInformations;
- let itemDatas = timeInformations.concat(GameGlobal._fixInformations);
- let originLength = this._itemsData.length;
- let upLength = updateCount == -1 ? itemDatas.length : updateCount;
- let max = upLength + originLength;
- let sub = max - 8;
- /// 如果当前的长度已经大于8了
- if (sub > 0) {
- //// 如果是实时的信息流 那么减去所加的
- let timeLength = isTime ? timeInformations.length - updateCount : timeInformations.length;
- let arrIndex = timeInformations.length;
- for (let i = 0; i < sub; i++) {
- let index = timeLength + i;
- let item = this._items[index];
- this._items.splice(index, 1);
- item.active = false;
- item.destroy();
- item = null;
- this._itemsData.splice(index, 1);
- itemDatas.splice(arrIndex + i, 1);
- GameGlobal._fixInformations.splice(i, 1);
- }
- max -= sub;
- originLength -= sub;
- }
- for (let i = originLength; i < max; ++i) {
- let item = cc.instantiate(this.messageItem);
- let itemData = itemDatas[i];
- item.getComponent('MessageItem').init(itemData);
- this.node.addChild(item);
- this._items.push(item);
- }
- this._itemsData = itemDatas;
- if (isTime === true) {
- this.reloadAllItemData();
- }
- },
- reloadAllItemData() {
- for(let i = 0; i < this._items.length; ++ i) {
- let item = this._items[i];
- let itemData = this._itemsData[i];
- item.getComponent('MessageItem').init(itemData);
- }
- },
- timeAction() {
- let hiddenIndexArr = [];
- for (let i = 0; i < this._items.length; ++ i) {
- let itemNode = this._items[i];
- let itemScript = itemNode.getComponent('MessageItem');
- itemScript.updateTime();
- let messageData = itemScript._messageData;
- /// 如果是技能并且可以使用的时候 那么就什么都不修改
- if (messageData.type === 2 && messageData.skillStatus === 0) {
- continue;
- }
- if (messageData.cdTime === 0) {
- hiddenIndexArr.push(i);
- }
- }
- if (hiddenIndexArr.length > 0) {
- for (let i = 0; i < hiddenIndexArr.length; ++ i) {
- this.hiddenItem(hiddenIndexArr[i]);
- }
- }
- },
- hiddenItem(index) {
- if (index < this._items.length) {
- let item = this._items[index];
- let fadeAction = cc.fadeTo(0.5, 0); //0.5秒透明度从255降到0
- let action = cc.sequence(fadeAction, cc.callFunc(() => {
- this.deleteItem(index);
- }));
- item.runAction(action);
- }
- },
- deleteItem(index) {
- if (index < this._items.length) {
- let item = this._items[index];
- item.active = false;
- this._items.splice(index, 1);
- item.destroy();
- item = null;
- this._itemsData.splice(index, 1);
- if (index < GameGlobal._timeInformations.length) {
- GameGlobal._timeInformations.splice(index, 1);
- } else {
- GameGlobal._fixInformations.splice(index - GameGlobal._timeInformations.length - 1, 1);
- }
- }
- },
- start () {
- },
- // update (dt) {},
- });
|