123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- const JobPageType = require('../utils/GameEnum').JobPageType;
- const JobApi = require('../net/JobApi');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const jobLevelList = require('../data/jobLevel');
- const jobList = require('../data/job');
- const cardList = require('../data/item');
- const GameModule = require('../utils/GameModule');
- cc.Class({
- extends: cc.Component,
- properties: {
- titleText: cc.RichText,
- confirmButton: cc.Button,
- confirmText: cc.RichText,
- pageView: cc.PageView,
- levelUpNode: cc.Node,
- bgNode: cc.Node,
- top: cc.Node,
- consume: cc.Node,
- user: cc.Node,
- myActorList: [],
- changeJobSuccessPrefab: cc.Prefab,
- levelUpSuccessPrefab: cc.Prefab,
- failPrefab: cc.Prefab,
- tipsNode: cc.Node,
- tipsLabel: cc.Label,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- this.node.height = cc.view.getVisibleSize().height;
- if (cc.view.getVisibleSize().height >= 1624) {
- this.top.getComponent(cc.Widget).top = 50;
- this.bgNode.getComponent(cc.Widget).top = -50;
- // this.informationNode.getComponent(cc.Widget).top = 185;
- // this.infoTop = 185;
- }
- this.consume.getComponent('Consume').setConfirmButton(this.confirmButton);
- },
- start() {
- },
- showFromTalent(type, actors) {
- this.myActorList = actors;
- this.show(type, this.myActorList.pop(), 0);
- },
- show(type, actorInfo, zIndex) {
- this.type = type;
- this.actorInfo = actorInfo;
- this.node.parent = cc.find('Canvas');
- this.node.active = true;
- this.node.zIndex = zIndex + 1;
- switch (type) {
- case JobPageType.ChangeJob:
- this.changeJob();
- break;
- case JobPageType.ChooseJob:
- this.chooseJob(actorInfo);
- break;
- case JobPageType.LevelUp:
- this.levelUp();
- break;
- }
- },
- changeJob() {
- this.consume.active = true;
- this.user.active = false;
- this.pageView.node.active = true;
- this.levelUpNode.active = false;
- this.pageView.getComponent('PVCtrl').bind(this.actorInfo.jobId, this.actorInfo.gender);
- this.titleText.string = '<b>职业转换</b>';
- this.confirmText.string = '<outline color=#690802 width=1><b>转职</b></outline>';
- this.pageViewScript = this.pageView.getComponent('PVCtrl');
- JobApi.changeJobList(this.actorInfo.uid,
- (response) => {
- this.userPack = response.userPack;
- this.bindChangeJobComsume(this.pageViewScript.getSelectedJob());
- },
- (code, msg) => {
- this.showTips('网络错误');
- }
- );
- },
- bindChangeJobComsume(selectedJob) {
- let needCard = '';
- let itemKey = Object.keys(selectedJob.itemInfo)[0];
- cardList.forEach((cardInfo) => {
- if (cardInfo.id == itemKey) {
- needCard = cardInfo;
- needCard.number = selectedJob.itemInfo[itemKey];
- }
- });
- this.pageViewScript.bindSelectedJobText();
- this.consume.getComponent('Consume').bindChangeJob(selectedJob.gold, needCard, this.userPack);
- },
- chooseJob() {
- this.consume.active = false;
- this.user.active = true;
- this.pageView.node.active = true;
- this.levelUpNode.active = false;
- this.pageView.getComponent('PVCtrl').bind(0, this.actorInfo.gender);
- this.titleText.string = '<b>选择职业</b>';
- this.confirmText.string = '<outline color=#690802 width=1><b>确定</b></outline>';
- this.pageViewScript = this.pageView.getComponent('PVCtrl');
- this.pageViewScript.bindSelectedJobText();
- this.bindChooseJob(this.actorInfo);
- },
- levelUp() {
- this.consume.active = true;
- this.user.active = false;
- this.pageView.node.active = false;
- this.levelUpNode.active = true;
- this.titleText.string = '<b>进阶</b>';
- this.confirmText.string = '<outline color=#690802 width=1><b>进阶</b></outline>';
- this.currentJobLevel = null;
- this.nextJobLevel = null;
- for (var i = 0; i < jobLevelList.length; i++) {
- let jobLevelInfo = jobLevelList[i];
- if (this.actorInfo.jobId === jobLevelInfo.jobId && this.actorInfo.jobLevel === jobLevelInfo.level) {
- this.currentJobLevel = jobLevelInfo;
- if (i >= jobLevelList.length - 1) {
- return;
- }
- this.nextJobLevel = jobLevelList[i + 1];
- this.spend = this.nextJobLevel.salary;
- }
- }
- let needCard = '';
- let itemKey = Object.keys(this.nextJobLevel.itemInfo)[0];
- cardList.forEach((cardInfo) => {
- if (cardInfo.id == itemKey) {
- needCard = cardInfo;
- needCard.number = this.nextJobLevel.itemInfo[itemKey];
- }
- });
- this.upgradeName = this.nextJobLevel.name;
- this.upgradeLevel = this.nextJobLevel.level;
- let self = this;
- JobApi.levelUpInfo(this.actorInfo.uid,
- (response) => {
- this.consume.getComponent('Consume').bindDataLevelUp(self.nextJobLevel.salary, needCard, response.userPack);
- this.levelUpNode.getComponent('LevelUp').bind(self.actorInfo, self.nextJobLevel, response.wish);
- },
- (code, msg) => {
- this.showTips('网络错误');
- }
- );
- },
- confirmClick() {
- switch (this.type) {
- case JobPageType.ChangeJob:
- var job = this.pageView.getComponent('PVCtrl').getSelectedJob();
- this.spend = job.gold;
- JobApi.changeJob(this.actorInfo.uid, job.id,
- (response, msg) => {
- this.onChangeJobSuccess(msg);
- },
- (code, msg) => {
- this.onFail(msg);
- });
- break;
- case JobPageType.ChooseJob:
- var job = this.pageView.getComponent('PVCtrl').getSelectedJob();
- JobApi.chooseJob(this.actorInfo.uid, job.id,
- (response) => {
- this.onFail('选择成功', () => {
- this.nextChoose();
- });
- },
- (code, msg) => {
- this.onFail(msg);
- });
- break;
- case JobPageType.LevelUp:
- JobApi.levelUp(this.actorInfo.uid,
- (response) => {
- this.onLevelUpSuccess();
- },
- (code, msg) => {
- this.onFail(msg);
- });
- break;
- }
- },
- close() {
- GameEvent.fire(GameNotificationKey.RefreshFriendList);
- this.node.zIndex = 0;
- this.node.destroy();
- },
- nextChoose() {
- if (this.myActorList && this.myActorList.length > 0) {
- this.actorInfo = this.myActorList.pop();
- this.bindChooseJob();
- } else {
- this.close();
- GameEvent.fire(GameNotificationKey.RefreshUserInformation);
- }
- },
- bindChooseJob() {
- this.user.getComponent('Actor').bind(this.actorInfo);
- },
- onChangeJobSuccess(msg) {
- GameModule.userInfo.grossIncome -= this.spend;
- let self = this;
- let targetJob = this.pageViewScript.getSelectedJob();
- let lastJob = null;
- jobList.forEach(jobInfo => {
- if (jobInfo.id === this.actorInfo.jobId) {
- lastJob = jobInfo;
- }
- });
- this.changeJobSuccess = cc.instantiate(this.changeJobSuccessPrefab);
- this.changeJobSuccess = this.changeJobSuccess.getComponent('ChangeJobSuccess');
- this.changeJobSuccess.show(this.node, lastJob, targetJob, () => {
- self.close();
- });
- GameEvent.fire(GameNotificationKey.RefreshUserInformation);
- GameEvent.fire(GameNotificationKey.PlaySuccessAnimation);
- },
- onLevelUpSuccess() {
- GameModule.userInfo.grossIncome -= this.spend;
- let self = this;
- this.levelUpSuccess = cc.instantiate(this.levelUpSuccessPrefab);
- this.levelUpSuccess = this.levelUpSuccess.getComponent('JobLevelUpSuccess');
- this.levelUpSuccess.show(this.node, '进阶成功', '恭喜你的艺人进阶成为:', this.upgradeLevel, this.upgradeName, () => {
- self.close();
- });
- GameEvent.fire(GameNotificationKey.RefreshUserInformation);
- GameEvent.fire(GameNotificationKey.PlaySuccessAnimation);
- },
- onFail(msg, callback) {
- this.fail = cc.instantiate(this.failPrefab);
- this.fail = this.fail.getComponent('JobPageFail');
- this.fail.show(this.node, msg, callback);
- },
- setNeedChooseJobUsers(users) {
- this.myActorList = users;
- },
- pageviewChangeEvent() {
- if (this.type === JobPageType.ChangeJob) {
- this.bindChangeJobComsume(this.pageViewScript.getSelectedJob());
- } else if (this.type === JobPageType.ChooseJob) {
- this.pageViewScript.bindSelectedJobText();
- }
- },
- showTips(text) {
- this.tipsNode.active = true;
- this.tipsLabel.string = text;
- this.scheduleOnce(() => {
- this.tipsNode.active = false;
- }, 2);
- }
- // update (dt) {},
- });
|