ManageUI.js 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  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. //判断钻石数量是否大于等于3万个
  536. if (GlobalD.GameData.GetDiamond() < 30000) {
  537. GlobalD.GameData.showToast(
  538. cc.find('Canvas/UICamera'),
  539. '钻石数量不够,累积到30000个钻石即可免费兑换一包辣椒种子。',
  540. 2
  541. )
  542. return
  543. }
  544. //调用兑换接口
  545. GlobalD.GameData.exchangeSeed((res, value) => {
  546. //兑换成功
  547. if (0 === value.code) {
  548. this.onSetTouchStatus(this.DiamondSeedsView, true)
  549. } else {
  550. //兑换失败
  551. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '兑换失败', 2)
  552. }
  553. })
  554. },
  555. //点击钻石兑换的确认按钮
  556. onButtonEvent_DiamondSure() {
  557. this.onSetTouchStatus(this.DiamondSeedsView, false)
  558. this.onSetTouchStatus(this.DiamondGapView, false)
  559. },
  560. //音效设置界面
  561. onButtonEvent_Setting_OPen() {
  562. this.onHideMenu()
  563. this.onSetTouchStatus(this.SettingInfoView, true)
  564. },
  565. onButtonEvent_Setting_Close() {
  566. this.onSetTouchStatus(this.SettingInfoView, false)
  567. },
  568. //建造界面
  569. onButtonEvent_Building_OPen() {
  570. this.onHideMenu()
  571. this.onSetTouchStatus(this.BuildView, true)
  572. this.BuildView.getComponent('BuildingView').onSwitchBuildingContent(
  573. this.Evn.getComponent(cc.Button),
  574. 0
  575. )
  576. },
  577. //商城界面
  578. onButtonEvent_Store_OPen() {
  579. this.onHideMenu()
  580. this.onSetTouchStatus(this.StoreView, true)
  581. this.StoreView.getComponent('StoreView').onSwitchBuildingContent(
  582. this.Seed.getComponent(cc.Button),
  583. 0
  584. )
  585. },
  586. novice: function () {
  587. var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
  588. task.removeTaskNode(task.taskCursorName[2]) //左上
  589. task.addTaskTips(
  590. BuildingView,
  591. task.taskPrefab[1],
  592. -180,
  593. 180,
  594. task.taskCursorName[2],
  595. function (nodePrefabs) {
  596. //手指
  597. this.nodePrefabs = nodePrefabs
  598. }.bind(this)
  599. )
  600. },
  601. novice1: function () {
  602. var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
  603. task.addTaskTips(
  604. BuildingView,
  605. task.novice[1],
  606. 0,
  607. 50,
  608. task.taskCursorName[3],
  609. function (node) {
  610. UtilsPrefabs.setOn(
  611. node.getChildByName('SureBtn'),
  612. function () {
  613. UtilsPrefabs.setOff(node.getChildByName('SureBtn'))
  614. var mt = cc.moveTo(1, 110, 180) //右上
  615. var finished = cc.callFunc(
  616. function () {
  617. task.removeTaskNode(task.taskCursorName[3])
  618. this.novice2()
  619. }.bind(this)
  620. )
  621. var sequence = cc.sequence(mt, finished)
  622. this.nodePrefabs.runAction(sequence)
  623. task.isShowTaskNode(task.taskCursorName[3], false)
  624. }.bind(this)
  625. )
  626. }.bind(this)
  627. )
  628. },
  629. novice2: function () {
  630. var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
  631. task.addTaskTips(
  632. BuildingView,
  633. task.novice[2],
  634. 0,
  635. 50,
  636. task.taskCursorName[3],
  637. function (node) {
  638. UtilsPrefabs.setOn(
  639. node.getChildByName('SureBtn'),
  640. function () {
  641. UtilsPrefabs.setOff(node.getChildByName('SureBtn'))
  642. var mt = cc.moveTo(1, -200, 0) //
  643. var finished = cc.callFunc(
  644. function () {
  645. task.removeTaskNode(task.taskCursorName[3])
  646. this.novice3()
  647. }.bind(this)
  648. )
  649. var sequence = cc.sequence(mt, finished)
  650. this.nodePrefabs.runAction(sequence)
  651. task.isShowTaskNode(task.taskCursorName[3], false)
  652. }.bind(this)
  653. )
  654. }.bind(this)
  655. )
  656. },
  657. novice3: function () {
  658. var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
  659. task.addTaskTips(
  660. BuildingView,
  661. task.novice[3],
  662. 0,
  663. -150,
  664. task.taskCursorName[3],
  665. function (node) {
  666. UtilsPrefabs.setOn(
  667. node.getChildByName('SureBtn'),
  668. function () {
  669. task.removeTaskNode(task.taskCursorName[3])
  670. }.bind(this)
  671. )
  672. }.bind(this)
  673. )
  674. },
  675. //外面管理的手指
  676. novicepersonnel: function () {
  677. task.removeTaskNode(task.taskCursorName[2]) //左上
  678. task.addTaskTips(
  679. task.personnelview,
  680. task.taskPrefab[1],
  681. 0,
  682. 0,
  683. task.taskCursorName[2],
  684. function (nodePrefabs) {
  685. //手指
  686. this.nodePrefabs = nodePrefabs
  687. }.bind(this)
  688. )
  689. },
  690. //外面的 建筑手指
  691. noviceBuilding: function () {
  692. //建造农舍指引
  693. task.showTiledTile(0, 0, 0, 23, 25)
  694. },
  695. novice4: function () {
  696. var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
  697. task.addTaskTips(
  698. BuildingView,
  699. task.novice[4],
  700. 0,
  701. -200,
  702. task.taskCursorName[3],
  703. function (node) {
  704. UtilsPrefabs.setOn(
  705. node.getChildByName('SureBtn'),
  706. function () {
  707. task.removeTaskNode(task.taskCursorName[3])
  708. }.bind(this)
  709. )
  710. }.bind(this)
  711. )
  712. },
  713. //关闭 建造框
  714. onButtonEvent_Building_Close() {
  715. // cc.log(this.BuildView);
  716. this.onSetTouchStatus(this.BuildView, false)
  717. },
  718. //关闭 商城框
  719. onButtonEvent_Store_Close() {
  720. this.onSetTouchStatus(this.StoreView, false)
  721. },
  722. //人才界面
  723. onButtonEvent_Personnel_OPen() {
  724. this.onHideMenu()
  725. this.onSetTouchStatus(this.PersonnelView, true)
  726. },
  727. onButtonEvent_Personnel_Close() {
  728. this.onSetTouchStatus(this.PersonnelView, false)
  729. },
  730. //股票界面
  731. onButtonEvent_Stock_OPen() {
  732. this.onHideMenu()
  733. this.onSetTouchStatus(this.StockView, true)
  734. // console.log("所有建筑物数据", GlobalD.game.buildingsTiledMapUnit);
  735. UtilsWX.lookRankList(true)
  736. this.showFriend()
  737. },
  738. //限制
  739. returnDialog: function (cursor) {
  740. var num = 0
  741. // console.log("要创建什么提示呢数字", cursor);
  742. switch (cursor) {
  743. case 1:
  744. num = 0
  745. break
  746. case 4:
  747. num = 1
  748. break
  749. case 6:
  750. num = 2
  751. break
  752. }
  753. console.log('要创建什么提示呢', task.returnPrefab[num])
  754. var Canvas = cc.find('Canvas/UICamera')
  755. task.addTaskTips(
  756. Canvas,
  757. task.returnPrefab[num],
  758. 0,
  759. 0,
  760. task.taskCursorName[4],
  761. function (nodePrefabs) {
  762. UtilsPrefabs.setOn(
  763. nodePrefabs.getChildByName('SureBtn'),
  764. function () {
  765. task.removeTaskNode(task.taskCursorName[4])
  766. }.bind(this)
  767. )
  768. }.bind(this)
  769. )
  770. },
  771. showFriend: function () {
  772. // var data1 = {
  773. // name: "Whoareyou",
  774. // openId : userData.openId
  775. // }
  776. // UtilsWX.postMessage(data1);
  777. var data = {
  778. name: 'showFriend',
  779. }
  780. UtilsWX.postMessage(data)
  781. },
  782. onButtonEvent_Stock_Close() {
  783. this.onSetTouchStatus(this.StockView, false)
  784. var data = {
  785. name: 'hideFriend',
  786. }
  787. UtilsWX.postMessage(data)
  788. setTimeout(
  789. function () {
  790. UtilsWX.lookRankList(false)
  791. }.bind(this),
  792. 200
  793. )
  794. },
  795. //转盘界面
  796. onButtonEvent_Luck_OPen() {
  797. this.onHideMenu()
  798. this.onSetTouchStatus(this.LuckView, true)
  799. if (this.nodePrefabsLuck != null) {
  800. task.removeNode(this.nodePrefabsLuck)
  801. }
  802. },
  803. isTask: function (obj) {
  804. var Canvas = cc.find('Canvas/UICamera')
  805. UtilsPrefabs.init(Canvas).addPrefabs(
  806. UtilsPrefabs.sharePrefab[1],
  807. null,
  808. function (node) {
  809. var gosharebtn = UtilsPrefabs.getNode('gosharebtn', node)
  810. var close = UtilsPrefabs.getNode('close', node)
  811. UtilsPrefabs.setOn(
  812. close,
  813. function () {
  814. UtilsPrefabs.removePrefabs(Canvas, node.name)
  815. if (task.TaskIconCountClick == 5) {
  816. if (obj.currentTarget.name == 'GetGift') {
  817. task.addTaskIconCountClick()
  818. task.removeTaskNodes()
  819. }
  820. }
  821. }.bind(this)
  822. )
  823. UtilsPrefabs.setOn(
  824. gosharebtn,
  825. function () {
  826. // console.log("点击分享按钮");
  827. UtilsWX.sharebtn(
  828. function () {
  829. UtilsPrefabs.setOff(gosharebtn)
  830. GlobalD.GameData.PlusGolden(GlobalD.GameData.shareGive[0])
  831. GlobalD.GameData.PlusDiamond(GlobalD.GameData.shareGive[1])
  832. if (task.TaskIconCountClick == 5) {
  833. if (obj.currentTarget.name == 'GetGift') {
  834. task.addTaskIconCountClick()
  835. task.removeTaskNodes()
  836. }
  837. }
  838. }.bind(this)
  839. )
  840. UtilsPrefabs.removePrefabs(Canvas, node.name)
  841. }.bind(this)
  842. )
  843. }.bind(this)
  844. )
  845. },
  846. isTask4: function () {
  847. if (task.TaskIconCountClick == 4) {
  848. task.addTaskIconCountClick()
  849. task.removeTaskNodes()
  850. }
  851. },
  852. onButtonEvent_Luck_Close(obj) {
  853. // console.log("现在是谁点的", obj);
  854. let Wheel = this.LuckView.getChildByName('Wheel').getComponent('Wheel')
  855. Wheel.node.active = true
  856. Wheel.ShowRewards.active = false
  857. this.onSetTouchStatus(this.LuckView, false)
  858. if (obj.target.name == 'GetGift') {
  859. this.isTask(obj)
  860. }
  861. },
  862. onButtonEvent_EveryDay_OPen() {
  863. this.onHideMenu()
  864. this.onSetTouchStatus(this.EveryDaySignView, true)
  865. //打开每日签到 外面的按钮
  866. if (task.TaskIconCountClick == 4) {
  867. var EveryDaySign = cc.find(
  868. 'Canvas/UICamera/OverTheMask/EveryDaySignContainer/EveryDaySignView'
  869. )
  870. // var Canvas = cc.find("Canvas/UICamera");
  871. // task.removeTaskNodes();
  872. task.removeTaskNode(task.taskCursorName[4])
  873. task.addTaskTips(
  874. EveryDaySign,
  875. task.taskPrefab[1],
  876. 20,
  877. -470,
  878. task.taskCursorName[4],
  879. function (nodePrefabs) {}.bind(this)
  880. )
  881. }
  882. },
  883. onButtonEvent_EveryDay_Close() {
  884. this.onSetTouchStatus(this.EveryDaySignView, false)
  885. },
  886. onShowRewards: function (Index) {
  887. let ManageBuildingScript = this.node.getComponent('ManageBuildings')
  888. console.log('走了吗', Index)
  889. let GivePrize = this.ShowRewards.getChildByName('GivePrize')
  890. let Rewards = GivePrize.getChildByName('Rewards')
  891. Rewards.getComponent(cc.Sprite).spriteFrame = this.BuildingFrameArray[
  892. Index
  893. ].getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame
  894. //开始播放
  895. var Sunshine =
  896. this.ShowRewards.getChildByName('GivePrize').getChildByName('Sunshine')
  897. Sunshine.scaleX = 0
  898. Sunshine.scaleY = 0
  899. GivePrize.scaleX = 0
  900. GivePrize.scaleY = 0
  901. Sunshine.stopAllActions()
  902. GivePrize.stopAllActions()
  903. this.scheduleOnce(function () {
  904. this.ShowRewards.opacity = 255
  905. this.ShowRewards.active = true
  906. var sc2 = cc.scaleTo(1, 0.5, 0.5)
  907. Sunshine.runAction(sc2)
  908. var sc3 = cc.scaleTo(1, 1, 1)
  909. GivePrize.runAction(sc3)
  910. var repeat = cc.repeatForever(cc.rotateBy(5.0, 360))
  911. Sunshine.runAction(repeat)
  912. }, 0.1)
  913. },
  914. onCloseShowRewards: function () {
  915. this.ShowRewards.active = false
  916. },
  917. DiamondGapViewShow: function () {
  918. this.DiamondGapView.active = true
  919. },
  920. GoldenChangeCallBack: function (Num, LastMoney, CurrentMoney) {
  921. let Scale = 30
  922. let Index = -1
  923. // if(Num>10*Scale)
  924. // {
  925. // Index = 7;//伐木场
  926. // }
  927. // if(Num>30*Scale)
  928. // {
  929. // Index = 8;//矿坑
  930. // }
  931. // if(Num>70*Scale)
  932. // {
  933. // // Index = 9;//加工厂
  934. // }
  935. // if(Num>350*Scale && Num<450*Scale)
  936. // {
  937. // Index = 4;//单元楼
  938. // }
  939. if (Num > 4000 && Num < 4500) {
  940. Index = 4 //单元楼
  941. }
  942. // else if(Num>450*Scale && Num<550*Scale)
  943. // {
  944. // Index = 11;//鲜花店
  945. // }
  946. else if (Num > 4500 && Num < 5500) {
  947. Index = 11 //鲜花店
  948. } else if (Num > 550 * Scale && Num < 650 * Scale) {
  949. Index = 12 //甜品店
  950. }
  951. if (Num > 650 * Scale && Num < 750 * Scale) {
  952. Index = 7 //伐木场
  953. } else if (Num > 750 * Scale && Num < 950 * Scale) {
  954. Index = 13 //汉堡店
  955. }
  956. // else if(Num>850*Scale)
  957. // {
  958. // Index = 0;//公路
  959. // }
  960. else if (Num > 950 * Scale && Num < 1050 * Scale) {
  961. Index = 14 //咖啡店
  962. } else if (Num > 1050 * Scale && Num < 1150 * Scale) {
  963. Index = 5 //别墅
  964. } else if (Num > 1150 * Scale && Num < 1250 * Scale) {
  965. Index = 15 //洋装店
  966. }
  967. if (Num > 1250 * Scale && Num < 1350 * Scale) {
  968. Index = 8 //矿坑
  969. } else if (Num > 1350 * Scale) {
  970. Index = 16 //酒吧
  971. }
  972. // else if(Num>250*Scale)
  973. // {
  974. // Index = 4;//单元楼
  975. // }
  976. // else if(Num>600*Scale)
  977. // {
  978. // Index = 5;//别墅
  979. // }
  980. var BuildingStateArray = GlobalD.GameData.GetBuildingStateArray()
  981. if (Index == 0) {
  982. if (BuildingStateArray[Index] != 1) {
  983. BuildingStateArray[0] = 1 //公路
  984. BuildingStateArray[1] = 1 //路铲
  985. BuildingStateArray[2] = 1 //拆迁
  986. let Building0 =
  987. this.node.getComponent('ManageBuildings').BuildingArray[0]
  988. let Building1 =
  989. this.node.getComponent('ManageBuildings').BuildingArray[1]
  990. let Building2 =
  991. this.node.getComponent('ManageBuildings').BuildingArray[2]
  992. Building0.active = true
  993. Building1.active = true
  994. Building2.active = true
  995. GlobalD.GameData.SetBuildingStateArray(BuildingStateArray)
  996. this.onShowRewards(Index)
  997. }
  998. } else {
  999. if (BuildingStateArray[Index] != 1 && Index != -1) {
  1000. cc.log('Index=' + Index)
  1001. BuildingStateArray[Index] = 1
  1002. let Building =
  1003. this.node.getComponent('ManageBuildings').BuildingArray[Index]
  1004. Building.active = true
  1005. GlobalD.GameData.SetBuildingStateArray(BuildingStateArray)
  1006. this.onShowRewards(Index)
  1007. }
  1008. }
  1009. let Diff = CurrentMoney - LastMoney
  1010. let InitMoneyNum = LastMoney
  1011. let AnimTimes = 0
  1012. let Times = 3
  1013. this.schedule(
  1014. function () {
  1015. if (Diff > 0) {
  1016. InitMoneyNum += parseInt((CurrentMoney - LastMoney) / Times)
  1017. } else {
  1018. InitMoneyNum -= parseInt((CurrentMoney - LastMoney) / Times)
  1019. }
  1020. let result = this.FormatMoney(InitMoneyNum)
  1021. if (AnimTimes == Times - 1) {
  1022. this.Goldenlabel.getComponent(cc.Label).string =
  1023. this.FormatMoney(CurrentMoney)
  1024. return
  1025. }
  1026. this.Goldenlabel.getComponent(cc.Label).string = result
  1027. AnimTimes++
  1028. },
  1029. 0.05,
  1030. Times
  1031. )
  1032. },
  1033. DiamondChangeCallBack: function (Num, LastMoney, CurrentMoney) {
  1034. let Diff = CurrentMoney - LastMoney
  1035. let InitMoneyNum = LastMoney
  1036. let AnimTimes = 0
  1037. let Times = 3
  1038. this.schedule(
  1039. function () {
  1040. if (Diff > 0) {
  1041. InitMoneyNum += parseInt((CurrentMoney - LastMoney) / Times)
  1042. } else {
  1043. InitMoneyNum -= parseInt((CurrentMoney - LastMoney) / Times)
  1044. }
  1045. let result = this.FormatMoney(InitMoneyNum)
  1046. if (AnimTimes == Times - 1) {
  1047. this.DiamondNowlabel.string = result + '/30000'
  1048. this.Diamondlabel.getComponent(cc.Label).string =
  1049. this.FormatMoney(CurrentMoney)
  1050. return
  1051. }
  1052. this.DiamondNowlabel.string = result + '/30000'
  1053. this.Diamondlabel.getComponent(cc.Label).string = result
  1054. AnimTimes++
  1055. },
  1056. 0.05,
  1057. Times
  1058. )
  1059. },
  1060. CNTChangeCallBack: function (Num) {
  1061. this.CNTlabel.getComponent(cc.Label).string = this.FormatMoney(Num)
  1062. },
  1063. SNBChangeCallBack: function (Num) {
  1064. this.SNBlabel.getComponent(cc.Label).string = this.FormatMoney(Num)
  1065. },
  1066. FormatMoney(s, n) {
  1067. n = n > 0 && n <= 20 ? n : 2
  1068. s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(n) + ''
  1069. var l = s.split('.')[0].split('').reverse(),
  1070. r = s.split('.')[1]
  1071. let t = ''
  1072. for (let i = 0; i < l.length; i++) {
  1073. t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? ',' : '')
  1074. }
  1075. return t.split('').reverse().join('') //+ "." + r;
  1076. },
  1077. })