ManageUI.js 33 KB

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