LeaseFarmlandInfo.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. import date from "../Unit/date.js"
  2. import gameToast from "../Network/gameToast"
  3. /**
  4. * 操作租赁土地的相关业务
  5. */
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. leasePanelPrefabs: {
  10. default: null,
  11. type: cc.Prefab,
  12. serializable: true,
  13. },
  14. /**
  15. * 显示天数部分
  16. */
  17. upSliderNode: {
  18. default: null,
  19. type: cc.Node,
  20. serializable: true,
  21. },
  22. multipleLabel: {
  23. default: null,
  24. type: cc.Label,
  25. serializable: true,
  26. toolTip: "显示的倍数"
  27. },
  28. leaseDate: {
  29. default: null,
  30. type: cc.Label,
  31. serializable: true,
  32. toolTip: "剩余天数/总天数"
  33. },
  34. /**
  35. * 成熟期部分
  36. */
  37. midSliderNode: {
  38. default: null,
  39. type: cc.Node,
  40. serializable: true,
  41. },
  42. midDate: {
  43. default: null,
  44. type: cc.Label,
  45. serializable: true,
  46. toolTip: "剩余天数/总天数"
  47. },
  48. midSliderProgressNode: {
  49. default: null,
  50. type: cc.Node,
  51. serializable: true,
  52. toolTip: "进度条"
  53. },
  54. notLeased: {
  55. default: null,
  56. type: cc.Node,
  57. serializable: true,
  58. },
  59. // configLandId: 1
  60. // createTime: "2022-01-10 21:25:30"
  61. // id: 1
  62. // isLease: 1
  63. // isPlant: 0
  64. // landDescribe: "土地1xxx"
  65. // leaseMultiple: 1
  66. // leaseTime: "2022-01-10 21:25:17"
  67. // name: "土地1"
  68. // plantMature: 0
  69. // plantStart: "2022-01-10 21:25:22"
  70. // updateTime: "2022-01-10 21:25:33"
  71. // userId: "4"
  72. // 已经租赁的土地信息
  73. leaseLandInfo: {
  74. default: null,
  75. visible: false
  76. },
  77. // createTime: "2022-01-10 21:25:30"
  78. // id: 4
  79. // initMultiple: 1
  80. // isInit: 1
  81. // isLease: 0
  82. // isPlant: 0
  83. // landDescribe: "一倍土地"
  84. // leaseMultiple: 1
  85. // leaseTime: "2022-01-10 21:25:17"
  86. // name: "土地4"
  87. // plantMature: 0
  88. // plantStart: "2022-01-10 21:25:22"
  89. // posX: 19
  90. // posY: 10
  91. // sizeX: 2
  92. // sizeY: 2
  93. // updateTime: "2022-01-10 21:25:33"
  94. // 未初始化时候的土地信息
  95. configLandInfo: {
  96. default: null,
  97. visible: false
  98. },
  99. showLandInfo: {
  100. default: null,
  101. type: cc.Node,
  102. serializable: true,
  103. toolTip: "显示土地信息"
  104. },
  105. landInfoPrefabs: {
  106. default: null,
  107. type: cc.Prefab,
  108. serializable: true,
  109. },
  110. // 已经种植的作物信息
  111. plantInfo: {
  112. default: null,
  113. visible: false
  114. },
  115. showPlantInfo: {
  116. default: null,
  117. type: cc.Node,
  118. serializable: true,
  119. toolTip: "显示种植信息"
  120. },
  121. plantInfoPrefabs: {
  122. default: null,
  123. type: cc.Prefab,
  124. serializable: true,
  125. },
  126. //收获阶段
  127. harvestNode: {
  128. default: null,
  129. type: cc.Node,
  130. serializable: true,
  131. }
  132. },
  133. // LIFE-CYCLE CALLBACKS:
  134. // onLoad () {},
  135. start() {
  136. },
  137. onSpawnLeasePanel() {
  138. let leasePanel = cc.instantiate(this.leasePanelPrefabs);
  139. let parent = cc.find('Canvas/UICamera/DAPPContainer');
  140. leasePanel.parent = parent;
  141. leasePanel.setPosition(0, 0);
  142. // leasePanel.zIndex = 999;
  143. //把操作对象传入
  144. let leasePanelScript = leasePanel.getComponent("LeaseInfo");
  145. leasePanelScript.leaseFarmlandInfoNode = this;
  146. /**
  147. * 初始化两个操作。一个是续约,续约的话,不给操作,只有续约按钮可点,相当于原来配置再购买一次
  148. *
  149. * this.leaseLandInfo 如果购买了土地,这个参数不为空
  150. */
  151. if (this.leaseLandInfo) {
  152. //续约时候拦截输入,固定倍数
  153. leasePanelScript.blockInput.active = true;
  154. //传入当前计算倍数
  155. leasePanelScript.onInitLeaseInfo(this.leaseLandInfo.leaseMultiple);
  156. } else if (0 === this.configLandInfo.initMultiple) {
  157. // 固定土地开启,限制输入,设置默认值是1
  158. leasePanelScript.blockInput.active = true;
  159. leasePanelScript.onInitLeaseInfo(1);
  160. } else {
  161. //多倍土地,可以自己输入
  162. leasePanelScript.onInitLeaseInfo(this.configLandInfo.initMultiple);
  163. }
  164. },
  165. /**
  166. * 解锁土地操作
  167. */
  168. onUnlockLand() {
  169. //直接删除此节点
  170. if(this.notLeased){
  171. this.notLeased.destroy();
  172. this.notLeased = null;
  173. }
  174. },
  175. //设置config的土地信息
  176. setConfigLandInfo(value) {
  177. this.configLandInfo = value;
  178. },
  179. //设置已租赁参数
  180. setLeaseLandInfo(value) {
  181. this.leaseLandInfo = value;
  182. //更新一下土地信息
  183. this.updateLandState();
  184. },
  185. updateLandState() {
  186. if (!this.leaseLandInfo) return;
  187. if (1 === this.leaseLandInfo.isLease) {
  188. //已解锁
  189. //显示剩余天数
  190. this.upSliderNode.parent.active = true;
  191. this.multipleLabel.string = this.leaseLandInfo.leaseMultiple;
  192. //计算天数
  193. let day1 = date.datedifference(date.formatTime(new Date()), this.leaseLandInfo.leaseTime);
  194. let allDay = date.datedifference(this.leaseLandInfo.createTime, this.leaseLandInfo.leaseTime);
  195. this.leaseDate.string = "剩余" + day1 + "天数,共" + allDay + "天";
  196. let sliderProgressScript = this.upSliderNode.getComponent("slider_progress");
  197. sliderProgressScript.onSetProcgress(day1 / allDay);
  198. //todo 到期处理
  199. //删除解锁图标
  200. this.onUnlockLand();
  201. /**
  202. * 绑定生成显示信息面板,现在土地信息
  203. */
  204. this.showLandInfo.on(cc.Node.EventType.TOUCH_START, () => {
  205. let leasePanel = cc.instantiate(this.landInfoPrefabs);
  206. let parent = cc.find('Canvas/UICamera/DAPPContainer');
  207. leasePanel.parent = parent;
  208. leasePanel.setPosition(0, 0);
  209. // leasePanel.zIndex = 999;
  210. let leasePanelScript = leasePanel.getComponent("LandInfo");
  211. //price,date,start,end,multiple,describe
  212. let _date = date.datedifference(this.leaseLandInfo.createTime, this.leaseLandInfo.leaseTime);
  213. let { rentalExpenses, createTime, leaseTime, leaseMultiple, landDescribe } = this.leaseLandInfo;
  214. leasePanelScript.setInfo(rentalExpenses, _date + "天", createTime, leaseTime, leaseMultiple + "倍", landDescribe);
  215. })
  216. if (this.leaseLandInfo.seedInfo) {
  217. this.midSliderNode.active = true;
  218. this.midSliderProgressNode.getComponent(cc.ProgressBar).progress = 0.5;
  219. let _currentDay = date.dateAddDate(this.leaseLandInfo.plantStart, this.leaseLandInfo.seedInfo.maturity)
  220. // console.log(_currentDay,date.formatTime(new Date()));
  221. let [_remainingDay, _remainingHour] = date.dayAndHour(_currentDay, date.formatTime(new Date()));
  222. this.midDate.string = "剩余" + _remainingDay + "天" + _remainingHour + "小时";
  223. /**
  224. * 绑定生成显示信息面板,种植信息
  225. */
  226. this.showPlantInfo.on(cc.Node.EventType.TOUCH_START, () => {
  227. let leasePanel = cc.instantiate(this.plantInfoPrefabs);
  228. let parent = cc.find('Canvas/UICamera/DAPPContainer');
  229. leasePanel.parent = parent;
  230. leasePanel.setPosition(0, 0);
  231. // leasePanel.zIndex = 999;
  232. let leasePanelScript = leasePanel.getComponent("PlantInfo");
  233. let _harvest = 0;
  234. if (this.leaseLandInfo.leaseDate === 1) {
  235. _harvest = this.leaseLandInfo.seedInfo.harvest1;
  236. } else if (this.leaseLandInfo.leaseDate === 2) {
  237. _harvest = this.leaseLandInfo.seedInfo.harvest2;
  238. } else if (this.leaseLandInfo.leaseDate === 3) {
  239. _harvest = this.leaseLandInfo.seedInfo.harvest3;
  240. }
  241. //price,maturity,plantStart,harvestQuantity,describe
  242. let { priceCnt, maturity, seedDescribe } = this.leaseLandInfo.seedInfo;
  243. leasePanelScript.setInfo(priceCnt, maturity + "天", this.leaseLandInfo.plantStart, _harvest, seedDescribe);
  244. })
  245. }
  246. } else {
  247. }
  248. },
  249. /**
  250. * 点击之后,重置土地信息, 并且收入进仓库果实列表中去
  251. */
  252. onShowHarvest() {
  253. this.harvestNode.active = true;
  254. this.harvestNode.on(cc.Node.EventType.TOUCH_START, () => {
  255. console.log("点击收获");
  256. let data = { landId: this.leaseLandInfo.id };
  257. //果实收入仓库,重置土地种植信息
  258. GlobalD.GameData.onAddFruit(data, (res, value) => {
  259. // console.log(value);
  260. if (value.code === 0) {
  261. //收成后处理相关状态
  262. this.harvestNode.active = false;
  263. this.midSliderNode.active = false
  264. let _workingBuilding = this.node.getComponent("WorkingBuilding");
  265. _workingBuilding.onSetGrow(0, null);
  266. // "收获成功!"
  267. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "收获成功!", 2, () => {
  268. console.log("finish toast!");
  269. });
  270. } else {
  271. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 2, () => {
  272. console.log("finish toast!");
  273. });
  274. }
  275. });
  276. })
  277. },
  278. onPayCnt() {
  279. }
  280. });