ManageUI.js 33 KB

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