DrawStarSuccss.js 3.0 KB

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