commAlert.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const DWTool = require("../utils/DWTool");
  2. const GameModule = require("../utils/GameModule");
  3. const ArtistManager = require('../utils/ArtistManager');
  4. const {GameNotificationKey, WechatShareType} = require('../utils/GameEnum');
  5. const WeChat = require('../net/WeChat');
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. iconSprite: cc.Sprite,
  10. titleRichText: cc.RichText,
  11. descRichText: cc.RichText,
  12. sureRichText: cc.RichText,
  13. sureButton: cc.Button,
  14. closeButton: cc.Node,
  15. /// 增加钻石的
  16. diamond: 0,
  17. },
  18. // LIFE-CYCLE CALLBACKS:
  19. // onLoad () {},
  20. initBuyStar(imageId, desc, title, isRichText = false) {
  21. ArtistManager.loadStarAvatarSpriteFrame(imageId, this.iconSprite);
  22. if (isRichText) {
  23. this.descRichText.string = desc;
  24. } else {
  25. this.descRichText.string = `<color=#540904>${desc}</color>`;
  26. }
  27. this.closeButton.active = true;
  28. this.titleRichText.string = `<b><color=#540904>${title}</c></b>`;
  29. this.sureRichText.string = `<b><color=#ffffff>炫耀</c></b>`;
  30. this._isBuyStar = true;
  31. },
  32. init(iconPath, desc, title, isRichText = false) {
  33. DWTool.loadResSpriteFrame(iconPath)
  34. .then((spriteFrame) => {
  35. this.iconSprite.spriteFrame = spriteFrame;
  36. }).catch((err) => {
  37. console.log(err);
  38. });
  39. if (isRichText) {
  40. this.descRichText.string = desc;
  41. } else {
  42. this.descRichText.string = `<color=#540904>${desc}</color>`;
  43. }
  44. this.titleRichText.string = `<b><color=#540904>${title}</c></b>`;
  45. this._isBuyStar = false;
  46. },
  47. /// 初始化上次
  48. initAddDiamond(iconPath, desc, title, diamond) {
  49. this.diamond = diamond;
  50. this.init(iconPath, desc, title);
  51. },
  52. start () {
  53. },
  54. //// 只有购买明星才有关闭按钮
  55. closeAction() {
  56. GameEvent.fire('commAlert_BuyStar_hidden');
  57. this.node.destroy();
  58. },
  59. sureAction() {
  60. if (this.diamond > 0) {
  61. GameModule.userInfo.diamond += this.diamond;
  62. }
  63. GameModule.audioMng.playClickButton();
  64. if (this._isBuyStar) {
  65. this.sureButton.interactable = false;
  66. GameEvent.on(GameNotificationKey.ShowShareAction, this, (type, isOk) => {
  67. if (type != WechatShareType.buyStar) { return; }
  68. if (isOk) {
  69. GameEvent.fire('commAlert_BuyStar_hidden');
  70. this.node.destroy();
  71. } else {
  72. this.sureButton.interactable = true;
  73. }
  74. GameEvent.off(GameNotificationKey.ShowShareAction, this);
  75. });
  76. WeChat.shareAction(WechatShareType.buyStar, () => {
  77. }, () => {
  78. this.sureButton.interactable = true;
  79. console.log('分享失败或取消');
  80. });
  81. } else {
  82. GameEvent.fire('commAlert_hidden');
  83. this.node.destroy();
  84. }
  85. }
  86. // update (dt) {},
  87. });