ManageUI.js 35 KB

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