123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- import { _decorator, EventTouch, Node, Label,Animation, Vec3, EditBox, Tween, tween, easing} from 'cc';
- import List from '../third/List';
- import { Utils } from '../utils/Utils';
- import MsgHints from '../utils/MsgHints';
- import { userIns } from '../data/UserData';
- import { BaseExp } from '../core/base/BaseExp';
- import { autoBind } from '../extend/AutoBind';
- import { Constants } from '../data/Constants';
- import { uiMgr } from '../core/manager/UIManager';
- import { TaskItem } from '../items/item/TaskItem';
- import { stateMgr } from '../core/manager/StateManager';
- import { Game } from '../game/Game';
- import i18n from '../core/i18n/runtime-scripts/LanguageData';
- import { audioMgr } from '../core/manager/AudioManager';
- import { ResUtil } from '../utils/ResUtil';
- const { ccclass, property } = _decorator;
- @ccclass('Main')
- export class Main extends BaseExp {
- @autoBind(EditBox)
- public editBox: EditBox = null!;
- @autoBind({ type: Label, tooltip: "金币文本" })
- public gold_lable: Label;
- @autoBind({ type: Label, tooltip: "钻石文本" })
- public diamond_lable: Label;
- @autoBind({ type: Label, tooltip: "任务描述" })
- public task_des_lable: Label;
- @autoBind({ type: Label, tooltip: "关卡等级" })
- public level_lable: Label;
- @autoBind({ type: List, tooltip: "任务数据" })
- public task_scrollView: List;
- @property({ type: [Node], tooltip: "武器按钮、飞镖按钮、任务列表界面 动画位置节点数组" })
- public animPosArr: Array<Node> = [];
- //所有主要页面
- private sceneNames: Array<string> = [Constants.mainUIs.main];
- //tabBars数组下标
- public _tabBarIndex: number = -1;
- public set tabBarIndex(index: number) {
- this.cutTabBarIndex(null,index);
- }
- public get tabBarIndex(){
- return this._tabBarIndex;
- }
- //保存点击的页面
- private preIndexs: Array<number> = [0];
- //任务数据
- private taskDatas: Array<any> = [];
- //属性存储初始位置
- private originalPositions: Vec3[] = [];
- //是否重新启动加载地图
- private isLoad: boolean = false;
- //关卡背景音乐
- private audio_BGM: string = '';
- start() {
- this.hasAnim = false;
- this.closeOnBlank = false;
- uiMgr.panels.set(Constants.mainUIs.main, this.node);
- //注册动态变化值
- stateMgr.registerUI(Constants.gold, this.gold_lable);
- stateMgr.registerUI(Constants.diamond, this.diamond_lable);
- //加载数据
- this.loadData();
- //注册事件
- this.node.on(Node.EventType.TOUCH_START, this.playBtn.bind(this), this);
- if(!Constants.isDebug){
- this.editBox.node.active = false;
- }
- //存储初始位置到类属性
- this.originalPositions = this.animPosArr.map(e => e.position.clone());
- this.playBGM();
- //这两个页面悄无声息的加载一下
- this.scheduleOnce(()=>{
- ResUtil.loadRes(Constants.popUIs.arsenalUI);
- ResUtil.loadRes(Constants.popUIs.upgradeGunUI);
- },0.2);
- }
- /**
- * 进入的时候的动画
- */
- public enterAnim(){
- const task_view_pos: Vec3 = this.originalPositions[0];
- const arsenal_btn_pos: Vec3 = this.originalPositions[1];
- const boomerang_btn_pos: Vec3 = this.originalPositions[2];
- let posArr:Vec3[] = [
- new Vec3(task_view_pos.x,task_view_pos.y + 622,task_view_pos.z),
- new Vec3(arsenal_btn_pos.x - 148,arsenal_btn_pos.y,arsenal_btn_pos.z),
- new Vec3(boomerang_btn_pos.x + 148,boomerang_btn_pos.y,boomerang_btn_pos.z)
- ];
- this.animPosArr.forEach((e: Node,i: number) => {
- tween(e)
- .to(0.7, { position: posArr[i]}, { easing: easing.backOut})
- .start();
- });
- }
- /**
- * 加载数据
- */
- public loadData() {
- const data: any = userIns.getCurLevelData();
- if(!data)return;
- //设置任务描述关卡任务:%{value}
- this.task_des_lable.string = i18n.isZh ? data.task : data.task_lang;
- this.level_lable.string = i18n("main.关卡任务:%{value}",{value: data.id});
- this.taskDatas = []
- //拆分并处理每个敌人配置
- data.dispose.split('|').forEach((item: string) => {
- const [enemyId, count] = item.split('_').map(Number);
- const enemyData = Utils.clone(userIns.enemyTable).find((e: any) => e.id === enemyId);
- enemyData.count = count;
- this.taskDatas.push(enemyData);
- });
- if(this.taskDatas.length <= 0)return;
- this.task_scrollView.numItems = this.taskDatas.length;
- }
-
- /**
- * 任务数据
- * @param item item节点
- * @param idx 数据下标
- */
- public setTaskItemData(item: Node, idx: number) {
- const task: any = this.taskDatas[idx];
- item.getComponent(TaskItem).init(task);
- }
- /**
- * 暂停关卡内的背景音乐
- */
- public playOrStopBGM(isPlay: boolean){
- if(!this.audio_BGM)return;
- if(isPlay){
- audioMgr.play(this.audio_BGM,true,2);
- }else{
- audioMgr.stop(this.audio_BGM,2);
- }
- }
- /**
- * 播放背景音乐
- */
- public playBGM(){
- audioMgr.play(Constants.audios.BGM,true,2);
- }
- /**
- * 开始游戏
- */
- public playBtn(){
- if(this.isLoad){
- Game.I.loadMap();
- }
- userIns.data.cutNum -= 1;
- audioMgr.stop(Constants.audios.BGM);
- //播放关卡背景音乐
- let bgms:string[] = [Constants.audios.bgm_1,Constants.audios.bgm_2,Constants.audios.bgm_3];
- this.audio_BGM = Utils.randomArray(bgms)[0];
- audioMgr.play(this.audio_BGM,true);
- Game.I.player.restart();
- if(Constants.isDebug && !Utils.isNull(this.editBox.string)){
- userIns.data.level = parseInt(this.editBox.string);
- }
- this.isLoad = true;
- this.enterAnim();
- this.scheduleOnce(() => {
- //加载敌人
- Game.I.buildEnemys.loadLevelEnemys();
- uiMgr.hide(Constants.mainUIs.main,()=>{
- uiMgr.show(Constants.popUIs.gunfightShootUI);
- });
- },0.2)
- }
-
- /**
- * 点击事件
- * @param event 事件
- * @param customEventData 数据
- */
- public onBtnClicked(event: EventTouch, customEventData: any) {
- super.onBtnClicked(event,customEventData);
- let btnName = event.target.name;
- if (btnName === 'set_btn') { // 设置页面
- uiMgr.show(Constants.popUIs.settingUI);
- }else if (btnName === 'shop_btn') {//商店
- uiMgr.show(Constants.popUIs.storeUI);
- }else if (btnName === 'arsenal_btn') {//武器库
- uiMgr.show(Constants.popUIs.arsenalUI);
- }else if(btnName === 'boomerang_btn'){//扔飞镖
- uiMgr.show(Constants.popUIs.tossBoomerangUI);
- }else if(btnName === 'ads_free_btn'){//免广告按钮
- MsgHints.show('免广告按钮');
- }else if(btnName === 'bulls_eye_btn'){//准心开始按钮
- this.playBtn();
- }
- }
- /**
- * 切换游戏主页面
- * @param idx
- */
- public cutTabBarIndex(event: EventTouch,param: any){
- let index: number = parseInt(param);
- this._tabBarIndex = index;
- this.preIndexs.push(index);
- //设置层级
- let path: string = this.sceneNames[index];
- if(path == Constants.mainUIs.main){
- this.animPosArr.forEach((e, index) => e.position = this.originalPositions[index]);
- }
- //加载页面
- uiMgr.show(path);
- if(this.preIndexs.length > 2){
- this.preIndexs.shift()
- }
- }
- }
|