123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- const JobPageType = require('../utils/GameEnum').JobPageType;
- const JobApi = require('../net/JobApi');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- cc.Class({
- extends: cc.Component,
- properties: {
- titleText: cc.RichText,
- confirmText: cc.RichText,
- pageView: cc.PageView,
- levelUpNode: cc.Node,
- top: cc.Node,
- consume: cc.Node,
- user: cc.Node,
- myActor: [],
- changeJobSuccessPrefab: cc.Prefab,
- levelUpSuccessPrefab: cc.Prefab,
- failPrefab: cc.Prefab,
- tipsNode: cc.Node,
- tipsLabel: cc.Label,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- let offset = cc.view.getVisibleSize().height < 1624 ? 100 : 0;
- this.top.y = cc.view.getVisibleSize().height / 2 - this.top.height / 2 + offset;
- this.node.height = cc.view.getVisibleSize().height;
- },
- start() {
- },
- showFromTalent(type, actors) {
- this.myActor = actors;
- this.show(type, this.myActor.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.node.y = -174;
- this.pageView.getComponent('PVCtrl').bind(this.actorInfo.jobId);
- this.titleText.string = '<outline color=#690802 width=3><b>职业转换</b></outline>';
- this.confirmText.string = '<outline color=#690802 width=1><b>转职</b></outline>';
- JobApi.changeJobList(this.actorInfo.uid,
- (response) => {
- // this.pageView.getComponent('PVCtrl').bindJobList(response.jobList);
- this.consume.getComponent('Consume').bindChangeJob(response.itemConsume, response.userPack);
- },
- (code, msg) => {
- this.showTips('网络错误');
- }
- );
- },
- chooseJob() {
- this.consume.active = false;
- this.user.active = true;
- this.pageView.node.active = true;
- this.levelUpNode.active = false;
- this.pageView.node.y = -380;
- this.pageView.getComponent('PVCtrl').bind();
- this.titleText.string = '<outline color=#690802 width=3><b>选择职业</b></outline>';
- this.confirmText.string = '<outline color=#690802 width=1><b>确定</b></outline>';
- 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 = '<outline color=#690802 width=3><b>进阶</b></outline>';
- this.confirmText.string = '<outline color=#690802 width=1><b>进阶</b></outline>';
- let self = this;
- JobApi.levelUpInfo(this.actorInfo.uid,
- (response) => {
- this.consume.getComponent('Consume').bindDataLevelUp(response.itemConsume, response.userPack);
- this.levelUpNode.getComponent('LevelUp').bind(self.actorInfo, response.upgradeVo);
- this.upgradeName = response.upgradeVo.jobLevelName;
- this.upgradeLevel = self.actorInfo.jobLevel + 1;
- },
- (code, msg) => {
- this.showTips('网络错误');
- }
- );
- },
- confirmClick() {
- switch (this.type) {
- case JobPageType.ChangeJob:
- var job = this.pageView.getComponent('PVCtrl').getCurrentJob();
- 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').getCurrentJob();
- 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() {
- this.node.destroy();
- this.node.zIndex = 0;
- },
- nextChoose() {
- if (this.myActor && this.myActor.length > 0) {
- this.actorInfo = this.myActor.pop();
- this.bindChooseJob();
- } else {
- this.close();
- GameEvent.fire(GameNotificationKey.RefreshUserInformation);
- }
- },
- bindChooseJob() {
- this.user.getComponent('Actor').bind(this.actorInfo);
- },
- onChangeJobSuccess(msg) {
- let self = this;
- var job = this.pageView.getComponent('PVCtrl').getCurrentJob();
- this.changeJobSuccess = cc.instantiate(this.changeJobSuccessPrefab);
- this.changeJobSuccess = this.changeJobSuccess.getComponent('ChangeJobSuccess');
- this.changeJobSuccess.show(this.node, this.actorInfo, job, msg, () => {
- self.close();
- });
- GameEvent.fire(GameNotificationKey.RefreshUserInformation);
- },
- onLevelUpSuccess() {
- 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);
- },
- 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.myActor = users;
- },
- pageviewChangeEvent() {
- console.log('page change: ', this.pageView.getCurrentPageIndex());
- },
- showTips(text) {
- this.tipsNode.active = true;
- this.tipsLabel.string = text;
- this.scheduleOnce(() => {
- this.tipsNode.active = false;
- }, 2);
- }
- // update (dt) {},
- });
|