commAlert.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const DWTool = require("../utils/DWTool");
  2. const GameModule = require("../utils/GameModule");
  3. const ArtistManager = require('../utils/ArtistManager');
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. iconSprite: cc.Sprite,
  8. titleRichText: cc.RichText,
  9. descRichText: cc.RichText,
  10. },
  11. // LIFE-CYCLE CALLBACKS:
  12. // onLoad () {},
  13. initBuyStar(imageId, desc, title, isRichText = false) {
  14. ArtistManager.loadStarAvatarSpriteFrame(imageId, this.iconSprite);
  15. if (isRichText) {
  16. this.descRichText.string = desc;
  17. } else {
  18. this.descRichText.string = `<color=#540904>${desc}</color>`;
  19. }
  20. this.titleRichText.string = `<b><color=#540904>${title}</c></b>`;
  21. this._isBuyStar = true;
  22. },
  23. init(iconPath, desc, title, isRichText = false) {
  24. DWTool.loadResSpriteFrame(iconPath)
  25. .then((spriteFrame) => {
  26. this.iconSprite.spriteFrame = spriteFrame;
  27. }).catch((err) => {
  28. console.log(err);
  29. });
  30. if (isRichText) {
  31. this.descRichText.string = desc;
  32. } else {
  33. this.descRichText.string = `<color=#540904>${desc}</color>`;
  34. }
  35. this.titleRichText.string = `<b><color=#540904>${title}</c></b>`;
  36. this._isBuyStar = false;
  37. },
  38. start () {
  39. },
  40. sureAction() {
  41. GameModule.audioMng.playClickButton();
  42. let notificationStr = this._isBuyStar ? 'commAlert_BuyStar_hidden' : 'commAlert_hidden';
  43. GameEvent.fire(notificationStr);
  44. this.node.destroy();
  45. }
  46. // update (dt) {},
  47. });