123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735 |
- var Api = require('../net/Api');
- var UserInformationApi = require('../net/UserInformationApi');
- const PackApi = require('../net/PackApi');
- var { UserInformationType, UserInformationRelateOptType, GameNotificationKey, UserInteractionType, JobPageType, UserJobType} = require('../utils/GameEnum');
- var DWTool = require('../utils/DWTool');
- const AlertManager = require('../utils/AlertManager');
- const GameModule = require('../utils/GameModule');
- const tipsInfo = require('UserInformationTips');
- cc.Class({
- extends: cc.Component,
- properties: {
- titleNode: cc.Node,
- figureNode: cc.Node,
- backgroundNode: cc.Node,
- infoBackgroundNode: cc.Node,
- informationNode: cc.Node,
- userInformationNode: cc.Node,
- userAvatar: cc.Sprite,
- userNicknameLabel: cc.RichText,
- artistNameText: cc.RichText,
- bossButton: cc.Button,
- bossInformationNode: cc.Node,
- bossAvatar: cc.Sprite,
- bossNicknameLabel: cc.Label,
- bossArtistNameText: cc.RichText,
- timelineNode: cc.Node,
-
- infoRole: {
- default:UserInformationType.Mine,
- visible: false,
- },
-
- changeRelationNode: cc.Node,
-
- editNameNode: cc.Node,
- editboxName: cc.EditBox,
-
- errorNode: cc.Node,
- _userIdArray: [cc.Integer],
- themeNode: cc.Node,
- jobNode: cc.Node,
-
- propertyNode: cc.Node,
-
- interactionPrefab: cc.Prefab,
-
- packPrefab: cc.Prefab,
-
- insertCardNode: cc.Node,
- },
-
- onLoad() {
- this.bossInformationNode.on('touchend', this.showBossInfoToView, this);
- this.editNameNode.on('touchend', this.closeEditName, this);
- this.jobNode.on('touchend', this.changeJob, this);
- let XHeight = 1624;
- this.winSize = cc.view.getVisibleSize();
- let nodeY = this.winSize.height / 2.0;
- this.node.y = nodeY;
- this.infoTop = 135;
- if (this.winSize.height >= XHeight) {
- this.titleNode.getComponent(cc.Widget).top = 80;
- this.infoBackgroundNode.getComponent(cc.Widget).top = -50;
- this.informationNode.getComponent(cc.Widget).top = 185;
- this.infoTop = 185;
- }
- let timelineHeight = (this.winSize.height - this.infoTop - this.informationNode.height);
- this.timelineNode.height = timelineHeight;
- this.timelineNode.y = timelineHeight - this.winSize.height;
-
- if (this.winSize.height <= 1100) {
- this.backgroundNode.getComponent(cc.Widget).bottom = -500;
- this.scrollY = 0;
- this.node.setContentSize(cc.size(this.winSize.width, 1334));
- let maxHeight = 1334 - nodeY;
- this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
- this.scrollY = event.getLocation().y;
- }, this);
- this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
- let moveY = event.getLocation().y;
- if (moveY <= this.scrollY) {
- if (this.node.y <= nodeY) {
- this.node.y = nodeY;
- } else {
- this.node.y -= Math.min((this.scrollY - moveY), 20);
- }
- } else {
- if (this.node.y >= maxHeight) {
- this.node.y = maxHeight;
- } else {
- this.node.y += Math.min((moveY - this.scrollY), 20);
- }
- }
- this.scrollY = moveY;
- }, this);
- let timelineHeight = (1334 - this.infoTop - this.informationNode.height);
- this.timelineNode.height = timelineHeight;
- this.timelineNode.y = timelineHeight - 1334;
- }
- console.log('node node y '+this.node.y);
- this.artistNameText.getComponent('UserInformationRichText').init(this);
- this.errorMng = this.errorNode.getComponent('UserInformationAlert');
- this.timelineMng = this.timelineNode.getComponent('UserInformationTimeline');
- this.relationAlertMng = this.changeRelationNode.getComponent('UserInformationAlert');
- this.themeMng = this.themeNode.getComponent('UserInformationTheme');
- this.propertyMng = this.propertyNode.getComponent('UserInformationProperty');
- this.insertCardMng = this.insertCardNode.getComponent('UserInsertCard');
- this.figureNode = this.figureNode.getComponent('UserInformationFigure');
-
- this.interaction = cc.instantiate(this.interactionPrefab);
- this.interaction = this.interaction.getComponent('UserInteraction');
-
- this.pack = cc.instantiate(this.packPrefab);
- this.pack = this.pack.getComponent('UserPack');
- this.setEventListener();
- this.trainEvent = _.debounce(() => {
-
- if (this.userInfo.jobId == UserJobType.None) {
-
- AlertManager.showArtistTrainNoJob(() => {
- this.changeJob();
- }, this.node.zIndex);
- } else {
- AlertManager.showTrainAlert(this.userInfo.uid, this.node.zIndex);
- }
-
- }, 1000, true);
- this.visitEvent = _.debounce( () => {
- GameEvent.fire(GameNotificationKey.VisitFriendHome, this.userInfo.uid);
- }, 1000, true);
- },
- init(game, uid) {
- this.node.parent = cc.find("Canvas");
- this.node.setContentSize(cc.view.getVisibleSize());
- this.node.active = true;
- this.node.zIndex += 1;
- this.loadUserInformation(uid);
- this.game = game;
- },
- start() {
- },
- onEnable() {
- },
- setEventListener() {
- GameEvent.on(GameNotificationKey.ShowInteraction, this, () => {
- if (this.responseData.interactionInfo) {
- var isCommon = (this.infoRole == UserInformationType.Boss || this.infoRole == UserInformationType.MyArtist) ? false : true;
- this.interaction.showIntimacyInfo(isCommon);
- }
- });
- GameEvent.on(GameNotificationKey.RefreshUserInformation, this, () => {
- this.getNetworkData(true);
- });
- GameEvent.on(GameNotificationKey.OpenPack, this, (justOpen) => {
- this.openPack(justOpen);
- });
- GameEvent.on(GameNotificationKey.RefreshInsertCardsInfo, this, (cardInfo,isInsert) => {
- this.refreshCardsInfo(cardInfo,isInsert);
- });
- GameModule.homeGuide.on('Fire_state28', this.trainAction, this);
- GameModule.homeGuide.on('Fire_state31', this.showInseertCard, this);
- GameModule.homeGuide.on('Fire_state25', this.guideShowInteraction, this);
- GameModule.homeGuide.on('Fire_state15', this.changeRelationAction, this);
- },
- onDisable() {
- this.bossInformationNode.enabled = true;
- this.bossInformationNode.active = false;
- this.bossInformationNode.x = this.winSize.width / 2.0;
- this.bossButton.node.x = this.winSize.width / 2.0 - 80;
- this.bossButton.node.active = false;
- this.themeMng.relationButtonNode.enabled = true;
- this.themeMng.successNode.active = false;
- this.editNameNode.active = false;
- this.changeRelationNode.active = false;
- this.errorNode.active = false;
- this.node.zIndex = 0;
- this._userIdArray = [];
- this.clearUserData();
- if (this.winSize.height <= 1100) {
- this.node.y = this.winSize.height / 2.0;
- }
- },
- loadUserInformation(uid) {
- if (uid) {
- this.uid = uid;
- }
- if (Global.user.uid == this.uid) {
- this.isSelf = true;
- } else {
- this.isSelf = false;
- }
- this.getNetworkData(false);
- },
-
- getNetworkData(isRefresh) {
- this.isRefresh = isRefresh;
- UserInformationApi.getUserInformation(this.uid, (responseData) => {
-
- this.loadInformation(responseData);
- if (isRefresh == false) {
- this._userIdArray.push(this.uid);
- }
- this.clearUserData();
- }, (error) => {
- console.log('userinformation error' + error);
- this.bossInformationNode.enabled = true;
- });
- },
- loadInformation(responseData) {
- if (responseData) {
- this.role = responseData.role;
- this.userInfo = responseData.userInfo;
- this.bossInfo = responseData.bossInfo;
- this.responseData = responseData;
- this.refreshThemeUI();
-
- this.timelineMng.loadUserTimeline(this.uid);
- this.getCardsInfo();
- this.getRelationCondition();
- }
- },
-
- getCardsInfo() {
- PackApi.getUserCardsInfo(this.uid, (responseData) => {
-
- this.cardsList = responseData.list;
- this.themeMng.configCardsData(responseData.list, this.isRefresh);
- }, (error) => {
- console.log('userinformation error' + error);
- this.cardsList = null;
- this.themeMng.equipCardNode.active = false;
- });
- },
-
- getRelationCondition() {
- var opt = UserInformationRelateOptType.None;
- switch (this.infoRole) {
- case UserInformationType.Boss:
- opt = UserInformationRelateOptType.Redeem;
- break;
- case UserInformationType.OtherArtist:
- opt = UserInformationRelateOptType.Loot;
- break;
- case UserInformationType.ArtistFree:
- opt = UserInformationRelateOptType.Sign;
- break;
- case UserInformationType.MyArtist:
- opt = UserInformationRelateOptType.Fire;
- break;
- default:
- break;
- }
- UserInformationApi.getRelationCondition(this.uid, opt, (responseData) => {
-
- this.conditionData = responseData;
- this.themeMng.refreshRelationNode();
- }, (error) => {
- console.log('condition error' + error);
- this.conditionData = null;
- this.themeMng.relationButtonNode.active = false;
- });
- },
-
- closeInformationAction() {
- if (this._userIdArray.length > 1) {
- let uid = this._userIdArray[this._userIdArray.length - 2];
- this.loadUserInformation(uid);
- this.removeItems(this._userIdArray, 2);
- } else {
- this.node.active = false;
- if (this.game != undefined) {
- this.game.gameFSM.historyBack();
- }
- }
- },
- removeItems(arr, item) {
- for (var i = 0; i < item; i++) {
- arr.pop();
- }
- },
-
- clearUserData() {
- this.cardsList = [];
- this.conditionData = null;
- this.themeMng.equipCardNode.active = false;
- this.themeMng.relationButtonNode.active = false;
- },
-
-
- refreshThemeUI() {
- if (this.userInfo) {
- if (this.userInfo.head) {
- Api.createImageFromUrl(this.userInfo.head, (spriteFrame) => {
- this.userAvatar.spriteFrame = spriteFrame;
- });
- }
- if (this.isSelf) {
- this.infoRole = UserInformationType.Mine;
- } else {
- switch (this.role) {
- case UserInformationType.Boss:
- this.infoRole = UserInformationType.Boss;
- break;
- case UserInformationType.MyArtist:
- this.infoRole = UserInformationType.MyArtist;
- if (this.userInfo.artistName) {
- this.editNameNode.string = this.userInfo.artistName;
- }
- break;
- case UserInformationType.ArtistFree:
- this.infoRole = UserInformationType.ArtistFree;
- break;
- case UserInformationType.OtherArtist:
- this.infoRole = UserInformationType.OtherArtist;
- break;
- default:
- break
- }
- }
- var genderIcon = 'artist_female';
- if (this.userInfo.gender == 1) {
- genderIcon = 'artist_male';
- }
- if (this.userInfo.nick) {
- this.userNicknameLabel.string = "<img src='"+ genderIcon +"'/> " + this.userInfo.nick;
- }
- var artistName = " 无艺名 ";
- if (this.userInfo.artistName) {
- artistName = " " + this.userInfo.artistName.slice(0,5) + " ";
- }
- var artistString = artistName;
- if (this.infoRole == UserInformationType.MyArtist) {
- let editName = " <img src='artist_name_edit' click='clickEditName'/>";
- artistString += editName;
- }
- this.artistNameText.string = artistString;
- this.propertyMng.setUserData(this.userInfo, this.infoRole);
- }
- if (this.bossInfo) {
- this.bossButton.node.active = true;
- if (this.bossInfo.head) {
- Api.createImageFromUrl(this.bossInfo.head, (spriteFrame) => {
- this.bossAvatar.spriteFrame = spriteFrame;
- });
- }
- if (this.bossInfo.nick) {
- this.bossNicknameLabel.string = this.bossInfo.nick;
- }
- var genderIcon = 'user_female';
- if (this.bossInfo.gender == 1) {
- genderIcon = 'user_male';
- }
- var artistName = " 无艺名";
- if (this.bossInfo.artistName) {
- artistName = " " + this.bossInfo.artistName.slice(0,4);
- }
- var artistString = "<img src='"+ genderIcon +"'/><outline color=white width=2> " + artistName + "</outline>";
- this.bossArtistNameText.string = artistString;
- } else {
- this.bossButton.node.active = false;
- }
- this.bossInformationNode.enabled = true;
- this.bossInformationNode.active = false;
- this.bossInformationNode.x = this.winSize.width / 2.0;
- this.bossButton.node.x = this.winSize.width / 2.0 - 80;
- let hasBoss = this.bossInfo ? true : false;
- let hasJob = this.userInfo.jobId != UserJobType.None;
- this.themeMng.changeTheme(this.infoRole, hasBoss, hasJob);
- this.figureNode.changeFigure(this.userInfo);
- if (this.responseData.interactionInfo) {
- this.interaction.init(this.uid, this.responseData.interactionInfo, this);
- this.configIntimacy(this.responseData.interactionInfo);
- }
- },
- showBossInfo() {
- if (this.bossInformationNode.active === true) {
- let callBack = cc.callFunc(function () {
- this.bossInformationNode.active = false;
- }, this);
- let positionAction = cc.moveBy(0.15, 153, 0);
- this.bossInformationNode.runAction(cc.sequence(positionAction, callBack));
- let buttonAction = cc.moveBy(0.15, 152, 0);
- this.bossButton.node.runAction(buttonAction);
- } else {
- this.bossInformationNode.active = true;
- let positionAction = cc.moveBy(0.15, -153, 0);
- this.bossInformationNode.runAction(positionAction);
- let buttonAction = cc.moveBy(0.15, -152, 0);
- this.bossButton.node.runAction(buttonAction);
- }
- },
- showBossInfoToView() {
- this.bossInformationNode.enabled = false;
- this.loadUserInformation(this.bossInfo.uid);
- },
-
- changeRelationAction() {
- if (!this.conditionData) {
- return;
- }
- this.themeMng.relationButtonNode.enabled = false;
- var opt = UserInformationRelateOptType.None;
- switch (this.infoRole) {
- case UserInformationType.Boss:
- opt = UserInformationRelateOptType.Redeem;
- break;
- case UserInformationType.OtherArtist:
- opt = UserInformationRelateOptType.Loot;
- break;
- case UserInformationType.ArtistFree:
- opt = UserInformationRelateOptType.Sign;
- break;
- case UserInformationType.MyArtist:
- opt = UserInformationRelateOptType.Fire;
- break;
- default:
- break;
- }
- let string = tipsInfo.changeRelationTitle[opt].content;
- this.relationAlertMng.showRelationAlert(string, this.conditionData, () => {
- this.changeRelationNode.active = false;
- }, () => {
- this.confirmChangeRelation(opt);
- });
-
- if (this.infoRole == UserInformationType.OtherArtist || this.infoRole == UserInformationType.ArtistFree ) {
- this.scheduleOnce(function() {
- GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state15', 'state16');
- }, 0.1);
- }
- },
- confirmChangeRelation(opt) {
- this.changeRelate(opt);
- this.changeRelationNode.active = false;
- },
-
- changeRelate(opt) {
- UserInformationApi.postRelate(this.uid, opt, (responseData) => {
-
- var bossUid = 0;
- switch (opt) {
- case UserInformationRelateOptType.Loot:
- bossUid = this.bossInfo.uid;
- break;
- default:
- break;
- }
- this.themeMng.showChangeRelationSuccess(tipsInfo.relationSuccess[opt].image);
- if (bossUid > 0) {
- GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.uid, opt, bossUid);
- } else {
- GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.uid, opt);
- }
- GameModule.userInfo.grossIncome -= this.conditionData.coin;
- this.themeMng.relationButtonNode.enabled = true;
- this.isRefresh = true;
- this.loadInformation(responseData);
- GameEvent.fire(GameNotificationKey.RefreshFriendList);
- }, (code, msg) => {
- var errorString = msg;
- if (code == 805) {
- errorString = tipsInfo.relationFail805[opt].content;
- }
- let errorImage = tipsInfo.relationFail[opt].image;
- this.errorMng.showRelationErrorAlert(errorImage, errorString, () => {
- });
- this.themeMng.relationButtonNode.enabled = true;
- });
- },
-
- showEditName() {
- this.editNameNode.active = true;
- if (this.userInfo.artistName) {
- this.editboxName.string = this.userInfo.artistName;
- }
- this.editboxName.setFocus(true);
- },
- confirmEditName() {
- UserInformationApi.editArtistName(this.uid, this.editboxName.string, (responseData) => {
-
- this.reloadArtistName();
- this.closeEditName();
- }, (error) => {
- console.log('修改艺名失败' + error);
- });
- this.editNameNode.active = false;
- },
- reloadArtistName() {
- this.userInfo.artistName = this.editboxName.string;
- var genderIcon = 'artist_female';
- if (this.userInfo.gender == 1) {
- genderIcon = 'artist_male';
- }
- var artistName = " 无艺名 ";
- if (this.userInfo.artistName) {
- artistName = " " + this.userInfo.artistName.slice(0,5) + " ";
- }
- var artistString = "<img src='"+ genderIcon +"'/><outline color=white width=2> " + artistName + "</outline>";
- if (this.infoRole == UserInformationType.MyArtist) {
- let editName = " <img src='artist_name_edit' click='clickEditName'/>";
- artistString += editName;
- }
- this.artistNameText.string = artistString;
- },
- closeEditName() {
- this.editboxName.setFocus(false);
- if (window.wx != undefined) {
- wx.hideKeyboard();
- }
- this.editNameNode.active = false;
- },
-
- showUserHome() {
- this.node.active = false;
- this.visitEvent();
- },
-
- trainAction() {
- this.trainEvent();
- },
-
- configIntimacy(interactionInfo) {
- this.themeMng.configIntimacyData(interactionInfo);
- },
- showInteraction(event,customEventData) {
-
- var isGood = false;
- if (customEventData == 'true') {
- isGood = true;
- }
- var interactionType = UserInteractionType.Common;
- switch (this.infoRole) {
- case UserInformationType.Boss:
- interactionType = isGood ? UserInteractionType.PlayUp : UserInteractionType.Revolt;
- break;
- case UserInformationType.MyArtist:
- interactionType = isGood ? UserInteractionType.Pacify : UserInteractionType.Order;
- break;
- default:
- break;
- }
- this.interaction.showInteraction(interactionType);
- },
- guideShowInteraction() {
- this.scheduleOnce(function() {
- this.interaction.showInteraction(UserInteractionType.Pacify);
- }, 0.1);
- },
-
- levelUpgradeAction() {
- if (this.userInfo) {
- GameEvent.fire(GameNotificationKey.ShowJobPage, JobPageType.LevelUp, this.userInfo, this.node.zIndex);
- }
- },
-
- changeJob() {
- if (this.infoRole == UserInformationType.MyArtist && this.userInfo) {
-
- if (this.userInfo.jobId == UserJobType.None) {
- GameEvent.fire(GameNotificationKey.ShowJobPage, JobPageType.ChooseJob, this.userInfo, this.node.zIndex);
- } else {
- GameEvent.fire(GameNotificationKey.ShowJobPage, JobPageType.ChangeJob, this.userInfo, this.node.zIndex);
- }
- }
- },
-
- openPackAction() {
- GameEvent.fire(GameNotificationKey.OpenPack,true);
- },
- openPack(justOpen) {
- this.pack.init(justOpen,this.uid);
- this.pack.showPack();
- },
-
- showInseertCard() {
- this.insertCardNode.active = true;
- this.insertCardMng.init(this.cardsList, this.uid);
- },
- refreshCardsInfo(cardInfo,isInsert) {
- if (isInsert) {
- if (this.cardsList != undefined) {
- this.cardsList.push(cardInfo);
- } else {
- this.cardsList = [];
- this.cardsList.push(cardInfo);
- }
- } else {
- for(var index in this.cardsList) {
- let item = this.cardsList[index];
- if (item.id == cardInfo.id) {
- this.cardsList.splice(index,1);
- break;
- }
- }
- }
- this.themeMng.configCardsData(this.cardsList);
- }
- });
|