ManageUI.js 36 KB

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