MessageItem.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. const DWTool = require("../utils/DWTool");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. titleLabel: cc.Label,
  6. iconSprite: cc.Sprite,
  7. },
  8. // cdTime 剩余时间 是 [long] 查看
  9. // 5 desc 描述 是 [string] 查看
  10. // 6 name 名称 是 [string] 查看
  11. // 7 sId 业务ID 如果是商品就是商品ID 如果是技能就是技能id 是 [string] 查看
  12. // 8 type 类别 1商品 2技能
  13. // level 技能等级
  14. init(messageData) {
  15. if (messageData.type === 3) {
  16. messageData.icon = 900013;
  17. }
  18. let iconPath = './textures/messageList/' + messageData.icon;
  19. this._messageData = messageData;
  20. DWTool.loadResSpriteFrame(iconPath)
  21. .then((spriteFrame) => {
  22. this.iconSprite.spriteFrame = spriteFrame;
  23. }).catch((err) => {
  24. console.log(err);
  25. });
  26. /// 如果cdTime为0那么就是一直存在的 并且是技能的话
  27. // this._isFix = 0;
  28. // if (messageData.type === 2) {
  29. // this._isFix = messageData.skillStatus === 0;
  30. // }
  31. if (messageData.type === 2 && messageData.skillStatus === 0) {
  32. this._messageData.infoDesc = `${messageData.name}可使用`;
  33. this.titleLabel.string = this._messageData.infoDesc;
  34. /// 不是好友助手
  35. } else if (messageData.type !== 3) {
  36. let timeStr = '';
  37. if (messageData.cdTime > 0) {
  38. timeStr = ' -- ' + DWTool.calculateTime(messageData.cdTime / 1000);
  39. }
  40. let infoDesc = this._messageData.infoDesc;
  41. //// 是技能 而且不是第二个技能 并且包含num 如果是本地构建的 那么是没有{num}的
  42. if (this._messageData.type === 2 && this._messageData.sId != 2 && infoDesc.indexOf('{num}') != -1) {
  43. let skillLevel = this._messageData.level;
  44. let skillId = this._messageData.sId;
  45. let skillLevelInfo = GameGlobal.BuildingManager.getSkillLevelInfo(skillId, skillLevel);
  46. /// 第一个技能
  47. if (skillId === 1) {
  48. let num = skillLevel > 11 ? (10 + skillLevel - 11) : 10;
  49. infoDesc = infoDesc.replace('{num}', num);
  50. /// 第三个技能
  51. } else {
  52. infoDesc = infoDesc.replace('${num}', skillLevelInfo.mt * 100);
  53. }
  54. this._messageData.infoDesc = infoDesc;
  55. }
  56. this.titleLabel.string = messageData.infoDesc + timeStr;
  57. /// 如果是好友助手
  58. } else if (messageData.type === 3) {
  59. let timeStr = '';
  60. if (messageData.cdTime > 0) {
  61. timeStr = ' -- ' + DWTool.calculateTime(messageData.cdTime / 1000);
  62. }
  63. this._messageData.infoDesc = '好友助力自动点击';
  64. this.titleLabel.string = this._messageData.infoDesc + timeStr;
  65. }
  66. },
  67. updateTime() {
  68. /// 如果是技能 并且可以用的话 那么直接就不更新了
  69. if (this._messageData.type === 2 && this._messageData.skillStatus === 0) {
  70. this.titleLabel.string = this._messageData.infoDesc;
  71. } else {
  72. if (this._messageData.cdTime > 0) {
  73. this._messageData.cdTime -= 1000;
  74. if (this._messageData.cdTime < 0) {
  75. this._messageData.cdTime = 0;
  76. }
  77. let timeStr = '';
  78. if (this._messageData.cdTime > 0) {
  79. timeStr = ' -- ' + DWTool.calculateTime(this._messageData.cdTime / 1000);
  80. }
  81. this.titleLabel.string = this._messageData.infoDesc + timeStr;
  82. } else if (this._messageData.cdTime < 0) {
  83. this._messageData.cdTime += 1000;
  84. if (this._messageData.cdTime > 0) {
  85. this._messageData.cdTime = 0;
  86. }
  87. this.titleLabel.string = this._messageData.infoDesc;
  88. }
  89. }
  90. },
  91. onDestroy() {
  92. console.log("释放一个信息流item");
  93. },
  94. // LIFE-CYCLE CALLBACKS:
  95. // onLoad () {},
  96. start () {
  97. },
  98. // update (dt) {},
  99. });