ManageUI.js 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  1. // const constants = require('Constants');
  2. // var reGameStates = require('GameStates');
  3. var AConfig = require('../Config')
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. //左上角按钮列表
  8. LeftMenu: cc.Node,
  9. //编辑建筑物时候的ui显示
  10. EditorialBuildings: cc.Node,
  11. //记录编辑按钮的父对象
  12. _thisEditBuildingsParent: cc.Node,
  13. _Cancellation: cc.Button,
  14. _Comfirmation: cc.Button,
  15. _buildTarget: cc.Node,
  16. //显示建筑的详细信息
  17. //建筑面板
  18. BuildingInfoView: cc.Node,
  19. //ui Mask 对应的touch
  20. UITouch: {
  21. default: null,
  22. type: cc.Node,
  23. },
  24. //设置面板
  25. SettingInfoView: cc.Node,
  26. //建筑面板
  27. //建筑物列表.后面根据数据动态添加content的内容。
  28. //todo..
  29. BuildView: cc.Node,
  30. StoreView: cc.Node,
  31. BuildContent_Button: { default: null, type: cc.Button, visible: false },
  32. BuildContent_OldButton: { default: null, type: cc.Button, visible: false },
  33. BuildContent_Normal_Sprite: cc.SpriteFrame,
  34. BuildContent_Pressed_Sprite: cc.SpriteFrame,
  35. ButtonSelectedFrame: cc.Node,
  36. //建筑版面的介绍模板
  37. BuildContent_Name: cc.Label,
  38. BuildContent_Price: cc.Label,
  39. BuildContent_Mature: cc.Label,
  40. BuildContent_Synopsis: cc.Label,
  41. //人才面板
  42. PersonnelView: cc.Node,
  43. //股票面板
  44. StockView: cc.Node,
  45. //幸运转盘
  46. LuckView: cc.Node,
  47. // 底部的菜单栏
  48. BottomView: cc.Node,
  49. // 其他农场用户的界面节点
  50. OtherFarmerMask: cc.Node,
  51. Evn: cc.Node,
  52. Seed: cc.Node,
  53. EveryDaySignView: cc.Node,
  54. //提示面板
  55. TipView: cc.Node,
  56. //提示面板预制
  57. TipViewPrefab: cc.Prefab,
  58. ShowRewards: cc.Node,
  59. BuildingFrameArray: {
  60. default: [],
  61. type: [cc.Node],
  62. serializable: true,
  63. },
  64. Goldenlabel: cc.Node,
  65. Diamondlabel: cc.Node,
  66. CNTlabel: cc.Node,
  67. SNBlabel: cc.Node,
  68. Strengthlabel: cc.Node,
  69. Luckylabel: cc.Node,
  70. //显示的库存总量,人才界面
  71. cropContent: cc.Label,
  72. woodContent: cc.Label,
  73. mineContent: cc.Label,
  74. //钻石兑换金币
  75. DiamondGapView: cc.Node,
  76. DiamondNowlabel: cc.Label,
  77. ExchangeBtn: cc.Button,
  78. //钻石足够获得种子
  79. DiamondSeedsView: cc.Node,
  80. LightRotate: cc.Node,
  81. DiamondSeeds_SureBtn: cc.Button,
  82. inviteNode: cc.Node,
  83. listUserInfoNode: cc.Node,
  84. //商店面的介绍模板
  85. mallContent_Name: cc.Label,
  86. mallContent_Price: cc.Label,
  87. mallContent_SNBPrice: cc.Label,
  88. mallContent_Mature: cc.Label,
  89. mallContent_Synopsis: cc.Label,
  90. seedBottomLineBg: {
  91. default: null,
  92. type: cc.Node,
  93. },
  94. seedBottomCntNode: {
  95. default: null,
  96. type: cc.Node,
  97. },
  98. seedBottomSnbNode: {
  99. default: null,
  100. type: cc.Node,
  101. },
  102. seedBottomOrLabelNode: {
  103. default: null,
  104. type: cc.Node,
  105. },
  106. //偷取成功生成一个提示
  107. StealViewSuccessPrefab: cc.Prefab,
  108. //场景开始时候,打开的黑色遮罩
  109. surroundingBlack: cc.Node,
  110. dogButtonNode: cc.Node,
  111. stickButtonNode: cc.Node,
  112. //村长领取snb
  113. VillageReceivesSNBView: cc.Node,
  114. VillageReceivesSNBButton: cc.Node
  115. },
  116. onLoad() {
  117. cc.game.setFrameRate(30)
  118. cc.director.preloadScene('Login', function () { }.bind(this))
  119. if (this.EditorialBuildings) {
  120. this._thisEditBuildingsParent = this.EditorialBuildings.parent
  121. this._Cancellation = this.EditorialBuildings.getChildByName(
  122. 'Cancellation'
  123. ).getComponent(cc.Button)
  124. this._Comfirmation = this.EditorialBuildings.getChildByName(
  125. 'Confirmation'
  126. ).getComponent(cc.Button)
  127. }
  128. task.managerUi = this
  129. var data1 = {
  130. name: 'Whoareyou',
  131. openId: userData.openId,
  132. }
  133. UtilsWX.postMessage(data1)
  134. UtilsWX.shareMenu()
  135. UtilsWX.initWXSubContextView(cc.find('Canvas/UICamera/wx'))
  136. UtilsWX.openWXSubContextView(false)
  137. },
  138. isGame: function () {
  139. this.times = 0
  140. cc.game.on(
  141. cc.game.EVENT_HIDE,
  142. function () {
  143. console.log('游戏进入后台', this.getTime())
  144. if (UtilsWX.shareTag == 0) {
  145. // this.onHideGame();//处理游戏切到后台时的事件
  146. this.times = this.getTime()
  147. task.onLoad()
  148. // this.onShowGame();//处理游戏切回前台时的事件
  149. cc.director.loadScene(
  150. 'Login',
  151. function () {
  152. task.showPointerNode = null
  153. }.bind(this)
  154. )
  155. }
  156. },
  157. this
  158. )
  159. cc.game.on(
  160. cc.game.EVENT_SHOW,
  161. function () {
  162. console.log('重新返回游戏', this.getTime())
  163. // if (this.getTime()-this.times>=30000) {
  164. if (UtilsWX.shareTag == 0) {
  165. }
  166. UtilsWX.setShareTag(0)
  167. // }
  168. },
  169. this
  170. )
  171. },
  172. getTime: function () {
  173. return new Date().getTime()
  174. },
  175. // InitTask(BFirstLoadGame) {
  176. // // todo 新手教学 初始化
  177. // console.log("初始化真的假的", BFirstLoadGame);
  178. // if (!BFirstLoadGame) {
  179. // //首次初始化
  180. // task.onLoad();
  181. // //创建员工
  182. // cc.find('GameNode/ManageWorker').getComponent('ManageWorker').onRecruit();
  183. // cc.find('GameNode/ManageWorker').getComponent('ManageWorker').onRecruit();
  184. // } else {
  185. // task._init();
  186. // task.addSeneceTaskIcon();
  187. // task.onLoadno();
  188. // }
  189. // this.Init();
  190. // },
  191. start() {
  192. /*
  193. 其中第一个参数为捕捉的时间名,在官方文档中给出了几个选择,我们主要列举下触碰时间
  194. cc.Node.EventType.TOUCH_START 当手按下时触发
  195. cc.Node.EventType.TOUCH_END 当手抬起时候
  196. cc.Node.EventType.TOUCH_MOVE 当手按下滑动时
  197. cc.Node.EventType.TOUCH_CANCEL 当手按下滑动后 抬起时
  198. */
  199. if (this._Cancellation)
  200. this._Cancellation.node.on(
  201. cc.Node.EventType.TOUCH_END,
  202. this.onCancellationEditor,
  203. this
  204. )
  205. if (this._Comfirmation)
  206. this._Comfirmation.node.on(
  207. cc.Node.EventType.TOUCH_END,
  208. this.onConfirmationEditor,
  209. this
  210. )
  211. },
  212. Init() {
  213. this._setLockBuildingColor()
  214. let BuildingStateArray = GlobalD.GameData.GetBuildingLockStateArray()
  215. for (let i = 0; i < BuildingStateArray.length; i++) {
  216. if (BuildingStateArray[i] == 1) {
  217. if (this.BuildingFrameArray[i]) this.OpenBuildingUILock(i, false)
  218. }
  219. if (this.BuildingFrameArray[i])
  220. this.BuildingFrameArray[i]
  221. .getChildByName('Lock')
  222. .getChildByName('PriceBG')
  223. .getChildByName('label')
  224. .getComponent(cc.Label).string = this.FormatMoney(
  225. AConfig.BuildingUnlockMoneyArray[i]
  226. )
  227. }
  228. // *********** todo *************
  229. //初始化,面板信息
  230. //运营费用数组
  231. let _runningCostArray = AConfig.RunningCostArray
  232. for (let i = 0; i < _runningCostArray.length; i++) {
  233. if (this.BuildingFrameArray[i]) {
  234. let _contentButton =
  235. this.BuildingFrameArray[i].getComponent('Content_Button')
  236. _contentButton.Price = AConfig.RunningCostArray[i] //运营费用
  237. //设置新的钻石价格
  238. let _DiamondNumArray = GlobalD.GameData.GetDiamondNumArray()
  239. _contentButton.DiamondPrice = _DiamondNumArray[i] //钻石费用
  240. }
  241. }
  242. //如果用户未租赁过土地且未用钻石兑换过种子,则显示
  243. GlobalD.GameData.getPlayerExchangeState((res, value) => {
  244. //warn 这里需要增加对结果的判断
  245. if (0 === value.code) {
  246. //没有兑换过和没有租赁过
  247. if (!value.data.isExchange && !value.data.isLeased) {
  248. this.DiamondGapViewShow()
  249. }
  250. }
  251. })
  252. //显示背景
  253. this.surroundingBlack.active = true;
  254. },
  255. _setLockBuildingColor() {
  256. let BuildingStateArray = GlobalD.GameData.GetBuildingLockStateArray()
  257. for (let index = 0; index < BuildingStateArray.length; index++) {
  258. if (this.BuildingFrameArray[index] && BuildingStateArray[index] == 0) {
  259. this.BuildingFrameArray[index].color = new cc.Color(150, 150, 150, 150)
  260. this.BuildingFrameArray[index].getChildByName(
  261. 'New Sprite(Splash)'
  262. ).color = new cc.Color(0, 0, 0, 255)
  263. this.BuildingFrameArray[index].getChildByName('Name').active = false
  264. }
  265. }
  266. },
  267. OpenBuildingUILock(Index, BLock) {
  268. let Lock = (this.BuildingFrameArray[Index].getChildByName('Lock').active =
  269. BLock)
  270. let BuildingStateArray = GlobalD.GameData.GetBuildingLockStateArray()
  271. if (!BLock && BuildingStateArray[Index] == 0) {
  272. BuildingStateArray[Index] = 1
  273. this.BuildingFrameArray[Index].color = new cc.Color(255, 255, 255, 255)
  274. this.BuildingFrameArray[Index].getChildByName(
  275. 'New Sprite(Splash)'
  276. ).color = new cc.Color(255, 255, 255, 255)
  277. this.BuildingFrameArray[Index].getChildByName('Name').active = true
  278. GlobalD.GameData.SetBuildingLockStateArray(BuildingStateArray)
  279. }
  280. },
  281. OnUnLockBuilding(event, CustomEventData, callback) {
  282. cc.loader.loadRes(
  283. 'prefab/UnlockBuiding',
  284. function (err, texture) {
  285. this.UnlockBuildingDialogView = cc.instantiate(texture)
  286. this.BuildView.addChild(this.UnlockBuildingDialogView)
  287. {
  288. //CloseBtn
  289. let close = this.UnlockBuildingDialogView.getChildByName('close')
  290. let clickEventHandler = new cc.Component.EventHandler()
  291. clickEventHandler.target = this.node
  292. clickEventHandler.component = 'ManageUI'
  293. clickEventHandler.handler = 'onClickCloseInUnlockBuilding'
  294. let button = close.getComponent(cc.Button)
  295. button.clickEvents.push(clickEventHandler)
  296. }
  297. {
  298. //NoBtn
  299. let NoBTN = this.UnlockBuildingDialogView.getChildByName('NoBTN')
  300. let clickEventHandler = new cc.Component.EventHandler()
  301. clickEventHandler.target = this.node
  302. clickEventHandler.component = 'ManageUI'
  303. clickEventHandler.handler = 'onClickNoBTNInUnlockBuilding'
  304. let button = NoBTN.getComponent(cc.Button)
  305. button.clickEvents.push(clickEventHandler)
  306. }
  307. {
  308. //YesBtn
  309. let YesBTN = this.UnlockBuildingDialogView.getChildByName('YesBTN')
  310. let clickEventHandler = new cc.Component.EventHandler()
  311. clickEventHandler.target = this.node
  312. clickEventHandler.component = 'ManageUI'
  313. clickEventHandler.handler = 'onClickYesBTNInUnlockBuilding'
  314. clickEventHandler.customEventData = CustomEventData
  315. let button = YesBTN.getComponent(cc.Button)
  316. button.clickEvents.push(clickEventHandler)
  317. }
  318. //Close
  319. if (callback != null) {
  320. callback(this.UnlockBuildingDialogView)
  321. }
  322. }.bind(this)
  323. )
  324. },
  325. onClickCloseInUnlockBuilding(event) {
  326. this.UnlockBuildingDialogView.destroy()
  327. },
  328. onClickNoBTNInUnlockBuilding(event) {
  329. this.UnlockBuildingDialogView.destroy()
  330. },
  331. onClickYesBTNInUnlockBuilding(event, CustomEventData) {
  332. this.UnlockBuildingDialogView.destroy()
  333. let Index = parseInt(CustomEventData)
  334. let CostCoin = AConfig.BuildingUnlockMoneyArray[Index]
  335. if (
  336. GlobalD.GameData.GetDiamond() > CostCoin ||
  337. GlobalD.GameData.GetDiamond() == CostCoin
  338. ) {
  339. GlobalD.GameData.PlusDiamond(-CostCoin)
  340. this.OpenBuildingUILock(Index, false)
  341. cc.loader.loadRes(
  342. 'prefab/show',
  343. function (err, texture) {
  344. this.ShowRewardsView = cc.instantiate(texture)
  345. this.BuildView.addChild(this.ShowRewardsView)
  346. let Rewards =
  347. this.ShowRewardsView.getChildByName('GivePrize').getChildByName(
  348. 'Rewards'
  349. )
  350. Rewards.getComponent(cc.Sprite).spriteFrame = this.BuildingFrameArray[
  351. Index
  352. ].getChildByName('New Sprite(Splash)').getComponent(
  353. cc.Sprite
  354. ).spriteFrame
  355. var Sunshine =
  356. this.ShowRewardsView.getChildByName('GivePrize').getChildByName(
  357. 'Sunshine'
  358. )
  359. var GivePrize = this.ShowRewardsView.getChildByName('GivePrize')
  360. Sunshine.scaleX = 0
  361. Sunshine.scaleY = 0
  362. GivePrize.scaleX = 0
  363. GivePrize.scaleY = 0
  364. Sunshine.stopAllActions()
  365. GivePrize.stopAllActions()
  366. this.scheduleOnce(function () {
  367. var sc2 = cc.scaleTo(0.5, 0.8, 0.8)
  368. Sunshine.runAction(sc2)
  369. var sc3 = cc.scaleTo(0.5, 1.3, 1.3)
  370. GivePrize.runAction(sc3)
  371. var repeat = cc.repeatForever(cc.rotateBy(5.0, 360))
  372. Sunshine.runAction(repeat)
  373. }, 0.1)
  374. //CloseBtn
  375. let close = this.ShowRewardsView.getChildByName('close')
  376. let clickEventHandler = new cc.Component.EventHandler()
  377. clickEventHandler.target = this.node
  378. clickEventHandler.component = 'ManageUI'
  379. clickEventHandler.handler = 'OnShowRewardsViewClose'
  380. let button = close.getComponent(cc.Button)
  381. button.clickEvents.push(clickEventHandler)
  382. }.bind(this)
  383. )
  384. return
  385. }
  386. //No Enough Diamond
  387. cc.loader.loadRes(
  388. 'prefab/ShowNoMoney',
  389. function (err, texture) {
  390. this.ShowNoMoneyView = cc.instantiate(texture)
  391. this.BuildView.addChild(this.ShowNoMoneyView)
  392. let DetailLabel = this.ShowNoMoneyView.getChildByName('DetailLabel')
  393. DetailLabel.getComponent(cc.Label).string = '钻石不够!'
  394. this.scheduleOnce(
  395. function () {
  396. this.ShowNoMoneyView.destroy()
  397. }.bind(this),
  398. 1
  399. )
  400. }.bind(this)
  401. )
  402. },
  403. OnShowRewardsViewClose(event, CustomEventData) {
  404. this.ShowRewardsView.destroy()
  405. },
  406. //弹出购买提示
  407. onPurchaseTips(_contentButton) {
  408. // cc.log('是否用钻石购买建筑', _contentButton.node.name);
  409. if (this.TipViewPrefab) {
  410. let _TipView
  411. _TipView = cc.instantiate(this.TipViewPrefab)
  412. _TipView.parent = this.TipView
  413. _TipView.setPosition(cc.v2(0, 0))
  414. _TipView
  415. .getComponent('TipView')
  416. .onShowTip({ ContentButton: _contentButton, TipViewNode: this.TipView })
  417. // cc.log(_TipView.name);
  418. }
  419. },
  420. //点击了建造列表里面的按钮时候改变样式
  421. onSetButtonState(Data, Synopsis) {
  422. cc.Component.EventHandler.emitEvents(Data.Target.clickEvents)
  423. },
  424. onSetButtonInfoState(Data, Synopsis) {
  425. if (Synopsis) {
  426. this.onSetButtonInfo(Synopsis.Name, Synopsis.Price, Synopsis.Mature, Synopsis.Synopsis)
  427. }
  428. },
  429. //设置介绍信息
  430. onSetButtonInfo(_Name, _Price, _Mature, _Synopsis) {
  431. this.BuildContent_Name.string = _Name
  432. this.BuildContent_Mature.string = _Mature
  433. this.BuildContent_Price.string = "x" + _Price
  434. this.BuildContent_Synopsis.string = _Synopsis.replace(/\n|\r/g, '')
  435. },
  436. /**
  437. * 设置商城信息
  438. * @param {}} Data
  439. * @param {*} Synopsis
  440. */
  441. onSetMallInfoState(Data, Synopsis) {
  442. if (Synopsis) {
  443. this.onSetMallInfo(
  444. Synopsis.Name,
  445. Synopsis.Mature,
  446. Synopsis.CNT,
  447. Synopsis.SNB,
  448. Synopsis.Synopsis,
  449. Synopsis.showConsumeType
  450. )
  451. }
  452. },
  453. //设置介绍信息
  454. onSetMallInfo(_Name, _mature, _CNT, _SNB, _Synopsis, showConsumeType) {
  455. this.mallContent_Name.string = _Name;
  456. this.mallContent_Price.string = _CNT;
  457. this.mallContent_SNBPrice.string = _SNB;
  458. this.mallContent_Mature.string = _mature;
  459. this.mallContent_Synopsis.string = _Synopsis.replace(/\n|\r/g, '');
  460. // CNTORSNB: 0,
  461. // CNT: 1,
  462. // SNB: 2
  463. if (0 === showConsumeType) {
  464. this.seedBottomLineBg.width = 376;
  465. this.seedBottomCntNode.active = true;
  466. this.seedBottomOrLabelNode.active = true;
  467. this.seedBottomSnbNode.active = true;
  468. } else if (1 === showConsumeType) {
  469. this.seedBottomLineBg.width = 188;
  470. this.seedBottomCntNode.active = true;
  471. this.seedBottomOrLabelNode.active = false;
  472. this.seedBottomSnbNode.active = false;
  473. } else if (2 === showConsumeType) {
  474. this.seedBottomLineBg.width = 188;
  475. this.seedBottomCntNode.active = false;
  476. this.seedBottomOrLabelNode.active = false;
  477. this.seedBottomSnbNode.active = true;
  478. }
  479. },
  480. //编辑对应的建筑
  481. onEditorialBuildings(mUI_buildTarget) {
  482. if (!this.EditorialBuildings) {
  483. cc.warn('EditorialBuildings is Null!')
  484. return
  485. }
  486. this.EditorialBuildings.active = true
  487. //重置上一个编辑建筑的状态
  488. if (this._buildTarget && this._buildTarget.getComponent('buildingsTouch')) {
  489. this._buildTarget.getComponent('buildingsTouch').onCancelEdit()
  490. }
  491. this._buildTarget = mUI_buildTarget
  492. this.EditorialBuildings.parent = mUI_buildTarget
  493. this.EditorialBuildings.setPosition(cc.v2(0, 0))
  494. },
  495. //取消编辑
  496. onCancellationEditor() {
  497. //获取建筑物上的组件
  498. let buildTouch = this._buildTarget.getComponent('buildingsTouch')
  499. let isTaskNext = buildTouch.onTaskBuild()
  500. if (!isTaskNext) return
  501. if (task.isMushBuildState) {
  502. cc.loader.loadRes(
  503. 'resUI/ShowNotEnoughMoney',
  504. function (err, texture) {
  505. var prefab = cc.instantiate(texture)
  506. prefab.getComponent('ShowNotEnoughMoney').Text("请点击'√'号")
  507. this._buildTarget.addChild(prefab)
  508. }.bind(this)
  509. )
  510. return
  511. }
  512. // if (buildTouch) {
  513. buildTouch.onCancelEdit()
  514. // }
  515. this.EditorialBuildings.active = false
  516. this.EditorialBuildings.parent = this._thisEditBuildingsParent
  517. this.EditorialBuildings.setPosition(cc.v2(10000, 100))
  518. this._buildTarget = null
  519. },
  520. //确定编辑(创建建筑物 对号)
  521. onConfirmationEditor() {
  522. //获取建筑物上的组件
  523. let buildTouch = this._buildTarget.getComponent('buildingsTouch')
  524. let isTaskNext = buildTouch.onTaskBuild()
  525. if (!isTaskNext) return
  526. // if (buildTouch) {
  527. buildTouch.onFinishEdit()
  528. // }
  529. this.EditorialBuildings.active = false
  530. this.EditorialBuildings.parent = this._thisEditBuildingsParent
  531. this.EditorialBuildings.setPosition(cc.v2(10000, 100))
  532. this._buildTarget = null
  533. },
  534. //如果相等的话返回true
  535. verctor3IsEqual(vector1, vector2) {
  536. let isEqual = false
  537. let out = new cc.Vec3()
  538. out.x = vector2.x - vector1.x
  539. out.y = vector2.y - vector1.y
  540. out.z = vector2.z - vector1.z
  541. if (out.x == 0 && out.y == 0 && out.z == 0) {
  542. isEqual = true
  543. }
  544. return isEqual
  545. },
  546. //收起全部菜单
  547. onHideMenu() {
  548. // if (this.BuildView) {
  549. // this.BuildView.active = false;
  550. // }
  551. //音效设置界面
  552. if (this.SettingInfoView.active)
  553. this.onSetTouchStatus(this.SettingInfoView, false)
  554. //建造界面
  555. // if (this.BuildView.active) this.onSetTouchStatus(this.BuildView, false)
  556. //人才界面
  557. // if (this.PersonnelView.active)
  558. // this.onSetTouchStatus(this.PersonnelView, false)
  559. //股票界面
  560. // if (this.StockView.active) this.onSetTouchStatus(this.StockView, false)
  561. //转盘界面
  562. // if (this.LuckView.active) this.onSetTouchStatus(this.LuckView, false)
  563. //商城界面
  564. if (this.StoreView.active) this.onSetTouchStatus(this.StoreView, false)
  565. },
  566. //底部菜单栏
  567. onBottomMenuView(isActive) {
  568. if (this.BottomView) {
  569. this.BottomView.active = isActive
  570. }
  571. // cc.log('不能显示面板信息:');
  572. GlobalD.GameControl._isBuildingCanEdit = !isActive
  573. },
  574. //农场界面相关菜单
  575. onOtherFarmerView(isActive) {
  576. if (this.OtherFarmerMask) {
  577. this.OtherFarmerMask.active = isActive
  578. }
  579. },
  580. //开启信息显示
  581. onShowBuildingInfo(buildingInfo) {
  582. this.BuildingInfoView.active = true
  583. if (!this._buildingInfoViewScript)
  584. this._buildingInfoViewScript =
  585. this.BuildingInfoView.getComponent('buildingInfoView')
  586. //显示房屋信息
  587. this._buildingInfoViewScript.onSetBuildingInfoView(buildingInfo)
  588. },
  589. //关闭信息显示
  590. onCloseBuildingInfo() {
  591. this.BuildingInfoView.active = false
  592. },
  593. //进入编辑模式,
  594. onEnterEditing() { },
  595. onSetTouchStatus(target, isActive) {
  596. target.active = isActive
  597. if (this.UITouch) {
  598. this.UITouch.active = isActive
  599. }
  600. },
  601. /**
  602. * 绑定邀请
  603. */
  604. onInvite_Open() {
  605. this.inviteNode.getComponent('inviteInfo').onOpenInviteInfo()
  606. },
  607. onListUserInfo_Open() {
  608. this.listUserInfoNode.getComponent('userListInfo').onOpen()
  609. },
  610. onListUserInfo_Close() {
  611. this.listUserInfoNode.getComponent('userListInfo').onClose()
  612. },
  613. //点击钻石兑换
  614. onButtonEvent_Exchange() {
  615. this.DiamondGapView.active = true
  616. // this.onSetTouchStatus(this.DiamondGapView, true)
  617. //判断钻石数量是否大于等于3万个
  618. if (GlobalD.GameData.GetDiamond() < 30000) {
  619. this.ExchangeBtn.interactable = false
  620. // GlobalD.GameData.showToast(
  621. // cc.find('Canvas/UICamera'),
  622. // '钻石数量不够,累积到30000个钻石即可免费兑换一包辣椒种子。',
  623. // 2
  624. // )
  625. return
  626. } else {
  627. this.ExchangeBtn.interactable = true
  628. }
  629. },
  630. //点击取消钻石兑换
  631. onButtonEvent_ExchangeCancel() {
  632. this.DiamondGapView.active = false
  633. },
  634. //点击确认钻石兑换辣椒种子
  635. onButtonEvent_ExchangeChili() {
  636. let diamonAmount = 30000
  637. //调用兑换接口
  638. GlobalD.GameData.exchangeSeed(diamonAmount, (value) => {
  639. return
  640. //兑换成功
  641. if (0 === value.code) {
  642. var BuildingView = cc
  643. .find('Canvas/UICamera/BuildingContainer/BuildingView')
  644. .getComponent('BuildingView')
  645. BuildingView.onUpdateList()
  646. this.DiamondGapView.active = false
  647. this.DiamondSeedsView.active = true
  648. //光芒旋转
  649. var rotate = cc.repeatForever(cc.rotateBy(2, -100, 0))
  650. this.LightRotate.runAction(rotate)
  651. } else {
  652. //兑换失败
  653. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2)
  654. }
  655. })
  656. },
  657. //点击钻石兑换的确认按钮
  658. onButtonEvent_DiamondSure() {
  659. this.DiamondSeedsView.active = false
  660. //停止光芒旋转
  661. this.LightRotate.stopAllActions()
  662. },
  663. /**
  664. * 村长领取snb
  665. */
  666. onSetSnbButtonActive(isShow) {
  667. this.VillageReceivesSNBButton.active = isShow
  668. },
  669. onButtonEvent_VillageSnbReceive() {
  670. this.VillageReceivesSNBView.active = true
  671. },
  672. onButtonEvent_VillageSnbReceive_Close() {
  673. this.VillageReceivesSNBView.active = false
  674. },
  675. onSetVillageReceivesSNBViewInfo(data) {
  676. this.onSetSnbButtonActive(true);
  677. this.VillageReceivesSNBView.getComponent('VillageReceivesSNBView').setVillageReceivesSnbInfo(data);
  678. },
  679. //音效设置界面
  680. onButtonEvent_Setting_OPen() {
  681. this.onHideMenu()
  682. this.onSetTouchStatus(this.SettingInfoView, true)
  683. },
  684. onButtonEvent_Setting_Close() {
  685. this.onSetTouchStatus(this.SettingInfoView, false)
  686. },
  687. //建造界面
  688. onButtonEvent_Building_OPen() {
  689. this.onHideMenu()
  690. this.onSetTouchStatus(this.BuildView, true)
  691. this.BuildView.getComponent('BuildingView').onSwitchBuildingContent(
  692. null, //this.Evn.getComponent(cc.Button)
  693. 4
  694. )
  695. },
  696. //商城界面
  697. onButtonEvent_Store_OPen() {
  698. this.onHideMenu()
  699. this.onSetTouchStatus(this.StoreView, true)
  700. this.StoreView.getComponent('StoreView').onSwitchBuildingContent(
  701. this.Seed.getComponent(cc.Button),
  702. 0
  703. )
  704. },
  705. novice: function () {
  706. var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
  707. task.removeTaskNode(task.taskCursorName[2]) //左上
  708. task.addTaskTips(
  709. BuildingView,
  710. task.taskPrefab[1],
  711. -180,
  712. 180,
  713. task.taskCursorName[2],
  714. function (nodePrefabs) {
  715. //手指
  716. this.nodePrefabs = nodePrefabs
  717. }.bind(this)
  718. )
  719. },
  720. novice1: function () {
  721. var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
  722. task.addTaskTips(
  723. BuildingView,
  724. task.novice[1],
  725. 0,
  726. 50,
  727. task.taskCursorName[3],
  728. function (node) {
  729. UtilsPrefabs.setOn(
  730. node.getChildByName('SureBtn'),
  731. function () {
  732. UtilsPrefabs.setOff(node.getChildByName('SureBtn'))
  733. var mt = cc.moveTo(1, 110, 180) //右上
  734. var finished = cc.callFunc(
  735. function () {
  736. task.removeTaskNode(task.taskCursorName[3])
  737. this.novice2()
  738. }.bind(this)
  739. )
  740. var sequence = cc.sequence(mt, finished)
  741. this.nodePrefabs.runAction(sequence)
  742. task.isShowTaskNode(task.taskCursorName[3], false)
  743. }.bind(this)
  744. )
  745. }.bind(this)
  746. )
  747. },
  748. novice2: function () {
  749. var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
  750. task.addTaskTips(
  751. BuildingView,
  752. task.novice[2],
  753. 0,
  754. 50,
  755. task.taskCursorName[3],
  756. function (node) {
  757. UtilsPrefabs.setOn(
  758. node.getChildByName('SureBtn'),
  759. function () {
  760. UtilsPrefabs.setOff(node.getChildByName('SureBtn'))
  761. var mt = cc.moveTo(1, -200, 0) //
  762. var finished = cc.callFunc(
  763. function () {
  764. task.removeTaskNode(task.taskCursorName[3])
  765. this.novice3()
  766. }.bind(this)
  767. )
  768. var sequence = cc.sequence(mt, finished)
  769. this.nodePrefabs.runAction(sequence)
  770. task.isShowTaskNode(task.taskCursorName[3], false)
  771. }.bind(this)
  772. )
  773. }.bind(this)
  774. )
  775. },
  776. novice3: function () {
  777. var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
  778. task.addTaskTips(
  779. BuildingView,
  780. task.novice[3],
  781. 0,
  782. -150,
  783. task.taskCursorName[3],
  784. function (node) {
  785. UtilsPrefabs.setOn(
  786. node.getChildByName('SureBtn'),
  787. function () {
  788. task.removeTaskNode(task.taskCursorName[3])
  789. }.bind(this)
  790. )
  791. }.bind(this)
  792. )
  793. },
  794. //外面管理的手指
  795. novicepersonnel: function () {
  796. task.removeTaskNode(task.taskCursorName[2]) //左上
  797. task.addTaskTips(
  798. task.personnelview,
  799. task.taskPrefab[1],
  800. 0,
  801. 0,
  802. task.taskCursorName[2],
  803. function (nodePrefabs) {
  804. //手指
  805. this.nodePrefabs = nodePrefabs
  806. }.bind(this)
  807. )
  808. },
  809. //外面的 建筑手指
  810. noviceBuilding: function () {
  811. //建造农舍指引
  812. task.showTiledTile(0, 0, 0, 23, 25)
  813. },
  814. novice4: function () {
  815. var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
  816. task.addTaskTips(
  817. BuildingView,
  818. task.novice[4],
  819. 0,
  820. -200,
  821. task.taskCursorName[3],
  822. function (node) {
  823. UtilsPrefabs.setOn(
  824. node.getChildByName('SureBtn'),
  825. function () {
  826. task.removeTaskNode(task.taskCursorName[3])
  827. }.bind(this)
  828. )
  829. }.bind(this)
  830. )
  831. },
  832. //关闭 建造框
  833. onButtonEvent_Building_Close() {
  834. // cc.log(this.BuildView);
  835. this.onSetTouchStatus(this.BuildView, false)
  836. },
  837. //关闭 商城框
  838. onButtonEvent_Store_Close() {
  839. this.onSetTouchStatus(this.StoreView, false)
  840. },
  841. //人才界面
  842. onButtonEvent_Personnel_OPen() {
  843. this.onHideMenu()
  844. this.onSetTouchStatus(this.PersonnelView, true)
  845. },
  846. onButtonEvent_Personnel_Close() {
  847. this.onSetTouchStatus(this.PersonnelView, false)
  848. },
  849. //股票界面
  850. onButtonEvent_Stock_OPen() {
  851. this.onHideMenu()
  852. this.onSetTouchStatus(this.StockView, true)
  853. // console.log("所有建筑物数据", GlobalD.game.buildingsTiledMapUnit);
  854. UtilsWX.lookRankList(true)
  855. this.showFriend()
  856. },
  857. //限制
  858. returnDialog: function (cursor) {
  859. var num = 0
  860. // console.log("要创建什么提示呢数字", cursor);
  861. switch (cursor) {
  862. case 1:
  863. num = 0
  864. break
  865. case 4:
  866. num = 1
  867. break
  868. case 6:
  869. num = 2
  870. break
  871. }
  872. console.log('要创建什么提示呢', task.returnPrefab[num])
  873. var Canvas = cc.find('Canvas/UICamera')
  874. task.addTaskTips(
  875. Canvas,
  876. task.returnPrefab[num],
  877. 0,
  878. 0,
  879. task.taskCursorName[4],
  880. function (nodePrefabs) {
  881. UtilsPrefabs.setOn(
  882. nodePrefabs.getChildByName('SureBtn'),
  883. function () {
  884. task.removeTaskNode(task.taskCursorName[4])
  885. }.bind(this)
  886. )
  887. }.bind(this)
  888. )
  889. },
  890. showFriend: function () {
  891. // var data1 = {
  892. // name: "Whoareyou",
  893. // openId : userData.openId
  894. // }
  895. // UtilsWX.postMessage(data1);
  896. var data = {
  897. name: 'showFriend',
  898. }
  899. UtilsWX.postMessage(data)
  900. },
  901. onButtonEvent_Stock_Close() {
  902. this.onSetTouchStatus(this.StockView, false)
  903. var data = {
  904. name: 'hideFriend',
  905. }
  906. UtilsWX.postMessage(data)
  907. setTimeout(
  908. function () {
  909. UtilsWX.lookRankList(false)
  910. }.bind(this),
  911. 200
  912. )
  913. },
  914. //转盘界面
  915. onButtonEvent_Luck_OPen() {
  916. this.onHideMenu()
  917. this.onSetTouchStatus(this.LuckView, true)
  918. if (this.nodePrefabsLuck != null) {
  919. task.removeNode(this.nodePrefabsLuck)
  920. }
  921. },
  922. isTask: function (obj) {
  923. var Canvas = cc.find('Canvas/UICamera')
  924. UtilsPrefabs.init(Canvas).addPrefabs(
  925. UtilsPrefabs.sharePrefab[1],
  926. null,
  927. function (node) {
  928. var gosharebtn = UtilsPrefabs.getNode('gosharebtn', node)
  929. var close = UtilsPrefabs.getNode('close', node)
  930. UtilsPrefabs.setOn(
  931. close,
  932. function () {
  933. UtilsPrefabs.removePrefabs(Canvas, node.name)
  934. if (task.TaskIconCountClick == 5) {
  935. if (obj.currentTarget.name == 'GetGift') {
  936. task.addTaskIconCountClick()
  937. task.removeTaskNodes()
  938. }
  939. }
  940. }.bind(this)
  941. )
  942. UtilsPrefabs.setOn(
  943. gosharebtn,
  944. function () {
  945. // console.log("点击分享按钮");
  946. UtilsWX.sharebtn(
  947. function () {
  948. UtilsPrefabs.setOff(gosharebtn)
  949. GlobalD.GameData.PlusGolden(GlobalD.GameData.shareGive[0])
  950. GlobalD.GameData.PlusDiamond(GlobalD.GameData.shareGive[1])
  951. if (task.TaskIconCountClick == 5) {
  952. if (obj.currentTarget.name == 'GetGift') {
  953. task.addTaskIconCountClick()
  954. task.removeTaskNodes()
  955. }
  956. }
  957. }.bind(this)
  958. )
  959. UtilsPrefabs.removePrefabs(Canvas, node.name)
  960. }.bind(this)
  961. )
  962. }.bind(this)
  963. )
  964. },
  965. isTask4: function () {
  966. if (task.TaskIconCountClick == 4) {
  967. task.addTaskIconCountClick()
  968. task.removeTaskNodes()
  969. }
  970. },
  971. onButtonEvent_Luck_Close(obj) {
  972. // console.log("现在是谁点的", obj);
  973. let Wheel = this.LuckView.getChildByName('Wheel').getComponent('Wheel')
  974. Wheel.node.active = true
  975. Wheel.ShowRewards.active = false
  976. this.onSetTouchStatus(this.LuckView, false)
  977. if (obj.target.name == 'GetGift') {
  978. this.isTask(obj)
  979. }
  980. },
  981. onButtonEvent_EveryDay_OPen() {
  982. this.onHideMenu()
  983. this.onSetTouchStatus(this.EveryDaySignView, true)
  984. //打开每日签到 外面的按钮
  985. if (task.TaskIconCountClick == 4) {
  986. var EveryDaySign = cc.find(
  987. 'Canvas/UICamera/OverTheMask/EveryDaySignContainer/EveryDaySignView'
  988. )
  989. // var Canvas = cc.find("Canvas/UICamera");
  990. // task.removeTaskNodes();
  991. task.removeTaskNode(task.taskCursorName[4])
  992. task.addTaskTips(
  993. EveryDaySign,
  994. task.taskPrefab[1],
  995. 20,
  996. -470,
  997. task.taskCursorName[4],
  998. function (nodePrefabs) { }.bind(this)
  999. )
  1000. }
  1001. },
  1002. onButtonEvent_EveryDay_Close() {
  1003. this.onSetTouchStatus(this.EveryDaySignView, false)
  1004. },
  1005. onShowRewards: function (Index) {
  1006. let ManageBuildingScript = this.node.getComponent('ManageBuildings')
  1007. console.log('走了吗', Index)
  1008. let GivePrize = this.ShowRewards.getChildByName('GivePrize')
  1009. let Rewards = GivePrize.getChildByName('Rewards')
  1010. Rewards.getComponent(cc.Sprite).spriteFrame = this.BuildingFrameArray[
  1011. Index
  1012. ].getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame
  1013. //开始播放
  1014. var Sunshine =
  1015. this.ShowRewards.getChildByName('GivePrize').getChildByName('Sunshine')
  1016. Sunshine.scaleX = 0
  1017. Sunshine.scaleY = 0
  1018. GivePrize.scaleX = 0
  1019. GivePrize.scaleY = 0
  1020. Sunshine.stopAllActions()
  1021. GivePrize.stopAllActions()
  1022. this.scheduleOnce(function () {
  1023. this.ShowRewards.opacity = 255
  1024. this.ShowRewards.active = true
  1025. var sc2 = cc.scaleTo(1, 0.5, 0.5)
  1026. Sunshine.runAction(sc2)
  1027. var sc3 = cc.scaleTo(1, 1, 1)
  1028. GivePrize.runAction(sc3)
  1029. var repeat = cc.repeatForever(cc.rotateBy(5.0, 360))
  1030. Sunshine.runAction(repeat)
  1031. }, 0.1)
  1032. },
  1033. onCloseShowRewards: function () {
  1034. this.ShowRewards.active = false
  1035. },
  1036. DiamondGapViewShow: function () {
  1037. this.DiamondGapView.active = true
  1038. },
  1039. GoldenChangeCallBack: function (Num, LastMoney, CurrentMoney) {
  1040. let Scale = 30
  1041. let Index = -1
  1042. // if(Num>10*Scale)
  1043. // {
  1044. // Index = 7;//伐木场
  1045. // }
  1046. // if(Num>30*Scale)
  1047. // {
  1048. // Index = 8;//矿坑
  1049. // }
  1050. // if(Num>70*Scale)
  1051. // {
  1052. // // Index = 9;//加工厂
  1053. // }
  1054. // if(Num>350*Scale && Num<450*Scale)
  1055. // {
  1056. // Index = 4;//单元楼
  1057. // }
  1058. if (Num > 4000 && Num < 4500) {
  1059. Index = 4 //单元楼
  1060. }
  1061. // else if(Num>450*Scale && Num<550*Scale)
  1062. // {
  1063. // Index = 11;//鲜花店
  1064. // }
  1065. else if (Num > 4500 && Num < 5500) {
  1066. Index = 11 //鲜花店
  1067. } else if (Num > 550 * Scale && Num < 650 * Scale) {
  1068. Index = 12 //甜品店
  1069. }
  1070. if (Num > 650 * Scale && Num < 750 * Scale) {
  1071. Index = 7 //伐木场
  1072. } else if (Num > 750 * Scale && Num < 950 * Scale) {
  1073. Index = 13 //汉堡店
  1074. }
  1075. // else if(Num>850*Scale)
  1076. // {
  1077. // Index = 0;//公路
  1078. // }
  1079. else if (Num > 950 * Scale && Num < 1050 * Scale) {
  1080. Index = 14 //咖啡店
  1081. } else if (Num > 1050 * Scale && Num < 1150 * Scale) {
  1082. Index = 5 //别墅
  1083. } else if (Num > 1150 * Scale && Num < 1250 * Scale) {
  1084. Index = 15 //洋装店
  1085. }
  1086. if (Num > 1250 * Scale && Num < 1350 * Scale) {
  1087. Index = 8 //矿坑
  1088. } else if (Num > 1350 * Scale) {
  1089. Index = 16 //酒吧
  1090. }
  1091. // else if(Num>250*Scale)
  1092. // {
  1093. // Index = 4;//单元楼
  1094. // }
  1095. // else if(Num>600*Scale)
  1096. // {
  1097. // Index = 5;//别墅
  1098. // }
  1099. var BuildingStateArray = GlobalD.GameData.GetBuildingStateArray()
  1100. if (Index == 0) {
  1101. if (BuildingStateArray[Index] != 1) {
  1102. BuildingStateArray[0] = 1 //公路
  1103. BuildingStateArray[1] = 1 //路铲
  1104. BuildingStateArray[2] = 1 //拆迁
  1105. let Building0 =
  1106. this.node.getComponent('ManageBuildings').BuildingArray[0]
  1107. let Building1 =
  1108. this.node.getComponent('ManageBuildings').BuildingArray[1]
  1109. let Building2 =
  1110. this.node.getComponent('ManageBuildings').BuildingArray[2]
  1111. Building0.active = true
  1112. Building1.active = true
  1113. Building2.active = true
  1114. GlobalD.GameData.SetBuildingStateArray(BuildingStateArray)
  1115. this.onShowRewards(Index)
  1116. }
  1117. } else {
  1118. if (BuildingStateArray[Index] != 1 && Index != -1) {
  1119. cc.log('Index=' + Index)
  1120. BuildingStateArray[Index] = 1
  1121. let Building =
  1122. this.node.getComponent('ManageBuildings').BuildingArray[Index]
  1123. Building.active = true
  1124. GlobalD.GameData.SetBuildingStateArray(BuildingStateArray)
  1125. this.onShowRewards(Index)
  1126. }
  1127. }
  1128. let Diff = CurrentMoney - LastMoney
  1129. let InitMoneyNum = LastMoney
  1130. let AnimTimes = 0
  1131. let Times = 3
  1132. this.schedule(
  1133. function () {
  1134. if (Diff > 0) {
  1135. InitMoneyNum += parseInt((CurrentMoney - LastMoney) / Times)
  1136. } else {
  1137. InitMoneyNum -= parseInt((CurrentMoney - LastMoney) / Times)
  1138. }
  1139. let result = this.FormatMoney(InitMoneyNum)
  1140. if (AnimTimes == Times - 1) {
  1141. this.Goldenlabel.getComponent(cc.Label).string =
  1142. this.FormatMoney(CurrentMoney)
  1143. return
  1144. }
  1145. this.Goldenlabel.getComponent(cc.Label).string = result
  1146. AnimTimes++
  1147. },
  1148. 0.05,
  1149. Times
  1150. )
  1151. },
  1152. DiamondChangeCallBack: function (Num, LastMoney, CurrentMoney) {
  1153. let Diff = CurrentMoney - LastMoney
  1154. let InitMoneyNum = LastMoney
  1155. let AnimTimes = 0
  1156. let Times = 3
  1157. this.schedule(
  1158. function () {
  1159. if (Diff > 0) {
  1160. InitMoneyNum += parseInt((CurrentMoney - LastMoney) / Times)
  1161. } else {
  1162. InitMoneyNum -= parseInt((CurrentMoney - LastMoney) / Times)
  1163. }
  1164. let result = this.FormatMoney(InitMoneyNum)
  1165. if (AnimTimes == Times - 1) {
  1166. // this.DiamondNowlabel.string = result + '/30000'
  1167. this.Diamondlabel.getComponent(cc.Label).string =
  1168. this.FormatMoney(CurrentMoney)
  1169. return
  1170. }
  1171. // this.DiamondNowlabel.string = result + '/30000'
  1172. this.Diamondlabel.getComponent(cc.Label).string = result
  1173. AnimTimes++
  1174. },
  1175. 0.05,
  1176. Times
  1177. )
  1178. },
  1179. CNTChangeCallBack: function (Num) {
  1180. this.CNTlabel.getComponent(cc.Label).string = this.formatPrice(Num)
  1181. },
  1182. SNBChangeCallBack: function (Num) {
  1183. this.SNBlabel.getComponent(cc.Label).string = this.formatPrice(Num);
  1184. },
  1185. formatPrice(price) {
  1186. return String(price).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  1187. },
  1188. FormatMoney(s, n) {
  1189. n = n > 0 && n <= 20 ? n : 2
  1190. s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(n) + ''
  1191. var l = s.split('.')[0].split('').reverse(),
  1192. r = s.split('.')[1]
  1193. let t = ''
  1194. for (let i = 0; i < l.length; i++) {
  1195. t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? ',' : '')
  1196. }
  1197. return t.split('').reverse().join('') //+ "." + r;
  1198. },
  1199. /**
  1200. * 偷取果实
  1201. */
  1202. onStealAllFruit() {
  1203. //todo 偷取之前本地判断下体力值
  1204. if (GlobalD.PlayerAttribute.currentStrength <= 0) {
  1205. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "体力不足,无法收取作物!", 1);
  1206. return;
  1207. }
  1208. GlobalD.GameData.onStealAllFruit({ otherUserId: GlobalD.OtherUserInfo.userId }, (value) => {
  1209. console.log(value);
  1210. if (0 === value.code) {
  1211. if (0 !== value.data.stealSum) {
  1212. // if (this.StealViewSuccessPrefab) {
  1213. // let _TipView = cc.instantiate(this.StealViewSuccessPrefab)
  1214. // _TipView.parent = this.TipView
  1215. // _TipView.setPosition(cc.v2(0, 0))
  1216. // _TipView
  1217. // .getComponent('StealViewSuccess')
  1218. // .setInfo({ amount: value.data.stealSum });
  1219. // }
  1220. this.onInitStealViewSuccessPrefab(value.data);
  1221. let BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView').getComponent('BuildingView');
  1222. BuildingView.onUpdateList();
  1223. //偷取成功后,关闭对应土地的提示图标
  1224. let _landBuildingsInfo = cc.find("Canvas/MyMapNode").children;
  1225. let _stealList = value.data.steals;
  1226. for (let j = 0; j < _stealList.length; j++) {
  1227. for (let i = _landBuildingsInfo.length - 1; i >= 0; i--) {
  1228. let resetLandInfo = _landBuildingsInfo[i];
  1229. if (resetLandInfo.name == "Labour_205_Holy_Farmland") {
  1230. let leaseFarmlandInfoScript = resetLandInfo.getComponent("LeaseFarmlandInfo");
  1231. if (leaseFarmlandInfoScript.leaseLandInfo && leaseFarmlandInfoScript.leaseLandInfo.configLandId == _stealList[j].landId) {
  1232. leaseFarmlandInfoScript.onHideStealHarvest();
  1233. }
  1234. }
  1235. }
  1236. }
  1237. } else {
  1238. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "未偷取到果实!", 1);
  1239. }
  1240. } else {
  1241. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
  1242. }
  1243. });
  1244. },
  1245. /**
  1246. * 生成一个提示面板
  1247. * @param {偷取对象} stealObj
  1248. */
  1249. onInitStealViewSuccessPrefab(stealObj) {
  1250. if (this.StealViewSuccessPrefab) {
  1251. let _TipView = cc.instantiate(this.StealViewSuccessPrefab)
  1252. _TipView.parent = this.TipView
  1253. _TipView.setPosition(cc.v2(0, 0))
  1254. _TipView
  1255. .getComponent('StealViewSuccess')
  1256. .setSingleStealInfo(stealObj);
  1257. }
  1258. },
  1259. //体力值
  1260. StrengthChangeCallBack: function (Num) {
  1261. this.Strengthlabel.getComponent(cc.Label).string = Num
  1262. },
  1263. //幸运值
  1264. LuckyChangeCallBack: function (Num) {
  1265. this.Luckylabel.getComponent(cc.Label).string = Num
  1266. },
  1267. //小狗和木棒
  1268. onSettingDogAlpha(opacity) {
  1269. this.dogButtonNode.opacity = opacity;
  1270. },
  1271. onSettingStickAlpha(opacity) {
  1272. this.stickButtonNode.opacity = opacity;
  1273. },
  1274. onDetectDog() {
  1275. if (GlobalD.Dog) {
  1276. if (GlobalD.Dog.remainingConsumption > 0) {
  1277. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "已经拥有小狗。", 1);
  1278. } else {
  1279. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "需要点击狗盆购买狗粮。", 1);
  1280. }
  1281. } else {
  1282. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "尚未拥有小狗。", 1);
  1283. }
  1284. },
  1285. onDetectStick() {
  1286. if (GlobalD.Stick) {
  1287. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "已经装备打狗棒。", 1);
  1288. } else {
  1289. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "尚未购买打狗棒。", 1);
  1290. }
  1291. }
  1292. })