123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- const HomeApi = require('../net/HomeApi');
- const DWTool = require("../utils/DWTool");
- const AlertManager = require('../utils/AlertManager');
- const GameModule = require("../utils/GameModule");
- const TapTapTool = require("../utils/TapTapTool");
- const GameRedDot = require('../utils/GameEnum').GameRedDot;
- cc.Class({
- extends: cc.Component,
- properties: {
- /// 领取奖励的按钮
- getButton: cc.Button,
- /// 按钮背景
- getAwardSprite: cc.Sprite,
- },
- // award_get_gray
- // award_get_light
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
-
- },
- setupAwardBtn(isActive) {
- let imgPath = isActive ? './textures/dayAward/award_get_light' : './textures/dayAward/award_get_gray';
- DWTool.loadResSpriteFrame(imgPath)
- .then((spriteFrame) => {
- this.getAwardSprite.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- this.getButton.interactable = isActive;
- },
-
- start () {
- this.getButton.interactable = false;
- HomeApi.getReward( (respondData) => {
- if (respondData.status == 1) {
- this.setupAwardBtn(true);
- } else {
- TapTapTool.removeRedDot(GameRedDot.award);
- }
- }, (code, msg) => {
- console.log(code, msg);
- });
- },
- closeAction() {
- this.node.destroy();
- },
- getAwardAction() {
- this.getButton.interactable = false;
- HomeApi.reward(() => {
- let gold = TapTapTool.multiple(GameModule.userInfo.coinTap, {'n': 5000, 'e': 0});
- let text = TapTapTool.parseToString(gold);
- let showText = `金币 x ${text}`;
- AlertManager.showActGiftAlert('coin', showText);
- GameModule.userInfo.gold = TapTapTool.add(GameModule.userInfo.gold, gold);
- this.setupAwardBtn(false);
- /// 移除红点
- TapTapTool.removeRedDot(GameRedDot.award);
- }, (code, msg) => {
- console.log(msg);
- this.setupAwardBtn(true);
- });
- }
- });
|