const SceneCtrlBase = require('SceneCtrlBase'); const JMLoadProgressBar = require('JMLoadProgressBar'); const JMNetImage = require('JMNetImage'); const LoginPanel = require('../view/login/LoginPanel'); const RegisterPanel = require('../view/login/RegisterPanel'); const TagType = { LOGIN: 0, REGISTER: 1 }; cc.Class({ extends: SceneCtrlBase, editor: { menu: 'Ctrl/LoginCtrl' }, properties: { loginPanel: { default: undefined, type: LoginPanel, }, registerPanel: { default: undefined, type: RegisterPanel, }, loadProgressBar: JMLoadProgressBar, }, onLoad () { this._super(); this._tagType = TagType.LOGIN; // 进行授权、登录、注册等操作 this.initAuth(); this.initUI(); cc.game.on('e_socket_on_logined', this._handleSocketOnLogined, this); cc.game.on('e_socket_on_closed', this._handleSocketOnClosed, this); }, onDestroy () { cc.game.targetOff(this); this._super(); }, initAuth () { }, initUI () { this.showpanel(TagType.LOGIN); this.loginPanel.reloadData(()=> { this.showpanel(TagType.REGISTER); }); this.registerPanel.reloadData(()=> { this.showpanel(TagType.LOGIN); }); // 隐藏进度 this.showDownloadProgress(false); }, /** * 是否显示下载进度。不显示下载进度时,展示授权按钮 * * @param {Boolean} isShow */ showDownloadProgress (isShow) { // 更新布局 this.loadProgressBar.node.active = isShow; if (isShow) { this.loadProgressBar.progressBar.progress = 0; this.loadProgressBar.setProgress(15, 1); } }, showpanel (tagType) { this._tagType = tagType; this.loginPanel.node.active = tagType == TagType.LOGIN; this.registerPanel.node.active = tagType == TagType.REGISTER; }, /** * 登录成功 * */ _handleSocketOnLogined () { this.didLoginSuccessful(); }, /** * 登录成功 * */ _handleSocketOnClosed () { this.didLoginFailed(); }, /** * 登录成功 * */ didLoginSuccessful () { G.LogUtils.log('didLoginSuccessful'); this.enterMainScene(); }, /** * 登录失败 * */ didLoginFailed () { G.LogUtils.log('didLoginFailed'); }, // 进入主界面 enterMainScene () { // 避免反复进入 if (this._alreadyEnterScene) return; // 提前预加载大厅场景 if (!this.didLoadMainScene) { this.preLoadMainScene(); } this._alreadyEnterScene = true; this.scheduleOnce(() => { G.AppUtils.runScene('scene_main'); }, 0.1); this.showDownloadProgress(true); this.loadProgressBar.setProgress(0.1, 1); }, // 预加载主界面 preLoadMainScene () { // 加载中、或者加载成功时,不再加载 if (this.isPreLoading || this.didLoadHomeScene) { return; } this.isPreLoading = true; // 开始预加载资源 let temp = undefined; cc.director.preloadScene('scene_main', (completedCount, totalCount, item)=>{ temp = G.AppUtils.getLoadProgressInfo(temp, completedCount, totalCount); this.downloadPercent = Math.floor(temp.precent * 100); }, (error, asset) => { this.isPreLoading = false; if (error) { this.addToast('网络异常!场景加载失败'); return; } this.didLoadMainScene = true; this.enterMainScene(); }); }, });