|
@@ -8,8 +8,8 @@ import GameStart, { PropsStart } from "../res/luojigouStart/src/LuojigouStart";
|
|
import GameFinish, { PropsFinish } from "../res/luojigouFinish/src/LuojigouFinish";
|
|
import GameFinish, { PropsFinish } from "../res/luojigouFinish/src/LuojigouFinish";
|
|
import AudioCB from "../src/audioUitls/AudioCB";
|
|
import AudioCB from "../src/audioUitls/AudioCB";
|
|
import Tools from "../src/common/Tools";
|
|
import Tools from "../src/common/Tools";
|
|
-import PopupManager, { PopupCacheMode } from "../src/popUp/PopupManager";
|
|
|
|
import AudioManager from "../src/audioUitls/AudioManager";
|
|
import AudioManager from "../src/audioUitls/AudioManager";
|
|
|
|
+import PopupManager, { PopupCacheMode } from "../src/popUp/PopupManager";
|
|
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
const { ccclass, property } = cc._decorator;
|
|
@ccclass
|
|
@ccclass
|
|
@@ -44,12 +44,19 @@ export default class Scene extends cc.Component {
|
|
prefabs: cc.Prefab | any,
|
|
prefabs: cc.Prefab | any,
|
|
} = { bundles: {}, prefabs: {} };
|
|
} = { bundles: {}, prefabs: {} };
|
|
|
|
|
|
|
|
+ protected onLoad(): void {
|
|
|
|
+ // 设置游戏窗口变化的回调(仅 Web 平台有效)
|
|
|
|
+ cc.view.setResizeCallback(() => this.onResize());
|
|
|
|
+ }
|
|
|
|
+
|
|
/** 注册监听事件 */
|
|
/** 注册监听事件 */
|
|
protected onEnable(): void {
|
|
protected onEnable(): void {
|
|
NotifierCenter.listen(CConst.EVENT_LJG_START, this.showLgjStart, this, false);
|
|
NotifierCenter.listen(CConst.EVENT_LJG_START, this.showLgjStart, this, false);
|
|
NotifierCenter.listen(CConst.EVENT_LJG_FINISH, this.showLgjFinish, this, false);
|
|
NotifierCenter.listen(CConst.EVENT_LJG_FINISH, this.showLgjFinish, this, false);
|
|
NotifierCenter.listen(CConst.EVENT_ENTER_UNIT, this.msgResultEnterUnit, this, false);
|
|
NotifierCenter.listen(CConst.EVENT_ENTER_UNIT, this.msgResultEnterUnit, this, false);
|
|
NotifierCenter.listen(CConst.EVENT_ENTER_GAME, this.msgResultEnterGame, this, false);
|
|
NotifierCenter.listen(CConst.EVENT_ENTER_GAME, this.msgResultEnterGame, this, false);
|
|
|
|
+
|
|
|
|
+ this.adapt();
|
|
}
|
|
}
|
|
|
|
|
|
/** 取消监听事件 */
|
|
/** 取消监听事件 */
|
|
@@ -60,47 +67,16 @@ export default class Scene extends cc.Component {
|
|
/** 游戏开始 */
|
|
/** 游戏开始 */
|
|
async start() {
|
|
async start() {
|
|
common.hideLoading();
|
|
common.hideLoading();
|
|
- let result = common.isDebug ? true : await this.checkUser();
|
|
|
|
|
|
+ let result = common.isDebug ? true : await common.httpCheckToken();
|
|
if (result) {
|
|
if (result) {
|
|
this.enterGame();
|
|
this.enterGame();
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- // const options = {
|
|
|
|
- // title: '',
|
|
|
|
- // content: '请下载应用!'
|
|
|
|
- // };
|
|
|
|
- // const params = {
|
|
|
|
- // mode: PopupCacheMode.Once,
|
|
|
|
- // };
|
|
|
|
- // let prefab = await PopupManager.load('prefab/popUp');
|
|
|
|
- // PopupManager.show(cc.instantiate(prefab), options, params);
|
|
|
|
window.location.href = common.urlClass;
|
|
window.location.href = common.urlClass;
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- /** 用户检测 */
|
|
|
|
- async checkUser(): Promise<boolean> {
|
|
|
|
- // 验证token
|
|
|
|
- let token = Tools.getLocalStorage('token', null);
|
|
|
|
- return new Promise((resolve) => {
|
|
|
|
- let xhr = new XMLHttpRequest();
|
|
|
|
- xhr.open("GET", common.urlToken, true);
|
|
|
|
- xhr.setRequestHeader('token', token);
|
|
|
|
- xhr.onreadystatechange = function () {
|
|
|
|
- if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
|
|
|
|
- common.log(xhr.responseText);
|
|
|
|
- let json = JSON.parse(xhr.responseText);
|
|
|
|
- resolve(json.status == 200);
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- xhr.onerror = function () {
|
|
|
|
- resolve(false);
|
|
|
|
- }
|
|
|
|
- xhr.send();
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/** 进入游戏 */
|
|
/** 进入游戏 */
|
|
async enterGame() {
|
|
async enterGame() {
|
|
// 获取网络地址信息
|
|
// 获取网络地址信息
|
|
@@ -123,16 +99,15 @@ export default class Scene extends cc.Component {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- // const options = {
|
|
|
|
- // title: '',
|
|
|
|
- // content: '当前动画游戏不存在!',
|
|
|
|
- // };
|
|
|
|
- // const params = {
|
|
|
|
- // mode: PopupCacheMode.Once,
|
|
|
|
- // };
|
|
|
|
- // let prefab = await PopupManager.load('prefab/popUp');
|
|
|
|
- // PopupManager.show(cc.instantiate(prefab), options, params);
|
|
|
|
- window.location.href = common.urlClass;
|
|
|
|
|
|
+ const options = {
|
|
|
|
+ title: '',
|
|
|
|
+ content: '当前动画游戏不存在!',
|
|
|
|
+ };
|
|
|
|
+ const params = {
|
|
|
|
+ mode: PopupCacheMode.Once,
|
|
|
|
+ };
|
|
|
|
+ let prefab = await PopupManager.load('prefab/popUp');
|
|
|
|
+ PopupManager.show(cc.instantiate(prefab), options, params);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -235,7 +210,7 @@ export default class Scene extends cc.Component {
|
|
if (common.isDebug) {
|
|
if (common.isDebug) {
|
|
this.btnNext.active = true;
|
|
this.btnNext.active = true;
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
this.btnNext.active = false;// 显示下一步按钮
|
|
this.btnNext.active = false;// 显示下一步按钮
|
|
if (!show) return;
|
|
if (!show) return;
|
|
let gameOne = common.getGameFormLocal();
|
|
let gameOne = common.getGameFormLocal();
|
|
@@ -283,30 +258,14 @@ export default class Scene extends cc.Component {
|
|
let curPage = common.getPageNum();
|
|
let curPage = common.getPageNum();
|
|
let attribute: AttributeUnit = common.attributeMap[curUint];
|
|
let attribute: AttributeUnit = common.attributeMap[curUint];
|
|
let length = attribute.config.length;
|
|
let length = attribute.config.length;
|
|
- common.log('curPage: ', curPage + 1, '; length: ', length);
|
|
|
|
if (curPage < length) {
|
|
if (curPage < length) {
|
|
this.addPrefab(curUint, curPage + 1);
|
|
this.addPrefab(curUint, curPage + 1);
|
|
}
|
|
}
|
|
- else{
|
|
|
|
- let funcSB = (req, right)=>{
|
|
|
|
- common.log('上报 ', right, ' : ', JSON.stringify(req));
|
|
|
|
|
|
+ else {
|
|
|
|
+ this.scheduleOnce(()=>{
|
|
// 返回课程详情页
|
|
// 返回课程详情页
|
|
window.location.href = common.urlClass;
|
|
window.location.href = common.urlClass;
|
|
- };
|
|
|
|
- let token = Tools.getLocalStorage('token', null);
|
|
|
|
- let xhr = new XMLHttpRequest();
|
|
|
|
- xhr.open("GET", common.urlOver + common.getItemId(), true);
|
|
|
|
- xhr.setRequestHeader('token', token);
|
|
|
|
- xhr.onreadystatechange = function () {
|
|
|
|
- if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
|
|
|
|
- funcSB(xhr, true);
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- xhr.onerror = function () {
|
|
|
|
- funcSB(xhr, false);
|
|
|
|
- }
|
|
|
|
- xhr.send();
|
|
|
|
-
|
|
|
|
|
|
+ }, 0.5);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -324,6 +283,55 @@ export default class Scene extends cc.Component {
|
|
return script;
|
|
return script;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 窗口变化回调
|
|
|
|
+ */
|
|
|
|
+ protected onResize() {
|
|
|
|
+ // 适配
|
|
|
|
+ this.adapt();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 适配
|
|
|
|
+ */
|
|
|
|
+ protected adapt() {
|
|
|
|
+ // 实际屏幕比例
|
|
|
|
+ const winSize = cc.winSize,
|
|
|
|
+ screenRatio = winSize.width / winSize.height;
|
|
|
|
+ // 设计比例
|
|
|
|
+ const designResolution = cc.Canvas.instance.designResolution,
|
|
|
|
+ designRatio = designResolution.width / designResolution.height;
|
|
|
|
+
|
|
|
|
+ // 对比判断
|
|
|
|
+ common.log('win ratio: ', screenRatio, '; w: ', winSize.width, '; h: ', winSize.height);
|
|
|
|
+ common.log('des ratio: ', designRatio, '; w: ', designResolution.width, '; h: ', designResolution.height);
|
|
|
|
+ if (screenRatio < designRatio) {
|
|
|
|
+ common.log("适配宽 屏幕宽高比 小于 设计比例");
|
|
|
|
+ this.setFitWidth();
|
|
|
|
+ } else {
|
|
|
|
+ common.log("适配高 屏幕宽高比 大于等于 设计比例");
|
|
|
|
+ this.setFitHeight();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 适配高度模式
|
|
|
|
+ */
|
|
|
|
+ protected setFitHeight() {
|
|
|
|
+ const canvas = cc.Canvas.instance;
|
|
|
|
+ canvas.fitHeight = true;
|
|
|
|
+ canvas.fitWidth = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 适配宽度模式
|
|
|
|
+ */
|
|
|
|
+ protected setFitWidth() {
|
|
|
|
+ const canvas = cc.Canvas.instance;
|
|
|
|
+ canvas.fitHeight = false;
|
|
|
|
+ canvas.fitWidth = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
/** 下载游戏zip */
|
|
/** 下载游戏zip */
|
|
downLoadZip(zipName) {
|
|
downLoadZip(zipName) {
|
|
window['luojigou']['downloadAssets'](zipName);
|
|
window['luojigou']['downloadAssets'](zipName);
|