Explorar o código

建筑部分?

slambb %!s(int64=3) %!d(string=hai) anos
pai
achega
a1773dc709

+ 52 - 0
assets/Script/build/CommodityItem.js

@@ -0,0 +1,52 @@
+// Learn cc.Class:
+//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
+//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
+// Learn Attribute:
+//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
+//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
+// Learn life-cycle callbacks:
+//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
+//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
+
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+
+        //商品名称
+        commodityName: {
+            default: null,
+            type: cc.Label,
+        },
+        //商品价格
+        commodityPrice: {
+            default: null,
+            type: cc.Label,
+        },
+
+        //商品材料
+        commodityMaterial: {
+            default: null,
+            type: cc.Label,
+        },
+        //记录当前商品的信息
+        commodity: {
+            default: null,
+            visible: false,
+        },
+
+    },
+
+    updateItem: function (tmplId, itemId, commodity) {
+        // cc.log('设置食物种类', commodity);
+        this.commodity = commodity;
+        // goodsId: 0
+        // goodsMaterial: goodsMaterialClass {crops: 2, wood: 0, mineral: 0}
+        // goodsName: "方便面"
+        // goodsPrice: 50
+        // goodsSalesRate: 70
+        this.commodityName.string = commodity.goodsName;
+        this.commodityPrice.string = commodity.goodsPrice;
+        this.commodityMaterial.string = '农:'+commodity.goodsMaterial.crops+' 木:'+commodity.goodsMaterial.wood
+    },
+});

+ 9 - 0
assets/Script/build/CommodityItem.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "f33c78d9-f595-4b7f-8b8e-7e5c21794dec",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 712 - 0
assets/Script/build/DynamicBuilding.js

@@ -0,0 +1,712 @@
+
+const Constants = require('Constants');
+var reGameStates = require('GameStates');
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+        HighWay: {
+            // ATTRIBUTES:
+            default: [],        // The default value will be used only when the component attaching
+            // to a node for the first time
+            type: cc.Prefab, // optional, default is typeof default
+            serializable: true,   // optional, default is true
+        },
+
+        _tiledMap: {
+            default: null,
+            type: cc.TiledMap,
+            serializable: false,
+            visible: false,
+        },
+        _MainCamera: {
+            default: null,
+            type: cc.Camera,
+            serializable: false,
+            visible: false,
+        },
+
+        //触摸一开始的位置
+        _touchPosition: {
+            default: new cc.Vec2(),
+            visible: false,
+            serializable: false
+        },
+
+        _StartPosition: {
+            default: new cc.Vec2(),
+            serializable: false
+        },
+
+        _EndPosition: {
+            default: new cc.Vec2(),
+            serializable: false
+        },
+        //上一个位置
+        _LastPosition: {
+            default: new cc.Vec2(),
+            serializable: false
+        },
+
+        _highPath: {
+            default: [],
+            type: [cc.Node],
+            visible: false,
+        },
+
+        selectTouch: {
+            default: null,
+            type: cc.Node,
+        },
+        buildingTouch: {
+            default: null,
+            type: cc.Node,
+        },
+
+        //如果只初始化一次的话
+        // _isInitOnce: {
+        //     default: false,
+        //     visible: false,
+        // }
+
+        //如果自动移动
+        isAutoMove: { default: false, visible: false },
+
+        //是否创建斑马线
+        isCreateZebra: { default: true, visible: false },
+        // createStartTiledPos: null,
+    },
+
+    // LIFE-CYCLE CALLBACKS:
+
+    onLoad() {
+        this.highwayPool = new cc.NodePool();
+        let initCount = 50;
+        for (let i = 0; i < initCount; ++i) {
+            let highway = cc.instantiate(this.HighWay[0]); // 创建节点
+            this.highwayPool.put(highway); // 通过 putInPool 接口放入对象池
+        }
+    },
+
+    start() {
+        var self = this;
+        self._MainCamera = GlobalD.game.MainCamera;
+        self._tiledMap = GlobalD.TiledMap._tiledMap;
+
+        //获取对应的地图层级
+        this.buildLayer = this._tiledMap.getLayer('BuildsHighway');
+
+        self._game = GlobalD.game;
+
+        //初始化时候设置一下位置
+        //后面只要点击生成铺路就需要重置一下
+        let startTiledPos = GlobalD.TiledMap._tilePosFromLocation(self.node.getPosition());
+        let startEndPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(startTiledPos);
+        self.node.setPosition(startEndPos);
+
+        //记录一下初始位置
+        // self.createStartTiledPos = startTiledPos;
+
+        self.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
+
+
+
+            // cc.log(event.touch.getDelta());
+            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;
+            // self.node.setPosition(self._touchPosition);
+
+            let tiledPos = GlobalD.TiledMap._tilePosFromLocation(self._touchPosition);
+            //不相等的时候才绘制
+            if (tiledPos.sub(self._EndPosition).mag() != 0) {
+
+                // cc.log('tiledPostiledPostiledPos', tiledPos,self._EndPosition)
+                self._EndPosition = tiledPos;
+
+                if (self.buildingTouch.active) {
+                    if (self._StartPosition.x == self._EndPosition.x
+                        || self._StartPosition.y == self._EndPosition.y) {
+                        self.onCancelCreateHighway();
+
+                        self.onBuildingFromPath(self._StartPosition, self._EndPosition);
+
+                        let endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(tiledPos);
+                        self.node.setPosition(endPos);
+                    }
+
+                } else {
+                    let endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(tiledPos);
+
+                    self.node.setPosition(endPos);
+                }
+
+
+            }
+
+            //开启编辑UI
+            // self._game._ManageUIScript.onEditorialBuildings(self.node);
+
+        }, self.node);
+
+        self.node.on(cc.Node.EventType.TOUCH_START, function (event) {
+            // var touches = event.getTouches();
+            // var touchLoc = touches[0].getLocation();
+            self.isMoving = true;
+            // if(!self._isInitOnce){
+            //     self._StartPosition = GlobalD.TiledMap._tilePosFromLocation(self.node.getPosition());
+            // }
+            //如果要选框就去掉这里
+            // self.onInitStartPosition();
+
+            self._touchPosition = self.node.getPosition();
+
+            // cc.log('self._StartPosition', self._StartPosition, self._touchPosition);
+
+
+
+        }, self.node);
+
+        self.node.on(cc.Node.EventType.TOUCH_END, function (event) {
+
+            //起始触摸位置
+            GlobalD.GameControl._isBuildingMove = false;
+        }, self.node);
+        self.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
+
+            //起始触摸位置
+            GlobalD.GameControl._isBuildingMove = false;
+        }, self.node);
+
+    },
+
+    // 自动移动,在ManagerControl 里面调用
+    onAutoMove(delta) {
+
+        this.isAutoMove = true;
+
+        let self = this;
+        self._touchPosition.x += delta.x;
+        self._touchPosition.y += delta.y;
+        let tiledPos = GlobalD.TiledMap._tilePosFromLocation(self._touchPosition);
+        //不相等的时候才绘制
+        if (tiledPos.sub(self._EndPosition).mag() != 0) {
+            self._EndPosition = tiledPos;
+            if (self.buildingTouch.active) {
+                if (self._StartPosition.x == self._EndPosition.x
+                    || self._StartPosition.y == self._EndPosition.y) {
+                    self.onCancelCreateHighway();
+                    self.onBuildingFromPath(self._StartPosition, self._EndPosition);
+                    let endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(tiledPos);
+                    self.node.setPosition(endPos);
+                }
+            } else {
+                let endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(tiledPos);
+                self.node.setPosition(endPos);
+            }
+        }
+    },
+    onCancleAutoMove() {
+        this.isAutoMove = false;
+
+    },
+
+    //隐藏时候铺路的状态
+    onHideSetTouchState() {
+        if (this.create1 || this.create2) {
+            let _cancel1 = this.selectTouch.getChildByName('Cancel').getComponent(cc.Button);
+            let _cancel2 = this.buildingTouch.getChildByName('Cancel').getComponent(cc.Button);
+            _cancel1.interactable = true;
+            _cancel1.enableAutoGrayEffect = false;
+            _cancel2.interactable = true;
+            _cancel2.enableAutoGrayEffect = false;
+            if (this.create1)
+                this.create1.stopAllActions();
+            if (this.create2)
+                this.create2.stopAllActions();
+        }
+
+    },
+    //新手教程时候设置铺路状态
+    onSetTouchState() {
+
+        if (!task.virtualShadowPos) return;
+
+        if (this.selectTouch.active) {
+            let _cancel = this.selectTouch.getChildByName('Cancel').getComponent(cc.Button);
+            _cancel.interactable = false;
+            _cancel.enableAutoGrayEffect = true;
+            this.create1 = this.selectTouch.getChildByName('Create');
+            this.create1.stopAllActions();
+            var s = cc.sequence(cc.scaleTo(0.6, 0.9), cc.scaleTo(0.9, 0.6));
+            var repeat = cc.repeatForever(s);
+            this.create1.runAction(repeat);
+
+        } else {
+            let _cancel = this.buildingTouch.getChildByName('Cancel').getComponent(cc.Button);
+            _cancel.interactable = false;
+            _cancel.enableAutoGrayEffect = true;
+            this.create2 = this.buildingTouch.getChildByName('Create');
+            this.create2.stopAllActions();
+            var s = cc.sequence(cc.scaleTo(0.6, 0.9), cc.scaleTo(0.9, 0.6));
+            var repeat = cc.repeatForever(s);
+            this.create2.runAction(repeat);
+        }
+
+
+    },
+    //切换状态
+    onSwitchBuidingTouch() {
+
+        //如果是新手指引的情况下,需要显示对应的遮挡模板
+        if (task.virtualShadowPos) {
+            let _curentTiled = GlobalD.TiledMap._tilePosFromLocation(this.node.getPosition());;
+            if (_curentTiled.sub(task.virtualShadowPos).mag() !== 0) {
+
+                // console.error('没有移动到指定位置:', _curentTiled, task.virtualShadowPos);
+                cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
+                    var prefab = cc.instantiate(texture);
+                    prefab.getComponent('ShowNotEnoughMoney').Text('请移动到虚影的<起始>位置!');
+                    cc.find('Canvas').getChildByName('UICamera').addChild(prefab);
+                }.bind(this));
+                return;
+            } else {
+                // console.log(task.virtualTarget);
+                let _taskHighway = task.getTaskNode('taskPrefabTiledTileHighway');
+
+                if (_taskHighway) {
+                    _taskHighway.getChildByName('Arrow').active = false;
+                    _taskHighway.getChildByName('Hand1').active = true;
+                }
+            }
+        }
+
+
+        this.selectTouch.active = false;
+        this.buildingTouch.active = true;
+
+        //设置一下状态
+        this.onSetTouchState();
+        //设置斑马线
+        this.isCreateZebra = true;
+        // this._isInitOnce = true;
+        // 记录编辑状态时候的初始位置
+        this.onInitStartPosition();
+    },
+    // 重置下初始位置
+    onInitStartPosition() {
+        this._StartPosition = GlobalD.TiledMap._tilePosFromLocation(this.node.getPosition());
+
+        // //如果是新手指引的情况下,需要显示对应的遮挡模板
+        // if (task.isMushBuildState) {
+        //     let _confirmButton = this.HighwayBuildingNode.getChildByName('SelectTouch').getChildByName('Create');
+        //     let _taskNodes = [];
+        //     _taskNodes.push(_confirmButton);
+        //     task.onInitTaskMask(_taskNodes);
+        // }
+    },
+    //相同一个点的时候点的时候
+    onBuildingFromPathEqual(tiledPos) {
+        // cc.log('onBuildingFromPathEqual');
+        if (!GlobalD.TiledMap.getTiledTileAt(tiledPos.x, tiledPos.y)) {
+
+            let highwayTemp = null;
+
+            if (this.highwayPool.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
+                highwayTemp = this.highwayPool.get();
+            } else { // 如果没有空闲对象,也就是对象池中备用对象不够时,我们就用 cc.instantiate 重新创建
+                highwayTemp = cc.instantiate(this.HighWay[0]);
+                // cc.log('重新创建')
+            }
+            highwayTemp.parent = this.buildLayer.node;
+            let tiledTile = highwayTemp.addComponent('TiledTile');
+            tiledTile.x = tiledPos.x;
+            tiledTile.y = tiledPos.y;
+
+        }
+    },
+
+    //不同点的时候
+    //在路径上面创建公路预制
+    onBuildingFromPath(start_tiledPos, end_tiledPos) {
+
+        //移动了就不创建斑马线了
+        this.isCreateZebra = false;
+
+        let _highwayStart = null;
+        let isChangeHighwayStart = false;
+
+        let spawnPos = 0;
+
+        //最后一个点判断是否重合
+        let EndPos = [];
+        let tempMaxY = 0;
+        let tempMinY = 0;
+        if (start_tiledPos.y > end_tiledPos.y) {
+            tempMaxY = start_tiledPos.y;
+            tempMinY = end_tiledPos.y;
+        } else {
+            tempMaxY = end_tiledPos.y;
+            tempMinY = start_tiledPos.y;
+        }
+        let tempY = end_tiledPos.y - start_tiledPos.y;
+        for (let i = tempMinY; i <= tempMaxY; i++) {
+            spawnPos = cc.v2(start_tiledPos.x, i);
+            //写入index 数组
+            GlobalD.TiledMap.setIndexArray(spawnPos, EndPos);
+
+            // if (!GlobalD.TiledMap.getTiledTileAt(spawnPos.x, spawnPos.y)) 
+            {
+                // cc.log('绘制Y', spawnPos)
+                let highwayTemp = null;
+
+                if (this.highwayPool.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
+                    highwayTemp = this.highwayPool.get();
+                } else { // 如果没有空闲对象,也就是对象池中备用对象不够时,我们就用 cc.instantiate 重新创建
+                    highwayTemp = cc.instantiate(this.HighWay[0]);
+                    // cc.log('重新创建')
+                }
+
+                highwayTemp.parent = this.buildLayer.node;
+                let tiledTile = highwayTemp.addComponent('TiledTile');
+                tiledTile.x = spawnPos.x;
+                tiledTile.y = spawnPos.y;
+
+                if (GlobalD.game.getManageGameIndexArrayAt(tiledTile)) {
+                    highwayTemp.getComponent('TipSprite').onSetRedSpriteFrame();
+                }
+                //没有重复的时候
+
+                // cc.log('设置Y值:', reGameStates.HighwayType.moveY);
+                highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.moveY);
+
+                //记录第一个临时节点
+                if (!_highwayStart) {
+                    _highwayStart = highwayTemp;
+                }
+            }
+        }
+
+
+
+        let tempMaxX = 0;
+        let tempMinX = 0;
+        if (start_tiledPos.x > end_tiledPos.x) {
+            tempMaxX = start_tiledPos.x;
+            tempMinX = end_tiledPos.x;
+        } else {
+            tempMaxX = end_tiledPos.x;
+            tempMinX = start_tiledPos.x;
+        }
+
+        for (let i = tempMinX; i <= tempMaxX; i++) {
+            spawnPos = cc.v2(i, start_tiledPos.y + tempY);
+            //这里判断最大最小点是否重合
+            if (!GlobalD.TiledMap.getIndexArrayAt(spawnPos, EndPos)) {
+                // cc.log('绘制x', spawnPos)
+                let highwayTemp = null;
+                if (this.highwayPool.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
+                    highwayTemp = this.highwayPool.get();
+                } else { // 如果没有空闲对象,也就是对象池中备用对象不够时,我们就用 cc.instantiate 重新创建
+                    highwayTemp = cc.instantiate(this.HighWay[0]);
+                    // cc.log('重新创建')
+                }
+                // let highwayTemp = cc.instantiate(this.HighWay[0]);
+                highwayTemp.parent = this.buildLayer.node;
+                let tiledTile = highwayTemp.addComponent('TiledTile');
+                tiledTile.x = spawnPos.x;
+                tiledTile.y = spawnPos.y;
+                // this._highPath.push(highwayTemp);
+
+                if (GlobalD.game.getManageGameIndexArrayAt(tiledTile)) {
+                    highwayTemp.getComponent('TipSprite').onSetRedSpriteFrame();
+                }
+
+                highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.moveX);
+
+
+                if (_highwayStart && !isChangeHighwayStart) {
+                    // cc.log('修正第一个起始点。');
+                    isChangeHighwayStart = true;
+                    _highwayStart.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.moveX);
+
+                }
+            }
+
+
+        }
+
+
+
+
+
+    },
+
+    //取消创建
+    //对象池回收
+    onCancelCreateHighway() {
+
+        //删除对应层的子节点
+        let tempNode = this.buildLayer.node.children;
+        let length = tempNode.length;
+        for (let i = length - 1; i >= 0; i--) {
+
+            //设置回默认的提示图片
+            tempNode[i].getComponent('TipSprite').onReset();
+            tempNode[i].getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.none);
+
+            if (tempNode[i].getComponent('TiledTile')) {
+                tempNode[i].removeComponent('TiledTile');
+            }
+            // 和初始化时的方法一样,将节点放进对象池,这个方法会同时调用节点的 removeFromParent
+            this.highwayPool.put(tempNode[i]);
+        }
+    },
+
+    //创建道路
+    onCreateHighway() {
+
+        //获取最后建造公路的层级
+        this.HighwayLayer = this._tiledMap.getLayer('Highway');
+
+        if (this.isCreateZebra) {
+            // cc.log('创建斑马线,', this._StartPosition);
+            //检测新手引导时候道路,不设计一个点
+            if (task.isMushBuildState) {
+                console.error('新手教程下不创建单个公路');
+                cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
+                    var prefab = cc.instantiate(texture);
+                    prefab.getComponent('ShowNotEnoughMoney').Text('请移动到虚影的<终点>位置!');
+                    cc.find('Canvas').getChildByName('UICamera').addChild(prefab);
+                }.bind(this));
+                return;
+            }
+
+            let buildIndex = GlobalD.TiledMap.getIndex(this._StartPosition);
+            if (GlobalD.game.onGetHighwayFromIndex(buildIndex)) {
+
+                let tempNode = this.HighwayLayer.node.children;
+                let length = tempNode.length;
+                for (let i = length - 1; i >= 0; i--) {
+                    let tiledTile = tempNode[i].getComponent('TiledTile');
+                    let tiledVector2 = new cc.Vec2(tiledTile.x, tiledTile.y);
+                    let tiledIndex = GlobalD.TiledMap.getIndex(tiledVector2);
+
+                    if (tiledIndex === buildIndex) {
+                        let _highwayInfo = tempNode[i].getComponent('HighwayInfo');
+                        // cc.log(_highwayInfo);
+                        let _switchHighwayType = reGameStates.HighwayType.none;
+                        if (_highwayInfo.currenHighwayType == reGameStates.HighwayType.moveX) {
+                            _switchHighwayType = reGameStates.HighwayType.ZebraCrossingX;
+                        } else if (_highwayInfo.currenHighwayType == reGameStates.HighwayType.moveY) {
+                            _switchHighwayType = reGameStates.HighwayType.ZebraCrossingY;
+                            // cc.log('Y', _switchHighwayType)
+                        }
+                        //修改节点样式
+                        _highwayInfo.onChangeHighwayStyles(_switchHighwayType);
+
+                        //更新公路样式
+                        GlobalD.game.onUpdateDifferentRoadStyles({
+                            _highwayType: _switchHighwayType,
+                            _roadIndex: buildIndex,
+                        });
+                        break;
+                    }
+
+                }
+            } else {//没有就创建
+
+                let tiledVector2 = this._StartPosition;
+                let highwayTemp = cc.instantiate(this.HighWay[1]);
+                highwayTemp.parent = this.HighwayLayer.node;
+
+                let tiledTile = highwayTemp.addComponent('TiledTile');
+                tiledTile.x = tiledVector2.x;
+                tiledTile.y = tiledVector2.y;
+
+                // cc.log('onCreateHighway');
+                AStar.setMapSolid(tiledVector2.x, tiledVector2.y, 0);
+
+                // _buildId ==0 是公路
+                let _buildId = 0;
+                let occupyTemp = cc.v2(_buildId, buildIndex);
+                GlobalD.game.OccupyArray.push(occupyTemp);
+
+                //添加公路样式
+                GlobalD.game.onCreateDifferentRoadStyles({
+                    _buildId: _buildId,
+                    _highwayType: reGameStates.HighwayType.ZebraCrossingX,
+                    _roadIndex: buildIndex,
+                    _hightwayNode: highwayTemp
+                });
+            }
+
+
+        } else {
+
+            let tempNode = this.buildLayer.node.children;
+            let length = tempNode.length;
+            //检测新手引导时候道路,检测最后一个点
+            //如果是新手指引的情况下,需要显示对应的遮挡模板
+            if (task.virtualShadowPosEnd) {
+                let _taskTiledTile = tempNode[length - 1].getComponent('TiledTile');
+
+
+                if (task.virtualShadowPosEnd.sub(cc.v2(_taskTiledTile.x, _taskTiledTile.y)).mag() !== 0) {
+
+                    console.error('没有移动到终点位置:', cc.v2(_taskTiledTile.x, _taskTiledTile.y), task.virtualShadowPosEnd);
+                    cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
+                        var prefab = cc.instantiate(texture);
+                        prefab.getComponent('ShowNotEnoughMoney').Text('请移动到虚影的<终点>位置!');
+                        cc.find('Canvas').getChildByName('UICamera').addChild(prefab);
+                    }.bind(this));
+                    return;
+                } else {
+                    //铺路教程成功
+                    //移除虚影路径
+                    task.removeTaskNode('taskPrefabTiledTileHighway');
+                    //设置任务状态
+                    task.onShadowArchitectureReset();
+                    dialogmanager.init(task.Canvas, function () {
+                        dialogmanager.paveEnd();
+                    }.bind(this));
+                    dialogmanager.setOnCloseDialog(function () {
+                        task.showManagerhide();
+                        // task.setListView(18);
+                        task._setTaskIconCountClick(1);
+
+                        setTimeout(() => {
+                            task.taskCallBack();
+                        }, 500);
+                    }.bind(this));
+                }
+            }
+
+            for (let i = length - 1; i >= 0; i--) {
+                let tiledTile = tempNode[i].getComponent('TiledTile');
+
+                //获取临时对象里面的公路脚本信息
+                let _highwayInfoTemp = tempNode[i].getComponent('HighwayInfo');
+
+                let tiledVector2 = new cc.Vec2(tiledTile.x, tiledTile.y);
+                //重复的道路模块不创建
+                if (!GlobalD.game.getManageGameIndexArrayAt(tiledVector2)) {
+                    let highwayTemp = cc.instantiate(this.HighWay[1]);
+                    highwayTemp.parent = this.HighwayLayer.node;
+
+                    let tiledTile = highwayTemp.addComponent('TiledTile');
+                    tiledTile.x = tiledVector2.x;
+                    tiledTile.y = tiledVector2.y;
+
+                    // cc.log('onCreateHighway');
+                    AStar.setMapSolid(tiledVector2.x, tiledVector2.y, 0);
+
+                    let index = GlobalD.TiledMap.getIndex(tiledVector2);
+                    // _buildId ==0 是公路
+                    let _buildId = 0;
+                    let occupyTemp = cc.v2(_buildId, index);
+                    GlobalD.game.OccupyArray.push(occupyTemp);
+
+                    // cc.log('创建时候的值:', _highwayInfoTemp.currenHighwayType)
+                    // highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(_highwayInfoTemp.currenHighwayType);
+
+                    //添加公路样式
+                    GlobalD.game.onCreateDifferentRoadStyles({
+                        _buildId: _buildId,
+                        _highwayType: _highwayInfoTemp.currenHighwayType,
+                        _roadIndex: index,
+                        _hightwayNode: highwayTemp
+                    });
+                }
+
+                else {
+                    // cc.log('有道路重复!', tiledVector2);
+                    let buildIndex = GlobalD.TiledMap.getIndex(tiledVector2);
+                    let tempNode = this.HighwayLayer.node.children;
+                    let length = tempNode.length;
+                    for (let i = length - 1; i >= 0; i--) {
+                        let tiledTile = tempNode[i].getComponent('TiledTile');
+                        let tiledVector2 = new cc.Vec2(tiledTile.x, tiledTile.y);
+                        let tiledIndex = GlobalD.TiledMap.getIndex(tiledVector2);
+
+                        if (tiledIndex === buildIndex) {
+                            let _highwayInfo = tempNode[i].getComponent('HighwayInfo');
+                            //修改节点样式
+                            _highwayInfo.onChangeHighwayStyles(_highwayInfoTemp.currenHighwayType);
+
+                            //更新公路样式
+                            GlobalD.game.onUpdateDifferentRoadStyles({
+                                _highwayType: _highwayInfoTemp.currenHighwayType,
+                                _roadIndex: buildIndex,
+                            });
+                            break;
+                        }
+
+                    }
+                }
+
+            }
+        }
+
+
+        //清空回收临时对象
+        this.onCancelCreateHighway();
+
+        //统一取消
+        this.onHide();
+
+        // if (this.isCreateZebra) {
+        //     this.onHide();
+        // } else {
+        //     //成功创建后,重置下初始位置
+        //     this.onInitStartPosition();
+        // }
+
+    },
+
+    //删除
+    onDelete() {
+        this.onCancelCreateHighway();
+        this.highwayPool.clear();// 调用这个方法就可以清空对象池
+        this.node.destroy();
+    },
+    //隐藏
+    onHide() {
+        this.onCancelCreateHighway();
+        this.node.active = false;
+        // this._isInitOnce = false;
+
+        //绿色选中框选中要下面两个代码切换
+        this.selectTouch.active = true;
+        this.buildingTouch.active = false;
+
+
+        GlobalD.game.onClearCurrentBuildingTarget();
+
+        //显示铺路引导
+        task.onTaskPaveRoadsMask();
+    },
+    onDisable() {
+        //隐藏时候重置下状态
+        this.onHideSetTouchState();
+        //收起底部菜单栏
+        GlobalD.game._ManageUIScript.onBottomMenuView(true);
+    },
+
+    onEnable() {
+
+        // console.log(111);
+        //修改按钮状态
+        this.onSetTouchState();
+        //收起底部菜单栏
+        GlobalD.game._ManageUIScript.onBottomMenuView(false);
+
+    }
+
+
+    // update (dt) {},
+});

+ 9 - 0
assets/Script/build/DynamicBuilding.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "e5f66dec-53c6-4871-8f35-8f48cf5c6c5d",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 53 - 0
assets/Script/build/Farmland.js

@@ -0,0 +1,53 @@
+
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+        stateArray: {
+
+            default: [],
+            type: cc.SpriteFrame,
+            serializable: true,
+        },
+
+        changeSprite: {
+            default: null,
+            type: cc.Sprite,
+            serializable: true,
+        },
+
+
+        //工作状态
+        workingStatus: {
+            default: null,
+            type: cc.Node,
+            serializable: true,
+        },
+    },
+    // start(){
+    //     this.onChangeSpriteFunction(2);
+    // },
+
+    onChangeSpriteFunction(consume) {
+
+        if (consume <= 0 || consume >= 50) {
+            this.workingStatus.active = false;
+        } else if (!this.workingStatus.active) {
+            this.workingStatus.active = true
+        }
+
+        let index = 50 - consume;
+        // let index = consume%3;
+        // cc.log(Math.floor(this._Strength % 3));
+        if (index >= 15 && index <= 25)
+            this.changeSprite.spriteFrame = this.stateArray[1];
+        else if (index > 25)
+            this.changeSprite.spriteFrame = this.stateArray[2];
+    },
+
+
+    onResetSprite() {
+
+        this.changeSprite.spriteFrame = this.stateArray[0];
+    }
+});

+ 9 - 0
assets/Script/build/Farmland.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "7c73c9e8-9ca7-40d8-8cc0-ccc0f0defc68",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 68 - 0
assets/Script/build/HighwayInfo.js

@@ -0,0 +1,68 @@
+var reGameStates = require('GameStates');
+
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+        //斑马线的图片
+        HighwaySpriteFrame: {
+            default: [],
+            type: cc.SpriteFrame,
+        },
+
+        //公路对应的sprite
+        roadSprite: cc.Sprite,
+
+        //当前图片的下标
+        currenHighwayType:{
+            default:0,
+            type:cc.Integer,
+        }
+    },
+
+    // LIFE-CYCLE CALLBACKS:
+
+    // onLoad () {},
+
+    start() {
+
+
+    },
+
+    //切换公路图片
+    onChangeHighwayStyles(_highwayType) {
+        // cc.log( _highwayType,this.currenHighwayType)
+
+        let currentSpriteFrame;
+        switch (_highwayType) {
+            case reGameStates.HighwayType.none:
+                currentSpriteFrame = this.HighwaySpriteFrame[0];
+                this.roadSprite.node.scaleX = 1;
+                break;
+            case reGameStates.HighwayType.moveX:
+                currentSpriteFrame = this.HighwaySpriteFrame[2];
+                this.currenHighwayType = reGameStates.HighwayType.moveX;
+                this.roadSprite.node.scaleX = 1;
+                break;
+            case reGameStates.HighwayType.moveY:
+                currentSpriteFrame = this.HighwaySpriteFrame[2];
+                this.roadSprite.node.scaleX = -1;
+                this.currenHighwayType = reGameStates.HighwayType.moveY;
+                break;
+            case reGameStates.HighwayType.ZebraCrossingX:
+                currentSpriteFrame = this.HighwaySpriteFrame[1];
+                this.currenHighwayType = reGameStates.HighwayType.ZebraCrossingX;
+                this.roadSprite.node.scaleX = -1;
+
+                break;
+            case reGameStates.HighwayType.ZebraCrossingY:
+                currentSpriteFrame = this.HighwaySpriteFrame[1];
+                this.currenHighwayType = reGameStates.HighwayType.ZebraCrossingY;
+                this.roadSprite.node.scaleX = 1;
+                break;
+        }
+        this.roadSprite.spriteFrame = currentSpriteFrame;
+
+    }
+    // update (dt) {},
+});

+ 9 - 0
assets/Script/build/HighwayInfo.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "8fb36df5-7e64-4ffa-8086-00f26893cc55",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 53 - 0
assets/Script/build/ObjTouch.js

@@ -0,0 +1,53 @@
+// Learn cc.Class:
+//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
+//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
+// Learn Attribute:
+//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
+//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
+// Learn life-cycle callbacks:
+//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
+//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
+
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+        // foo: {
+        //     // ATTRIBUTES:
+        //     default: null,        // The default value will be used only when the component attaching
+        //                           // to a node for the first time
+        //     type: cc.SpriteFrame, // optional, default is typeof default
+        //     serializable: true,   // optional, default is true
+        // },
+        // bar: {
+        //     get () {
+        //         return this._bar;
+        //     },
+        //     set (value) {
+        //         this._bar = value;
+        //     }
+        // },
+    },
+
+    // LIFE-CYCLE CALLBACKS:
+
+    // onLoad () {},
+
+    start () {
+        this._camera = GlobalD.game.MainCamera;
+        
+        
+        this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
+            // this.node.opacity = 0.1;
+            var delta = event.touch.getDelta();
+            this.node.x += delta.x / this._camera.zoomRatio;
+            this.node.y += delta.y / this._camera.zoomRatio;
+
+
+        }, this);
+
+
+    },
+
+    // update (dt) {},
+});

+ 9 - 0
assets/Script/build/ObjTouch.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "c685a333-d381-40ba-97d5-8fbb91f61bed",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 94 - 0
assets/Script/build/TipSprite.js

@@ -0,0 +1,94 @@
+
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+        //建筑底下碰撞区域
+        Red: {
+            // ATTRIBUTES:
+            default: null,        // The default value will be used only when the component attaching
+            // to a node for the first time
+            type: cc.SpriteFrame, // optional, default is typeof default
+            serializable: true,   // optional, default is true
+        },
+        Green: {
+            // ATTRIBUTES:
+            default: null,        // The default value will be used only when the component attaching
+            // to a node for the first time
+            type: cc.SpriteFrame, // optional, default is typeof default
+            serializable: true,   // optional, default is true
+        },
+        Tip: cc.Sprite,
+
+        //如果是数组
+        isChildenArray: false,
+
+
+        //建筑对周围的影响力
+        effectYellow: {
+            // ATTRIBUTES:
+            default: null,
+            type: cc.SpriteFrame,
+            serializable: true,
+        },
+        effectGreen: {
+            // ATTRIBUTES:
+            default: null,        // The default value will be used only when the component attaching
+            // to a node for the first time
+            type: cc.SpriteFrame, // optional, default is typeof default
+            serializable: true,   // optional, default is true
+        },
+    },
+
+    //设置红色提示
+    onSetRedSpriteFrame(_opacity) {
+        if (_opacity)
+            this.Tip.node.opacity = _opacity;
+        if (this.isChildenArray) {
+            let TipArray = this.node.children;
+            // cc.log(TipArray)
+            let length = TipArray.length;
+            for (let i = 0; i < length; i++) {
+                TipArray[i].getComponent(cc.Sprite).spriteFrame = this.Red;
+            }
+        } else {
+            this.Tip.spriteFrame = this.Red;
+        }
+    },
+
+
+    //重新设置图片
+    onReset() {
+        this.Tip.node.scale = 1;
+        // this.Tip.node.color.setA(1);
+        this.Tip.node.opacity = 230;
+        if (this.isChildenArray) {
+
+            let TipArray = this.node.children;
+            let length = TipArray.length;
+            for (let i = 0; i < length; i++) {
+                TipArray[i].getComponent(cc.Sprite).spriteFrame = this.Green;
+
+            }
+        } else {
+            this.Tip.spriteFrame = this.Green;
+        }
+    },
+
+
+    //设置影响力黄色
+    onSetEffectYellowSpriteFrame() {
+        this.Tip.spriteFrame = this.effectYellow;
+        this.Tip.node.scale = 0.8;
+        // this.Tip.node.color.setA(0.5);
+        this.Tip.node.opacity = 200;
+    },
+
+    //设置影响力 绿色
+    onSetEffectGreenSpriteFrame() {
+        this.Tip.spriteFrame = this.effectGreen;
+        this.Tip.node.scale = 0.8;
+        // this.Tip.node.color.setA(0.5);
+        this.Tip.node.opacity = 200;
+    },
+});

+ 9 - 0
assets/Script/build/TipSprite.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "d8d5ee6f-feec-4321-aa74-6645e3ba01b9",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 198 - 0
assets/Script/build/WorkingBuilding.js

@@ -0,0 +1,198 @@
+var reGameStates = require('GameStates');
+
+
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+        stateArray: {
+
+            default: [],
+            type: cc.SpriteFrame,
+            serializable: true,
+        },
+        workArray: {
+
+            default: [],
+            type: cc.SpriteFrame,
+            serializable: true,
+        },
+        changeSprite: {
+            default: null,
+            type: cc.Sprite,
+            serializable: true,
+        },
+
+
+        //工作状态
+        workingStatus: {
+            default: null,
+            type: cc.Node,
+            serializable: true,
+        },
+
+        workPlace: {
+            default: reGameStates.BuildType.Farmland,
+            type: cc.Enum(reGameStates.BuildType),
+            serializable: true,
+        },
+    },
+    start() {
+
+        if (this.workPlace == reGameStates.BuildType.TimberYard) {
+            // this.onChangeSpriteFromGrow();
+        }
+    },
+
+
+    onChangeFromAIWorker(_workPlace, _consume) {
+        // cc.log('this.workPlace',_workPlace,_consume);
+
+        if (_workPlace == reGameStates.BuildType.Farmland) {
+            this.onChangeSpriteFromWork(_consume);
+        } else if (_workPlace == reGameStates.BuildType.TimberYard) {
+            this.onChangeSpriteFromTimberYardWork(_consume);
+
+        } else if (_workPlace == reGameStates.BuildType.MiningPit) {
+            this.onChangeSpriteFromWork(_consume);
+
+        }
+    },
+
+    // 工作时候
+    onChangeSpriteFromWork(consume) {
+
+        if (consume <= 0 || consume >= 50) {
+            this.workingStatus.active = false;
+        } else if (!this.workingStatus.active) {
+            this.workingStatus.active = true
+        }
+        let index = 50 - consume;
+        /*
+        //这部分是旧的代码
+        if (index < 20 && index > 10)
+            // this.changeSprite.spriteFrame = this.workArray[0];
+            this.changeSprite.spriteFrame = this.workArray[0];
+        else if (index >= 20 && index <= 35)
+            this.changeSprite.spriteFrame = this.workArray[1];
+        else if (index > 35)
+            this.changeSprite.spriteFrame = this.workArray[2];
+        */
+        if (index < 20 && index > 10) {
+            this.changeSprite.spriteFrame = this.workArray[0];
+            // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
+            // this.changeSprite.node.width = this.workArray[0].getRect().width;
+            // this.changeSprite.node.height = this.workArray[0].getRect().height;
+        }
+        else if (index >= 20 && index <= 35) {
+            this.changeSprite.spriteFrame = this.workArray[1];
+            // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
+            // this.changeSprite.node.width = this.workArray[1].getRect().width;
+            // this.changeSprite.node.height = this.workArray[1].getRect().height;
+        }
+        else if (index > 35) {
+            this.changeSprite.spriteFrame = this.workArray[2];
+            // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
+            // this.changeSprite.node.width = this.workArray[2].getRect().width;
+            // this.changeSprite.node.height = this.workArray[2].getRect().height;
+        }
+
+    },
+
+
+    onChangeSpriteFromTimberYardWork(consume) {
+        if (consume <= 0 || consume >= 50) {
+            this.workingStatus.active = false;
+        } else if (!this.workingStatus.active) {
+            this.workingStatus.active = true
+        }
+        let index = 50 - consume;
+        /*
+        //这部分是旧的代码
+        if (index < 25 && index > 10)
+            this.changeSprite.spriteFrame = this.workArray[0];
+        else if (index >= 25 && index <= 40)
+            this.changeSprite.spriteFrame = this.workArray[1];
+        else if (index > 40)
+            this.changeSprite.spriteFrame = this.workArray[2];
+        */
+
+        if (index < 25 && index > 10) {
+            this.changeSprite.spriteFrame = this.workArray[0];
+            // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
+            // this.changeSprite.node.width = this.workArray[0].getRect().width;
+            // this.changeSprite.node.height = this.workArray[0].getRect().height;
+            // cc.log(this.workArray[0].getRect().width);
+        }
+        else if (index >= 25 && index <= 40) {
+            this.changeSprite.spriteFrame = this.workArray[1];
+            // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
+            // this.changeSprite.node.width = this.workArray[1].getRect().width;
+            // this.changeSprite.node.height = this.workArray[1].getRect().height;
+        }
+        else if (index > 40) {
+            this.changeSprite.spriteFrame = this.workArray[2];
+            // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
+            // this.changeSprite.node.width = this.workArray[2].getRect().width;
+            // this.changeSprite.node.height = this.workArray[2].getRect().height;
+        }
+    },
+
+    // 运输时候调用
+    onChangeSpriteFromGrow() {
+
+        this.count = 0;
+        this.callback = function () {
+            if (this.count === this.stateArray.length - 1) {
+                // 在第六次执行回调时取消这个计时器
+                this.unschedule(this.callback);
+            }
+            this.onTreeGrowth(this.count);
+            this.count++;
+        }
+        this.schedule(this.callback, 0.5);
+    },
+    /**
+     * 神龙田地的直接生长
+     */
+    onHolyFarmlandSeedFromGrow() {
+        this.count = 0;
+        this.callback = function () {
+            if (this.count === this.stateArray.length - 1) {
+                // 在第六次执行回调时取消这个计时器
+                this.unschedule(this.callback);
+            }
+            this.onTreeGrowth(this.count);
+            this.count++;
+        }
+        this.schedule(this.callback, 0.5);
+    },
+    // 生长
+    onTreeGrowth(count) {
+        this.changeSprite.spriteFrame = this.stateArray[count];
+    },
+
+    onResetSprite(_workPlace) {
+        if (_workPlace == reGameStates.BuildType.Farmland) {
+            // this.changeSprite.spriteFrame = this.stateArray[0];
+            this.changeSprite.spriteFrame = this.stateArray[0];
+            this.onChangeSpriteFromGrow();
+        } else if (_workPlace == reGameStates.BuildType.TimberYard) {
+            //运输时候木材清空
+            this.changeSprite.spriteFrame = this.workArray[3];
+
+            this.onChangeSpriteFromGrow();
+
+        } else if (_workPlace == reGameStates.BuildType.MiningPit) {
+            this.changeSprite.spriteFrame = this.stateArray[0];
+        }
+    },
+
+    //设置当前的完成状态
+
+    //读取数据时候设置
+    //todo....
+    onSetWorkStateFormReadingData(_Index) {
+        this.changeSprite.spriteFrame = this.workArray[_Index];
+    },
+});

+ 9 - 0
assets/Script/build/WorkingBuilding.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "9635d312-a324-4b4b-afd9-4ee068bca140",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 305 - 0
assets/Script/build/buildingInfoView.js

@@ -0,0 +1,305 @@
+var reGameStates = require('GameStates');
+
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+
+        //名称
+        buildName: {
+            default: null,
+            type: cc.Label,
+        },
+        //维护费
+        runingCost: {
+            default: null,
+            type: cc.Label,
+        },
+        //库存
+        inventory: {
+            default: null,
+            type: cc.Label,
+        },
+        //简介
+        synopsis: {
+            default: null,
+            type: cc.Label,
+        },
+        //介绍图片
+        imageSprite: {
+            default: null,
+            type: cc.Sprite,
+        },
+
+        //商品名称
+        commodityName: {
+            default: null,
+            type: cc.Label,
+        },
+        //商品价格
+        commodityPrice: {
+            default: null,
+            type: cc.Label,
+        },
+
+        strength: {
+            default: null,
+            type: cc.Label,
+        },
+
+        //列表的对象
+        // CommodityItems: {
+        //     default: [],
+        //     visible: false,
+        // },
+
+        //记录当前商品的信息
+        goodsArray: {
+            default: null,
+            visible: false,
+        },
+
+        SalesInfoBg: {
+            default: null,
+            type: cc.Node
+        },
+        ProductionInfoBg: {
+            default: null,
+            type: cc.Node
+        },
+
+
+        //需要的农作物
+        materialCrops: {
+            default: null,
+            type: cc.Label,
+        },
+        //需要的木材
+        materialWood: {
+            default: null,
+            type: cc.Label,
+        },
+        //需要的矿石
+        materialMineral: {
+            default: null,
+            type: cc.Label,
+        },
+
+
+        //除了商店,展开otherNode时候的模板
+        //名称
+        otherBuildName: {
+            default: null,
+            type: cc.Label,
+        },
+        //维护费
+        otherRuningCost: {
+            default: null,
+            type: cc.Label,
+        },
+        //库存
+        otherInventory: {
+            default: null,
+            type: cc.Label,
+        },
+        //简介
+        otherSynopsis: {
+            default: null,
+            type: cc.Label,
+        },
+        //介绍图片
+        otherImageSprite: {
+            default: null,
+            type: cc.Sprite,
+        },
+
+        //商品名称
+        otherCommodityName: {
+            default: null,
+            type: cc.Label,
+        },
+        //商品价格
+        otherCommodityPrice: {
+            default: null,
+            type: cc.Label,
+        },
+        //销售或者生产力
+        otherProductivity: {
+            default: null,
+            type: cc.Label,
+        },
+    },
+
+
+    onSetBuildingInfoView(buildingInfo) {
+
+        switch (buildingInfo.buildType) {
+            // //特殊建筑
+            // case reGameStates.BuildType.Special:
+            //     break;
+            // //住房
+            // case reGameStates.BuildType.Housing:
+            //     break;
+
+            case reGameStates.BuildType.Shop:
+                this.inventory.string = buildingInfo._inventory;
+                this.buildName.string = buildingInfo.buildingName;
+
+                this.runingCost.string = buildingInfo.RunningCost;
+                this.synopsis.string = buildingInfo.BuildingSynopsis;
+
+                if (buildingInfo.BuildingSprite)
+                    this.imageSprite.spriteFrame = buildingInfo.BuildingSprite.spriteFrame;
+                else
+                    this.imageSprite.spriteFrame = null;
+
+                //显示当前商品信息
+                if (buildingInfo._goods) {
+                    this.commodityName.string = buildingInfo._goods.goodsName;
+                    this.commodityPrice.string = buildingInfo._goods.goodsPrice;
+
+
+                    //原材料
+                    this.materialCrops.string = buildingInfo._goods.goodsMaterial.crops;
+                    this.materialWood.string = buildingInfo._goods.goodsMaterial.wood;
+                    this.materialMineral.string = buildingInfo._goods.goodsMaterial.mineral;
+                }
+
+                this.strength.string = buildingInfo.totalConsumption;
+
+                //保存当前的商品信息
+                this.goodsArray = buildingInfo.goodsArray;
+                if (this.SalesInfoBg)
+                    this.SalesInfoBg.active = true;
+                if (this.ProductionInfoBg)
+                    this.ProductionInfoBg.active = false;
+                break;
+            //如果是农田,采木场,矿坑
+            case reGameStates.BuildType.Farmland:
+            case reGameStates.BuildType.TimberYard:
+            case reGameStates.BuildType.MiningPit:
+                this.onSetProductionInfo(buildingInfo);
+                let goodsArray = buildingInfo.goodsArray;
+                let length = goodsArray.length;
+                if (length == 0) {
+                    this.otherCommodityName.string = '';
+                    this.otherCommodityPrice.string = '';
+                } else {
+                    //当前销售的商品
+                    for (let i = 0; i < length; i++) {
+                        if (goodsArray[i].isItSale) {
+                            this.otherCommodityName.string = goodsArray[i].goodsName;
+                            this.otherCommodityPrice.string = goodsArray[i].goodsPrice;
+                            break;
+                        }
+                    }
+                }
+                break;
+            case reGameStates.BuildType.Factory:
+                //如果true,就是点击了工厂
+                this.onSetProductionInfo(buildingInfo);
+                if (buildingInfo._goods) {
+                    this.otherCommodityName.string = buildingInfo._goods.goodsName;
+                    this.otherCommodityPrice.string = buildingInfo._goods.goodsPrice;
+                } else {
+                    this.otherCommodityName.string = '';
+                    this.otherCommodityPrice.string = '';
+                }
+                break;
+        }
+    },
+
+    //显示销售的信息
+    onSetProductionInfo(buildingInfo) {
+        this.otherInventory.string = buildingInfo._inventory;
+        this.otherBuildName.string = buildingInfo.buildingName;
+
+        this.otherRuningCost.string = buildingInfo.RunningCost;
+        this.otherSynopsis.string = buildingInfo.BuildingSynopsis;
+
+
+        if (buildingInfo.BuildingSprite)
+            this.otherImageSprite.spriteFrame = buildingInfo.BuildingSprite.spriteFrame;
+        else
+            this.otherImageSprite.spriteFrame = null;
+
+        this.otherProductivity.string = buildingInfo.totalConsumption;
+
+        if (this.SalesInfoBg)
+            this.SalesInfoBg.active = false;
+        if (this.ProductionInfoBg)
+            this.ProductionInfoBg.active = true;
+    },
+
+    //显示商店信息
+    onSetShopInfo(buildingInfo) {
+        //显示对应的父节点
+        this.inventory.string = buildingInfo._inventory;
+        this.buildName.string = buildingInfo.buildingName;
+
+        this.runingCost.string = buildingInfo.RunningCost;
+        this.synopsis.string = buildingInfo.BuildingSynopsis;
+        if (buildingInfo.BuildingSprite)
+            this.imageSprite.spriteFrame = buildingInfo.BuildingSprite.spriteFrame;
+
+        // cc.log('buildingInfo',buildingInfo);
+        //显示当前商品信息
+        if (buildingInfo._goods) {
+            this.commodityName.string = buildingInfo._goods.goodsName;
+            this.commodityPrice.string = buildingInfo._goods.goodsPrice;
+
+            //原材料
+            this.materialCrops.string = buildingInfo._goods.goodsMaterial.crops;
+            this.materialWood.string = buildingInfo._goods.goodsMaterial.wood;
+            this.materialMineral.string = buildingInfo._goods.goodsMaterial.mineral;
+        }
+
+        this.strength.string = buildingInfo.totalConsumption;
+        //保存当前的商品信息
+        this.goodsArray = buildingInfo.goodsArray;
+
+
+        if (this.SalesInfoBg)
+            this.SalesInfoBg.active = true;
+
+        if (this.ProductionInfoBg)
+            this.ProductionInfoBg.active = false;
+    },
+
+    //点击更换商品时候显示
+    // onSetCommodityInfo() {
+    //     //隐藏对应的父节点
+    //     this.buildName.string = '商品列表';
+    //     this.content = this.CommodityScrollView.content;
+    //     this.spacing = 10;
+
+    //     this.ClearItems();
+    //     let length = this.goodsArray.length;
+    //     this.initialize(length, length);
+
+    // },
+
+    //生成商品列表
+    // initialize: function (totalCount, spawnCount) {
+    //     this.content.height = totalCount * (this.CommodityTemplate.height + this.spacing) + this.spacing; // get total content height
+    //     for (let i = 0; i < spawnCount; ++i) { // spawn items, we only need to do this once
+    //         let item = cc.instantiate(this.CommodityTemplate);
+    //         item.active = true;
+    //         this.content.addChild(item);
+    //         item.setPosition(0, -item.height * (0.5 + i) - this.spacing * (i + 1));
+    //         item.getComponent('CommodityItem').updateItem(i, i, this.goodsArray[i]);
+    //         this.CommodityItems.push(item);
+    //     }
+    // },
+
+    //清空UI商品列表
+    // ClearItems() {
+
+    //     let length = this.CommodityItems.length;
+
+    //     for (let i = length - 1; i >= 0; i--) { // spawn items, we only need to do this once
+    //         this.CommodityItems[i].destroy();
+
+    //     }
+    // }
+});

+ 9 - 0
assets/Script/build/buildingInfoView.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "fbea7901-1a47-4787-8732-08b9fd24882f",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 615 - 0
assets/Script/build/buildingsInfo.js

@@ -0,0 +1,615 @@
+var reGameStates = require('GameStates');
+//建筑物信息
+var BuildInfo = cc.Class({
+    name: "BuildInfo",
+    properties: {
+        //建筑类型
+        buildType: {
+            default: reGameStates.BuildType.Housing,
+            type: cc.Enum(reGameStates.BuildType),
+        },
+        //建筑id
+        id: -1,
+        //建筑所占区域
+        occupyArea: new cc.Vec2(),
+        //起始位置,代码动态设置
+        startTilePos: {
+            default: new cc.Vec2(),
+            visible: false,
+        },
+        //是否激活建筑物
+        //建筑在地图上,但是没激活,不能给游客们进行相应的操作
+        isItActive: {
+            default: false,
+            tooltip: '是否激活建筑物',
+        },
+        //是否有人占用
+        isItOccupied: {
+            default: false,
+            visible: false,
+        },
+        //占用对象用的信息
+        //AI_worker_Player
+        occupantPlayerInfo: {
+            default: null,
+            visible: false,
+        },
+        //有东西吗?//是否存在物品
+        //
+        isThereAnItem: {
+            default: false,
+            visible: false,
+        },
+        //是否可以销售产品
+        isItSaleable: {
+            default: false,
+            visible: false,
+            tooltip: '动态设定,是否允许销售',
+        },
+
+        //是否停运
+        isItStopOperation: {
+            default: false,
+            visible: false,
+            tooltip: '动态设定,是否停止运营',
+        },
+        //建筑名称
+         /**
+         * 重要:建筑时候 要用名字匹配来做减法 ManageGame.MuinusBuilding
+         */
+        buildingName: {
+            default: '',
+        },
+        BuildingPrefabName: {
+            default: '',
+        },
+        EnglishName: {
+            default: '',
+        },
+        //建筑简介
+        BuildingSynopsis: {
+            default: '',
+        },
+        //建筑图片
+        BuildingSprite: {
+            default: null,
+            type: cc.Sprite
+        },
+        //此建筑维护费用
+        RunningCost: {
+            default: 200,
+            type: cc.Integer,
+            visible: true,
+            tooltip: '消耗:维护费用/每月',
+        },
+        //此建筑每分钟消耗的体力值
+        consumeStrength: {
+            default: 0,
+            type: cc.Integer,
+            visible: true,
+            // displayName: '体力',
+            tooltip: '消耗:体力/每分钟',
+        },
+        //此建筑总共消耗的体力值
+        //工厂的生产力,
+        totalConsumption: {
+            default: 50,
+            type: cc.Integer,
+            visible: true,
+            // displayName: '体力',
+            tooltip: '这个建筑总共消耗的体力值,工厂代表生成力,商店代表销售力',
+        },
+        //商品的库存总量
+        totalInventory: {
+            default: 0,
+            type: cc.Integer,
+            tooltip: '商品的库存总量:销售商店需要,工厂',
+        },
+        //工厂:代表生产的商品
+        //商店:代表销售的商品
+
+        //定义的商品类型,也可动态添加
+        //todo...
+        goodsArray: {
+            default: [],
+            type: reGameStates.goods,
+        },
+        //当前销售的商品
+        _goods: {
+            default: null,
+            visible: false,
+        },
+        //商品的库存
+        _inventory: {
+            default: 0,
+            type: cc.Integer,
+            visible: false,
+        },
+        //目标建筑信息
+        //工厂只对应商店
+        _targetBuildingsInfo: {
+            default: null,
+            visible: false,
+        },
+        //可以寻找的目标点
+        //记录图块的二位数组
+        _gotoPosistion: {
+            default: [],
+            visible: false,
+        },
+
+        //特殊建筑用到的影响值,在预制设置
+        specialSetValue: {
+            default: 3,
+            type: cc.Integer,
+            visible: true,
+            tooltip: '特殊建筑需要填写的值',
+        },
+
+
+        consumeStrengthAddValue: {
+            default: 0,
+            type: cc.Integer,
+            visible: false,
+            tooltip: '消耗加成值:体力/每分钟',
+        },
+
+        goodsPriceAddValue: {
+            default: 0,
+            type: cc.Integer,
+            visible: false,
+            tooltip: '商品销售加成值',
+        },
+        AssetValue: {
+            default: 0,
+            type: cc.Integer,
+            visible: false,
+            tooltip: '资产值',
+        },
+    },
+    //设置当前存量
+    onSetCurrentInventory(value) {
+        // cc.log("onSetCurrentInventory", value);
+        //购买的个数
+        let callBackNum = Math.abs(value);
+        this._inventory += Number(value);
+        if (this._inventory <= 0) {
+            // cc.warn("onSetCurrentInventory", this._inventory);
+            //如果商品库存不够,返回只购买剩余的个数
+            callBackNum += this._inventory;
+            this._inventory = 0;
+        }
+        if (this._inventory > this.totalInventory)
+            this._inventory = this.totalInventory;
+
+        // this.node.getComponent("buildingTips").setShowStockData(null,"x"+this._inventory);
+        if (this.updatainventory != null) {
+            this.updatainventory();
+        }
+
+        // console.log("现在调用这个了",value);
+
+        return callBackNum;
+    },
+    updatainventory: function () {
+
+    },
+    setCallBackinventory: function (updatainventory) {
+        this.updatainventory = updatainventory;
+    }
+
+});
+cc.Class({
+    extends: cc.Component,
+    properties: {
+        title: cc.Label,
+        //建筑物信息
+        buildInfo: {
+            type: BuildInfo,
+            default: null
+        },
+        //绘制提示区域
+        buildZone: cc.Node,
+        _canBuild: false,
+
+        //是否是从数据初始化
+        InitPosFromStore: {
+            default: false,
+            visible: false,
+        },
+        //初始化位置
+        InitPos: false,
+        //建筑初始化的开始位置
+        InitStartPos: new cc.Vec2(),
+        //初始化商店的商品信息
+        InitBuildingInfo: {
+            default: false,
+            tooltip: '初始化商店的商品信息',
+        },
+        ShowTip: {
+            default: null,
+            type: cc.Label,
+            tooltip: '显示状态提示UI节点',
+        },
+        ShowTipString: '',
+        //初始工作地点的状态
+        InitWorkBuildingInfo: {
+            default: false,
+            tooltip: '初始工作地点的状态',
+        },
+        InitWorkBuildingIndex: {
+            default: 0,
+            type: cc.Integer,
+            tooltip: '下标:初始工作地点的状态',
+        },
+        // //是否添加到原料地
+        // isAddMatrialArray: {
+        //     default: false,
+        //     tooltip: '是否添加到原料地',
+        // },
+
+    },
+    onLoad() {
+        this._buildZone = this.buildZone.getComponent('buildZone');
+
+        //设置空字符
+        this.title.string = '';
+
+        // this.buildInfo.setCallBackinventory(function () {
+        //     this.node.getComponent("buildingTips").setShowStockData(null,"x"+this.buildInfo._inventory);
+        // }.bind(this));
+
+
+        this.AssetValues = [];
+        this.AssetValues.push(5000);
+        this.AssetValues.push(10000);
+        this.AssetValues.push(15000);
+        this.AssetValues.push(400);
+        this.AssetValues.push(500);
+        this.AssetValues.push(600);
+        this.AssetValues.push(700);
+        this.AssetValues.push(800);
+        this.AssetValues.push(900);
+        // console.log("我经过吗",this.buildInfo.id);
+        //设置财产值
+
+        //银行
+        // 406001
+        //加工厂
+        // 610002
+        //农田
+        // 610003
+        //绿化带
+        // 401001
+        //花坛
+        // 402001
+        //游乐场
+        // 403001
+        //医院
+        // 404001
+        //住宅
+        // 101001
+        //单元楼
+        // 102001
+        //别墅
+        // 103001
+        //矿坑
+        // 610005
+        //伐木场
+        // 610004
+
+        // 神龙相关id
+        //农田 
+        // 610006
+
+        //警察局
+        // 405001
+        //甜品店
+        // 610010
+        //甜品店
+        // 610011
+        //甜品店
+        // 610012
+        //甜品店
+        // 610013
+        //甜品店
+        // 610014
+        //甜品店
+        // 610015
+        //甜品店
+        // 610016
+
+
+        switch (this.buildInfo.id) {
+            case 101001:
+                this.buildInfo.AssetValue = this.AssetValues[0];
+                break;
+            case 102001:
+                this.buildInfo.AssetValue = this.AssetValues[1];
+                break;
+            case 103001:
+                this.buildInfo.AssetValue = this.AssetValues[1];
+                break;
+            case 610003:
+                this.buildInfo.AssetValue = this.AssetValues[0];
+                break;
+            case 610004:
+                this.buildInfo.AssetValue = this.AssetValues[1];
+                break;
+            case 610005:
+                this.buildInfo.AssetValue = this.AssetValues[1];
+                break;
+            case 610002:
+                this.buildInfo.AssetValue = this.AssetValues[0];
+                break;
+            case 610010:
+            case 610013:
+            case 610016:
+                this.buildInfo.AssetValue = this.AssetValues[0];
+                break;
+            case 610011:
+            case 610014:
+                this.buildInfo.AssetValue = this.AssetValues[1];
+                break;
+            case 610012:
+            case 610015:
+                this.buildInfo.AssetValue = this.AssetValues[2];
+                break;
+            case 401001:
+                this.buildInfo.AssetValue = this.AssetValues[0];
+                break;
+            case 402001:
+                this.buildInfo.AssetValue = this.AssetValues[1];
+                break;
+            case 403001:
+                this.buildInfo.AssetValue = this.AssetValues[2];
+                break;
+        }
+
+
+
+
+
+        // if (this.buildInfo.buildType == reGameStates.BuildType.Housing) {
+        //
+        //     this.buildInfo.AssetValue = this.AssetValues[0];
+        // } else if (this.buildInfo.buildType == reGameStates.BuildType.Farmland) {
+        //     this.buildInfo.AssetValue = this.AssetValues[1];
+        // } else if (this.buildInfo.buildType == reGameStates.BuildType.TimberYard) {
+        //     this.buildInfo.AssetValue = this.AssetValues[2];
+        // } else if (this.buildInfo.buildType == reGameStates.BuildType.MiningPit) {
+        //     this.buildInfo.AssetValue = this.AssetValues[3];
+        // } else if (this.buildInfo.buildType == reGameStates.BuildType.Factory) {
+        //     this.buildInfo.AssetValue = this.AssetValues[4];
+        // } else if (this.buildInfo.buildType == reGameStates.BuildType.Shop) {
+        //     this.buildInfo.AssetValue = this.AssetValues[5];
+        // } else if (this.buildInfo.buildType == reGameStates.BuildType.Special) {
+        //     this.buildInfo.AssetValue = this.AssetValues[6];
+        // }
+
+
+    },
+    start() {
+        this._tileMap = GlobalD.TiledMap;
+
+        //开始初始化位置,添加到数组里面
+        if (this.InitPos) {
+
+            //场景的预制初始化可销售状态
+            if (this.buildInfo.buildType == reGameStates.BuildType.Farmland) {
+                //设置销售状态,
+                this.buildInfo.isItSaleable = true;
+            }
+
+            //把物体定位到对应的坐标上去
+            this._currentTiledValue = this.InitStartPos;
+            if (this._currentTiledValue) {
+                //往前移一格
+                var endTiledPos = cc.v2(this._currentTiledValue.x, this._currentTiledValue.y);
+                var endPos = this._tileMap._getTheMiddleLocationFromtilePos(endTiledPos);
+                this.node.setPosition(endPos);
+                let isHas = GlobalD.game.doesItExistArray(this.buildInfo.id);
+                if (!isHas) {
+                    //起始坐标,占位范围,是否占位
+                    GlobalD.game.addBuildTiled(this.buildInfo.id, this._currentTiledValue, this.buildInfo.occupyArea);
+
+                    this.buildInfo.startTilePos = this._currentTiledValue;
+                    GlobalD.game.addBuilding(this);
+                } else {//如果已经存在,更新新位置
+                    //可以移动
+                    let isMove = true;
+                    GlobalD.game.updateBuildOccupy(isMove, this.buildInfo.id, this._currentTiledValue, this.buildInfo.occupyArea);
+
+                    this.buildInfo.startTilePos = this._currentTiledValue;
+                    GlobalD.game.updateBuilding(this);
+                }
+            }
+        }
+
+
+        //初始化设置房屋信息
+        if (this.InitBuildingInfo) {
+            //设置销售物品
+            this.onSettingBuildingState();
+        }
+        if (this.InitWorkBuildingInfo) {
+            this.onInitBuildingState();
+        }
+        if (this.buildInfo.consumeStrength == 0 && this.buildInfo.buildType !== reGameStates.BuildType.Shop && this.buildInfo.buildType !== reGameStates.BuildType.Special) {
+            cc.warn('这个建筑可能需要消耗或者增加体力值:', this.buildInfo.startTilePos);
+        }
+    },
+    //代码设置位置
+    setInitStartPos: function (x, y) {
+        this.InitStartPos = cc.v2(x, y);
+        //把物体定位到对应的坐标上去
+        this._currentTiledValue = this.InitStartPos;
+        if (this._currentTiledValue) {
+            //往前移一格
+            var endTiledPos = cc.v2(this._currentTiledValue.x, this._currentTiledValue.y);
+            var endPos = this._tileMap._getTheMiddleLocationFromtilePos(endTiledPos);
+            this.node.setPosition(endPos);
+            let isHas = GlobalD.game.doesItExistArray(this.buildInfo.id);
+            if (!isHas) {
+                //起始坐标,占位范围,是否占位
+                GlobalD.game.addBuildTiled(this.buildInfo.id, this._currentTiledValue, this.buildInfo.occupyArea);
+
+                this.buildInfo.startTilePos = this._currentTiledValue;
+                GlobalD.game.addBuilding(this);
+            } else {//如果已经存在,更新新位置
+                //可以移动
+                let isMove = true;
+                GlobalD.game.updateBuildOccupy(isMove, this.buildInfo.id, this._currentTiledValue, this.buildInfo.occupyArea);
+
+                this.buildInfo.startTilePos = this._currentTiledValue;
+                GlobalD.game.updateBuilding(this);
+            }
+        }
+    },
+
+
+    //初始化时候,生成房屋的数据状态
+    onInitBuildingState() {
+        // if (this.buildInfo.buildType == reGameStates.BuildType.Farmland)
+        {
+            //设置库存
+            this.buildInfo._inventory = this.buildInfo.totalInventory;
+            //设置满库存状态
+            this.node.getComponent('WorkingBuilding').onSetWorkStateFormReadingData(this.InitWorkBuildingIndex);
+
+        }
+    },
+    //设置房屋当前状态
+    //比如,商店:没有商品,
+    onSettingBuildingState() {
+        //如果是商店的话
+        if (this.buildInfo.buildType == reGameStates.BuildType.Shop) {
+            let num = this.buildInfo.onSetCurrentInventory(-1000);
+            // cc.log(num);
+            //初始化销售的商品
+            for (let i = 0; i < this.buildInfo.goodsArray.length; i++) {
+                if (this.buildInfo.goodsArray[i].isItSale) {
+                    this.buildInfo._goods = this.buildInfo.goodsArray[i];
+                    break;
+                }
+            }
+        }
+    },
+    //在预制初始化时候调用
+    onInitFromPrefabs() {
+
+    },
+    onShowTip(tipString) {
+        if (!this.ShowTip) return;
+        this.ShowTip.string = tipString;
+        this.ShowTip.node.parent.active = true;
+
+        setTimeout(() => {
+            this.ShowTip.node.parent.active = false;
+        }, 1000)
+    },
+    //商品售罄
+    onSetTipSellOut() {
+
+        // cc.log('商店售罄');
+        // this.onShowTip(this.ShowTipString);
+        //通知工厂生产销售商品
+        //{buildingInfo,goodsItem}
+        GlobalD.game.onNotificationFactory(this);
+    },
+    //工人送完商品设置
+    //商店
+    onResetFromWorkersFinished() {
+        //暂时设置最高的库存量
+        this.buildInfo.onSetCurrentInventory(5);
+        //清空对应的工厂信息
+        this.buildInfo._targetBuildingsInfo = null;
+    },
+    //工厂到商店流程中断时候设置
+    onResetFromWorkersSuspend() {
+        //暂时设置最高的库存量
+        // this.buildInfo.onSetCurrentInventory(0);
+        //清空对应的工厂信息
+        this.buildInfo._targetBuildingsInfo = null;
+    },
+    //商店重置对应工厂信息
+    onResetProductionRequest() {
+        //通知工厂对应的工人
+        if (this.buildInfo.occupantPlayerInfo != null) {
+            //工厂设置值
+            this.buildInfo.occupantPlayerInfo.transTarget = null;
+        }
+
+        this.buildInfo._goods = null;
+        this.buildInfo._targetBuildingsInfo = null;
+        this.buildInfo.isItOccupied = false;
+
+    },
+
+
+    //清除建筑后,调用此函数 
+    onClearSelfResetFromType() {
+        // cc.log('清除类型:', this.buildInfo.buildType)
+        if (this.buildInfo.buildType == reGameStates.BuildType.Shop) {
+            //如果清除的建筑是商店
+            //通知工厂工作清除
+            if (this.buildInfo._targetBuildingsInfo) {
+                this.buildInfo._targetBuildingsInfo.onResetProductionRequest();
+            }
+
+        } else if (this.buildInfo.buildType == reGameStates.BuildType.Factory) {
+            //如果是工厂拆除了
+
+            //通知工厂对应的工人
+            if (this.buildInfo.occupantPlayerInfo != null) {
+                // this.occupantPlayerInfo.AIAttribute.isWorking = false;
+                // this.occupantPlayerInfo._isColletion = false;
+                //工厂设置值
+                this.buildInfo.occupantPlayerInfo.transTarget = null;
+            }
+
+            //通知商店,通知清除对应的工厂目标
+            if (this.buildInfo._targetBuildingsInfo)
+                this.buildInfo._targetBuildingsInfo.onResetFromWorkersSuspend();
+
+
+        } else if (this.buildInfo.buildType == reGameStates.BuildType.Housing) {
+            //如果是房子拆除
+            if (this.buildInfo.occupantPlayerInfo) {
+                this.buildInfo.occupantPlayerInfo.onDismantleBuilding();
+            }
+        }
+        // else {
+        //     //其他工作地点,比如农田,矿厂,伐木场
+        //     //特殊建筑可以忽略
+        //     // cc.log('清除类型:', this.buildInfo.buildType)
+        // }
+    },
+
+    //如果商店停运调用这个函数
+    onStopOperation() {
+        if (this.buildInfo.buildType == reGameStates.BuildType.Shop) {
+            if (this.buildInfo._targetBuildingsInfo)
+                this.buildInfo._targetBuildingsInfo.onResetProductionRequest();
+
+            //如果商店停运
+            this.onResetFromWorkersSuspend();
+
+            // cc.log('停运后,',this.buildInfo._targetBuildingsInfo);
+        } else if (this.buildInfo.buildType == reGameStates.BuildType.Factory) {
+
+            if (this.buildInfo._targetBuildingsInfo) {
+                //如果工厂停运,就把工厂对应的商店目标,通知商店,清空工厂自己
+                this.buildInfo._targetBuildingsInfo.buildInfo._targetBuildingsInfo = null;
+            }
+            this.onResetProductionRequest();
+        }
+    },
+
+    /**
+     * 植物生长
+     */
+    onInitHolyFarmlandSeedFromGrow(){
+        this.node.getComponent('WorkingBuilding').onHolyFarmlandSeedFromGrow();
+    }
+});

+ 9 - 0
assets/Script/build/buildingsInfo.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "665c9393-d91d-4e82-aa4e-e96ea89e5690",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 405 - 0
assets/Script/build/buildingsTouch.js

@@ -0,0 +1,405 @@
+
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+
+        //是否显示房屋信息
+        isShowBuildingInfo: { default: false },
+
+        // 是否是在预制生成
+        _isInstance: { default: false, visible: false },
+        //如果进入编辑状态
+        _ifCanEdit: { default: false, visible: false },
+
+        //触摸多久进入编辑状态
+        touchTimer: { default: 0.8, visible: false },
+
+        // //绘制底部颜色区域
+        // Draw: cc.Node,
+
+        //触摸一开始的位置
+        _touchPosition: {
+            default: new cc.Vec2(),
+            visible: false,
+            serializable: false
+        },
+        _EndPosition: {
+            default: new cc.Vec2(),
+            visible: false,
+            serializable: false
+        },
+
+        //如果自动移动
+        isAutoMove: { default: false, visible: false },
+
+        targetNode: cc.Node,
+
+        //编辑时候,记录旧的遮挡位置
+        _OldIndex: 0,
+
+        //如果是在新手引导时候建造的建筑
+        //只要拖拽到虚影对应的位置,才能成功建造
+    },
+
+    // LIFE-CYCLE CALLBACKS:
+
+    onLoad() {
+        this._buildingsInfo = this.node.getComponent('buildingsInfo');
+        this.buildInfo = this._buildingsInfo.buildInfo;
+        this.title = this._buildingsInfo.title;
+
+        this.node.on(cc.Node.EventType.TOUCH_START, this.TouchStartFunction, this);
+        this.node.on(cc.Node.EventType.TOUCH_END, this.TouchEndFunction, this);
+        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.TouchCancelFunction, this);
+        //不规则碰撞绑定
+        // this.node._oldHitTest = this.node._hitTest.bind(this.node);
+        // this.node._hitTest = this.polygonHitTest.bind(this.node);
+        this.Draw = this._buildingsInfo._buildZone;
+        if (!this.Draw)
+            this.Draw = this.node.getChildByName('Draw');
+        this.Draw.active = false;
+    },
+
+    start() {
+        this.InitStartPos = this._buildingsInfo.InitStartPos;
+
+        this._camera = GlobalD.game.MainCamera;
+        this._canvas = GlobalD.game.Canvas;
+        this._tileMap = GlobalD.TiledMap;
+    },
+
+
+    TouchStartFunction() {
+        // cc.log('isItSaleable:',this._buildingsInfo.buildInfo.isItSaleable,
+        // 'isItOccupied:',this._buildingsInfo.buildInfo.isItOccupied,
+        // 'isItActive:',this._buildingsInfo.buildInfo.isItActive,
+        // 'isThereAnItem:',this._buildingsInfo.buildInfo.isThereAnItem,this._buildingsInfo.buildInfo.startTilePos)
+
+        // cc.log('consumeStrength:', this._buildingsInfo.buildInfo.consumeStrength,
+        //     "consumeStrengthAddValue:", this._buildingsInfo.buildInfo.consumeStrengthAddValue,
+        //     "goodsPriceAddValue:", this._buildingsInfo.buildInfo.goodsPriceAddValue);
+
+
+        // GlobalD.game._showUpEffectPrefab(this._buildingsInfo);
+
+        this._touchPosition = this.node.getPosition();
+
+        // cc.warn('touch start!');
+        GlobalD.GameControl._isBuildingMove = false;
+        this._isMove = false;
+        this.unschedule(this.callback);
+
+        this.scheduleOnce(this.callback = function () {
+            //编辑器移动的话,返回
+            if (GlobalD.GameControl.isUICameraMove) return;
+            //进入编辑状态
+            // cc.log('进入编辑状态!',GlobalD.GameControl.isUICameraMove);
+            // this.onEditorStatus(false);
+            //按住可以编辑
+        }, this.touchTimer);
+
+    },
+    //生成房屋时候的预制状态
+    // 编辑状态
+    onEditorStatus(isInstance) {
+
+        // cc.log('onEditorStatus', isInstance);
+        //如果是编辑状态下,返回
+        if (this._ifCanEdit) return;
+
+        //只要是编辑状态下。设为true
+        GlobalD.GameControl._isBuildingCanEdit = true;
+
+        this._isInstance = isInstance;
+        this._ifCanEdit = true;
+        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.MoveFunction, this);
+        GlobalD.game._ManageUIScript.onEditorialBuildings(this.node);
+        GlobalD.game.onSetCurrentBuildingTarget(this.node);
+
+        if (!this.Draw)
+            this.Draw = this.node.getChildByName('Draw')
+        this.Draw.active = true;
+
+        if (isInstance) {
+            // cc.log(11111);
+            this._currentTiledValue = GlobalD.TiledMap._tilePosFromLocation(this.node.position);
+            let endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(this._currentTiledValue);
+            this.node.setPosition(endPos);
+            this._canNotBuild = GlobalD.game.areTheraOverlappingAreas(this._currentTiledValue, this.buildInfo.occupyArea, 1);
+
+        } else {// if (this._tileMap) 
+            // cc.log(22222);
+            this._currentTiledValue = this._tileMap._tilePosFromLocation(this._touchPosition);
+            this._canNotBuild = GlobalD.game.areTheraOverlappingAreas(this._currentTiledValue, this.buildInfo.occupyArea, 1);
+        }
+
+        if (task.virtualShadowPos)
+            this._canNotBuild = this._currentTiledValue.sub(task.virtualShadowPos).mag() == 0 ? false : true;
+
+        GlobalD.game.onSpawnEditorBuildingTip(this.Draw, this._currentTiledValue, this.buildInfo.occupyArea, this._canNotBuild, this.buildInfo.buildType);
+
+        this._OldIndex = this.node.zIndex;
+        //设置最高显示
+        this.node.zIndex = 1000;
+    },
+    TouchCancelFunction() {
+        // cc.warn('touch cancel!');
+        this.unschedule(this.callback);
+        GlobalD.GameControl._isBuildingMove = false;
+    },
+    TouchEndFunction() {
+        // console.log("点击建筑物 之后",this.getOnClickTags());
+        if (this.getOnClickTags()) {
+            return;
+        }
+
+        GlobalD.GameControl._isBuildingMove = false;
+
+        this.unschedule(this.callback);
+        // cc.warn('touch End!');
+
+        //如果没有移动就判断点击
+        if (!this._isMove
+            && this.isShowBuildingInfo
+            && !this._ifCanEdit
+            && !GlobalD.GameControl.isUICameraMove
+            && !GlobalD.GameControl._isBuildingCanEdit)
+            GlobalD.game._ManageUIScript.onShowBuildingInfo(this.buildInfo);
+
+    },
+    MoveFunction(event) {
+        // cc.log("MoveFunction");
+        var delta = event.touch.getDelta();
+        this._touchPosition.x += delta.x / this._camera.zoomRatio;
+        this._touchPosition.y += delta.y / this._camera.zoomRatio;
+        // var worldPos = this.node.parent.convertToWorldSpaceAR(this._touchPosition);
+        //取得的节点减去canvas的偏移
+        // let tempPos = cc.v2(worldPos.x - this._canvas.x, worldPos.y - this._canvas.y);
+        this._currentTiledValue = this._tileMap._tilePosFromLocation(this._touchPosition);
+        //不相等的时候才绘制
+        if (this._currentTiledValue.sub(this._EndPosition).mag() != 0) {
+
+            this._EndPosition = this._currentTiledValue;
+            let endPos = this._tileMap._getTheMiddleLocationFromtilePos(this._currentTiledValue);
+            this.node.setPosition(endPos);
+            let isHas = this._canNotBuild = GlobalD.game.areTheraOverlappingAreas(this._currentTiledValue, this.buildInfo.occupyArea, 1);
+            // this.title.string = "(" + (this._currentTiledValue.x) + "," + (this._currentTiledValue.y) + ")" + isHas;
+
+            if (task.virtualShadowPos)
+                this._canNotBuild = this._EndPosition.sub(task.virtualShadowPos).mag() == 0 ? false : true;
+
+
+            GlobalD.game.onSpawnEditorBuildingTip(this.Draw, this._currentTiledValue, this.buildInfo.occupyArea, this._canNotBuild, this.buildInfo.buildType);
+
+        }
+        this._isMove = true;
+        GlobalD.GameControl._isBuildingMove = true;
+    },
+    // 自动移动,在ManagerControl 里面调用
+    onAutoMove(delta) {
+        this.isAutoMove = true;
+        this._touchPosition.x += delta.x;
+        this._touchPosition.y += delta.y;
+        this._currentTiledValue = this._tileMap._tilePosFromLocation(this._touchPosition);
+        //不相等的时候才绘制
+        if (this._currentTiledValue.sub(this._EndPosition).mag() != 0) {
+            this._EndPosition = this._currentTiledValue;
+            let endPos = this._tileMap._getTheMiddleLocationFromtilePos(this._currentTiledValue);
+            this.node.setPosition(endPos);
+            let isHas = this._canNotBuild = GlobalD.game.areTheraOverlappingAreas(this._currentTiledValue, this.buildInfo.occupyArea, 1);
+            // this.title.string = "(" + (this._currentTiledValue.x) + "," + (this._currentTiledValue.y) + ")" + isHas;
+
+            if (task.virtualShadowPos)
+                this._canNotBuild = this._EndPosition.sub(task.virtualShadowPos).mag() == 0 ? false : true;
+
+            GlobalD.game.onSpawnEditorBuildingTip(this.Draw, this._currentTiledValue, this.buildInfo.occupyArea, this._canNotBuild, this.buildInfo.buildType);
+
+
+        }
+    },
+
+    onCancleAutoMove() {
+        this.isAutoMove = false;
+
+    },
+
+    /**
+     * 编辑房子时候
+     * 完成建造房子流程
+     */
+    onFinishEdit() {
+
+        GlobalD.GameControl._isBuildingCanEdit = false;
+        GlobalD.game.onClearCurrentBuildingTarget();
+        // cc.log(this._ifCanEdit, this._canNotBuild);
+        if (this._canNotBuild) {
+            //如果不可建造区域,跳回起始位置
+            this.onCancelEdit();
+            return;
+        }
+        //如果完成时候,还在初始化生成的状态,重置为false
+        if (this._isInstance) {
+            this._isInstance = false;
+            GlobalD.game._ManageUIScript.onBottomMenuView(true);
+
+            //只有初始化建筑建造成功才移除建筑数据
+            /**
+             * 操作记录的数据减少1
+             */
+            GlobalD.game.MuinusBuilding(this.buildInfo.buildingName);
+        }
+        if (!this._ifCanEdit) return;
+        //把物体定位到对应的坐标上去
+        if (this._currentTiledValue) {
+            //如果可以移动的话,更新一次位置
+            this.InitStartPos = this._currentTiledValue;
+            var endTiledPos = cc.v2(this._currentTiledValue.x, this._currentTiledValue.y);
+            var endPos = this._tileMap._getTheMiddleLocationFromtilePos(endTiledPos);
+            this.node.setPosition(endPos);
+            let isHas = GlobalD.game.doesItExistArray(this.buildInfo.id);
+            if (!isHas) {
+                //起始坐标,占位范围,是否占位
+                GlobalD.game.addBuildTiled(this.buildInfo.id, this._currentTiledValue, this.buildInfo.occupyArea);
+                this.buildInfo.startTilePos = this._currentTiledValue;
+                GlobalD.game.addBuilding(this._buildingsInfo);
+            } else {//如果已经存在,更新新位置
+                //可以移动
+                let isMove = true;
+                GlobalD.game.updateBuildOccupy(isMove, this.buildInfo.id, this._currentTiledValue, this.buildInfo.occupyArea);
+                this.buildInfo.startTilePos = this._currentTiledValue;
+                GlobalD.game.updateBuilding(this._buildingsInfo);
+            }
+        }
+
+        //完成后从新设置状态
+        this.Draw.active = false;
+        this._ifCanEdit = false;
+        this.node.off(cc.Node.EventType.TOUCH_MOVE, this.MoveFunction, this);
+
+        // cc.log('this.Draw.active', this.Draw.active);
+        // cc.log('this._buildingsInfo='+this._buildingsInfo.buildInfo.EnglishName);
+
+        //设置影响力
+        GlobalD.game.onFinishAddEditorBuildingsEffect(this._buildingsInfo);
+
+        if (task.TaskIconCountClick >= 13)
+            return;
+        //引导 开始 建造 农舍 确定之后
+        if (task.taskCursor == 0 && this.node.name == "Env_101_house_low") {
+            task.taskShare();
+            task.onShadowArchitectureReset();
+
+        }
+
+        if (this.node.name == "Labour_201_Farmland") {
+            task.Farming();
+            task.onShadowArchitectureReset();
+        }
+
+
+        // if (this.node.name == "Labour_204_Factory") {
+        //     //盖一个工厂
+        //     task.taskfactory();
+        // }
+        // if (this.node.name == "Shops_30101_ColdDrinkStall") {
+        //     //盖一个便利店
+        //     task.taskConvenienceStore();
+        // }
+        // //
+        // if (this.node.name == "Spe_402_GreenBelt") {
+
+        //     task.taskGreenBeltShare();
+        // }
+        // if (this.node.name == "Env_101_house_low") {
+        //     task.taskFarmhouse();
+        // }
+        UtilsWX.getAllBuild();
+    },
+
+
+
+    onTaskBuild() {
+        // console.log(this._canNotBuild, task.isMushBuildState);
+        if (task.isMushBuildState && this._canNotBuild) {
+            //如果不可建造区域
+            if (this.node.name == "Env_101_house_low" || this.node.name == "Labour_201_Farmland") {
+                // task.onTaskBuildAHouseMask();
+                cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
+                    var prefab = cc.instantiate(texture);
+                    prefab.getComponent('ShowNotEnoughMoney').Text('请在指定位置建造!');
+                    // this.node.addChild(prefab);
+                    cc.find('Canvas').getChildByName('UICamera').addChild(prefab);
+                }.bind(this));
+            }
+            return false;
+        }
+
+        return true;
+    },
+
+
+    onCancelEdit() {
+
+        GlobalD.GameControl._isBuildingCanEdit = false;
+
+        this.node.zIndex = this._OldIndex;
+        // cc.log('onCancelEdit');
+        GlobalD.game.onClearCurrentBuildingTarget();
+
+        if (this._isInstance) {
+            // cc.log('删除1');
+            //清除底部的提示,放回对象池
+            GlobalD.game.onClearSpawnEditorBuildingTip();
+            GlobalD.game._ManageUIScript.onBottomMenuView(true);
+            //如果是预制生成的,取消生成的时候,删除预制
+            this.scheduleOnce(() => {
+                this.node.destroy();
+            }, 0)
+        } else {
+            // cc.log('删除2');
+            this.Draw.active = false;
+            this._ifCanEdit = false;
+            // cc.log(' buildingsInfo.buildInfo.InitStartPos', this.InitStartPos);
+            this.node.off(cc.Node.EventType.TOUCH_MOVE, this.MoveFunction, this);
+            var endTiledPos = cc.v2(this.InitStartPos.x, this.InitStartPos.y);
+            var endPos = this._tileMap._getTheMiddleLocationFromtilePos(endTiledPos);
+            this.node.setPosition(endPos);
+        }
+
+    },
+
+
+    /**
+     * 需要添加碰撞体
+   * 不规则多边形触摸测试
+   * @param {触摸点} point 
+   * @param {监听} listener 
+   */
+    polygonHitTest(point, listener) {
+        var polygonCollider = this.getComponent(cc.PolygonCollider);
+        if (polygonCollider) {
+            point = this.convertToNodeSpace(point);
+            point.x -= this.getContentSize().width / 2;
+            point.y -= this.getContentSize().height / 2;
+            return cc.Intersection.pointInPolygon(point, polygonCollider.points);
+        } else {
+            return this._oldHitTest(point, listener);
+        }
+    },
+
+    /**
+     * 判断是否可以被优先点击
+     * @returns {*}
+     */
+    getOnClickTags: function () {
+        if (this.getComponent("Collect") != null) {
+            return this.getComponent("Collect").getOnClickTag();
+        } else {
+            return false;
+        }
+
+
+    }
+
+});

+ 9 - 0
assets/Script/build/buildingsTouch.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "c818f0c7-3402-4bfc-a500-9da3ca6de92d",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}