ManageUI.js 34 KB

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