ManageUI.js 34 KB

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