9fb43611-00ba-4ec4-9be2-40e39ada30e5.js 8.02 KB
"use strict";
cc._RF.push(module, '9fb43YRALpOxJviQOOa2jDl', 'UISign');
// scripts/ui/uiView/UISign.ts

"use strict";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var SaveDataManager_1 = require("../../component/SaveDataManager");
var Global_1 = require("../../Global");
var BattleConst_1 = require("../../kernel/battle/BattleConst");
var TableDefine_1 = require("../../kernel/table/TableDefine");
var SignItem_1 = require("../../prefabs/SignItem");
var UIBase_1 = require("../UIBase");
var UIManager_1 = require("../UIManager");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var UISign = /** @class */ (function (_super) {
    __extends(UISign, _super);
    function UISign() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        // private _itemList: SignItem[] = [];
        _this.btn_ad = null;
        _this.adNode = null;
        _this.btn_start = null;
        _this.btn_bonus = null;
        _this.openCount = 0;
        return _this;
    }
    UISign.prototype.onLoad = function () {
        // SaveDataManager.ins.runtimeData.loginRewardData.freshTime = 0;
    };
    UISign.prototype.onEnable = function () {
        this.refresh();
        this.btn_ad.active = true;
        // this.adNode.getComponent(CustomNativeAdView).showNativeAd((result) => {
        //     if (result) {
        //         this.btn_ad.active = true;
        //     } else {
        //         this.btn_ad.active = false;
        //     }
        // });
        this.btn_ad.getChildByName('Background').getChildByName('UI_General_Btn_yellow_ckgg').active = true;
        this.btn_ad.getChildByName('Background').getChildByName('UI_Finish_kxsx').active = false;
        this.openCount++;
        if (this.openCount > 1) {
            this.BtnPos_Change();
        }
    };
    //按钮位置轮换
    UISign.prototype.BtnPos_Change = function () {
        var tempPos = this.btn_start.position;
        this.btn_start.position = this.btn_bonus.position;
        this.btn_bonus.position = this.btn_ad.position;
        this.btn_ad.position = tempPos;
    };
    UISign.prototype.onDisable = function () {
        var tip = cc.find('main/tips', this.node);
        cc.Tween.stopAllByTarget(tip);
        tip.active = false;
    };
    UISign.prototype.hide_btn_ad = function () {
        this.btn_ad.active = false;
    };
    UISign.prototype.refresh = function () {
        var num = cc.find('main/container', this.node).children.length;
        var now = SaveDataManager_1.SaveDataManager.ins.getNowTime();
        var valid = (now >= SaveDataManager_1.SaveDataManager.ins.runtimeData.loginRewardData.freshTime);
        // valid = true;
        if (valid && SaveDataManager_1.SaveDataManager.ins.runtimeData.loginRewardData.step >= 7) {
            SaveDataManager_1.SaveDataManager.ins.runtimeData.loginRewardData.step = 0;
            SaveDataManager_1.SaveDataManager.ins.saveData();
        }
        for (var i = 0; i < num; ++i) {
            var item = (cc.find('main/container/SignItem' + (i + 1).toString(), this.node).getComponent(SignItem_1.default));
            item.setDay(i + 1);
            item.setLock(i + 1 <= SaveDataManager_1.SaveDataManager.ins.runtimeData.loginRewardData.step);
            item.setCurrent(i - SaveDataManager_1.SaveDataManager.ins.runtimeData.loginRewardData.step == 0);
        }
        // cc.find('main/btnDouble', this.node).getComponent(cc.Button).interactable = valid;
        // cc.find('main/btnGet', this.node).getComponent(cc.Button).interactable = valid; 
    };
    UISign.prototype.onCloseClick = function () {
        UIManager_1.UIManager.ins.closeWindow(Global_1.WindowName.SIGN);
    };
    UISign.prototype.onDoubleClick = function () {
        var now = SaveDataManager_1.SaveDataManager.ins.getNowTime();
        var valid = (now >= SaveDataManager_1.SaveDataManager.ins.runtimeData.loginRewardData.freshTime);
        if (valid) {
            //AD 放完广告调 get(2)
            // HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => {
            if (true) {
                this.get(2);
            }
            else {
                console.log('视频播放失败');
            }
            // });
        }
        else {
            this.showTip();
        }
    };
    UISign.prototype.onAdClick = function () {
        //AD 纯放广告
    };
    UISign.prototype.onGetClick = function () {
        var now = SaveDataManager_1.SaveDataManager.ins.getNowTime();
        var valid = (now >= SaveDataManager_1.SaveDataManager.ins.runtimeData.loginRewardData.freshTime);
        if (valid) {
            this.get(1);
        }
        else {
            this.showTip();
        }
    };
    UISign.prototype.get = function (rate) {
        if (rate === void 0) { rate = 1; }
        var cur = SaveDataManager_1.SaveDataManager.ins.runtimeData.loginRewardData.step;
        var config = Global_1.tMgr.getConfig(TableDefine_1.TableName.SIGN, cur + 1);
        if (config.Type == 1) {
            SaveDataManager_1.SaveDataManager.ins.adjustDiamond(config.Num * rate, true);
        }
        else if (config.Type == 2) {
            SaveDataManager_1.SaveDataManager.ins.setUserSkillNumDelta(BattleConst_1.UserSkill.BOMB, config.Num * rate);
        }
        else if (config.Type == 3) {
            // SaveDataManager.ins.setUserSkillNumDelta(UserSkill.SHURIKEN, config.Num * rate);
            SaveDataManager_1.SaveDataManager.ins.unlockBallSkin(2);
        }
        SaveDataManager_1.SaveDataManager.ins.runtimeData.loginRewardData.step++;
        var endTime = new Date();
        endTime.setHours(23, 59, 59);
        SaveDataManager_1.SaveDataManager.ins.runtimeData.loginRewardData.freshTime = endTime.getTime();
        SaveDataManager_1.SaveDataManager.ins.saveData();
        this.refresh();
    };
    UISign.prototype.showTip = function () {
        var tip = cc.find('main/tips', this.node);
        tip.active = true;
        tip.scale = 0;
        cc.Tween.stopAllByTarget(tip);
        cc.tween(tip).to(0.3, { scale: 1 }, { easing: 'backOut' }).delay(2).to(0.3, { scale: 0 }, { easing: 'backIn' }).call(function () { tip.active = false; }).start();
    };
    __decorate([
        property(cc.Node)
    ], UISign.prototype, "btn_ad", void 0);
    __decorate([
        property(cc.Node)
    ], UISign.prototype, "adNode", void 0);
    __decorate([
        property(cc.Node)
    ], UISign.prototype, "btn_start", void 0);
    __decorate([
        property(cc.Node)
    ], UISign.prototype, "btn_bonus", void 0);
    UISign = __decorate([
        ccclass
    ], UISign);
    return UISign;
}(UIBase_1.UIBase));
exports.default = UISign;

cc._RF.pop();