MessageList.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  2. // const GameModule = require("../utils/GameModule");
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. messageItem: cc.Prefab,
  7. /// 最大同时8条信息流
  8. maxCount: 8,
  9. },
  10. // LIFE-CYCLE CALLBACKS:
  11. onLoad () {
  12. this._items = [];
  13. this._itemsData = [];
  14. this.updateInitData(-1);
  15. GameEvent.on(GameNotificationKey.GameUpdateMessageList, this, (updateCount, isTime = false) => {
  16. // this._updateCount =
  17. this.updateInitData(updateCount, isTime);
  18. });
  19. this.schedule(this.timeAction, 1);
  20. },
  21. updateInitData(updateCount, isTime) {
  22. let timeInformations = Global._timeInformations;
  23. let itemDatas = timeInformations.concat(Global._fixInformations);
  24. let originLength = this._itemsData.length;
  25. let upLength = updateCount == -1 ? itemDatas.length : updateCount;
  26. let max = upLength + originLength;
  27. let sub = max - 8;
  28. /// 如果当前的长度已经大于8了
  29. if (sub > 0) {
  30. //// 如果是实时的信息流 那么减去所加的
  31. let timeLength = isTime ? timeInformations.length - updateCount : timeInformations.length;
  32. let arrIndex = timeInformations.length;
  33. for (let i = 0; i < sub; i++) {
  34. let index = timeLength + i;
  35. let item = this._items[index];
  36. this._items.splice(index, 1);
  37. item.active = false;
  38. item.destroy();
  39. item = null;
  40. this._itemsData.splice(index, 1);
  41. itemDatas.splice(arrIndex + i, 1);
  42. Global._fixInformations.splice(i, 1);
  43. }
  44. max -= sub;
  45. originLength -= sub;
  46. }
  47. for (let i = originLength; i < max; ++i) {
  48. let item = cc.instantiate(this.messageItem);
  49. let itemData = itemDatas[i];
  50. item.getComponent('MessageItem').init(itemData);
  51. this.node.addChild(item);
  52. this._items.push(item);
  53. }
  54. this._itemsData = itemDatas;
  55. if (isTime === true) {
  56. this.reloadAllItemData();
  57. }
  58. },
  59. reloadAllItemData() {
  60. for(let i = 0; i < this._items.length; ++ i) {
  61. let item = this._items[i];
  62. let itemData = this._itemsData[i];
  63. item.getComponent('MessageItem').init(itemData);
  64. }
  65. },
  66. timeAction() {
  67. let hiddenIndexArr = [];
  68. for (let i = 0; i < this._items.length; ++ i) {
  69. let itemNode = this._items[i];
  70. let itemScript = itemNode.getComponent('MessageItem');
  71. itemScript.updateTime();
  72. let messageData = itemScript._messageData;
  73. /// 如果是技能并且可以使用的时候 那么就什么都不修改
  74. if (messageData.type === 2 && messageData.skillStatus === 0) {
  75. continue;
  76. }
  77. if (messageData.cdTime === 0) {
  78. hiddenIndexArr.push(i);
  79. }
  80. }
  81. if (hiddenIndexArr.length > 0) {
  82. for (let i = 0; i < hiddenIndexArr.length; ++ i) {
  83. this.hiddenItem(hiddenIndexArr[i]);
  84. }
  85. }
  86. // count 已经免费升级总部大楼的次数
  87. // maxCount 免费设计总部大头的最大次数
  88. // cdTime
  89. /// 看视频分享免费获取的cd时间
  90. if (Global._upBuildingInfo == undefined) {
  91. return;
  92. }
  93. let buildingCount = Global._upBuildingInfo.maxCount - Global._upBuildingInfo.count;
  94. if (Global._upBuildingInfo.cdTime > 0 && buildingCount > 0) {
  95. Global._upBuildingInfo.cdTime -= 1000;
  96. if (Global._upBuildingInfo.cdTime <= 0) {
  97. // GameEvent.fire(GameNotificationKey.AdBuildingStateUpdate);
  98. }
  99. }
  100. let upRoomCount = Global._upRoomInfo.maxCount - Global._upRoomInfo.count;
  101. if (Global._upRoomInfo.cdTime > 0 && upRoomCount > 0) {
  102. Global._upRoomInfo.cdTime -= 1000;
  103. if (Global._upRoomInfo.cdTime <= 0) {
  104. GameEvent.fire(GameNotificationKey.AdRoomStateUpdate);
  105. }
  106. }
  107. let starCount = Global._buyStarInfo.maxCount - Global._buyStarInfo.count;
  108. if (Global._buyStarInfo.cdTime > 0 && starCount > 0) {
  109. Global._buyStarInfo.cdTime -= 1000;
  110. if (Global._buyStarInfo.cdTime <= 0) {
  111. GameEvent.fire(GameNotificationKey.AdStarStateUpdate);
  112. }
  113. }
  114. },
  115. hiddenItem(index) {
  116. if (index < this._items.length) {
  117. let item = this._items[index];
  118. let fadeAction = cc.fadeTo(0.5, 0); //0.5秒透明度从255降到0
  119. let action = cc.sequence(fadeAction, cc.callFunc(() => {
  120. this.deleteItem(index);
  121. }));
  122. item.runAction(action);
  123. }
  124. },
  125. deleteItem(index) {
  126. if (index < this._items.length) {
  127. let item = this._items[index];
  128. item.active = false;
  129. this._items.splice(index, 1);
  130. item.destroy();
  131. item = null;
  132. this._itemsData.splice(index, 1);
  133. if (index < Global._timeInformations.length) {
  134. Global._timeInformations.splice(index, 1);
  135. } else {
  136. Global._fixInformations.splice(index - Global._timeInformations.length - 1, 1);
  137. }
  138. }
  139. },
  140. start () {
  141. },
  142. // update (dt) {},
  143. });