DrawStarSuccss.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const DrawApi = require("../net/DrawApi");
  2. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  3. const GameModule = require("../utils/GameModule");
  4. const DWTool = require("../utils/DWTool");
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. starNameLabel: cc.Label,
  9. bottomTitleLabel: cc.Label,
  10. starNode: cc.Node,
  11. againButton: cc.Button,
  12. againRichText: cc.RichText,
  13. againSprite: cc.Sprite,
  14. },
  15. // LIFE-CYCLE CALLBACKS:
  16. onLoad () {
  17. },
  18. start () {
  19. },
  20. init(drawData, typeId, backGroudId) {
  21. this.typeId = typeId;
  22. this.drawData = drawData;
  23. this.starNameLabel.string = '获得 ' + drawData.propName;
  24. this.bottomTitleLabel.string = drawData.propName + '加入你的明星图集';
  25. this.starNode.getComponent("DrawStarContent").init(backGroudId, drawData.propId);
  26. if (this.typeId == 1) {
  27. this._diamond = this.drawData.diamond1;
  28. } else if (this.typeId == 2) {
  29. this._diamond = this.drawData.diamond2;
  30. } else {
  31. this._diamond = this.drawData.diamond3;
  32. }
  33. this.againRichText.string = `<img src='skill_diamond'/><b><color=#ffffff> ${this._diamond}</c></b>`;
  34. ////发通知 已经获取明星
  35. GameEvent.fire(GameNotificationKey.StarEnterRoom, this.drawData.propId, this.drawData.roomId);
  36. console.log(`抽奖获得明星 starid${this.drawData.propId} roomid${this.drawData.roomId}`);
  37. if (GameModule.userInfo.diamond < this._diamond) {
  38. this.setUpUseBtnBg(false);
  39. }
  40. },
  41. /// 设置签约的button是否能点击 type 123
  42. setUpUseBtnBg(isActive) {
  43. let path = isActive ? './textures/draw/draw_green_btn_bg' : './textures/draw/draw_gray_btn_bg';
  44. this.againButton.interactable = isActive;
  45. DWTool.loadResSpriteFrame(path)
  46. .then((spriteFrame) => {
  47. this.againSprite.spriteFrame = spriteFrame;
  48. });
  49. },
  50. dismissAction () {
  51. GameModule.audioMng.playClickButton();
  52. this.node.destroy();
  53. GameEvent.fire("draw_done_action");
  54. },
  55. scrollAgainAction() {
  56. GameModule.audioMng.playClickButton();
  57. this.againButton.interactable = false
  58. this.startDrawRequest(this.typeId).then((respondData) => {
  59. this.againButton.interactable = true;
  60. GameModule.userInfo.diamond -= this._diamond;
  61. this.node.destroy();
  62. GameEvent.fire("draw_again", respondData);
  63. }).catch(({code, msg}) => {
  64. this.againButton.interactable = true;
  65. cc.log(code, msg);
  66. });
  67. },
  68. startDrawRequest(typeId) {
  69. return new Promise((resolve, reject) => {
  70. ///开始抽奖
  71. DrawApi.startLottery(typeId, 1, (respondData) => {
  72. resolve(respondData);
  73. }, (code, msg) => {
  74. reject({code, msg});
  75. });
  76. })
  77. },
  78. // update (dt) {},
  79. });