84fb8c34-bbd6-40f2-9cad-c86f6c7e60fc.js 9.49 KB
"use strict";
cc._RF.push(module, '84fb8w0u9ZA8pytyG9sfmD8', 'UIWheel');
// scripts/ui/uiView/UIWheel.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 WheelItem_1 = require("../../prefabs/WheelItem");
var UIBase_1 = require("../UIBase");
var UIManager_1 = require("../UIManager");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var UIWheel = /** @class */ (function (_super) {
    __extends(UIWheel, _super);
    function UIWheel() {
        //#region  LIFE-CYCLE CALLBACKS:
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.radius = 1;
        _this.itemPrefab = null;
        _this.adNode = null;
        _this.btn_ad = null;
        _this._tweenObject = { progress: 0 };
        /**权重列表 */
        _this._weightList = [];
        return _this;
        //#endregion
    }
    UIWheel.prototype.start = function () {
        // [3]
        this._wheelNode = cc.find('main/wheel', this.node);
        this.btn_ad.active = true;
        var num = Global_1.tMgr.getTableCount(TableDefine_1.TableName.WHEEL);
        var rad = -2 * Math.PI / num;
        // let deg = slib.MathUtil.getDegreeByRadian(rad);
        var vec = new cc.Vec2(0, this.radius);
        for (var i = 0; i < num; ++i) {
            if (i > 0) {
                vec.rotateSelf(rad);
            }
            var config = Global_1.tMgr.getConfig(TableDefine_1.TableName.WHEEL, i + 1);
            this._weightList.push(config.Rate);
            var foo = cc.instantiate(this.itemPrefab);
            foo.getComponent(WheelItem_1.default).setId(i + 1);
            foo.setPosition(vec.x, vec.y);
            // foo.angle = i * deg;
            foo.scale = 0.7;
            cc.find('main/UI_wheel_zp', this.node).addChild(foo);
        }
        this.refresh();
    };
    UIWheel.prototype.hide_btn_ad = function () {
        this.btn_ad.active = false;
    };
    UIWheel.prototype.onEnable = function () {
        this.refresh();
        this.btn_ad.active = true;
        // this.adNode.getComponent(CustomNativeAdView).showNativeAd((result) => {
        //     if (result == true) {
        //         this.btn_ad.active = true;
        //     } else {
        //         this.btn_ad.active = false;
        //     }
        // });
        this.btn_ad.getChildByName('Background').getChildByName('UI_wheel_btn_ckgg').active = true;
        this.btn_ad.getChildByName('Background').getChildByName('UI_wheel_btn_kxsx').active = false;
    };
    UIWheel.prototype.onDisable = function () {
    };
    UIWheel.prototype.onLoad = function () {
        BattleConst_1.getGlobalNode().on(Global_1.GlobalEvent.WHEEL_REWARD_GET, this.refresh, this);
    };
    UIWheel.prototype.onDestroy = function () {
        BattleConst_1.getGlobalNode().targetOff(this);
    };
    UIWheel.prototype.refresh = function () {
        cc.find('main/UI_wheel_zp/UI_wheel_cjcs', this.node).active = (SaveDataManager_1.SaveDataManager.ins.runtimeData.freeWheelNum > 0);
        cc.find('main/btnGo', this.node).active = (SaveDataManager_1.SaveDataManager.ins.runtimeData.freeWheelNum > 0);
        cc.find('main/btnAdGo', this.node).active = (SaveDataManager_1.SaveDataManager.ins.runtimeData.freeWheelNum <= 0);
        // cc.find('main/btn_kxsx', this.node).active = (SaveDataManager.ins.runtimeData.freeWheelNum <= 0);
        var container = cc.find('main/UI_wheel_zp', this.node);
        for (var i = 0; i < container.childrenCount; ++i) {
            var cmpt = container.children[i].getComponent(WheelItem_1.default);
            cmpt && cmpt.refresh();
        }
    };
    UIWheel.prototype.go = function () {
        var _this = this;
        this._wheelNode.angle = 0;
        var configId = 0;
        // if (SaveDataManager.ins.runtimeData.freeWheelNum) {
        //     //免费的,固定奖励
        //     configId = 1;
        // }
        // else {
        configId = slib.MathUtil.randomTestByWeightList(this._weightList) + 1;
        // }
        this._reward = Global_1.tMgr.getConfig(TableDefine_1.TableName.WHEEL, configId);
        // log('奖品', configId);
        var num = Global_1.tMgr.getTableCount(TableDefine_1.TableName.WHEEL);
        var rad = 2 * Math.PI / num;
        var deg = slib.MathUtil.getDegreeByRadian(rad);
        var total = -6 * 360 + (-deg) * (configId - 1);
        this._tweenObject.progress = 0;
        cc.tween(this._tweenObject).to(5, { progress: 1 }, {
            easing: 'sineOut',
            onUpdate: function (target, ratio) {
                // this._wheelNode.setRotationFromEuler(0, 0, total * ratio);
                _this._wheelNode.angle = total * (target['progress']);
            }
        }).call(this.onTweenComplete.bind(this)).start();
        // SoundManager.ins.playEffect(SOUND_EFFECT.WHEEL);
    };
    UIWheel.prototype.onTweenComplete = function () {
        // log('complete');
        if (SaveDataManager_1.SaveDataManager.ins.runtimeData.freeWheelNum > 0) {
            SaveDataManager_1.SaveDataManager.ins.runtimeData.freeWheelNum--;
        }
        // if (this._reward.Type == 1) {
        //     //钻石
        //     // uiMgr().open('UI/UIGet', { type: 3, num: this._reward.Num });
        // }
        // else if (this._reward.Type == 2) {
        //     //炸弹
        //     // battleMgr().battle.startSkill(2);
        //     // uiMgr().open('UI/UIGet', { type: 2, num: 1 });
        // }
        // else if (this._reward.Type == 3) {
        //     //分裂炮
        //     // uiMgr().open('UI/UIGet', { type: 1, num: 1 });
        //     // battleMgr().battle.startSkill(1);
        // }
        // else if (this._reward.Type == 4) {
        //     //飞轮
        // }
        // else if (this._reward.Type == 5) {
        //     //西瓜球
        // }
        UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.GET, this._reward);
        SaveDataManager_1.SaveDataManager.ins.saveData();
        // console.log('reward', this._reward.ID);
        cc.find('main/btnClose', this.node).getComponent(cc.Button).interactable = true;
        cc.find('main/btnAd', this.node).getComponent(cc.Button).interactable = true;
        cc.find('main/btnAdGo', this.node).getComponent(cc.Button).interactable = true;
        cc.find('main/btnGo', this.node).getComponent(cc.Button).interactable = true;
        this.refresh();
    };
    UIWheel.prototype.onCloseClick = function () {
        UIManager_1.UIManager.ins.closeWindow(Global_1.WindowName.WHEEL);
    };
    UIWheel.prototype.onBtnAdClick = function () {
        //AD 纯放广告
    };
    UIWheel.prototype.onBtnGoClick = function () {
        if (SaveDataManager_1.SaveDataManager.ins.runtimeData.freeWheelNum > 0) {
            //免费次数
            this.go();
        }
        else {
            //AD 放广告,播完后调用 go
            // HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => {
            if (true) {
                this.go();
            }
            else {
                console.log('视频播放失败');
            }
            // });
        }
        cc.find('main/btnClose', this.node).getComponent(cc.Button).interactable = false;
        cc.find('main/btnAd', this.node).getComponent(cc.Button).interactable = false;
        cc.find('main/btnGo', this.node).getComponent(cc.Button).interactable = false;
        cc.find('main/btnAdGo', this.node).getComponent(cc.Button).interactable = false;
    };
    __decorate([
        property(cc.Integer)
    ], UIWheel.prototype, "radius", void 0);
    __decorate([
        property(cc.Prefab)
    ], UIWheel.prototype, "itemPrefab", void 0);
    __decorate([
        property(cc.Node)
    ], UIWheel.prototype, "adNode", void 0);
    __decorate([
        property(cc.Node)
    ], UIWheel.prototype, "btn_ad", void 0);
    UIWheel = __decorate([
        ccclass
    ], UIWheel);
    return UIWheel;
}(UIBase_1.UIBase));
exports.default = UIWheel;

cc._RF.pop();