// 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 import { GuideManager } from "../../component/GuideManager"; import { SaveDataManager } from "../../component/SaveDataManager"; import { ADID, tMgr, WindowName } from "../../Global"; import { MapData } from "../../kernel/battle/map/MapData"; import { MapManager } from "../../kernel/battle/map/MapManager"; import { GamePlayTable, TableName } from "../../kernel/table/TableDefine"; import { UIBase } from "../UIBase"; import { UIManager } from "../UIManager"; import { UITitleData } from "./UITitleData"; const { ccclass, property } = cc._decorator; @ccclass export default class UILevelPreview extends UIBase { private _txtLevel: cc.Label; @property(cc.Node) btn_ad: cc.Node = null; @property(cc.Node) btn_start: cc.Node = null; @property(cc.Node) btn_bonus: cc.Node = null; //#region LIFE-CYCLE CALLBACKS: openCount: number = 0; onLoad() { this._txtLevel = this.node.getChildByName('titleNode').getComponentInChildren(cc.Label); } // start() { // } // update (dt) {} protected onEnable(): void { let container = this.node.getChildByName('containerBack').getChildByName('container').getChildByName('view').getChildByName('content'); container.destroyAllChildren(); let levelId = this.enableParam as number; this._txtLevel.string = (levelId).toString(); let mapUrl = levelId == 0 ? 'test1' : 'map-' + levelId.toString(); 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(); } } //按钮位置轮换 BtnPos_Change() { let 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; } protected onPopUpEffectFinish(): void { let levelId = this.enableParam as number; if (levelId == 1 && SaveDataManager.ins.runtimeData.guideStep == 1) { let wpos = this.node.getChildByName('btnStart').convertToWorldSpaceAR(cc.v2(0, -60)); GuideManager.ins.showHand(wpos, false); wpos = this.node.getChildByName('btnStart').convertToWorldSpaceAR(cc.v2(0, 80)); GuideManager.ins.showTalk(wpos, (tMgr.getConfig(TableName.GAME_PLAY, 27) as GamePlayTable).Comment); } } protected onDisable(): void { let container = this.node.getChildByName('containerBack').getChildByName('container').getChildByName('view').getChildByName('content'); container.destroyAllChildren(); GuideManager.ins.hideHand(); GuideManager.ins.hideTalk(); } //#endregion //#region public method //#endregion //#region event onBtnCloseClick() { this._useCloseEffect = true; this.leave(); } onStartBattleClick() { this._useCloseEffect = false; //当进入战斗时,不使用关闭特效,否则异步后才会调用此界面的销毁接口,而此时地图正在创建,容易造成animation出错 this.go(); } onBonusClick() { this._useCloseEffect = false; //当进入战斗时,不使用关闭特效,否则异步后才会调用此界面的销毁接口,而此时地图正在创建,容易造成animation出错 //AD 放广告 放完后调go(true) // HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => { if (true) { this.go(true); } else { console.log('视频播放失败'); } // }) } onAdClick() { //AD 纯放广告 } //#endregion //#region private method onMapLoaded(data: MapData) { if (data.levelId == this.enableParam) { let view = MapManager.ins.renderMap(data, this.node.getChildByName('battlePrefab'), true); let content = this.node.getChildByName('containerBack').getChildByName('container').getChildByName('view').getChildByName('content'); let scaleX = content.width / view.width; view.setScale(scaleX, scaleX); let contentHeight = (data.maxContentY + 1) * data.gridSize.y; let 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)); } } private leave() { UIManager.ins.closeWindow(WindowName.PREVIEW); } private go(bonus: boolean = false) { this.leave(); let levelId = this.enableParam as number; if (SaveDataManager.ins.runtimeData.guideStep == 1) { //忽略关卡数,否则老玩家会卡住 SaveDataManager.ins.runtimeData.guideStep++; SaveDataManager.ins.saveData(); } 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.ins.openScene('Battle'); // } } //#endregion }