ManageSeedNode.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. var reGameStates = require('GameStates');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. seedType: {
  6. default: reGameStates.SeedType.Normal,
  7. type: cc.Enum(reGameStates.SeedType),
  8. },
  9. seedName:{
  10. default: ''
  11. },
  12. _EndPosition: {
  13. default: new cc.Vec2(),
  14. serializable: false,
  15. visible: false,
  16. },
  17. labelTip: {
  18. default: null,
  19. type: cc.Label,
  20. },
  21. labelTipString: {
  22. default: '移动可拆除对应建筑',
  23. },
  24. //记录节点
  25. targetBuildingsInfo: { default: null, visible: false },
  26. //移除的提示预制
  27. removeTipPrefab: { default: null, type: cc.Prefab },
  28. //记录要删除的节点
  29. selectedTarget: { default: [], type: cc.Node, visible: false },
  30. //记录选中的index
  31. selectedTargetIndex: { default: [], type: cc.Integer, visible: false },
  32. isMoveState: { default: true, visible: false },
  33. MoveStartNode: cc.Node,
  34. MoveEndNode: cc.Node,
  35. },
  36. // LIFE-CYCLE CALLBACKS:
  37. // onLoad () {},
  38. start() {
  39. //获取对应的地图层级
  40. this.buildLayer = GlobalD.TiledMap._tiledMap.getLayer('BuildsHighway');
  41. GlobalD.game._ManageUIScript.onBottomMenuView(false);
  42. var self = this;
  43. self._MainCamera = GlobalD.game.MainCamera;
  44. self._tiledMap = GlobalD.TiledMap._tiledMap;
  45. //获取最后建造公路的层级
  46. self.HighwayLayer = self._tiledMap.getLayer('Highway');
  47. self._game = GlobalD.game;
  48. //初始化时候设置一下位置
  49. //后面只要点击生成铺路就需要重置一下
  50. let startTiledPos = GlobalD.TiledMap._tilePosFromLocation(self.node.getPosition());
  51. let startEndPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(startTiledPos);
  52. self.node.setPosition(startEndPos);
  53. self._EndPosition = startTiledPos;
  54. if (reGameStates.SeedType.Normal === self.seedType) {
  55. //锤子类型
  56. let startIndex = GlobalD.TiledMap.getIndex(startTiledPos);
  57. let _targetBuildingsInfo = GlobalD.game.onGetBuildingsTiledMapUnitFromIndex(startIndex);
  58. if (_targetBuildingsInfo) {
  59. self.labelTip.string = '播种到' + _targetBuildingsInfo.buildInfo.buildingName + '上';
  60. self.targetBuildingsInfo = _targetBuildingsInfo;
  61. }
  62. else {
  63. self.labelTip.string = self.labelTipString;
  64. self.targetBuildingsInfo = null;
  65. }
  66. }
  67. self.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
  68. GlobalD.GameControl._isBuildingMove = true;
  69. var delta = event.touch.getDelta();
  70. self._touchPosition.x += delta.x / self._MainCamera.zoomRatio;
  71. self._touchPosition.y += delta.y / self._MainCamera.zoomRatio;
  72. let tiledPos = GlobalD.TiledMap._tilePosFromLocation(self._touchPosition);
  73. // //不相等的时候才绘制
  74. if (tiledPos.sub(self._EndPosition).mag() != 0) {
  75. self._EndPosition = tiledPos;
  76. self._SelectHighwayTiled(tiledPos);
  77. }
  78. }, self.node);
  79. self.node.on(cc.Node.EventType.TOUCH_START, function (event) {
  80. self.isMoving = true;
  81. self._touchPosition = self.node.getPosition();
  82. }, self.node);
  83. self.node.on(cc.Node.EventType.TOUCH_END, function (event) {
  84. //起始触摸位置
  85. GlobalD.GameControl._isBuildingMove = false;
  86. let buildIndex = GlobalD.TiledMap.getIndex(self._EndPosition);
  87. let _targetBuildingsInfo = GlobalD.game.onGetBuildingsTiledMapUnitFromIndex(buildIndex);
  88. if (_targetBuildingsInfo) {
  89. self.labelTip.string = '播种到' + _targetBuildingsInfo.buildInfo.buildingName + '上';
  90. self.targetBuildingsInfo = _targetBuildingsInfo;
  91. }
  92. else {
  93. self.labelTip.string = self.labelTipString;
  94. self.targetBuildingsInfo = null;
  95. }
  96. }, self.node);
  97. self.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
  98. //起始触摸位置
  99. GlobalD.GameControl._isBuildingMove = false;
  100. }, self.node);
  101. },
  102. onCancleSelf() {
  103. this.node.active = false;
  104. GlobalD.game._ManageUIScript.onBottomMenuView(true);
  105. },
  106. //播种
  107. onSowOnTheGround(){
  108. //调用土地相关
  109. if (!this.targetBuildingsInfo) return;
  110. // cc.log('this.targetBuildingsInfo', this.targetBuildingsInfo)
  111. // this.targetBuildingsInfo.onClearSelfResetFromType();
  112. //面板种子消耗减少1
  113. console.log('种子减少的类型名字',this.seedName);
  114. GlobalD.game.MuinusBuilding(this.seedName);
  115. this.targetBuildingsInfo.onInitHolyFarmlandSeedFromGrow();
  116. //隐藏种子和显示UI
  117. this.node.active = false;
  118. GlobalD.game._ManageUIScript.onBottomMenuView(true);
  119. },
  120. _SelectHighwayTiled(tiledPos) {
  121. let endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(tiledPos);
  122. this.node.setPosition(endPos);
  123. }
  124. });