ManageUI.js 39 KB

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