ManageUI.js 35 KB

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