68ff49aa-71ab-4ac8-a93d-60ba9a90b9c4.js 8.35 KB
"use strict";
cc._RF.push(module, '68ff4mqcatKyKk9YLqakLnE', 'UILevelPreview');
// scripts/ui/uiView/UILevelPreview.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 GuideManager_1 = require("../../component/GuideManager");
var SaveDataManager_1 = require("../../component/SaveDataManager");
var Global_1 = require("../../Global");
var MapManager_1 = require("../../kernel/battle/map/MapManager");
var TableDefine_1 = require("../../kernel/table/TableDefine");
var UIBase_1 = require("../UIBase");
var UIManager_1 = require("../UIManager");
var UITitleData_1 = require("./UITitleData");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var UILevelPreview = /** @class */ (function (_super) {
    __extends(UILevelPreview, _super);
    function UILevelPreview() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.btn_ad = null;
        _this.btn_start = null;
        _this.btn_bonus = null;
        //#region  LIFE-CYCLE CALLBACKS:
        _this.openCount = 0;
        return _this;
        //#endregion
    }
    UILevelPreview.prototype.onLoad = function () {
        this._txtLevel = this.node.getChildByName('titleNode').getComponentInChildren(cc.Label);
    };
    // start() {
    // }
    // update (dt) {}
    UILevelPreview.prototype.onEnable = function () {
        var container = this.node.getChildByName('containerBack').getChildByName('container').getChildByName('view').getChildByName('content');
        container.destroyAllChildren();
        var levelId = this.enableParam;
        this._txtLevel.string = (levelId).toString();
        var mapUrl = levelId == 0 ? 'test1' : 'map-' + levelId.toString();
        MapManager_1.MapManager.ins.loadMap(mapUrl, this.onMapLoaded, this);
        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();
        }
    };
    //按钮位置轮换
    UILevelPreview.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;
    };
    UILevelPreview.prototype.onPopUpEffectFinish = function () {
        var levelId = this.enableParam;
        if (levelId == 1 && SaveDataManager_1.SaveDataManager.ins.runtimeData.guideStep == 1) {
            var wpos = this.node.getChildByName('btnStart').convertToWorldSpaceAR(cc.v2(0, -60));
            GuideManager_1.GuideManager.ins.showHand(wpos, false);
            wpos = this.node.getChildByName('btnStart').convertToWorldSpaceAR(cc.v2(0, 80));
            GuideManager_1.GuideManager.ins.showTalk(wpos, Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 27).Comment);
        }
    };
    UILevelPreview.prototype.onDisable = function () {
        var container = this.node.getChildByName('containerBack').getChildByName('container').getChildByName('view').getChildByName('content');
        container.destroyAllChildren();
        GuideManager_1.GuideManager.ins.hideHand();
        GuideManager_1.GuideManager.ins.hideTalk();
    };
    //#endregion
    //#region public method
    //#endregion
    //#region event
    UILevelPreview.prototype.onBtnCloseClick = function () {
        this._useCloseEffect = true;
        this.leave();
    };
    UILevelPreview.prototype.onStartBattleClick = function () {
        this._useCloseEffect = false; //当进入战斗时,不使用关闭特效,否则异步后才会调用此界面的销毁接口,而此时地图正在创建,容易造成animation出错
        this.go();
    };
    UILevelPreview.prototype.onBonusClick = function () {
        this._useCloseEffect = false; //当进入战斗时,不使用关闭特效,否则异步后才会调用此界面的销毁接口,而此时地图正在创建,容易造成animation出错
        //AD 放广告 放完后调go(true)
        // HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => {
        if (true) {
            this.go(true);
        }
        else {
            console.log('视频播放失败');
        }
        // })
    };
    UILevelPreview.prototype.onAdClick = function () {
        //AD 纯放广告
    };
    //#endregion
    //#region private method
    UILevelPreview.prototype.onMapLoaded = function (data) {
        if (data.levelId == this.enableParam) {
            var view = MapManager_1.MapManager.ins.renderMap(data, this.node.getChildByName('battlePrefab'), true);
            var content = this.node.getChildByName('containerBack').getChildByName('container').getChildByName('view').getChildByName('content');
            var scaleX = content.width / view.width;
            view.setScale(scaleX, scaleX);
            var contentHeight = (data.maxContentY + 1) * data.gridSize.y;
            var blankHeight = (data.mapGridSize.y - data.maxContentY - 1) * data.gridSize.y;
            view.setPosition(0, (-blankHeight + data.gridSize.y) * scaleX / 2);
            // view.setPosition(0,)
            // content.height = contentHeight * scaleX;
            content.setContentSize(content.width, contentHeight * scaleX);
            content.addChild(view);
            this.node.getChildByName('containerBack').getChildByName('container').getComponent(cc.ScrollView).scrollTo(cc.v2(0.5, 0));
        }
    };
    UILevelPreview.prototype.leave = function () {
        UIManager_1.UIManager.ins.closeWindow(Global_1.WindowName.PREVIEW);
    };
    UILevelPreview.prototype.go = function (bonus) {
        if (bonus === void 0) { bonus = false; }
        this.leave();
        var levelId = this.enableParam;
        if (SaveDataManager_1.SaveDataManager.ins.runtimeData.guideStep == 1) {
            //忽略关卡数,否则老玩家会卡住
            SaveDataManager_1.SaveDataManager.ins.runtimeData.guideStep++;
            SaveDataManager_1.SaveDataManager.ins.saveData();
        }
        UITitleData_1.UITitleData.isBattleBonus = bonus;
        // let levelId = this.enableParam as number;
        // let introConfig = IntroTableMgr.ins.getTableByLevel(levelId);
        // if (introConfig) {
        //     //需要弹提示
        //     UIManager.ins.openWindow(WindowName.INTRO, levelId);
        // }
        // else {
        UIManager_1.UIManager.ins.openScene('Battle');
        // }
    };
    __decorate([
        property(cc.Node)
    ], UILevelPreview.prototype, "btn_ad", void 0);
    __decorate([
        property(cc.Node)
    ], UILevelPreview.prototype, "btn_start", void 0);
    __decorate([
        property(cc.Node)
    ], UILevelPreview.prototype, "btn_bonus", void 0);
    UILevelPreview = __decorate([
        ccclass
    ], UILevelPreview);
    return UILevelPreview;
}(UIBase_1.UIBase));
exports.default = UILevelPreview;

cc._RF.pop();