commAlert.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /// 初始化上次
  39. initAddDiamond(iconPath, desc, title, diamond) {
  40. this.diamond = diamond;
  41. this.init(iconPath, desc, title);
  42. },
  43. start () {
  44. },
  45. sureAction() {
  46. if (this.diamond > 0) {
  47. GameModule.userInfo.diamond += this.diamond;
  48. }
  49. GameModule.audioMng.playClickButton();
  50. let notificationStr = this._isBuyStar ? 'commAlert_BuyStar_hidden' : 'commAlert_hidden';
  51. GameEvent.fire(notificationStr);
  52. this.node.destroy();
  53. }
  54. // update (dt) {},
  55. });