ManageUI.js 34 KB

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