ManageUI.js 35 KB

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