ManageUI.js 35 KB

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