import { SaveDataManager } from "../../../component/SaveDataManager"; import { tMgr } from "../../../Global"; import ObjBaseView from "../../../prefabs/ObjBaseView"; import { BallSkinTable, TableName } from "../../table/TableDefine"; import { ObjType } from "../BattleConst"; import { MapData } from "./MapData"; import { RectBlockData } from "./RectBlockData"; export class MapView extends cc.Node { private _colliderLayer: cc.Node; get colliderLayer(): cc.Node { return this._colliderLayer; } private _blockImgLayer: cc.Node; /**砖块图层 */ get blockImgLayer(): cc.Node { return this._blockImgLayer; } private _blockIconLayer: cc.Node; /**砖块的图标图层 */ get blockIconLayer(): cc.Node { return this._blockIconLayer; } private _effectLayer: cc.Node; /**砖块的效果特效图层 */ get effectLayer(): cc.Node { return this._effectLayer; } private _lightLayer: cc.Node; /**砖块的高亮图层 */ get lightLayer(): cc.Node { return this._lightLayer; } private _txtLayer: cc.Node; /**数字图层 */ get txtLayer(): cc.Node { return this._txtLayer; } private _txtUpLayer: cc.Node; /** 遮住数字的图层*/ get txtUpLayer(): cc.Node { return this._txtUpLayer; } private _ballLayer: cc.Node; /**弹球 */ get ballLayer(): cc.Node { return this._ballLayer; } private _mapData: MapData; private _prefabCollection: cc.Node; get prefabCollection(): cc.Node { return this._prefabCollection; } private _testBall: cc.Node; get testBall(): cc.Node { return this._testBall; } private _rectBlcokUidList: number[] = []; init(data: MapData, prefabCollection: cc.Node, preview: boolean) { this._mapData = data; this._prefabCollection = prefabCollection; let height = data.mapGridSize.y * data.gridSize.y; this.setContentSize(data.mapGridSize.x * data.gridSize.x, height); this._colliderLayer = this.createLayer('colliderLayer'); this.addChild(this._colliderLayer); this._blockImgLayer = this.createLayer('blockImgLayer'); this.addChild(this._blockImgLayer); this._blockIconLayer = this.createLayer('blockIconLayer'); this.addChild(this._blockIconLayer); this._effectLayer = this.createLayer('effectLayer'); this.addChild(this._effectLayer); this._lightLayer = this.createLayer('lightLayer'); this.addChild(this._lightLayer); this._txtLayer = this.createLayer('txtLayer'); this.addChild(this._txtLayer); this._txtUpLayer = this.createLayer('txtUpLayer'); this.addChild(this._txtUpLayer); this._ballLayer = this.createLayer('ballLayer'); this.addChild(this._ballLayer); let foo: cc.Node; let cmpt: ObjBaseView; data.objData.forEach((obj, index, map) => { foo = null; if (obj.type == ObjType.PLUS_ONE || obj.type == ObjType.SPLITER) { foo = cc.instantiate(prefabCollection.getChildByName('dotSkill')); } else if (obj.type >= ObjType.LANCER_1 && obj.type <= ObjType.LANCER_3) { foo = cc.instantiate(prefabCollection.getChildByName('laser')); } else if (obj.type == ObjType.BIG_BOMB || obj.type == ObjType.BIG_BOMB_33) { foo = cc.instantiate(prefabCollection.getChildByName('bigBomb'));; } else if (obj.type == ObjType.TRANGLE_1 || obj.type == ObjType.TRANGLE_2 || obj.type == ObjType.TRANGLE_3 || obj.type == ObjType.TRANGLE_4) { let fff = obj.type - 2; foo = cc.instantiate(prefabCollection.getChildByName('trangleBlock' + fff.toString())); } else if (obj.type == ObjType.POT) { foo = cc.instantiate(prefabCollection.getChildByName('pot')); } else if (obj.type == ObjType.ROTATER) { foo = cc.instantiate(prefabCollection.getChildByName('rotater')); } else if (obj.type == ObjType.STATIC_IRON) { foo = cc.instantiate(prefabCollection.getChildByName('staticNail')); } else if (obj.type == ObjType.PATROL) { foo = cc.instantiate(prefabCollection.getChildByName('patrol')); } else { if (obj instanceof RectBlockData) { if (!this._rectBlcokUidList.includes(obj.uid)) { this._rectBlcokUidList.push(obj.uid); foo = cc.instantiate(prefabCollection.getChildByName('rectBlock'));; } } else { foo = cc.instantiate(prefabCollection.getChildByName('block'));; } } if (foo) { let cmpt = foo.getComponent(ObjBaseView); cmpt.init(obj, this); preview && cmpt.onPreview(); } }, this); this._testBall = cc.instantiate(prefabCollection.getChildByName('testBall')); this._ballLayer.addChild(this._testBall); } private createLayer(name: string): cc.Node { let layer = new cc.Node(name); layer.setContentSize(this._mapData.mapGridSize.x * this._mapData.gridSize.x, this._mapData.mapGridSize.y * this._mapData.gridSize.y); return layer; } playBlockParticle(node: cc.Node) { let parPrefab = this._prefabCollection.getChildByName('parBlockBoom'); let par = cc.instantiate(parPrefab); par.setPosition(node.position); par.active = false; let skinId = SaveDataManager.ins.runtimeData.ballSkinCurrent; SaveDataManager.ins.runtimeData.ballSkinTry > 0 && (skinId = SaveDataManager.ins.runtimeData.ballSkinTry); let ballSkin = tMgr.getConfig(TableName.BALL_SKIN, skinId) as BallSkinTable; cc.resources.load('battle/' + ballSkin.Particle, cc.SpriteFrame, (error, asset) => { if (!error) { par.active = true; par.getComponent(cc.ParticleSystem).custom = true; par.getComponent(cc.ParticleSystem).spriteFrame = asset as cc.SpriteFrame; par.getComponent(cc.ParticleSystem).resetSystem(); } }) // par.getComponent(cc.ParticleSystem).resetSystem(); this._effectLayer.addChild(par); } }