ManageUI.js 34 KB

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