// 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 { SaveDataManager } from "../../component/SaveDataManager"; import { SoundManager } from "../../component/SoundManager"; import { tMgr, WindowName } from "../../Global"; import { TableName, GamePlayTable } from "../../kernel/table/TableDefine"; import MainScene from "../../scenes/MainScene"; import { UIBase } from "../UIBase"; import { UIManager } from "../UIManager"; import UIBallSkin from "./UIBallSkin"; import UIShop from "./UIShop"; import { UITitleData } from "./UITitleData"; const { ccclass, property } = cc._decorator; @ccclass export default class UITitle extends UIBase { private _ballSkinView: cc.Node = null; private _shopView: cc.Node = null; // LIFE-CYCLE CALLBACKS: onLoad() { this.node.getChildByName('top').getChildByName('btnTemp').active = CC_DEBUG; this.node.getChildByName('bottom').getChildByName('btnTestFight').active = CC_DEBUG; this.node.getChildByName('bottom').getChildByName('txiLevel').active = CC_DEBUG; } start() { } protected onEnable(): void { this.schedule(this.lazyUpdate, 1 / 20); this.lazyUpdate(); } protected onDisable(): void { this.unschedule(this.lazyUpdate); } // update (dt) {} private lazyUpdate() { let maxLevel = (tMgr.getConfig(TableName.GAME_PLAY, 22) as GamePlayTable).Value; let nextLevel = SaveDataManager.ins.runtimeData.curLevel + 1; if (nextLevel > maxLevel) { nextLevel = maxLevel; } this.node.getChildByName('bottom').getChildByName('naviBar').getChildByName('btnLayer').getChildByName('btn3').getComponentInChildren(cc.Label).string = nextLevel.toString(); } //#region events onBtnTempClick() { // UIManager.ins.openScene('Temp'); SaveDataManager.ins.resetData(); SaveDataManager.ins.saveData(); location.reload(); } onBtnFightClick() { let id = Number(this.node.getChildByName('bottom').getChildByName('txiLevel').getComponent(cc.EditBox).string); UITitleData.id = id; // id > 0 ? UIManager.ins.openWindow(WindowName.PREVIEW, UITitleData.id) : UIManager.ins.openScene('Battle'); UIManager.ins.openWindow(WindowName.PREVIEW, UITitleData.id) } onBtnNaviClick(e: cc.Event, indexStr: string) { let index = Number(indexStr); switch (index) { case 1: UIManager.ins.loadWindow(WindowName.SHOP, (view: cc.Node) => { if (this.shopIsShowing == true) return; this.onBallSkinCloseClick();//自动关闭 this.node.getChildByName('middleMask').active = true; if (!this._shopView) { this._shopView = view; } view.active = true; this.shopIsShowing = true; if (!view.parent) { let container = this.node.getChildByName('middle'); let targetY = (1030 / 2 - container.height / 2); //界面底端对齐 container let startY = targetY - 1030; view.setPosition(0, startY); container.addChild(view); cc.tween(view).to(0.3, { position: cc.v3(0, targetY, 0) }, { easing: 'backOut' }).start(); } else { let container = this.node.getChildByName('middle'); let targetY = (1030 / 2 - container.height / 2); //界面底端对齐 container let startY = targetY - 1030; view.setPosition(0, startY); cc.tween(view).to(0.3, { position: cc.v3(0, targetY, 0) }, { easing: 'backOut' }).start(); } view.getComponent(UIShop).setAD(); }); break; case 2: // console.log('抽奖') UIManager.ins.openWindow(WindowName.WHEEL); break; case 99: (e.target as cc.Node).destroy(); this.node.parent.getComponent(MainScene).onGuideClick(); case 3: let maxLevel = (tMgr.getConfig(TableName.GAME_PLAY, 22) as GamePlayTable).Value; let nextLevel = SaveDataManager.ins.runtimeData.curLevel + 1; if (nextLevel > maxLevel) { nextLevel = maxLevel; } UITitleData.id = nextLevel; UIManager.ins.openWindow(WindowName.PREVIEW, UITitleData.id); // UIManager.ins.openScene('Battle'); break; case 4: UIManager.ins.openWindow(WindowName.SIGN); break; case 5: UIManager.ins.loadWindow(WindowName.BALL_SKIN, (view: cc.Node) => { if (this.ballSkinIsShowing == true) return; this.onShopCloseClick();//自动关闭 this.node.getChildByName('middleMask').active = true; if (!this._ballSkinView) { this._ballSkinView = view; } view.active = true; this.ballSkinIsShowing = true; if (!view.parent) { let container = this.node.getChildByName('middle'); let targetY = (1030 / 2 - container.height / 2); //界面底端对齐 container let startY = targetY - 1030; view.setPosition(0, startY); container.addChild(view); cc.tween(view).to(0.3, { position: cc.v3(0, targetY, 0) }, { easing: 'backOut' }).start(); } else { let container = this.node.getChildByName('middle'); let targetY = (1030 / 2 - container.height / 2); //界面底端对齐 container let startY = targetY - 1030; view.setPosition(0, startY); cc.tween(view).to(0.3, { position: cc.v3(0, targetY, 0) }, { easing: 'backOut' }).start(); } view.getComponent(UIBallSkin).setAD(); }); break; default: break; } } onBtnSettingClick() { UIManager.ins.openWindow(WindowName.SETTING); SoundManager.ins.playEffect('Click'); } ballSkinIsShowing: boolean = false; onBallSkinCloseClick() { if (this._ballSkinView && this._ballSkinView.parent) { let container = this.node.getChildByName('middle'); let targetY = (1030 / 2 - container.height / 2) - 1030; cc.Tween.stopAllByTarget(this._ballSkinView); cc.tween(this._ballSkinView).to(0.2, { position: cc.v3(0, targetY, 0) }).call(() => { UIManager.ins.closeWindow(WindowName.BALL_SKIN); this.ballSkinIsShowing = false; }).start(); this.node.getChildByName('middleMask').active = false; } } shopIsShowing: boolean = false; onShopCloseClick() { if (this._shopView && this._shopView.parent) { let container = this.node.getChildByName('middle'); let targetY = (1030 / 2 - container.height / 2) - 1030; cc.Tween.stopAllByTarget(this._shopView); cc.tween(this._shopView).to(0.2, { position: cc.v3(0, targetY, 0) }).call(() => { UIManager.ins.closeWindow(WindowName.SHOP); this.shopIsShowing = false; }).start(); this.node.getChildByName('middleMask').active = false; } } private _levelRankView: cc.Node onLevelRankClick() { // UIManager.ins.openWindow(WindowName.LEVEL_RANK); UIManager.ins.loadWindow(WindowName.LEVEL_RANK, (view: cc.Node) => { this._levelRankView = view; view.active = true; this.node.getChildByName('topWindow').addChild(view); }) } //#endregion }