009ca319-9670-4a94-bc9c-e12880cd6184.js 7.19 KB
"use strict";
cc._RF.push(module, '009caMZlnBKlLyc4SiAzWGE', 'BallSkinItem');
// scripts/prefabs/BallSkinItem.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 UIManager_1 = require("../ui/UIManager");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var BallSkinItem = /** @class */ (function (_super) {
    __extends(BallSkinItem, _super);
    function BallSkinItem() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._config = null;
        return _this;
    }
    BallSkinItem.prototype.onLoad = function () {
        BattleConst_1.getGlobalNode().on(Global_1.GlobalEvent.BALL_SKIN_UNLOCK, this.refreshState, this);
        BattleConst_1.getGlobalNode().on(Global_1.GlobalEvent.BALL_SKIN_USE, this.refreshState, this);
    };
    BallSkinItem.prototype.onDestroy = function () {
        BattleConst_1.getGlobalNode().targetOff(this);
    };
    BallSkinItem.prototype.setBallSkinItem = function (id) {
        var _this = this;
        if (id > 0) {
            var config = Global_1.tMgr.getConfig(TableDefine_1.TableName.BALL_SKIN, id);
            if (config) {
                this._config = config;
                this.node.getChildByName('icon').active = true;
                cc.resources.load('battle/' + config.Img, cc.SpriteFrame, function (error, asset) {
                    if (!error) {
                        _this.node.getChildByName('icon').getComponent(cc.Sprite).spriteFrame = asset;
                    }
                });
            }
        }
        else {
            this.node.getChildByName('icon').active = false;
            this._config = null;
        }
        this.refreshState();
    };
    BallSkinItem.prototype.refreshState = function () {
        var isAd = (this._config == null);
        var isUnlocked = !isAd && SaveDataManager_1.SaveDataManager.ins.runtimeData.ballSkinUnlocked.includes(this._config.ID);
        var isUsing = !isAd && (SaveDataManager_1.SaveDataManager.ins.runtimeData.ballSkinCurrent == this._config.ID);
        this.node.getChildByName('txtName').getComponent(cc.Label).string = (isAd ? "" : this._config.Name);
        //#region 显示尺寸
        this.node.getChildByName('imgSize1').active = (!isAd && this._config.Size == 1);
        this.node.getChildByName('imgSize2').active = (!isAd && this._config.Size == 2);
        this.node.getChildByName('imgSize3').active = (!isAd && this._config.Size == 3);
        //#endregion
        this.node.getChildByName('btnBuy').active = !isAd && !isUnlocked;
        this.node.getChildByName('btnSign').active = !isAd && !isUnlocked;
        this.node.getChildByName('btnWheel').active = !isAd && !isUnlocked;
        this.node.getChildByName('btnUse').active = !isAd && isUnlocked;
        this.node.getChildByName('btnUsing').active = !isAd && isUnlocked;
        this.node.getChildByName('btnAd').active = isAd;
        if (!isAd) {
            if (isUnlocked) {
                //已经解锁了
                this.node.getChildByName('btnUse').active = !isUsing;
                this.node.getChildByName('btnUsing').active = isUsing;
            }
            else {
                //未解锁
                this.node.getChildByName('btnBuy').active = (this._config.Price > 0);
                this.node.getChildByName('btnSign').active = (this._config.Price == -1);
                this.node.getChildByName('btnWheel').active = (this._config.Price == -2);
                if (this._config.Price > 0) {
                    this.node.getChildByName('btnBuy').getComponentInChildren(cc.Label).string = this._config.Price.toString();
                }
            }
        }
        else {
            this.node.getChildByName('btnAd').getChildByName('Background').getChildByName('UI_Skin_btn_cjhd').active = true;
            this.node.getChildByName('btnAd').getChildByName('Background').getChildByName('UI_Finish_kxsx').active = false;
            // this.node.getChildByName('nodeAd').getComponent(CustomNativeAdView).showNativeAd((result) => {
            //     if (result) {
            //         this.node.getChildByName('btnAd').active = true;
            //     } else {
            //         this.node.getChildByName('btnAd').active = false;
            //     }
            // });
        }
    };
    BallSkinItem.prototype.onBtnBuyClick = function () {
        if (this._config) {
            // let wpos = this.node.getChildByName('btnBuy').convertToWorldSpaceAR(cc.v3(0, 0, 0));
            // if (SaveDataManager.ins.adjustDiamond(-this._config.Price, true, wpos)) {
            //     SaveDataManager.ins.unlockBallSkin(this._config.ID);
            // }
            UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.BALL_SKIN_PREVIEW, this._config.ID);
        }
    };
    BallSkinItem.prototype.onHideAdBtn = function () {
        this.node.getChildByName('btnAd').active = false;
    };
    BallSkinItem.prototype.onBtnWheelClick = function () {
        UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.WHEEL);
    };
    BallSkinItem.prototype.onBtnSignClick = function () {
        UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.SIGN);
    };
    BallSkinItem.prototype.onBtnAdClick = function () {
        //AD 纯放广告
    };
    BallSkinItem.prototype.onBtnUseClick = function () {
        if (this._config) {
            SaveDataManager_1.SaveDataManager.ins.useBallSkin(this._config.ID);
        }
    };
    BallSkinItem = __decorate([
        ccclass
    ], BallSkinItem);
    return BallSkinItem;
}(cc.Component));
exports.default = BallSkinItem;

cc._RF.pop();