| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- var reGameStates = require('GameStates');
- cc.Class({
- extends: cc.Component,
- properties: {
- seedType: {
- default: reGameStates.SeedType.Normal,
- type: cc.Enum(reGameStates.SeedType),
- },
- seedName:{
- default: ''
- },
- _EndPosition: {
- default: new cc.Vec2(),
- serializable: false,
- visible: false,
- },
- labelTip: {
- default: null,
- type: cc.Label,
- },
- labelTipString: {
- default: '移动可拆除对应建筑',
- },
- //记录节点
- targetBuildingsInfo: { default: null, visible: false },
- //移除的提示预制
- removeTipPrefab: { default: null, type: cc.Prefab },
- //记录要删除的节点
- selectedTarget: { default: [], type: cc.Node, visible: false },
- //记录选中的index
- selectedTargetIndex: { default: [], type: cc.Integer, visible: false },
- isMoveState: { default: true, visible: false },
- MoveStartNode: cc.Node,
- MoveEndNode: cc.Node,
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start() {
- //获取对应的地图层级
- this.buildLayer = GlobalD.TiledMap._tiledMap.getLayer('BuildsHighway');
- GlobalD.game._ManageUIScript.onBottomMenuView(false);
- var self = this;
- self._MainCamera = GlobalD.game.MainCamera;
- self._tiledMap = GlobalD.TiledMap._tiledMap;
- //获取最后建造公路的层级
- self.HighwayLayer = self._tiledMap.getLayer('Highway');
- self._game = GlobalD.game;
- //初始化时候设置一下位置
- //后面只要点击生成铺路就需要重置一下
- let startTiledPos = GlobalD.TiledMap._tilePosFromLocation(self.node.getPosition());
- let startEndPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(startTiledPos);
- self.node.setPosition(startEndPos);
- self._EndPosition = startTiledPos;
- if (reGameStates.SeedType.Normal === self.seedType) {
- //锤子类型
- let startIndex = GlobalD.TiledMap.getIndex(startTiledPos);
- let _targetBuildingsInfo = GlobalD.game.onGetBuildingsTiledMapUnitFromIndex(startIndex);
- if (_targetBuildingsInfo) {
- self.labelTip.string = '播种到' + _targetBuildingsInfo.buildInfo.buildingName + '上';
- self.targetBuildingsInfo = _targetBuildingsInfo;
- }
- else {
- self.labelTip.string = self.labelTipString;
- self.targetBuildingsInfo = null;
- }
- }
- self.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
- GlobalD.GameControl._isBuildingMove = true;
- var delta = event.touch.getDelta();
- self._touchPosition.x += delta.x / self._MainCamera.zoomRatio;
- self._touchPosition.y += delta.y / self._MainCamera.zoomRatio;
- let tiledPos = GlobalD.TiledMap._tilePosFromLocation(self._touchPosition);
- // //不相等的时候才绘制
- if (tiledPos.sub(self._EndPosition).mag() != 0) {
- self._EndPosition = tiledPos;
- self._SelectHighwayTiled(tiledPos);
- }
- }, self.node);
- self.node.on(cc.Node.EventType.TOUCH_START, function (event) {
- self.isMoving = true;
- self._touchPosition = self.node.getPosition();
- }, self.node);
- self.node.on(cc.Node.EventType.TOUCH_END, function (event) {
- //起始触摸位置
- GlobalD.GameControl._isBuildingMove = false;
- let buildIndex = GlobalD.TiledMap.getIndex(self._EndPosition);
- let _targetBuildingsInfo = GlobalD.game.onGetBuildingsTiledMapUnitFromIndex(buildIndex);
- if (_targetBuildingsInfo) {
- self.labelTip.string = '播种到' + _targetBuildingsInfo.buildInfo.buildingName + '上';
- self.targetBuildingsInfo = _targetBuildingsInfo;
- }
- else {
- self.labelTip.string = self.labelTipString;
- self.targetBuildingsInfo = null;
- }
- }, self.node);
- self.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
- //起始触摸位置
- GlobalD.GameControl._isBuildingMove = false;
- }, self.node);
- },
- onCancleSelf() {
- this.node.active = false;
- GlobalD.game._ManageUIScript.onBottomMenuView(true);
- },
- //播种
- onSowOnTheGround(){
- //调用土地相关
- if (!this.targetBuildingsInfo) return;
- // cc.log('this.targetBuildingsInfo', this.targetBuildingsInfo)
- // this.targetBuildingsInfo.onClearSelfResetFromType();
- //面板种子消耗减少1
- console.log('种子减少的类型名字',this.seedName);
- GlobalD.game.MuinusBuilding(this.seedName);
- this.targetBuildingsInfo.onInitHolyFarmlandSeedFromGrow();
-
- //隐藏种子和显示UI
- this.node.active = false;
- GlobalD.game._ManageUIScript.onBottomMenuView(true);
- },
- _SelectHighwayTiled(tiledPos) {
- let endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(tiledPos);
- this.node.setPosition(endPos);
- }
-
- });
|