DrawStarSuccss.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. const lottery = require('../data/lottery');
  7. const TapTapTool = require("../utils/TapTapTool");
  8. cc.Class({
  9. extends: cc.Component,
  10. properties: {
  11. starNameLabel: cc.Label,
  12. bottomTitleLabel: cc.Label,
  13. starNode: cc.Node,
  14. againButton: cc.Button,
  15. againRichText: cc.RichText,
  16. againSprite: cc.Sprite,
  17. },
  18. // LIFE-CYCLE CALLBACKS:
  19. onLoad () {
  20. this._localDrawStarDatas = lottery;
  21. },
  22. start () {
  23. },
  24. // init(drawData, typeId) {
  25. // this.typeId = typeId;
  26. // this.drawData = drawData;
  27. // let drawSuccessData = drawData.drawSuccessData;
  28. // let nameString = '获得';
  29. // let desc = '';
  30. // let starId = -1;
  31. // /// 抽奖获得金币数
  32. // if (drawSuccessData.type == 1) {
  33. // let add = TapTapTool.multiple(GameModule.userInfo.coinTap, drawSuccessData.opt)
  34. // GameModule.userInfo.gold = TapTapTool.add(GameModule.userInfo.gold, add);
  35. // nameString += `金币 ${TapTapTool.parseToString(add)}`;
  36. // /// 如果是抽到了钻石
  37. // } else if (drawSuccessData.type == 2) {
  38. // GameModule.userInfo.diamond += drawSuccessData.opt;
  39. // nameString += `钻石 ${drawSuccessData.opt}`;
  40. // /// 如果是红包
  41. // } else if (drawSuccessData.type == 3) {
  42. // Global.userData.hb += drawSuccessData.hb;
  43. // nameString += ` ${(drawSuccessData.hb / 100).toFixed(3)}元`;
  44. // desc += '红包满十元可提现噢~';
  45. // /// 如果抽中的是明星
  46. // } else if (drawSuccessData.type == 4) {
  47. // let starData = lottery.filter((n) => {
  48. // return n.propId == drawSuccessData.starId;
  49. // })
  50. // nameString = '获得 ' + starData.propName;
  51. // desc = starData.propName + '加入你的明星图集';
  52. // GameModule.userInfo.perpetualClickMt = drawSuccessData.clickMt;
  53. // GameModule.userInfo.perpetualMt = drawSuccessData.mt;
  54. // GameEvent.fire(GameNotificationKey.StarEnterRoom, starData.propId, drawSuccessData.roomId);
  55. // starId = starData.propId;
  56. // }
  57. // this.starNameLabel.string = nameString;
  58. // this.bottomTitleLabel.string = desc;
  59. // let backGroudId = 70000 + typeId;
  60. // this.starNode.getComponent("DrawStarContent").init(backGroudId, starId);
  61. // if (this.typeId == 1) {
  62. // this._diamond = this.drawData.diamond1;
  63. // } else if (this.typeId == 2) {
  64. // this._diamond = this.drawData.diamond2;
  65. // } else {
  66. // this._diamond = this.drawData.diamond3;
  67. // }
  68. // this.againRichText.string = `<img src='skill_diamond'/><b><color=#ffffff> ${this._diamond}</c></b>`;
  69. // ////发通知 已经获取明星
  70. // console.log(`抽奖获得明星 starid${this.drawData.propId} roomid${this.drawData.roomId}`);
  71. // if (GameModule.userInfo.diamond < this._diamond) {
  72. // this.setUpUseBtnBg(false);
  73. // }
  74. // },
  75. init(drawData, typeId, backGroudId) {
  76. this.typeId = typeId;
  77. this.drawData = drawData;
  78. this.starNameLabel.string = '获得 ' + drawData.propName;
  79. this.bottomTitleLabel.string = drawData.propName + '加入你的明星图集';
  80. this.starNode.getComponent("DrawStarContent").init(backGroudId, drawData.propId);
  81. if (this.typeId == 1) {
  82. this._diamond = this.drawData.diamond1;
  83. } else if (this.typeId == 2) {
  84. this._diamond = this.drawData.diamond2;
  85. } else {
  86. this._diamond = this.drawData.diamond3;
  87. }
  88. this.againRichText.string = `<img src='skill_diamond'/><b><color=#ffffff> ${this._diamond}</c></b>`;
  89. ////发通知 已经获取明星
  90. GameEvent.fire(GameNotificationKey.StarEnterRoom, this.drawData.propId, this.drawData.roomId);
  91. console.log(`抽奖获得明星 starid${this.drawData.propId} roomid${this.drawData.roomId}`);
  92. if (GameModule.userInfo.diamond < this._diamond) {
  93. this.setUpUseBtnBg(false);
  94. }
  95. },
  96. /// 设置签约的button是否能点击 type 123
  97. setUpUseBtnBg(isActive) {
  98. let path = isActive ? './textures/draw/draw_green_btn_bg' : './textures/draw/draw_gray_btn_bg';
  99. this.againButton.interactable = isActive;
  100. DWTool.loadResSpriteFrame(path)
  101. .then((spriteFrame) => {
  102. this.againSprite.spriteFrame = spriteFrame;
  103. });
  104. },
  105. dismissAction () {
  106. GameModule.audioMng.playClickButton();
  107. this.node.destroy();
  108. GameEvent.fire("draw_done_action");
  109. },
  110. scrollAgainAction() {
  111. GameModule.audioMng.playClickButton();
  112. this.againButton.interactable = false
  113. this.startDrawRequest(this.typeId).then((respondData) => {
  114. this.againButton.interactable = true;
  115. GameModule.userInfo.diamond -= this._diamond;
  116. this.node.destroy();
  117. GameEvent.fire("draw_again", respondData);
  118. }).catch(({code, msg}) => {
  119. this.againButton.interactable = true;
  120. cc.log(code, msg);
  121. });
  122. },
  123. startDrawRequest(typeId) {
  124. return new Promise((resolve, reject) => {
  125. ///开始抽奖
  126. DrawApi.startLottery(typeId, 1, (respondData) => {
  127. resolve(respondData);
  128. }, (code, msg) => {
  129. reject({code, msg});
  130. });
  131. })
  132. },
  133. // update (dt) {},
  134. });