UserInformation.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. var Api = require('../net/Api');
  2. var UserInformationApi = require('../net/UserInformationApi');
  3. var { UserInformationType, UserInformationRelateOptType, GameNotificationKey, UserInteractionType, JobPageType, UserJobType} = require('../utils/GameEnum');
  4. var DWTool = require('../utils/DWTool');
  5. const AlertManager = require('../utils/AlertManager');
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. titleNode: cc.Node,
  10. infoBackgroundNode: cc.Node,
  11. informationNode: cc.Node, //用户信息节点
  12. userInformationNode: cc.Node, //左边当前人物信息节点
  13. userAvatar: cc.Sprite,
  14. userNicknameLabel: cc.Label,
  15. artistNameText: cc.RichText,
  16. bossButton: cc.Button, //显示老板按钮
  17. bossInformationNode: cc.Node,
  18. bossAvatar: cc.Sprite,
  19. bossNicknameLabel: cc.Label,
  20. bossArtistNameText: cc.RichText,
  21. timelineNode: cc.Node, //动态节点
  22. //用户角色
  23. infoRole: {
  24. default:UserInformationType.Mine,
  25. visible: false,
  26. },
  27. //关系改变弹窗:抢夺、赎身、签约
  28. changeRelationNode: cc.Node,
  29. //修改艺名节点
  30. editNameNode: cc.Node,
  31. editboxName: cc.EditBox,
  32. //提示框节点
  33. errorNode: cc.Node,
  34. _userIdArray: [cc.Integer],
  35. themeNode: cc.Node,
  36. jobNode: cc.Node,
  37. //个人属性节点
  38. propertyNode: cc.Node,
  39. //互动、亲密度相关操作
  40. interactionPrefab: cc.Prefab,
  41. //背包预制
  42. packPrefab: cc.Prefab,
  43. },
  44. // LIFE-CYCLE CALLBACKS:
  45. onLoad() {
  46. this.bossInformationNode.on('touchend', this.showBossInfoToView, this);
  47. this.editNameNode.on('touchend', this.closeEditName, this);
  48. this.jobNode.on('touchend', this.changeJob, this);
  49. let XHeight = 1624;
  50. this.winSize = cc.view.getVisibleSize();
  51. let nodeY = this.winSize.height / 2.0;
  52. this.node.y = nodeY;
  53. this.infoTop = 135;
  54. if (this.winSize.height >= XHeight) {
  55. this.titleNode.getComponent(cc.Widget).top = 80;
  56. this.infoBackgroundNode.getComponent(cc.Widget).top = -50;
  57. this.informationNode.getComponent(cc.Widget).top = 185;
  58. this.infoTop = 185;
  59. }
  60. let timelineHeight = (this.winSize.height - this.infoTop - this.informationNode.height);
  61. this.timelineNode.height = timelineHeight;
  62. this.timelineNode.y = timelineHeight - this.winSize.height;
  63. //适配pad尺寸修改
  64. if (this.winSize.height <= 1100) {
  65. this.scrollY = 0;
  66. this.node.setContentSize(cc.size(this.winSize.width, 1334));
  67. let maxHeight = 1334 - nodeY;
  68. this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
  69. this.scrollY = event.getLocation().y;
  70. }, this);
  71. this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
  72. let moveY = event.getLocation().y;
  73. if (moveY <= this.scrollY) {
  74. if (this.node.y <= nodeY) {
  75. this.node.y = nodeY;
  76. } else {
  77. this.node.y -= Math.min((this.scrollY - moveY), 20);
  78. }
  79. } else {
  80. if (this.node.y >= maxHeight) {
  81. this.node.y = maxHeight;
  82. } else {
  83. this.node.y += Math.min((moveY - this.scrollY), 20);
  84. }
  85. }
  86. this.scrollY = moveY;
  87. }, this);
  88. let timelineHeight = (1334 - this.infoTop - this.informationNode.height);
  89. this.timelineNode.height = timelineHeight;
  90. this.timelineNode.y = timelineHeight - 1334;
  91. }
  92. this.artistNameText.getComponent('UserInformationRichText').init(this);
  93. this.errorMng = this.errorNode.getComponent('UserInformationAlert');
  94. this.errorMng.init(this);
  95. this.timelineMng = this.timelineNode.getComponent('UserInformationTimeline');
  96. this.timelineMng.init();
  97. this.relationAlertMng = this.changeRelationNode.getComponent('UserInformationAlert');
  98. this.relationAlertMng.init(this);
  99. this.themeMng = this.themeNode.getComponent('UserInformationTheme');
  100. this.themeMng.init(this);
  101. this.propertyMng = this.propertyNode.getComponent('UserInformationProperty');
  102. this.propertyMng.init(this);
  103. //亲密度显示操作页面
  104. this.interaction = cc.instantiate(this.interactionPrefab);
  105. this.interaction = this.interaction.getComponent('UserInteraction');
  106. //背包页面
  107. //亲密度显示操作页面
  108. this.pack = cc.instantiate(this.packPrefab);
  109. this.pack = this.pack.getComponent('UserPack');
  110. this.setEventListener();
  111. this.trainEvent = _.debounce(() => {
  112. //0为还没选择职业将不能进行培养,跳去选择职业界面
  113. if (this.userInfo.jobId == UserJobType.None) {
  114. AlertManager.showArtistTrainNoJob(() => {
  115. this.changeJob();
  116. }, this.node.zIndex);
  117. } else {
  118. AlertManager.showTrainAlert(this.userInfo.uid, this.node.zIndex);
  119. }
  120. }, 1000, true);
  121. this.visitEvent = _.debounce( () => {
  122. Global.GameEvent.fire(GameNotificationKey.VisitFriendHome, this.userInfo.uid);
  123. }, 1000, true);
  124. },
  125. init(uid) {
  126. this.node.parent = cc.find("Canvas");
  127. this.node.setContentSize(cc.view.getVisibleSize());
  128. this.node.active = true;
  129. this.node.zIndex += 1;
  130. this.loadUserInformation(uid);
  131. },
  132. start() {
  133. },
  134. onEnable() {
  135. },
  136. setEventListener() {
  137. Global.GameEvent.on(GameNotificationKey.ShowInteraction, this, () => {
  138. if (this.responseData.interactionInfo) {
  139. var isCommon = (this.infoRole == UserInformationType.Boss || this.infoRole == UserInformationType.MyArtist) ? false : true;
  140. this.interaction.showIntimacyInfo(isCommon);
  141. }
  142. });
  143. Global.GameEvent.on(GameNotificationKey.RefreshUserInformation, this, () => {
  144. this.getNetworkData(true);
  145. });
  146. },
  147. onDisable() {
  148. this.bossInformationNode.enabled = true;
  149. this.bossInformationNode.active = false;
  150. this.bossInformationNode.x = this.winSize.width / 2.0;
  151. this.bossButton.node.x = this.winSize.width / 2.0 - 84;
  152. this.themeMng.relationButtonNode.enabled = true;
  153. this.themeMng.successNode.active = false;
  154. this.editNameNode.active = false;
  155. this.changeRelationNode.active = false;
  156. this.errorNode.active = false;
  157. this.node.zIndex = 0;
  158. this._userIdArray = [];
  159. },
  160. loadUserInformation(uid) {
  161. if (uid) {
  162. this.uid = uid;
  163. }
  164. if (Global.user.uid == this.uid) {
  165. this.isSelf = true;
  166. } else {
  167. this.isSelf = false;
  168. }
  169. this.getNetworkData(false);
  170. },
  171. //获取个人信息
  172. getNetworkData(isRefresh) {
  173. UserInformationApi.getUserInformation(this.uid, (responseData) => {
  174. // console.log("responseData: " + JSON.stringify(responseData));
  175. this.loadInformation(responseData);
  176. if (isRefresh == false) {
  177. this._userIdArray.push(this.uid);
  178. }
  179. }, (error) => {
  180. console.log('userinformation error' + error);
  181. this.bossInformationNode.enabled = true;
  182. });
  183. },
  184. loadInformation(responseData) {
  185. if (responseData) {
  186. this.role = responseData.role;
  187. this.currentUserCost = responseData.currentUserCost;
  188. this.userInfo = responseData.userInfo;
  189. this.bossInfo = responseData.bossInfo;
  190. this.responseData = responseData;
  191. this.refreshThemeUI();
  192. this.timelineMng.loadUserTimeline(this.uid);
  193. }
  194. },
  195. //关闭个人信息页
  196. closeInformationAction() {
  197. if (this._userIdArray.length > 1) {
  198. let uid = this._userIdArray[this._userIdArray.length - 2];
  199. this.loadUserInformation(uid);
  200. this.removeItems(this._userIdArray, 2);
  201. } else {
  202. this.node.active = false;
  203. }
  204. },
  205. removeItems(arr, item) {
  206. for (var i = 0; i < item; i++) {
  207. arr.pop();
  208. }
  209. },
  210. // update (dt) {},
  211. //根据不同用户状态信息显示
  212. refreshThemeUI() {
  213. if (this.userInfo) {
  214. if (this.userInfo.head) {
  215. Api.createImageFromUrl(this.userInfo.head, (spriteFrame) => {
  216. this.userAvatar.spriteFrame = spriteFrame;
  217. });
  218. }
  219. if (this.userInfo.nick) {
  220. this.userNicknameLabel.string = this.userInfo.nick;
  221. }
  222. var genderIcon = 'artist_female';
  223. if (this.userInfo.gender == 1) {
  224. genderIcon = 'artist_male';
  225. }
  226. var artistName = " 无艺名 ";
  227. if (this.userInfo.artistName) {
  228. artistName = " " + this.userInfo.artistName.slice(0,5) + " ";
  229. }
  230. var artistString = "<img src='"+ genderIcon +"'/><outline color=white width=2> " + artistName + "</outline>";
  231. if (this.role == 2) {
  232. let editName = "<img src='artist_name_edit' click='clickEditName'/>";
  233. artistString += editName;
  234. }
  235. this.artistNameText.string = artistString;
  236. if (this.isSelf) {
  237. this.infoRole = UserInformationType.Mine;
  238. } else {
  239. switch (this.role) {
  240. case UserInformationType.Boss:
  241. this.infoRole = UserInformationType.Boss;
  242. break;
  243. case UserInformationType.MyArtist:
  244. this.infoRole = UserInformationType.MyArtist;
  245. if (this.userInfo.artistName) {
  246. this.editNameNode.string = this.userInfo.artistName;
  247. }
  248. break;
  249. case UserInformationType.ArtistFree:
  250. this.infoRole = UserInformationType.ArtistFree;
  251. break;
  252. case UserInformationType.OtherArtist:
  253. this.infoRole = UserInformationType.OtherArtist;
  254. break;
  255. default:
  256. break
  257. }
  258. }
  259. this.propertyMng.setUserData(this.userInfo, this.infoRole);
  260. }
  261. if (this.bossInfo) {
  262. this.bossButton.node.active = true;
  263. if (this.bossInfo.head) {
  264. Api.createImageFromUrl(this.bossInfo.head, (spriteFrame) => {
  265. this.bossAvatar.spriteFrame = spriteFrame;
  266. });
  267. }
  268. if (this.bossInfo.nick) {
  269. this.bossNicknameLabel.string = this.bossInfo.nick;
  270. }
  271. var genderIcon = 'artist_female';
  272. if (this.userInfo.gender == 1) {
  273. genderIcon = 'artist_male';
  274. }
  275. var artistName = " 无艺名";
  276. if (this.bossInfo.artistName) {
  277. artistName = " " + this.bossInfo.artistName.slice(0,3);
  278. }
  279. var artistString = "<img src='"+ genderIcon +"'/><outline color=white width=2> " + artistName + "</outline>";
  280. this.bossArtistNameText.string = artistString;
  281. } else {
  282. this.bossButton.node.active = false;
  283. }
  284. this.bossInformationNode.enabled = true;
  285. this.bossInformationNode.active = false;
  286. this.bossInformationNode.x = this.winSize.width / 2.0;
  287. this.bossButton.node.x = this.winSize.width / 2.0 - 84;
  288. if (this.responseData.interactionInfo) {
  289. this.interaction.init(this.uid, this.responseData.interactionInfo, this);
  290. this.configIntimacy(this.responseData.interactionInfo);
  291. }
  292. this.themeMng.changeTheme(this.infoRole);
  293. },
  294. showBossInfo() {
  295. if (this.bossInformationNode.active === true) {
  296. let callBack = cc.callFunc(function () {
  297. this.bossInformationNode.active = false;
  298. }, this);
  299. let positionAction = cc.moveBy(0.15, 153, 0);
  300. this.bossInformationNode.runAction(cc.sequence(positionAction, callBack));
  301. let buttonAction = cc.moveBy(0.15, 148, 0);
  302. this.bossButton.node.runAction(buttonAction);
  303. } else {
  304. this.bossInformationNode.active = true;
  305. let positionAction = cc.moveBy(0.15, -153, 0);
  306. this.bossInformationNode.runAction(positionAction);
  307. let buttonAction = cc.moveBy(0.15, -148, 0);
  308. this.bossButton.node.runAction(buttonAction);
  309. }
  310. },
  311. showBossInfoToView() {
  312. this.bossInformationNode.enabled = false;
  313. this.loadUserInformation(this.bossInfo.uid);
  314. },
  315. //抢夺、赎身、签约操作
  316. changeRelationAction() {
  317. this.themeMng.relationButtonNode.enabled = false;
  318. var string = '';
  319. var coinString = '';
  320. switch (this.infoRole) {
  321. case UserInformationType.Boss:
  322. string = "赎身需要付出<color=#f73939>两倍</c>的签约费\n你确定要赎身吗?";
  323. coinString = (this.currentUserCost * 2).toString();
  324. break;
  325. case UserInformationType.OtherArtist:
  326. string = '是否签约该好友成为旗下艺人?\n签约该好友需要消耗:';
  327. coinString = (this.userInfo.cost).toString();
  328. break;
  329. case UserInformationType.ArtistFree:
  330. string = '是否签约该好友成为旗下艺人?\n签约该好友需要消耗:';
  331. coinString = (this.userInfo.cost).toString();
  332. break;
  333. default:
  334. break;
  335. }
  336. this.relationAlertMng.showRelationAlert(string, coinString, () => {
  337. this.changeRelationNode.active = false;
  338. }, () => {
  339. this.confirmChangeRelation();
  340. });
  341. },
  342. confirmChangeRelation() {
  343. switch (this.infoRole) {
  344. case UserInformationType.Boss:
  345. this.changeRelate(UserInformationRelateOptType.Redeem);
  346. break;
  347. case UserInformationType.OtherArtist:
  348. this.changeRelate(UserInformationRelateOptType.Loot);
  349. break;
  350. case UserInformationType.ArtistFree:
  351. this.changeRelate(UserInformationRelateOptType.Sign);
  352. break;
  353. default:
  354. break;
  355. }
  356. this.changeRelationNode.active = false;
  357. },
  358. /**
  359. * 修改用户状态
  360. * @param {UserInformationRelateOptType} type
  361. */
  362. changeRelate(type) {
  363. UserInformationApi.postRelate(this.uid, type, (responseData) => {
  364. console.log("responseData: " + JSON.stringify(responseData));
  365. switch (type) {
  366. case UserInformationRelateOptType.Redeem:
  367. this.themeMng.showChangeRelationSuccess('userInformation/userinformation_redeem_success');
  368. break;
  369. case UserInformationRelateOptType.Loot:
  370. this.themeMng.showChangeRelationSuccess('userInformation/userinformation_loot_success');
  371. break;
  372. case UserInformationRelateOptType.Sign:
  373. this.themeMng.showChangeRelationSuccess('userInformation/userinformation_sign_success');
  374. break;
  375. default:
  376. break;
  377. }
  378. this.themeMng.relationButtonNode.enabled = true;
  379. this.loadInformation(responseData);
  380. Global.GameEvent.fire(GameNotificationKey.RefreshFriendList);
  381. }, (code, msg) => {
  382. var errorString = msg;
  383. var errorImageUrl = '';
  384. switch (type) {
  385. case UserInformationRelateOptType.Redeem:
  386. if (code == 805) {
  387. errorString = "<color=#f73939>金币不足</c>,赚到更多的金币\n再来赎身吧~";
  388. }
  389. errorImageUrl = 'userInformation/userinformation_redeem_fail';
  390. break;
  391. case UserInformationRelateOptType.Loot:
  392. if (code == 805) {
  393. errorString = "<color=#f73939>金币不足</c>,赚到更多的金币\n再来抢夺吧~";
  394. }
  395. errorImageUrl = 'userInformation/userinformation_loot_fail';
  396. break;
  397. case UserInformationRelateOptType.Sign:
  398. if (code == 805) {
  399. errorString = "<color=#f73939>金币不足</c>,赚到更多的金币\n再来抢约吧~";
  400. }
  401. errorImageUrl = 'userInformation/userinformation_sign_fail';
  402. break;
  403. default:
  404. break;
  405. }
  406. this.errorMng.showRelationErrorAlert(errorImageUrl, errorString, () => {
  407. });
  408. this.themeMng.relationButtonNode.enabled = true;
  409. });
  410. },
  411. //修改艺人名字
  412. showEditName() {
  413. this.editNameNode.active = true;
  414. if (this.userInfo.artistName) {
  415. this.editboxName.string = this.userInfo.artistName;
  416. }
  417. this.editboxName.setFocus(true);
  418. },
  419. confirmEditName() {
  420. UserInformationApi.editArtistName(this.uid, this.editboxName.string, (responseData) => {
  421. console.log("修改艺名成功 " + JSON.stringify(responseData));
  422. this.reloadArtistName();
  423. this.closeEditName();
  424. }, (error) => {
  425. console.log('修改艺名失败' + error);
  426. // this.alertMng.showAlert('修改艺名失败','',this.infoRole);
  427. });
  428. this.editNameNode.active = false;
  429. },
  430. reloadArtistName() {
  431. this.userInfo.artistName = this.editboxName.string;
  432. var genderIcon = 'artist_female';
  433. if (this.userInfo.gender == 1) {
  434. genderIcon = 'artist_male';
  435. }
  436. var artistName = " 无艺名 ";
  437. if (this.userInfo.artistName) {
  438. artistName = " " + this.userInfo.artistName.slice(0,5) + " ";
  439. }
  440. var artistString = "<img src='"+ genderIcon +"'/><outline color=white width=2> " + artistName + "</outline>";
  441. if (this.role == 2) {
  442. let editName = "<img src='artist_name_edit' click='clickEditName'/>";
  443. artistString += editName;
  444. }
  445. this.artistNameText.string = artistString;
  446. },
  447. closeEditName() {
  448. this.editboxName.setFocus(false);
  449. if (window.wx != undefined) {
  450. wx.hideKeyboard();
  451. }
  452. this.editNameNode.active = false;
  453. },
  454. //跳转到指定用户家园
  455. showUserHome() {
  456. this.node.active = false;
  457. this.visitEvent();
  458. },
  459. //培养按钮点击
  460. trainAction() {
  461. this.trainEvent();
  462. },
  463. //亲密度数据设置
  464. configIntimacy(interactionInfo) {
  465. this.themeMng.configIntimacyData(interactionInfo);
  466. },
  467. showInteraction(event,customEventData) {
  468. //判断互动是否正向
  469. var isGood = false;
  470. if (customEventData == 'true') {
  471. isGood = true;
  472. }
  473. var interactionType = UserInteractionType.Common;
  474. switch (this.infoRole) {
  475. case UserInformationType.Boss:
  476. interactionType = isGood ? UserInteractionType.PlayUp : UserInteractionType.Revolt;
  477. break;
  478. case UserInformationType.MyArtist:
  479. interactionType = isGood ? UserInteractionType.Pacify : UserInteractionType.Order;
  480. break;
  481. default:
  482. break;
  483. }
  484. this.interaction.showInteraction(interactionType);
  485. },
  486. //突破按钮点击,职业进阶
  487. levelUpgradeAction() {
  488. if (this.userInfo) {
  489. Global.GameEvent.fire(GameNotificationKey.ShowJobPage, JobPageType.LevelUp, this.userInfo, this.node.zIndex);
  490. }
  491. },
  492. //选择或转换职业
  493. changeJob() {
  494. if (this.infoRole == UserInformationType.MyArtist && this.userInfo) {
  495. //0为还没有选择职业,其他为已选择职业转职
  496. if (this.userInfo.jobId == UserJobType.None) {
  497. Global.GameEvent.fire(GameNotificationKey.ShowJobPage, JobPageType.ChooseJob, this.userInfo, this.node.zIndex);
  498. } else {
  499. Global.GameEvent.fire(GameNotificationKey.ShowJobPage, JobPageType.ChangeJob, this.userInfo, this.node.zIndex);
  500. // this.levelUpgradeAction();
  501. }
  502. }
  503. },
  504. //打开背包
  505. openPack() {
  506. this.pack.init();
  507. this.pack.showPack();
  508. }
  509. });