DayAward.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const HomeApi = require('../net/HomeApi');
  2. const DWTool = require("../utils/DWTool");
  3. const AlertManager = require('../utils/AlertManager');
  4. const GameModule = require("../utils/GameModule");
  5. const TapTapTool = require("../utils/TapTapTool");
  6. const GameRedDot = require('../utils/GameEnum').GameRedDot;
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. /// 领取奖励的按钮
  11. getButton: cc.Button,
  12. /// 按钮背景
  13. getAwardSprite: cc.Sprite,
  14. },
  15. // award_get_gray
  16. // award_get_light
  17. // LIFE-CYCLE CALLBACKS:
  18. onLoad () {
  19. },
  20. setupAwardBtn(isActive) {
  21. let imgPath = isActive ? './textures/dayAward/award_get_light' : './textures/dayAward/award_get_gray';
  22. DWTool.loadResSpriteFrame(imgPath)
  23. .then((spriteFrame) => {
  24. this.getAwardSprite.spriteFrame = spriteFrame;
  25. }).catch((err) => {
  26. console.log(err);
  27. });
  28. this.getButton.interactable = isActive;
  29. },
  30. start () {
  31. this.getButton.interactable = false;
  32. HomeApi.getReward( (respondData) => {
  33. if (respondData.status == 1) {
  34. this.setupAwardBtn(true);
  35. } else {
  36. TapTapTool.removeRedDot(GameRedDot.award);
  37. }
  38. }, (code, msg) => {
  39. console.log(code, msg);
  40. });
  41. },
  42. closeAction() {
  43. this.node.destroy();
  44. },
  45. getAwardAction() {
  46. this.getButton.interactable = false;
  47. HomeApi.reward(() => {
  48. let gold = TapTapTool.multiple(GameModule.userInfo.coinTap, {'n': 5000, 'e': 0});
  49. let text = TapTapTool.parseToString(gold);
  50. let showText = `金币 x ${text}`;
  51. AlertManager.showActGiftAlert('coin', showText);
  52. GameModule.userInfo.gold = TapTapTool.add(GameModule.userInfo.gold, gold);
  53. this.setupAwardBtn(false);
  54. /// 移除红点
  55. TapTapTool.removeRedDot(GameRedDot.award);
  56. }, (code, msg) => {
  57. console.log(msg);
  58. this.setupAwardBtn(true);
  59. });
  60. }
  61. });