Game.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. var GameModule = require("./utils/GameModule");
  2. const FriendSystemApi = require('./net/FriendSystemApi');
  3. const ShareAction = require('./utils/ShareAction');
  4. var DWTool = require('./utils/DWTool');
  5. var HomeApi = require("./net/HomeApi");
  6. const JobApi = require('./net/JobApi');
  7. const { GameNotificationKey, SenceMap, JobPageType} = require('./utils/GameEnum');
  8. const AlertManager = require('./utils/AlertManager');
  9. cc.Class({
  10. extends: cc.Component,
  11. properties: {
  12. levelHomePrefab: cc.Prefab,
  13. wechatFriendNode: cc.Node,
  14. //用户信息页
  15. userInfoPrefab: cc.Prefab,
  16. myInfoTop: cc.Node,
  17. myTabBottom: cc.Node,
  18. friendInfoTop: cc.Node,
  19. friendTabBottom: cc.Node,
  20. _otherActor: cc.Node,
  21. friendSystemPrefab: cc.Prefab,
  22. friendHeadSprite: cc.Sprite,
  23. jobChangePrefab: cc.Prefab,
  24. talentPagePrefab: cc.Prefab,
  25. _isEnterFriendHome: false,
  26. chooseJob: cc.Node,
  27. },
  28. onLoad() {
  29. GameModule.game = this.node;
  30. this.senceHistory = [];
  31. this.buyTipNode = null;
  32. //我的家园
  33. let levelHome = cc.instantiate(this.levelHomePrefab);
  34. levelHome = levelHome.getComponent('LevelHome')
  35. levelHome.init(Global.user.uid, 1, true);
  36. this.levelHome = levelHome;
  37. //用户信息面板
  38. this.userInfo = cc.instantiate(this.userInfoPrefab);
  39. this.userInfo = this.userInfo.getComponent('UserInformation');
  40. //好友系统Tab面板
  41. let friendSystem = cc.instantiate(this.friendSystemPrefab);
  42. this.friendSystemScript = friendSystem.getComponent('FriendSystem');
  43. //好友家园
  44. let friendHome = cc.instantiate(this.levelHomePrefab);
  45. friendHome = friendHome.getComponent('LevelHome')
  46. this.friendHome = friendHome;
  47. //突破界面
  48. let breakOut = "";
  49. this.breakOut = breakOut;
  50. // //转职界面
  51. // this.jobChange = cc.instantiate(this.jobChangePrefab);
  52. // this.jobChange = this.jobChange.getComponent('ChangeJob');
  53. //星探界面
  54. this.finder = cc.instantiate(this.talentPagePrefab);
  55. this.finder = this.finder.getComponent('TalentPage');
  56. // 监听事件
  57. this.setEventListener();
  58. this.enterLevelHome();
  59. if (Global.shareUid != -1) {
  60. console.log('shareUid: ' + Global.shareUid);
  61. this.processShareAction();
  62. }
  63. this.friendHeadSprite.node.on(cc.Node.EventType.TOUCH_END, () => {
  64. Global.GameEvent.fire(GameNotificationKey.ShowUserInfomation, this.friendHome.uid);
  65. }, this);
  66. },
  67. /**
  68. * 进入好友家园
  69. * @param {Number} uid 用户id
  70. */
  71. enterFriendHome(uid) {
  72. this.friendHome.initFriend(uid, 1, res => {
  73. if (this._isEnterFriendHome) { return; }
  74. this._isEnterFriendHome = true;
  75. let actionTop = cc.moveBy(0.4, cc.v2(0, -this.friendInfoTop.height));
  76. this.friendInfoTop.runAction(actionTop);
  77. let actionRight = cc.moveBy(0.4, cc.v2(-270, 0));
  78. this.friendTabBottom.runAction(actionRight);
  79. this.friendHome.node.active = true;
  80. })
  81. },
  82. /**
  83. * 离开好友家园
  84. * @param {Number} uid 用户id
  85. */
  86. outFriendHome(uid) {
  87. this._isEnterFriendHome = false;
  88. let actionTop = cc.moveBy(0.4, cc.v2(0, this.friendInfoTop.height));
  89. this.friendInfoTop.runAction(actionTop);
  90. let actionRight = cc.moveBy(0.4, cc.v2(270, 0));
  91. this.friendTabBottom.runAction(actionRight);
  92. this.friendHome.node.active = false;
  93. },
  94. /**
  95. * 进入我的家园
  96. */
  97. enterLevelHome() {
  98. let actionTop = cc.moveBy(0.4, cc.v2(0, -this.myInfoTop.height));
  99. this.myInfoTop.runAction(actionTop);
  100. if (!this.isFirstLoad) {
  101. this.isFirstLoad = true;
  102. let actionBottom = cc.moveBy(0.4, cc.v2(0, this.myTabBottom.height + 6));
  103. this.myTabBottom.runAction(actionBottom);
  104. }
  105. this.levelHome.node.active = true;
  106. this.refreshActorNoJob();
  107. },
  108. /**
  109. * 离开我的家园
  110. */
  111. outLevelHome() {
  112. if (this._isEnterFriendHome) { return; }
  113. let actionTop = cc.moveBy(0.4, cc.v2(0, this.myInfoTop.height));
  114. this.myInfoTop.runAction(actionTop);
  115. },
  116. enterUserInfo() {
  117. this.userInfo.init(uid);
  118. },
  119. enterSence(senceName) {
  120. switch (senceName) {
  121. case SenceMap.LevelHome:
  122. //进入我的家园
  123. break;
  124. case SenceMap.UserPanel:
  125. //进入用户信息面板
  126. this.enterUserInfo();
  127. break;
  128. case SenceMap.FriendSystem:
  129. //进入好友Tab面板
  130. break;
  131. case SenceMap.FriendHome:
  132. //进入好友家园
  133. break;
  134. case SenceMap.BreakOut:
  135. //进入突破界面
  136. break;
  137. case SenceMap.Finder:
  138. //进入星探界面
  139. break;
  140. default:
  141. break;
  142. }
  143. //历史记录
  144. if (this.senceHistory[this.senceHistory.length - 1] != senceName) {
  145. this.senceHistory.push(senceName)
  146. }
  147. },
  148. senceBack() {
  149. this.senceHistory.pop()
  150. let lastSence = this.senceHistory[this.senceHistory.length - 1]
  151. this.enterSence(lastSence)
  152. },
  153. /**
  154. * 查看他人艺人列表
  155. */
  156. showOtherActors() {
  157. DWTool.loadResPrefab('./prefabs/other_actor')
  158. .then((result) => {
  159. this._otherActor = cc.instantiate(result);
  160. this._otherActor.getComponent("OtherActor").uid = this.friendHome.uid;
  161. this._otherActor.parent = cc.find("Canvas");
  162. }).catch((err) => {
  163. cc.error(err);
  164. });
  165. },
  166. /**
  167. * 关闭他人艺人列表
  168. */
  169. closeOtherActors() {
  170. this._otherActor.destroy();
  171. },
  172. showFriendSystem() {
  173. this.friendSystemScript.show(this.wechatFriendNode);
  174. },
  175. closeFriendSystem() {
  176. this.friendSystemScript.close();
  177. },
  178. // showJobChange() {
  179. // this.jobChange.show(JobPageType.ChangeJob);
  180. // },
  181. // showJobChoose() {
  182. // this.jobChange.show(JobPageType.ChooseJob);
  183. // },
  184. // showJobLevelUp() {
  185. // this.jobChange.show(JobPageType.LevelUp);
  186. // },
  187. //转职
  188. //选择职业
  189. //职业突破页面
  190. showJobPage(type, userInfo, zIndex) {
  191. let self = this;
  192. cc.loader.loadRes('/prefabs/change_job', cc.Prefab, (error, prefab) => {
  193. if (error === null) {
  194. let jobChange = cc.instantiate(prefab);
  195. this.jobChange = jobChange.getComponent('ChangeJob');
  196. this.jobChange.show(type, userInfo, zIndex);
  197. } else {
  198. console.log(JSON.stringify(error));
  199. }
  200. });
  201. },
  202. showChooseJob() {
  203. let self = this;
  204. cc.loader.loadRes('/prefabs/change_job', cc.Prefab, (error, prefab) => {
  205. if (error === null) {
  206. let jobChange = cc.instantiate(prefab);
  207. this.jobChange = jobChange.getComponent('ChangeJob');
  208. this.jobChange.showFromTalent(JobPageType.ChooseJob, self.noJobActors);
  209. } else {
  210. console.log(JSON.stringify(error));
  211. }
  212. });
  213. },
  214. //关闭转职,选择职业,突破页面
  215. closeJobPage() {
  216. this.jobChange.close();
  217. },
  218. showTalentPage() {
  219. this.finder.show();
  220. },
  221. showNoticePopup() {
  222. AlertManager.showNoticePopup();
  223. },
  224. // 监听事件
  225. setEventListener() {
  226. Global.GameEvent.on(GameNotificationKey.ShowFriendSystem, this, () => {
  227. this.showFriendSystem();
  228. });
  229. Global.GameEvent.on(GameNotificationKey.VisitFriendHome, this, (uid) => {
  230. if (uid) {
  231. this.closeFriendSystem();
  232. this.outLevelHome();
  233. this.enterFriendHome(uid)
  234. }
  235. // setTimeout(function () {
  236. // let otherHome = cc.instantiate(this.homePrefab);
  237. // otherHome.getComponent('Home').init(user.uid, 1, false);
  238. // otherHome.getComponent('Home').configUserInfo(user);
  239. // otherHome.zIndex = 1;
  240. // otherHome.parent = this.node;
  241. // }.bind(this), 800);
  242. });
  243. Global.GameEvent.on(GameNotificationKey.BackOwnerHome, this, (otherHomeNode) => {
  244. setTimeout(function () {
  245. otherHomeNode.destroy()
  246. }.bind(this), 1000);
  247. });
  248. Global.GameEvent.on(GameNotificationKey.ShowUserInfomation, this, (uid) => {
  249. this.userInfo.init(uid);
  250. });
  251. Global.GameEvent.on(GameNotificationKey.ProcessShareAction, this, this.processShareAction);
  252. Global.GameEvent.on(GameNotificationKey.ShowJobPage, this, this.showJobPage);
  253. Global.GameEvent.on(GameNotificationKey.ShowJobPageFromTalent, this, this.showChooseJob);
  254. Global.GameEvent.on(GameNotificationKey.RefreshFriendList, this, this.refreshActorNoJob);
  255. },
  256. onDestroy() {
  257. Global.GameEvent.off(GameNotificationKey.ShowFriendSystem, this);
  258. Global.GameEvent.off(GameNotificationKey.VisitFriendHome, this);
  259. Global.GameEvent.off(GameNotificationKey.BackOwnerHome, this);
  260. Global.GameEvent.off(GameNotificationKey.ProcessShareAction, this);
  261. Global.GameEvent.off(GameNotificationKey.ShowUserInfomation, this);
  262. Global.GameEvent.off(GameNotificationKey.ShowJobChoose, this);
  263. Global.GameEvent.off(GameNotificationKey.ShowJobPage, this);
  264. Global.GameEvent.off(GameNotificationKey.RefreshFriendList, this);
  265. Global.GameEvent.off(GameNotificationKey.ShowJobPageFromTalent, this);
  266. },
  267. processShareAction() {
  268. console.log('processShareAction');
  269. if (Global.user != null) {
  270. if (Global.shareType == ShareAction.ADD_FRIEND) {
  271. FriendSystemApi.addFriend(Global.shareUid, () => {
  272. Global.GameEvent.fire('refresh_friend_list');
  273. });
  274. }
  275. Global.shareUid = -1;
  276. Global.shareType = ShareAction.None;
  277. }
  278. },
  279. refreshActorNoJob() {
  280. JobApi.actorsNoJob(
  281. (response) => {
  282. if (response.list && !_.isEmpty(response.list) && response.list.length > 0) {
  283. this.chooseJob.active = true;
  284. this.noJobActors = response.list;
  285. } else {
  286. this.chooseJob.active = false;
  287. }
  288. },
  289. (code, msg) => {
  290. // this.chooseJob.active = false;
  291. }
  292. );
  293. },
  294. });