ManageUI.js 33 KB

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