MessageItem.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. let iconPath = './textures/messageList/' + messageData.icon;
  16. this._messageData = messageData;
  17. DWTool.loadResSpriteFrame(iconPath)
  18. .then((spriteFrame) => {
  19. this.iconSprite.spriteFrame = spriteFrame;
  20. }).catch((err) => {
  21. console.log(err);
  22. });
  23. /// 如果cdTime为0那么就是一直存在的 并且是技能的话
  24. // this._isFix = 0;
  25. // if (messageData.type === 2) {
  26. // this._isFix = messageData.skillStatus === 0;
  27. // }
  28. if (this._messageData.type === 2 && this._messageData.skillStatus === 0) {
  29. this._messageData.infoDesc = `${this._messageData.name}可使用`;
  30. this.titleLabel.string = this._messageData.infoDesc;
  31. } else {
  32. let timeStr = '';
  33. if (messageData.cdTime > 0) {
  34. timeStr = ' -- ' + DWTool.calculateTime(messageData.cdTime / 1000);
  35. }
  36. let infoDesc = this._messageData.infoDesc;
  37. //// 是技能 而且不是第二个技能 并且包含num 如果是本地构建的 那么是没有{num}的
  38. if (this._messageData.type === 2 && this._messageData.sId != 2 && infoDesc.indexOf('{num}') != -1) {
  39. let skillLevel = this._messageData.level;
  40. let skillId = this._messageData.sId;
  41. let skillLevelInfo = Global.BuildingManager.getSkillLevelInfo(skillId, skillLevel);
  42. /// 第一个技能
  43. if (skillId === 1) {
  44. let num = skillLevel > 11 ? (10 + skillLevel - 11) : 10;
  45. infoDesc = infoDesc.replace('{num}', num);
  46. /// 第三个技能
  47. } else {
  48. infoDesc = infoDesc.replace('${num}', skillLevelInfo.mt * 100);
  49. }
  50. this._messageData.infoDesc = infoDesc;
  51. }
  52. this.titleLabel.string = messageData.infoDesc + timeStr;
  53. }
  54. },
  55. updateTime() {
  56. /// 如果是技能 并且可以用的话 那么直接就不更新了
  57. if (this._messageData.type === 2 && this._messageData.skillStatus === 0) {
  58. this.titleLabel.string = this._messageData.infoDesc;
  59. } else {
  60. if (this._messageData.cdTime > 0) {
  61. this._messageData.cdTime -= 1000;
  62. if (this._messageData.cdTime < 0) {
  63. this._messageData.cdTime = 0;
  64. }
  65. let timeStr = '';
  66. if (this._messageData.cdTime > 0) {
  67. timeStr = ' -- ' + DWTool.calculateTime(this._messageData.cdTime / 1000);
  68. }
  69. this.titleLabel.string = this._messageData.infoDesc + timeStr;
  70. } else if (this._messageData.cdTime < 0) {
  71. this._messageData.cdTime += 1000;
  72. if (this._messageData.cdTime > 0) {
  73. this._messageData.cdTime = 0;
  74. }
  75. this.titleLabel.string = this._messageData.infoDesc;
  76. }
  77. }
  78. },
  79. onDestroy() {
  80. console.log("释放一个信息流item");
  81. },
  82. // LIFE-CYCLE CALLBACKS:
  83. // onLoad () {},
  84. start () {
  85. },
  86. // update (dt) {},
  87. });