Commit af303a9c authored by 范雪寒's avatar 范雪寒

feat:

parent e7abd40e
...@@ -3,62 +3,62 @@ cc.Class({ ...@@ -3,62 +3,62 @@ cc.Class({
properties: {}, properties: {},
getData(callBack) { getData(callBack) {
const uri = 'courseware/v1/getdata'; const uri = "courseware/v1/getdata";
let syllabus_id = this.bundleInfoList[this.currentBundleIndex].syllabus_id;
let syllabus_id;
if (this.bundleType == 'StoryBox') {
syllabus_id = this.syllabus_id;
} else if (this.bundleType == 'WW') {
syllabus_id = this.bundleInfoList[this.currentBundleIndex].syllabus_id;
}
const data = { const data = {
courseid: syllabus_id courseid: syllabus_id,
}; };
console.log("getData");
this.callNetworkApiGet(uri, data, (data) => { this.callNetworkApiGet(uri, data, (data) => {
console.log("data = " + JSON.stringify(data));
cc.debug.setDisplayStats(false); cc.debug.setDisplayStats(false);
callBack(JSON.parse(data.data)); callBack(JSON.parse(data.data));
}); });
}, },
onHomeworkFinish(callBack) { onHomeworkFinish(callBack) {
if (this.role == 'teacher') { console.log("onHomeworkFinish");
return;
if (this.role == "teacher") {
return; return;
} }
const uri = 'app_source/v1/student/homework/finished'; const uri = "app_source/v1/student/homework/finished";
const data = { const data = {
syllabus_id: this.syllabus_id, syllabus_id: this.syllabus_id,
homework_id: this.homework_id, homework_id: this.homework_id,
token: this.token, token: this.token,
score: 100 score: 100,
}; };
console.log('data = ' + JSON.stringify(data)); console.log("data = " + JSON.stringify(data));
this.callNetworkApiPost(uri, data, callBack); this.callNetworkApiPost(uri, data, callBack);
}, },
callNetworkApiGet(uri, data, callBack) { callNetworkApiGet(uri, data, callBack) {
let queryStr = ''; let queryStr = "";
for (const key in data) { for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) { if (Object.hasOwnProperty.call(data, key)) {
const value = data[key]; const value = data[key];
if (queryStr == '') { if (queryStr == "") {
queryStr += '?'; queryStr += "?";
} }
if (queryStr != '?') { if (queryStr != "?") {
queryStr += '&'; queryStr += "&";
} }
queryStr += `${key}=${value}`; queryStr += `${key}=${value}`;
} }
} }
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => { xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) { if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status < 400) {
const responseData = JSON.parse(xhr.responseText); const responseData = JSON.parse(xhr.responseText);
callBack(responseData); callBack(responseData);
} }
}; };
const url = `${this.baseUrl}${uri}${queryStr}`; const url = `${this.baseUrl}${uri}${queryStr}`;
console.log('url = ' + url); console.log("url = " + url);
xhr.open('GET', url, true); xhr.open("GET", url, true);
xhr.send(); xhr.send();
}, },
...@@ -66,16 +66,17 @@ cc.Class({ ...@@ -66,16 +66,17 @@ cc.Class({
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
const url = `${this.baseUrl}${uri}`; const url = `${this.baseUrl}${uri}`;
xhr.open("POST", url, true); xhr.open("POST", url, true);
xhr.setRequestHeader('content-type', 'application/json'); xhr.setRequestHeader("content-type", "application/json");
xhr.onreadystatechange = () => { xhr.onreadystatechange = () => {
if (xhr.readyState == 4) { if (xhr.readyState == 4) {
callBack(JSON.parse(xhr.responseText)); callBack(JSON.parse(xhr.responseText));
} }
} };
xhr.send(JSON.stringify(data)); xhr.send(JSON.stringify(data));
}, },
start() { start() {
this.baseUrl = "http://staging-teach.ireadabc.com/api/";
this.node.zIndex = 9999; this.node.zIndex = 9999;
this.showWaitingLetters(); this.showWaitingLetters();
...@@ -85,16 +86,6 @@ cc.Class({ ...@@ -85,16 +86,6 @@ cc.Class({
this.initListener(); this.initListener();
this.getBundleInfoList(); this.getBundleInfoList();
// this.baseUrl = 'http://staging-teach.ireadabc.com/api/';
// this.initStoryBoxView({
// // coursewareId: 18307
// // coursewareId: 18582
// coursewareId: 25687
// });
// this.bundleType = 'StoryBox';
this.log('汪汪汪');
}, },
asyncDelayLog(str) { asyncDelayLog(str) {
...@@ -107,360 +98,78 @@ cc.Class({ ...@@ -107,360 +98,78 @@ cc.Class({
}, },
getBundleInfoList() { getBundleInfoList() {
const jsonStr = this.callNativeFunction({ name: 'loadSceneList', value: '' }); const coursewareId = 21506;
this.callNetworkApiGet(
if (!jsonStr) { `courseware/v1/${coursewareId}/list`,
console.error('没有jsonStr!!') null,
return; (data) => {
} console.log("data = " + JSON.stringify(data));
this.defaultBundleIdx = 0;
const { bundleInfoList, defaultBundleIdx, bundleType, bundleInfo } = JSON.parse(jsonStr); this.bundleInfoList = data.rows.map((row) => {
const bundleInfo = row.conf;
if (bundleType == 'PetRoom') { bundleInfo.syllabus_id = row.id;
this.bundleType = 'PetRoom'; return bundleInfo;
this.baseUrl = bundleInfo.baseUrl;
this.token = bundleInfo.token;
this.homework_id = bundleInfo.homework_id;
this.syllabus_id = bundleInfo.syllabus_id;
this.role = bundleInfo.role;
this.initPetRoomView(bundleInfo);
} else if (bundleType == "StoryBox") {
this.bundleType = 'StoryBox';
const descLabel = cc.find('middleLayer/storyBox/menu/menuBase/title/name');
descLabel.getComponent(cc.Label).string = bundleInfo.coursewareDescription;
const nameLabel = cc.find('middleLayer/storyBox/menu/menuBase/title/Lession');
nameLabel.getComponent(cc.Label).string = bundleInfo.coursewareName;
this.baseUrl = bundleInfo.baseUrl;
this.initStoryBoxView(bundleInfo);
} else {
this.bundleType = 'WW';
// WW模板
this.bundleInfoList = bundleInfoList;
this.jumpToBundleByIndex(defaultBundleIdx);
}
},
initPetRoomView(bundleInfo) {
this.hideWWView();
this.loadBundle(bundleInfo);
},
initStoryBoxView(bundleInfo) {
this.hideWWView();
// this.showLog(bundleInfo.coursewareId);
this.callNetworkApiGet('syllabus/v1/tree', { orgid: 483, pid: bundleInfo.coursewareId }, (data) => {
console.log(data);
const defaultBondle = data.rows.find(row => row.name == '默认');
if (!defaultBondle) {
cc.find('middleLayer/storyBox/bg').active = true;
console.error('没有默认课件!');
return;
}
cc.find('middleLayer/storyBox/bg').active = false;
this.syllabus_id = defaultBondle.children[0].id;
this.loadBundleByConf(defaultBondle.children[0].conf, () => {
const ExitBtn = cc.find('middleLayer/storyBox/ExitBtn');
ExitBtn.active = true;
}); });
this.jumpToBundleByIndex(this.defaultBundleIdx);
this.menuItemNodeList = [];
data.rows.filter((row) => {
return row.name != '默认';
}).forEach((data, idx, arr) => {
console.log(data.name, idx);
const node = cc.instantiate(cc.find('middleLayer/menuItem'));
node.name = 'menuItem_' + idx;
node.parent = cc.find('middleLayer/storyBox/menu/menuBase');
node.active = true;
node.x = 0;
node.y = 50 + (arr.length - 1 - idx) * 100;
this.menuItemNodeList.push(node);
const menuBase = cc.find('bubbleBase', node);
const label = cc.find('label', node);
label.getComponent(cc.Label).string = data.name;
label.active = true;
const labelSelected = cc.find('labelSelected', node);
labelSelected.getComponent(cc.Label).string = data.name;
labelSelected.active = false;
const btn = cc.find('btn', node);
const btnLight = cc.find('btnHightLight', node);
const btnSelected = cc.find('btnSelected', node);
btn.active = true;
btnLight.active = false;
btnSelected.active = false;
btn.addComponent(cc.Button);
btn.on('click', () => {
console.log(data);
cc.tween(btn)
.to(0.1, { scale: 1.1 })
.to(0.1, { scale: 1.0 })
.call(() => {
if (data.has_child == '0') {
this.hideAllSubmenu();
this.resetAllMenu();
this.hideMenu();
btn.active = false;
btnSelected.active = true;
label.active = false;
labelSelected.active = true;
if (!data.children[0]) {
cc.find('middleLayer/storyBox/bg').active = true;
console.error('沒有課件!');
return;
} }
cc.find('middleLayer/storyBox/bg').active = false; );
this.syllabus_id = data.children[0].id;
this.loadBundleByConf(data.children[0].conf);
} else {
this.hideAllSubmenu();
menuBase.active = true;
btn.active = false;
btnLight.active = true;
}
})
.start();
cc.tween(label)
.to(0.1, { scale: 1.1 })
.to(0.1, { scale: 1.0 })
.start();
});
btnLight.addComponent(cc.Button)
btnLight.on('click', () => {
cc.tween(btnLight)
.to(0.1, { scale: 1.1 })
.to(0.1, { scale: 1.0 })
.call(() => {
menuBase.active = false;
btn.active = true;
btnLight.active = false;
})
.start();
cc.tween(label)
.to(0.1, { scale: 1.1 })
.to(0.1, { scale: 1.0 })
.start();
});
btnSelected.addComponent(cc.Button)
btnSelected.on('click', () => {
this.hideMenu();
});
if (data.has_child == '1') {
for (let i = 0; i < 10; i++) {
const optionNode = cc.find(`bubbleBase/bubbleBg/option_${i}`, node);
console.log("optionNode = " + optionNode);
optionNode.active = false;
}
data.children.forEach((menuData, idx) => {
const optionNode = cc.find(`bubbleBase/bubbleBg/option_${idx}`, node);
optionNode.active = true;
const label = cc.find('label', optionNode);
label.getComponent(cc.Label).string = menuData.name;
optionNode.on('click', () => {
cc.tween(optionNode)
.to(0.1, { scale: 1.05 })
.to(0.1, { scale: 1.00 })
.call(() => {
this.hideMenu();
this.syllabus_id = menuData.children[0].id;
this.loadBundleByConf(menuData.children[0].conf);
})
.start();
});
});
}
});
this.storyBoxMenuLength = this.menuItemNodeList.filter(node => node.active).length;
const titleNode = cc.find('middleLayer/storyBox/menu/menuBase/title');
titleNode.y = 30 + this.storyBoxMenuLength * 100;
const storyBox = cc.find('middleLayer/storyBox');
storyBox.active = true;
this.initStoryBoxListener();
});
},
hideAllSubmenu() {
this.menuItemNodeList.forEach(node => {
const menuBase = cc.find('bubbleBase', node);
menuBase.active = false;
});
},
resetAllMenu() {
this.menuItemNodeList.forEach(node => {
const btn = cc.find('btn', node);
const btnLight = cc.find('btnHightLight', node);
const btnSelected = cc.find('btnSelected', node);
btn.active = true;
btnLight.active = false;
btnSelected.active = false;
const label = cc.find('label', node);
const labelSelected = cc.find('labelSelected', node);
label.active = true;
labelSelected.active = false;
});
},
initStoryBoxListener() {
const ExitBtn = cc.find('middleLayer/storyBox/ExitBtn');
ExitBtn.on('click', () => {
cc.tween(ExitBtn)
.to(0.1, { scaleX: 0.9, scaleY: 1.1 })
.to(0.1, { scaleX: 1.1, scaleY: 0.9 })
.to(0.1, { scaleX: 1, scaleY: 1 })
.call(() => {
this.exit();
})
.start();
});
const lineBtnShow = cc.find('middleLayer/storyBox/menu/menuBase/lineBtnShow');
lineBtnShow.on('click', () => {
cc.tween(lineBtnShow)
.to(0.1, { scale: 1.1 })
.to(0.1, { scale: 1.0 })
.call(() => {
this.showMenu();
})
.start();
});
const lineBtnHide = cc.find('middleLayer/storyBox/menu/menuBase/lineBtnHide')
lineBtnHide.on('click', () => {
cc.tween(lineBtnHide)
.to(0.1, { scale: 1.1 })
.to(0.1, { scale: 1.0 })
.call(() => {
this.hideMenu();
})
.start();
});
},
showMenu() {
const lineBtnShow = cc.find('middleLayer/storyBox/menu/menuBase/lineBtnShow');
const lineBtnHide = cc.find('middleLayer/storyBox/menu/menuBase/lineBtnHide')
lineBtnHide.active = true;
lineBtnShow.active = false;
const canvas = cc.find('Canvas');
console.log('canvas.width = ' + canvas.width);
console.log('canvas.height = ' + canvas.height);
const menuBase = cc.find('middleLayer/storyBox/menu/menuBase');
cc.tween(menuBase)
.to(1, { y: this.storyBoxMenuLength * -100 - 80 }, { easing: 'bounceOut' })
.start();
},
hideMenu() {
this.hideAllSubmenu();
this.resetAllMenu();
const lineBtnShow = cc.find('middleLayer/storyBox/menu/menuBase/lineBtnShow');
const lineBtnHide = cc.find('middleLayer/storyBox/menu/menuBase/lineBtnHide')
lineBtnShow.active = true;
lineBtnHide.active = false;
const menuBase = cc.find('middleLayer/storyBox/menu/menuBase');
cc.tween(menuBase)
.to(1, { y: 0 }, { easing: 'cubicInOut' })
.start();
},
hideWWView() {
const exitBtn = cc.find('middleLayer/ExitBtn');
exitBtn.active = false;
const BtnLeft = cc.find('middleLayer/BtnLeft');
BtnLeft.active = false;
const BtnRight = cc.find('middleLayer/BtnRight');
BtnRight.active = false;
}, },
jumpToBundleByIndex(index) { jumpToBundleByIndex(index) {
this.currentBundleIndex = index; this.currentBundleIndex = index;
const currentBundleInfo = this.bundleInfoList[this.currentBundleIndex]; const currentBundleInfo = this.bundleInfoList[this.currentBundleIndex];
const btnLeft = this.node.getChildByName('BtnLeft'); const btnLeft = this.node.getChildByName("BtnLeft");
const btnRight = this.node.getChildByName('BtnRight'); const btnRight = this.node.getChildByName("BtnRight");
btnLeft.active = true; btnLeft.active = true;
btnRight.active = true; btnRight.active = true;
if (this.currentBundleIndex == 0) { if (this.currentBundleIndex == 0) {
btnLeft.active = false; btnLeft.active = false;
} }
if (this.currentBundleIndex == this.bundleInfoList.length - 1) { if (this.currentBundleIndex == this.bundleInfoList.length - 1) {
btnRight.active = false; btnRight.active = false;
} }
this.baseUrl = currentBundleInfo.baseUrl;
this.token = currentBundleInfo.token; this.token = currentBundleInfo.token;
this.homework_id = currentBundleInfo.homework_id; this.homework_id = currentBundleInfo.homework_id;
this.syllabus_id = currentBundleInfo.syllabus_id; this.syllabus_id = currentBundleInfo.syllabus_id;
this.role = currentBundleInfo.role; this.role = currentBundleInfo.role;
this.loadBundle(currentBundleInfo); // role
}, // syllabus_id
// homework_id
loadDefaultBundle() { // token
const jsonStr = this.callNativeFunction({ name: 'loadScene', value: '' });
const { this.loadBundleByConf(this.bundleInfoList[this.currentBundleIndex]);
sceneName,
version,
bondleUrl,
token,
baseUrl,
homework_id,
syllabus_id,
role
} = JSON.parse(jsonStr);
this.baseUrl = baseUrl;
this.token = token;
this.homework_id = homework_id;
this.syllabus_id = syllabus_id;
this.role = role;
this.loadBundle({ bondleUrl, version, sceneName });
}, },
// loadDefaultBundle() {
// const jsonStr = this.callNativeFunction({ name: "loadScene", value: "" });
// const {
// sceneName,
// version,
// bondleUrl,
// token,
// baseUrl,
// homework_id,
// syllabus_id,
// role,
// } = JSON.parse(jsonStr);
// this.baseUrl = baseUrl;
// this.token = token;
// this.homework_id = homework_id;
// this.syllabus_id = syllabus_id;
// this.role = role;
// this.loadBundle({ bondleUrl, version, sceneName });
// },
initListener() { initListener() {
const exitBtn = this.node.getChildByName('ExitBtn'); const exitBtn = this.node.getChildByName("ExitBtn");
exitBtn.on('click', () => { exitBtn.on("click", () => {
cc.tween(exitBtn) cc.tween(exitBtn)
.to(0.1, { scaleX: 0.9, scaleY: 1.1 }) .to(0.1, { scaleX: 0.9, scaleY: 1.1 })
.to(0.1, { scaleX: 1.1, scaleY: 0.9 }) .to(0.1, { scaleX: 1.1, scaleY: 0.9 })
...@@ -471,34 +180,34 @@ cc.Class({ ...@@ -471,34 +180,34 @@ cc.Class({
.start(); .start();
}); });
const btnLeft = this.node.getChildByName('BtnLeft'); const btnLeft = this.node.getChildByName("BtnLeft");
btnLeft.on('click', () => { btnLeft.on("click", () => {
if (this.currentBundleIndex - 1 < 0) { if (this.currentBundleIndex - 1 < 0) {
return; return;
} }
this.jumpToBundleByIndex(this.currentBundleIndex - 1); this.jumpToBundleByIndex(this.currentBundleIndex - 1);
}); });
const btnRight = this.node.getChildByName('BtnRight'); const btnRight = this.node.getChildByName("BtnRight");
btnRight.on('click', () => { btnRight.on("click", () => {
if (this.currentBundleIndex + 1 >= this.bundleInfoList.length) { if (this.currentBundleIndex + 1 >= this.bundleInfoList.length) {
return; return;
} }
this.jumpToBundleByIndex(this.currentBundleIndex + 1); this.jumpToBundleByIndex(this.currentBundleIndex + 1);
}); });
const btnClose = cc.find('middleLayer/ConsoleNode/BtnClose'); const btnClose = cc.find("middleLayer/ConsoleNode/BtnClose");
const btnOpen = cc.find('middleLayer/ConsoleNode/BtnOpen'); const btnOpen = cc.find("middleLayer/ConsoleNode/BtnOpen");
const consoleNode = cc.find('middleLayer/ConsoleNode/Console'); const consoleNode = cc.find("middleLayer/ConsoleNode/Console");
const consoleBg = cc.find('middleLayer/ConsoleNode/bg'); const consoleBg = cc.find("middleLayer/ConsoleNode/bg");
btnOpen.on('click', () => { btnOpen.on("click", () => {
btnClose.active = true; btnClose.active = true;
btnOpen.active = false; btnOpen.active = false;
consoleNode.active = true; consoleNode.active = true;
consoleBg.active = true; consoleBg.active = true;
}); });
btnClose.on('click', () => { btnClose.on("click", () => {
btnClose.active = false; btnClose.active = false;
btnOpen.active = true; btnOpen.active = true;
consoleNode.active = false; consoleNode.active = false;
...@@ -509,11 +218,11 @@ cc.Class({ ...@@ -509,11 +218,11 @@ cc.Class({
log(str) { log(str) {
const logStr = `${new Date().toLocaleString()}: ${str}`; const logStr = `${new Date().toLocaleString()}: ${str}`;
console.log(logStr); console.log(logStr);
const content = cc.instantiate(cc.find('middleLayer/ConsoleNode/content')); const content = cc.instantiate(cc.find("middleLayer/ConsoleNode/content"));
content.active = true; content.active = true;
const label = content.getChildByName('label'); const label = content.getChildByName("label");
label.getComponent(cc.Label).string = logStr; label.getComponent(cc.Label).string = logStr;
const consoleContent = cc.find('middleLayer/ConsoleNode/Console/content'); const consoleContent = cc.find("middleLayer/ConsoleNode/Console/content");
consoleContent.addChild(content); consoleContent.addChild(content);
consoleContent.getComponent(cc.Layout).updateLayout(); consoleContent.getComponent(cc.Layout).updateLayout();
}, },
...@@ -521,23 +230,32 @@ cc.Class({ ...@@ -521,23 +230,32 @@ cc.Class({
callNativeFunction(param) { callNativeFunction(param) {
const paramStr = JSON.stringify(param); const paramStr = JSON.stringify(param);
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) { if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
return jsb.reflection.callStaticMethod('CocosMng', 'cocosWithNativeProtocol:', paramStr); return jsb.reflection.callStaticMethod(
"CocosMng",
"cocosWithNativeProtocol:",
paramStr
);
} else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) { } else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) {
return jsb.reflection.callStaticMethod('com/iplayabc/cocos/AppActivity', 'cocosWithNativeProtocol', '(Ljava/lang/String;)Ljava/lang/String;', paramStr); return jsb.reflection.callStaticMethod(
"com/iplayabc/cocos/AppActivity",
"cocosWithNativeProtocol",
"(Ljava/lang/String;)Ljava/lang/String;",
paramStr
);
} else { } else {
console.error('非源生环境'); console.error("非源生环境");
} }
}, },
showWaitingLetters() { showWaitingLetters() {
const waitingLayer = cc.find('middleLayer/waitingLayer'); const waitingLayer = cc.find("middleLayer/waitingLayer");
waitingLayer.active = true; waitingLayer.active = true;
const colorList = this.getRainbowColorList(); const colorList = this.getRainbowColorList();
const layout = cc.find('middleLayer/layout'); const layout = cc.find("middleLayer/layout");
layout.removeAllChildren(); layout.removeAllChildren();
layout.active = true; layout.active = true;
const str = 'Now Loading...'; const str = "Now Loading...";
str.split('').forEach((word, idx) => { str.split("").forEach((word, idx) => {
const node = new cc.Node(); const node = new cc.Node();
const label = node.addComponent(cc.Label); const label = node.addComponent(cc.Label);
label.string = word; label.string = word;
...@@ -545,8 +263,8 @@ cc.Class({ ...@@ -545,8 +263,8 @@ cc.Class({
node.color = colorList[idx]; node.color = colorList[idx];
cc.tween(node) cc.tween(node)
.delay(idx / 4) .delay(idx / 4)
.by(0.3, { y: 50 }, { easing: 'sineOut' }) .by(0.3, { y: 50 }, { easing: "sineOut" })
.by(0.3, { y: -50 }, { easing: 'sineIn' }) .by(0.3, { y: -50 }, { easing: "sineIn" })
.delay((str.length - idx) / 4) .delay((str.length - idx) / 4)
.union() .union()
.repeatForever() .repeatForever()
...@@ -559,9 +277,9 @@ cc.Class({ ...@@ -559,9 +277,9 @@ cc.Class({
}, },
hideWaitingLetters() { hideWaitingLetters() {
const layout = cc.find('middleLayer/layout'); const layout = cc.find("middleLayer/layout");
layout.active = false; layout.active = false;
const waitingLayer = cc.find('middleLayer/waitingLayer'); const waitingLayer = cc.find("middleLayer/waitingLayer");
waitingLayer.active = false; waitingLayer.active = false;
}, },
...@@ -590,10 +308,7 @@ cc.Class({ ...@@ -590,10 +308,7 @@ cc.Class({
node.x = this.node.width / 4; node.x = this.node.width / 4;
node.y = -this.node.height / 2; node.y = -this.node.height / 2;
node.parent = this.node; node.parent = this.node;
cc.tween(node) cc.tween(node).to(5, { y: this.node.height }).removeSelf().start();
.to(5, { y: this.node.height })
.removeSelf()
.start();
setTimeout(() => { setTimeout(() => {
this.logList.shift(); this.logList.shift();
this.showOneLog(); this.showOneLog();
...@@ -602,42 +317,28 @@ cc.Class({ ...@@ -602,42 +317,28 @@ cc.Class({
loadBundle(conf, callback) { loadBundle(conf, callback) {
this.showWaitingLetters(); this.showWaitingLetters();
cc.assetManager.loadBundle(conf.bondleUrl, { version: conf.version }, async (err, bundle) => { cc.assetManager.loadBundle(
conf.bondleUrl,
{ version: conf.version },
async (err, bundle) => {
if (err) { if (err) {
return this.asyncDelayLog(err); return this.asyncDelayLog(err);
} }
bundle.loadScene(conf.sceneName, (err, scene) => { bundle.loadScene(conf.sceneName, (err, scene) => {
if (err) { if (err) {
this.asyncDelayLog('err: ', err); this.asyncDelayLog("err: ", err);
} }
cc.audioEngine.stopAll(); cc.audioEngine.stopAll();
cc.director.runScene(scene, null, () => { cc.director.runScene(scene, null, () => {
console.log('sceneName = ' + conf.sceneName); console.log("sceneName = " + conf.sceneName);
const canvas = cc.find('Canvas'); const canvas = cc.find("Canvas");
const middleLayer = cc.find('middleLayer'); const middleLayer = cc.find("middleLayer");
this.hideWaitingLetters(); this.hideWaitingLetters();
callback && callback(); callback && callback();
if (this.bundleType == 'StoryBox') {
canvas.getComponent(cc.Widget).updateAlignment();
middleLayer.getComponent(cc.Widget).updateAlignment();
const frameSize = cc.view.getFrameSize();
console.log(`Canvas.size = ${canvas.width}, ${canvas.height}`);
console.log(`frameSize.size = ${frameSize.width}, ${frameSize.height}`);
console.log(`middleLayer.size = ${middleLayer.width}, ${middleLayer.height}`);
const scale = (middleLayer.width / frameSize.width);
console.log('scale = ' + scale);
const middleLayerWidget = middleLayer.getComponent(cc.Widget);
middleLayerWidget.isAlignHorizontalCenter = true; // Boolean 是否水平方向对齐中点,开启此选项会将水平方向其他对齐选项取消。
middleLayerWidget.isAlignVerticalCenter = true; // Boolean 是否垂直方向对齐中点,开启此项会将垂直方向其他对齐选项取消。
// middleLayer.removeComponent(cc.Widget);
middleLayer.width = frameSize.width * scale;
middleLayer.height = frameSize.height * scale;
}
});
}); });
}); });
}
);
}, },
loadBundleByConf(conf, callback) { loadBundleByConf(conf, callback) {
...@@ -647,14 +348,14 @@ cc.Class({ ...@@ -647,14 +348,14 @@ cc.Class({
this.loadBundle(conf.android, callback); this.loadBundle(conf.android, callback);
} else { } else {
this.loadBundle(conf.web_desktop, callback); this.loadBundle(conf.web_desktop, callback);
console.error('非源生环境'); console.error("非源生环境");
} }
}, },
exit() { exit() {
cc.game.removePersistRootNode(this.node); cc.game.removePersistRootNode(this.node);
cc.director.loadScene("emptyScene", () => { cc.director.loadScene("emptyScene", () => {
this.callNativeFunction({ name: 'exit', value: '' }); this.callNativeFunction({ name: "exit", value: "" });
}); });
}, },
...@@ -678,5 +379,5 @@ cc.Class({ ...@@ -678,5 +379,5 @@ cc.Class({
cc.color(0, 0, 255), cc.color(0, 0, 255),
cc.color(128, 0, 255), cc.color(128, 0, 255),
]; ];
} },
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment