ManageUI.js 44 KB

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