commAlert.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. diamond: 0,
  12. },
  13. // LIFE-CYCLE CALLBACKS:
  14. // onLoad () {},
  15. initBuyStar(imageId, desc, title, isRichText = false) {
  16. ArtistManager.loadStarAvatarSpriteFrame(imageId, this.iconSprite);
  17. if (isRichText) {
  18. this.descRichText.string = desc;
  19. } else {
  20. this.descRichText.string = `<color=#540904>${desc}</color>`;
  21. }
  22. this.titleRichText.string = `<b><color=#540904>${title}</c></b>`;
  23. this._isBuyStar = true;
  24. },
  25. init(iconPath, desc, title, isRichText = false) {
  26. DWTool.loadResSpriteFrame(iconPath)
  27. .then((spriteFrame) => {
  28. this.iconSprite.spriteFrame = spriteFrame;
  29. }).catch((err) => {
  30. console.log(err);
  31. });
  32. if (isRichText) {
  33. this.descRichText.string = desc;
  34. } else {
  35. this.descRichText.string = `<color=#540904>${desc}</color>`;
  36. }
  37. this.titleRichText.string = `<b><color=#540904>${title}</c></b>`;
  38. this._isBuyStar = false;
  39. },
  40. /// 初始化上次
  41. initAddDiamond(iconPath, desc, title, diamond) {
  42. this.diamond = diamond;
  43. this.init(iconPath, desc, title);
  44. },
  45. start () {
  46. },
  47. sureAction() {
  48. if (this.diamond > 0) {
  49. GameModule.userInfo.diamond += this.diamond;
  50. }
  51. GameModule.audioMng.playClickButton();
  52. let notificationStr = this._isBuyStar ? 'commAlert_BuyStar_hidden' : 'commAlert_hidden';
  53. GameEvent.fire(notificationStr);
  54. this.node.destroy();
  55. }
  56. // update (dt) {},
  57. });