ManageUI.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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. return;
  223. //预加载广告
  224. // 'adunit-3031ded224c6f52a',//视频激励广告2
  225. AD.loadVideoAdFromIndex('ManageUI', 3, (res) => {
  226. console.log('预加载广告回调:', res);
  227. });
  228. }
  229. //Close
  230. if (callback != null) {
  231. callback(this.UnlockBuildingDialogView);
  232. }
  233. }.bind(this));
  234. },
  235. onWatchVideo(event) {
  236. this.UnlockBuildingDialogView.destroy();
  237. //观看广告视频
  238. AD.playVideoAd((res) => {
  239. if (!res.isPlay) {
  240. console.log('ManageUi不能播放广告:', res.data);
  241. } else {
  242. GlobalD.GameData.PlusGolden(GlobalD.GameData.manageUIVideoAdGive[0]);
  243. GlobalD.GameData.PlusDiamond(GlobalD.GameData.manageUIVideoAdGive[1]);
  244. }
  245. });
  246. },
  247. onClickCloseInUnlockBuilding(event) {
  248. this.UnlockBuildingDialogView.destroy();
  249. },
  250. onClickNoBTNInUnlockBuilding(event) {
  251. this.UnlockBuildingDialogView.destroy();
  252. },
  253. onClickYesBTNInUnlockBuilding(event, CustomEventData) {
  254. this.UnlockBuildingDialogView.destroy();
  255. let Index = parseInt(CustomEventData);
  256. let CostCoin = AConfig.BuildingUnlockMoneyArray[Index];
  257. if (GlobalD.GameData.GetDiamond() > CostCoin || GlobalD.GameData.GetDiamond() == CostCoin) {
  258. GlobalD.GameData.PlusDiamond(-CostCoin);
  259. this.OpenBuildingUILock(Index, false);
  260. cc.loader.loadRes("prefab/show", function (err, texture) {
  261. this.ShowRewardsView = cc.instantiate(texture);
  262. this.BuildView.addChild(this.ShowRewardsView);
  263. let Rewards = this.ShowRewardsView.getChildByName('GivePrize').getChildByName('Rewards');
  264. Rewards.getComponent(cc.Sprite).spriteFrame = this.BuildingFrameArray[Index].getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame;
  265. var Sunshine = this.ShowRewardsView.getChildByName('GivePrize').getChildByName('Sunshine');
  266. var GivePrize = this.ShowRewardsView.getChildByName('GivePrize');
  267. Sunshine.scaleX = 0;
  268. Sunshine.scaleY = 0;
  269. GivePrize.scaleX = 0;
  270. GivePrize.scaleY = 0;
  271. Sunshine.stopAllActions();
  272. GivePrize.stopAllActions();
  273. this.scheduleOnce(function () {
  274. var sc2 = cc.scaleTo(0.5, 0.5, 0.5);
  275. Sunshine.runAction(sc2);
  276. var sc3 = cc.scaleTo(0.5, 1, 1);
  277. GivePrize.runAction(sc3);
  278. var repeat = cc.repeatForever(cc.rotateBy(5.0, 360));
  279. Sunshine.runAction(repeat);
  280. }, 0.1);
  281. //CloseBtn
  282. let close = this.ShowRewardsView.getChildByName("close");
  283. let clickEventHandler = new cc.Component.EventHandler();
  284. clickEventHandler.target = this.node;
  285. clickEventHandler.component = "ManageUI";
  286. clickEventHandler.handler = "OnShowRewardsViewClose";
  287. let button = close.getComponent(cc.Button);
  288. button.clickEvents.push(clickEventHandler);
  289. }.bind(this));
  290. return;
  291. }
  292. //No Enough Diamond
  293. cc.loader.loadRes("prefab/ShowNoMoney", function (err, texture) {
  294. this.ShowNoMoneyView = cc.instantiate(texture);
  295. this.BuildView.addChild(this.ShowNoMoneyView);
  296. let DetailLabel = this.ShowNoMoneyView.getChildByName('DetailLabel');
  297. DetailLabel.getComponent(cc.Label).string = '钻石不够!'
  298. this.scheduleOnce(function () {
  299. this.ShowNoMoneyView.destroy();
  300. }.bind(this), 1);
  301. }.bind(this));
  302. },
  303. OnShowRewardsViewClose(event, CustomEventData) {
  304. this.ShowRewardsView.destroy();
  305. //分享页面
  306. //解锁房屋时候领取奖励后弹出分享
  307. task.startSharePrefab();
  308. },
  309. //欢迎光临
  310. taskCursor0: function () {
  311. //引导
  312. if (task.taskCursor == 0) {
  313. // let BelowTheMask = cc.find('Canvas/UICamera/BelowTheMask');
  314. //创建员工
  315. cc.find('GameNode/ManageWorker').getComponent('ManageWorker').onRecruit();
  316. cc.find('GameNode/ManageWorker').getComponent('ManageWorker').onRecruit();
  317. var Canvas = cc.find("Canvas/UICamera");
  318. dialogmanager.init(Canvas, function () {
  319. dialogmanager.dialog1();
  320. }.bind(this));
  321. dialogmanager.setOnCloseDialog(function () {
  322. task.CreatorBtnHelp();
  323. task.tasksstartBuildingview();
  324. this.noviceBuilding();
  325. }.bind(this));
  326. }
  327. },
  328. //去建造1
  329. taskCursor1: function () {
  330. //引导
  331. task.addTaskTips(this.nodePrefabsbg, task.newTaskName[2], 0, 0, task.taskCursorName[2], function (nodePrefabs) {
  332. UtilsPrefabs.setOn(nodePrefabs.getChildByName("SureBtn"), function () {
  333. task.removeTaskNode(task.taskCursorName[2]);
  334. this.taskCursor2();
  335. }.bind(this))
  336. }.bind(this));
  337. },
  338. //去建造农舍2
  339. taskCursor2: function () {
  340. task.addTaskTips(this.nodePrefabsbg, task.newTaskName[5], 0, 0, task.taskCursorName[2], function (nodePrefabs) {
  341. UtilsPrefabs.setOn(nodePrefabs.getChildByName("SureBtn"), function () {
  342. task.removeTaskNode(task.taskCursorName[2]);
  343. task.removeNode(this.nodePrefabsbg);
  344. //开始的 下面建造 提示
  345. task.tasksstartBuildingview();
  346. // this.taskCursor2();
  347. this.noviceBuilding();
  348. // this.novice();
  349. }.bind(this))
  350. }.bind(this));
  351. },
  352. //弹出购买提示
  353. onPurchaseTips(_contentButton) {
  354. // cc.log('是否用钻石购买建筑', _contentButton.node.name);
  355. if (this.TipViewPrefab) {
  356. let _TipView;
  357. _TipView = cc.instantiate(this.TipViewPrefab);
  358. _TipView.parent = this.TipView;
  359. _TipView.setPosition(cc.v2(0, 0));
  360. _TipView.getComponent('TipView').onShowTip({ ContentButton: _contentButton, TipViewNode: this.TipView });
  361. // cc.log(_TipView.name);
  362. }
  363. },
  364. //点击了建造列表里面的按钮时候改变样式
  365. onSetButtonState(Data, Synopsis) {
  366. // console.log("点了什么",Data);
  367. cc.Component.EventHandler.emitEvents(Data.Target.clickEvents);
  368. },
  369. onSetButtonInfoState(Data, Synopsis) {
  370. if (Synopsis) {
  371. this.onSetButtonInfo(Synopsis.Name, Synopsis.Price, Synopsis.Synopsis)
  372. }
  373. },
  374. //设置介绍信息
  375. onSetButtonInfo(_Name, _Price, _Synopsis) {
  376. this.BuildContent_Name.string = _Name;
  377. this.BuildContent_Price.string = _Price;
  378. this.BuildContent_Synopsis.string = _Synopsis;
  379. },
  380. //建筑详情
  381. openBuildView(event, index) {
  382. if (this.BuildView) {
  383. //面板设置index
  384. //环境
  385. if ('0' == index) {
  386. // this._className.string = '环境';
  387. }
  388. //劳动
  389. else if ('1' == index) {
  390. // this._className.string = '劳动';
  391. }
  392. //商铺
  393. else if ('2' == index) {
  394. // this._className.string = '商店';
  395. }
  396. }
  397. },
  398. //编辑对应的建筑
  399. onEditorialBuildings(mUI_buildTarget) {
  400. if (!this.EditorialBuildings) {
  401. cc.warn('EditorialBuildings is Null!')
  402. return;
  403. }
  404. this.EditorialBuildings.active = true;
  405. //重置上一个编辑建筑的状态
  406. if (this._buildTarget && this._buildTarget.getComponent('buildingsTouch')) {
  407. this._buildTarget.getComponent('buildingsTouch').onCancelEdit();
  408. }
  409. this._buildTarget = mUI_buildTarget;
  410. this.EditorialBuildings.parent = mUI_buildTarget;
  411. this.EditorialBuildings.setPosition(cc.v2(0, 0));
  412. },
  413. //取消编辑
  414. onCancellationEditor() {
  415. let buildTouch = this._buildTarget.getComponent('buildingsTouch');
  416. let isTaskNext = buildTouch.onTaskBuild();
  417. if (!isTaskNext) return;
  418. if (task.isMushBuildState) {
  419. cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
  420. var prefab = cc.instantiate(texture);
  421. prefab.getComponent('ShowNotEnoughMoney').Text("请点击'√'号");
  422. this._buildTarget.addChild(prefab);
  423. }.bind(this));
  424. return;
  425. }
  426. buildTouch.onCancelEdit();
  427. this.EditorialBuildings.active = false;
  428. this.EditorialBuildings.parent = this._thisEditBuildingsParent;
  429. this.EditorialBuildings.setPosition(cc.v2(10000, 100));
  430. this._buildTarget = null;
  431. },
  432. //确定编辑(创建建筑物 对号)
  433. onConfirmationEditor() {
  434. //获取建筑物上的组件
  435. let buildTouch = this._buildTarget.getComponent('buildingsTouch');
  436. let isTaskNext = buildTouch.onTaskBuild();
  437. if (!isTaskNext) return;
  438. buildTouch.onFinishEdit();
  439. this.EditorialBuildings.active = false;
  440. this.EditorialBuildings.parent = this._thisEditBuildingsParent;
  441. this.EditorialBuildings.setPosition(cc.v2(10000, 100));
  442. this._buildTarget = null;
  443. },
  444. //如果相等的话返回true
  445. verctor3IsEqual(vector1, vector2) {
  446. let isEqual = false;
  447. let out = new cc.Vec3();
  448. out.x = vector2.x - vector1.x;
  449. out.y = vector2.y - vector1.y;
  450. out.z = vector2.z - vector1.z;
  451. if (out.x == 0 && out.y == 0 && out.z == 0) {
  452. isEqual = true;
  453. }
  454. return isEqual;
  455. },
  456. //收起全部菜单
  457. onHideMenu() {
  458. // if (this.BuildView) {
  459. // this.BuildView.active = false;
  460. // }
  461. //音效设置界面
  462. if (this.SettingInfoView.active)
  463. this.onSetTouchStatus(this.SettingInfoView, false);
  464. //建造界面
  465. if (this.BuildView.active)
  466. this.onSetTouchStatus(this.BuildView, false);
  467. //人才界面
  468. if (this.PersonnelView.active)
  469. this.onSetTouchStatus(this.PersonnelView, false);
  470. //股票界面
  471. if (this.StockView.active)
  472. this.onSetTouchStatus(this.StockView, false);
  473. //转盘界面
  474. if (this.LuckView.active)
  475. this.onSetTouchStatus(this.LuckView, false);
  476. this._ManageAd.onCloseBannerAd();
  477. },
  478. //底部菜单栏
  479. onBottomMenuView(isActive) {
  480. if (this.BottomView) {
  481. this.BottomView.active = isActive;
  482. }
  483. if (isActive)
  484. this._ManageAd.onPlayBannerAd();
  485. else
  486. this._ManageAd.onCloseBannerAd();
  487. // cc.log('不能显示面板信息:');
  488. GlobalD.GameControl._isBuildingCanEdit = !isActive;
  489. },
  490. //开启信息显示
  491. onShowBuildingInfo(buildingInfo) {
  492. this.BuildingInfoView.active = true;
  493. if (!this._buildingInfoViewScript)
  494. this._buildingInfoViewScript = this.BuildingInfoView.getComponent('buildingInfoView');
  495. //显示房屋信息
  496. this._buildingInfoViewScript.onSetBuildingInfoView(buildingInfo);
  497. },
  498. //关闭信息显示
  499. onCloseBuildingInfo() {
  500. this.BuildingInfoView.active = false;
  501. },
  502. //进入编辑模式,
  503. onEnterEditing() {
  504. },
  505. onSetTouchStatus(target, isActive) {
  506. target.active = isActive;
  507. if (this.UITouch) {
  508. this.UITouch.active = isActive;
  509. }
  510. if (!isActive)
  511. this._ManageAd.onPlayBannerAd();
  512. },
  513. //音效设置界面
  514. onButtonEvent_Setting_OPen() {
  515. this.onHideMenu();
  516. this.onSetTouchStatus(this.SettingInfoView, true);
  517. },
  518. onButtonEvent_Setting_Close() {
  519. this.onSetTouchStatus(this.SettingInfoView, false);
  520. },
  521. //建造界面
  522. onButtonEvent_Building_OPen() {
  523. this.onHideMenu();
  524. this.onSetTouchStatus(this.BuildView, true);
  525. this.BuildView.getComponent('BuildingView').onSwitchBuildingContent(this.Evn.getComponent(cc.Button), 0);
  526. },
  527. novice: function () {
  528. var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView");
  529. task.removeTaskNode(task.taskCursorName[2]); //左上
  530. task.addTaskTips(BuildingView, task.taskPrefab[1], -180, 180, task.taskCursorName[2], function (nodePrefabs) {
  531. //手指
  532. this.nodePrefabs = nodePrefabs;
  533. }.bind(this));
  534. },
  535. novice1: function () {
  536. var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView");
  537. task.addTaskTips(BuildingView, task.novice[1], 0, 50, task.taskCursorName[3], function (node) {
  538. UtilsPrefabs.setOn(node.getChildByName("SureBtn"), function () {
  539. UtilsPrefabs.setOff(node.getChildByName("SureBtn"));
  540. var mt = cc.moveTo(1, 110, 180);//右上
  541. var finished = cc.callFunc(function () {
  542. task.removeTaskNode(task.taskCursorName[3]);
  543. this.novice2();
  544. }.bind(this));
  545. var sequence = cc.sequence(mt, finished);
  546. this.nodePrefabs.runAction(sequence);
  547. task.isShowTaskNode(task.taskCursorName[3], false);
  548. }.bind(this))
  549. }.bind(this));
  550. },
  551. novice2: function () {
  552. var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView");
  553. task.addTaskTips(BuildingView, task.novice[2], 0, 50, task.taskCursorName[3], function (node) {
  554. UtilsPrefabs.setOn(node.getChildByName("SureBtn"), function () {
  555. UtilsPrefabs.setOff(node.getChildByName("SureBtn"));
  556. var mt = cc.moveTo(1, -200, 0);//
  557. var finished = cc.callFunc(function () {
  558. task.removeTaskNode(task.taskCursorName[3]);
  559. this.novice3();
  560. }.bind(this));
  561. var sequence = cc.sequence(mt, finished);
  562. this.nodePrefabs.runAction(sequence);
  563. task.isShowTaskNode(task.taskCursorName[3], false);
  564. }.bind(this))
  565. }.bind(this));
  566. },
  567. novice3: function () {
  568. var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView");
  569. task.addTaskTips(BuildingView, task.novice[3], 0, -150, task.taskCursorName[3], function (node) {
  570. UtilsPrefabs.setOn(node.getChildByName("SureBtn"), function () {
  571. task.removeTaskNode(task.taskCursorName[3]);
  572. }.bind(this))
  573. }.bind(this));
  574. },
  575. noviceend: function () {
  576. // task.noviceend();
  577. },
  578. //外面管理的手指
  579. novicepersonnel: function () {
  580. task.removeTaskNode(task.taskCursorName[2]); //左上
  581. task.addTaskTips(task.personnelview, task.taskPrefab[1], 0, 0, task.taskCursorName[2], function (nodePrefabs) {
  582. //手指
  583. this.nodePrefabs = nodePrefabs;
  584. }.bind(this));
  585. },
  586. //外面的 建筑手指
  587. noviceBuilding: function () {
  588. // task.showManager(1,-50,-50);
  589. //建造农舍指引
  590. task.showTiledTile(0, 0, 0, 23, 25);
  591. task.onTaskBuildAHouseMask();
  592. },
  593. novice4: function () {
  594. var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView");
  595. task.addTaskTips(BuildingView, task.novice[4], 0, -200, task.taskCursorName[3], function (node) {
  596. UtilsPrefabs.setOn(node.getChildByName("SureBtn"), function () {
  597. task.removeTaskNode(task.taskCursorName[3]);
  598. }.bind(this))
  599. }.bind(this));
  600. },
  601. //关闭 建造框
  602. onButtonEvent_Building_Close() {
  603. // cc.log(this.BuildView);
  604. this.onSetTouchStatus(this.BuildView, false);
  605. },
  606. //人才界面
  607. onButtonEvent_Personnel_OPen() {
  608. this.onHideMenu();
  609. this.onSetTouchStatus(this.PersonnelView, true);
  610. },
  611. onButtonEvent_Personnel_Close() {
  612. this.onSetTouchStatus(this.PersonnelView, false);
  613. },
  614. //股票界面
  615. onButtonEvent_Stock_OPen() {
  616. this.onHideMenu();
  617. this.onSetTouchStatus(this.StockView, true);
  618. // console.log("所有建筑物数据", GlobalD.game.buildingsTiledMapUnit);
  619. UtilsWX.lookRankList(true);
  620. this.showFriend();
  621. },
  622. //限制
  623. returnDialog: function (cursor) {
  624. var num = 0;
  625. // console.log("要创建什么提示呢数字", cursor);
  626. switch (cursor) {
  627. case 1:
  628. num = 0;
  629. break;
  630. case 4:
  631. num = 1;
  632. break;
  633. case 6:
  634. num = 2;
  635. break;
  636. }
  637. console.log("要创建什么提示呢", task.returnPrefab[num]);
  638. var Canvas = cc.find("Canvas/UICamera");
  639. task.addTaskTips(Canvas, task.returnPrefab[num], 0, 0, task.taskCursorName[4], function (nodePrefabs) {
  640. UtilsPrefabs.setOn(nodePrefabs.getChildByName("SureBtn"), function () {
  641. task.removeTaskNode(task.taskCursorName[4]);
  642. }.bind(this))
  643. }.bind(this));
  644. },
  645. showFriend: function () {
  646. // var data1 = {
  647. // name: "Whoareyou",
  648. // openId : userData.openId
  649. // }
  650. // UtilsWX.postMessage(data1);
  651. var data = {
  652. name: "showFriend",
  653. }
  654. UtilsWX.postMessage(data);
  655. },
  656. onButtonEvent_Stock_Close() {
  657. this.onSetTouchStatus(this.StockView, false);
  658. var data = {
  659. name: "hideFriend",
  660. }
  661. UtilsWX.postMessage(data);
  662. setTimeout(function () {
  663. UtilsWX.lookRankList(false);
  664. }.bind(this), 200);
  665. },
  666. //转盘界面
  667. onButtonEvent_Luck_OPen() {
  668. this.onHideMenu();
  669. this.onSetTouchStatus(this.LuckView, true);
  670. if (this.nodePrefabsLuck != null) {
  671. task.removeNode(this.nodePrefabsLuck);
  672. }
  673. },
  674. isTask: function (obj) {
  675. var Canvas = cc.find("Canvas/UICamera");
  676. UtilsPrefabs
  677. .init(Canvas)
  678. .addPrefabs(UtilsPrefabs.sharePrefab[1], null, function (node) {
  679. var gosharebtn = UtilsPrefabs.getNode("gosharebtn", node);
  680. var close = UtilsPrefabs.getNode("close", node);
  681. UtilsPrefabs.setOn(close, function () {
  682. UtilsPrefabs.removePrefabs(Canvas, node.name);
  683. if (task.TaskIconCountClick == 5) {
  684. if (obj.currentTarget.name == "GetGift") {
  685. task.addTaskIconCountClick();
  686. task.removeTaskNodes();
  687. }
  688. }
  689. }.bind(this))
  690. UtilsPrefabs.setOn(gosharebtn, function () {
  691. // console.log("点击分享按钮");
  692. UtilsWX.sharebtn(function () {
  693. UtilsPrefabs.setOff(gosharebtn);
  694. GlobalD.GameData.PlusGolden(GlobalD.GameData.shareGive[0]);
  695. GlobalD.GameData.PlusDiamond(GlobalD.GameData.shareGive[1]);
  696. if (task.TaskIconCountClick == 5) {
  697. if (obj.currentTarget.name == "GetGift") {
  698. task.addTaskIconCountClick();
  699. task.removeTaskNodes();
  700. }
  701. }
  702. }.bind(this));
  703. UtilsPrefabs.removePrefabs(Canvas, node.name);
  704. }.bind(this))
  705. }.bind(this));
  706. },
  707. isTask4: function () {
  708. // console.log("现在是多少呢", task.TaskIconCountClick);
  709. if (task.TaskIconCountClick == 4) {
  710. task.addTaskIconCountClick();
  711. task.removeTaskNodes();
  712. }
  713. },
  714. onButtonEvent_Luck_Close(obj) {
  715. // console.log("现在是谁点的", obj);
  716. let Wheel = this.LuckView.getChildByName('Wheel').getComponent('Wheel');
  717. Wheel.node.active = true;
  718. Wheel.ShowRewards.active = false;
  719. this.onSetTouchStatus(this.LuckView, false);
  720. if (obj.target.name == "GetGift") {
  721. this.isTask(obj);
  722. }
  723. },
  724. onButtonEvent_EveryDay_OPen() {
  725. this.onHideMenu();
  726. this.onSetTouchStatus(this.EveryDaySignView, true);
  727. // console.log("我们进来了么",task.TaskIconCountClick);
  728. //打开每日签到 外面的按钮
  729. if (task.TaskIconCountClick == 4) {
  730. var EveryDaySign = cc.find("Canvas/UICamera/OverTheMask/EveryDaySignContainer/EveryDaySignView");
  731. task.removeTaskNode(task.taskCursorName[4]);
  732. task.addTaskTips(EveryDaySign, task.taskPrefab[1], 20, -470, task.taskCursorName[4], function (nodePrefabs) {
  733. }.bind(this));
  734. }
  735. },
  736. onButtonEvent_EveryDay_Close() {
  737. this.onSetTouchStatus(this.EveryDaySignView, false);
  738. // console.log("现在是多少呢",task.TaskIconCountClick);
  739. // this.isTask4();
  740. },
  741. onShowRewards: function (Index) {
  742. let ManageBuildingScript = this.node.getComponent('ManageBuildings');
  743. console.log("走了吗", Index);
  744. let GivePrize = this.ShowRewards.getChildByName('GivePrize');
  745. let Rewards = GivePrize.getChildByName('Rewards');
  746. Rewards.getComponent(cc.Sprite).spriteFrame = this.BuildingFrameArray[Index].getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame;
  747. //开始播放
  748. var Sunshine = this.ShowRewards.getChildByName('GivePrize').getChildByName('Sunshine');
  749. Sunshine.scaleX = 0;
  750. Sunshine.scaleY = 0;
  751. GivePrize.scaleX = 0;
  752. GivePrize.scaleY = 0;
  753. Sunshine.stopAllActions();
  754. GivePrize.stopAllActions();
  755. this.scheduleOnce(function () {
  756. this.ShowRewards.opacity = 255;
  757. this.ShowRewards.active = true;
  758. var sc2 = cc.scaleTo(1, 0.5, 0.5);
  759. Sunshine.runAction(sc2);
  760. var sc3 = cc.scaleTo(1, 1, 1);
  761. GivePrize.runAction(sc3);
  762. var repeat = cc.repeatForever(cc.rotateBy(5.0, 360));
  763. Sunshine.runAction(repeat);
  764. }, 0.1);
  765. },
  766. onCloseShowRewards: function () {
  767. this.ShowRewards.active = false;
  768. },
  769. GoldenChangeCallBack: function (Num, LastMoney, CurrentMoney) {
  770. let Scale = 30;
  771. let Index = -1;
  772. // if(Num>10*Scale)
  773. // {
  774. // Index = 7;//伐木场
  775. // }
  776. // if(Num>30*Scale)
  777. // {
  778. // Index = 8;//矿坑
  779. // }
  780. // if(Num>70*Scale)
  781. // {
  782. // // Index = 9;//加工厂
  783. // }
  784. // if(Num>350*Scale && Num<450*Scale)
  785. // {
  786. // Index = 4;//单元楼
  787. // }
  788. if (Num > 4000 && Num < 4500) {
  789. Index = 4;//单元楼
  790. }
  791. // else if(Num>450*Scale && Num<550*Scale)
  792. // {
  793. // Index = 11;//鲜花店
  794. // }
  795. else if (Num > 4500 && Num < 5500) {
  796. Index = 11;//鲜花店
  797. } else if (Num > 550 * Scale && Num < 650 * Scale) {
  798. Index = 12;//甜品店
  799. }
  800. if (Num > 650 * Scale && Num < 750 * Scale) {
  801. Index = 7;//伐木场
  802. } else if (Num > 750 * Scale && Num < 950 * Scale) {
  803. Index = 13;//汉堡店
  804. }
  805. // else if(Num>850*Scale)
  806. // {
  807. // Index = 0;//公路
  808. // }
  809. else if (Num > 950 * Scale && Num < 1050 * Scale) {
  810. Index = 14;//咖啡店
  811. } else if (Num > 1050 * Scale && Num < 1150 * Scale) {
  812. Index = 5;//别墅
  813. } else if (Num > 1150 * Scale && Num < 1250 * Scale) {
  814. Index = 15;//洋装店
  815. }
  816. if (Num > 1250 * Scale && Num < 1350 * Scale) {
  817. Index = 8;//矿坑
  818. } else if (Num > 1350 * Scale) {
  819. Index = 16;//酒吧
  820. }
  821. // else if(Num>250*Scale)
  822. // {
  823. // Index = 4;//单元楼
  824. // }
  825. // else if(Num>600*Scale)
  826. // {
  827. // Index = 5;//别墅
  828. // }
  829. var BuildingStateArray = GlobalD.GameData.GetBuildingStateArray();
  830. if (Index == 0) {
  831. if (BuildingStateArray[Index] != 1) {
  832. BuildingStateArray[0] = 1;//公路
  833. BuildingStateArray[1] = 1;//路铲
  834. BuildingStateArray[2] = 1;//拆迁
  835. let Building0 = this.node.getComponent('ManageBuildings').BuildingArray[0];
  836. let Building1 = this.node.getComponent('ManageBuildings').BuildingArray[1];
  837. let Building2 = this.node.getComponent('ManageBuildings').BuildingArray[2];
  838. Building0.active = true;
  839. Building1.active = true;
  840. Building2.active = true;
  841. GlobalD.GameData.SetBuildingStateArray(BuildingStateArray);
  842. this.onShowRewards(Index);
  843. }
  844. } else {
  845. if (BuildingStateArray[Index] != 1 && Index != -1) {
  846. cc.log('Index=' + Index);
  847. BuildingStateArray[Index] = 1;
  848. let Building = this.node.getComponent('ManageBuildings').BuildingArray[Index];
  849. Building.active = true;
  850. GlobalD.GameData.SetBuildingStateArray(BuildingStateArray);
  851. this.onShowRewards(Index);
  852. }
  853. }
  854. let Diff = CurrentMoney - LastMoney;
  855. let InitMoneyNum = LastMoney;
  856. let AnimTimes = 0;
  857. let Times = 3;
  858. this.schedule(function () {
  859. if (Diff > 0) {
  860. InitMoneyNum += parseInt((CurrentMoney - LastMoney) / Times);
  861. } else {
  862. InitMoneyNum -= parseInt((CurrentMoney - LastMoney) / Times);
  863. }
  864. let result = this.FormatMoney(InitMoneyNum);
  865. if (AnimTimes == Times - 1) {
  866. this.Goldenlabel.getComponent(cc.Label).string = this.FormatMoney(CurrentMoney);
  867. return;
  868. }
  869. this.Goldenlabel.getComponent(cc.Label).string = result;
  870. AnimTimes++;
  871. }, 0.05, Times);
  872. },
  873. DiamondChangeCallBack: function (Num, LastMoney, CurrentMoney) {
  874. let Diff = CurrentMoney - LastMoney;
  875. let InitMoneyNum = LastMoney;
  876. let AnimTimes = 0;
  877. let Times = 3;
  878. this.schedule(function () {
  879. if (Diff > 0) {
  880. InitMoneyNum += parseInt((CurrentMoney - LastMoney) / Times);
  881. } else {
  882. InitMoneyNum -= parseInt((CurrentMoney - LastMoney) / Times);
  883. }
  884. let result = this.FormatMoney(InitMoneyNum);
  885. if (AnimTimes == Times - 1) {
  886. this.Diamondlabel.getComponent(cc.Label).string = this.FormatMoney(CurrentMoney);
  887. return;
  888. }
  889. this.Diamondlabel.getComponent(cc.Label).string = result;
  890. AnimTimes++;
  891. }, 0.05, Times);
  892. },
  893. FormatMoney(s, n) {
  894. n = n > 0 && n <= 20 ? n : 2;
  895. s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
  896. var l = s.split(".")[0].split("").reverse(),
  897. r = s.split(".")[1];
  898. let t = "";
  899. for (let i = 0; i < l.length; i++) {
  900. t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
  901. }
  902. return t.split("").reverse().join(""); //+ "." + r;
  903. }
  904. });