Commit 774e1f7e authored by 范雪寒's avatar 范雪寒

style: 格式化

parent 1720e51d
cc.Class({ cc.Class({
extends: cc.Component, extends: cc.Component,
properties: {}, properties: {},
getData(callBack) { getData(callBack) {
const uri = 'courseware/v1/getdata'; const uri = "courseware/v1/getdata";
let syllabus_id; let syllabus_id;
if (this.bundleType == 'StoryBox') { if (this.bundleType == "StoryBox") {
syllabus_id = this.syllabus_id; syllabus_id = this.syllabus_id;
} else if (this.bundleType == 'WW') { } else if (this.bundleType == "WW") {
syllabus_id = this.bundleInfoList[this.currentBundleIndex].syllabus_id; syllabus_id = this.bundleInfoList[this.currentBundleIndex].syllabus_id;
} }
const data = { const data = {
courseid: syllabus_id courseid: syllabus_id,
}; };
this.callNetworkApiGet(uri, data, (data) => { this.callNetworkApiGet(uri, data, (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') { 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 != '?') {
queryStr += '&';
}
queryStr += `${key}=${value}`;
}
} }
const xhr = new XMLHttpRequest(); if (queryStr != "?") {
xhr.onreadystatechange = () => { queryStr += "&";
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
const responseData = JSON.parse(xhr.responseText);
callBack(responseData);
}
};
const url = `${this.baseUrl}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
xhr.send();
},
callNetworkApiPost(uri, data, callBack) {
const xhr = new XMLHttpRequest();
const url = `${this.baseUrl}${uri}`;
xhr.open("POST", url, true);
xhr.setRequestHeader('content-type', 'application/json');
xhr.onreadystatechange = () => {
if (xhr.readyState == 4) {
callBack(JSON.parse(xhr.responseText));
}
} }
xhr.send(JSON.stringify(data)); queryStr += `${key}=${value}`;
}, }
}
start() { const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status < 400) {
const responseData = JSON.parse(xhr.responseText);
callBack(responseData);
}
};
const url = `${this.baseUrl}${uri}${queryStr}`;
console.log("url = " + url);
xhr.open("GET", url, true);
xhr.send();
},
this.node.zIndex = 9999; callNetworkApiPost(uri, data, callBack) {
this.showWaitingLetters(); const xhr = new XMLHttpRequest();
const url = `${this.baseUrl}${uri}`;
xhr.open("POST", url, true);
xhr.setRequestHeader("content-type", "application/json");
xhr.onreadystatechange = () => {
if (xhr.readyState == 4) {
callBack(JSON.parse(xhr.responseText));
}
};
xhr.send(JSON.stringify(data));
},
cc.game.addPersistRootNode(this.node); start() {
this.node.zIndex = 9999;
this.showWaitingLetters();
this.initListener(); cc.game.addPersistRootNode(this.node);
this.getBundleInfoList(); this.initListener();
// this.baseUrl = 'http://staging-teach.ireadabc.com/api/'; this.getBundleInfoList();
// this.initStoryBoxView({
// // coursewareId: 18307
// // coursewareId: 18582
// coursewareId: 25687
// });
// this.bundleType = 'StoryBox';
this.log('汪汪汪'); // this.baseUrl = 'http://staging-teach.ireadabc.com/api/';
}, // this.initStoryBoxView({
// // coursewareId: 18307
// // coursewareId: 18582
// coursewareId: 25687
// });
// this.bundleType = 'StoryBox';
asyncDelayLog(str) { this.log("汪汪汪");
console.log(str); },
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, 1);
});
},
getBundleInfoList() { asyncDelayLog(str) {
const jsonStr = this.callNativeFunction({ name: 'loadSceneList', value: '' }); console.log(str);
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, 1);
});
},
if (!jsonStr) { getBundleInfoList() {
console.error('没有jsonStr!!') const jsonStr = this.callNativeFunction({
return; name: "loadSceneList",
} value: "",
});
const { bundleInfoList, defaultBundleIdx, bundleType, bundleInfo } = JSON.parse(jsonStr); if (!jsonStr) {
console.error("没有jsonStr!!");
if (bundleType == 'PetRoom') { return;
this.bundleType = 'PetRoom'; }
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; const { bundleInfoList, defaultBundleIdx, bundleType, bundleInfo } =
this.loadBundleByConf(defaultBondle.children[0].conf, () => { JSON.parse(jsonStr);
const ExitBtn = cc.find('middleLayer/storyBox/ExitBtn');
ExitBtn.active = true; if (bundleType == "PetRoom") {
}); this.bundleType = "PetRoom";
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;
this.menuItemNodeList = []; const nameLabel = cc.find(
"middleLayer/storyBox/menu/menuBase/title/Lession"
data.rows.filter((row) => { );
return row.name != '默认'; nameLabel.getComponent(cc.Label).string = bundleInfo.coursewareName;
}).forEach((data, idx, arr) => {
console.log(data.name, idx); this.baseUrl = bundleInfo.baseUrl;
this.initStoryBoxView(bundleInfo);
const node = cc.instantiate(cc.find('middleLayer/menuItem')); } else {
node.name = 'menuItem_' + idx; this.bundleType = "WW";
node.parent = cc.find('middleLayer/storyBox/menu/menuBase'); // WW模板
node.active = true; this.bundleInfoList = bundleInfoList;
node.x = 0; this.jumpToBundleByIndex(defaultBundleIdx);
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) initPetRoomView(bundleInfo) {
btnLight.on('click', () => { this.hideWWView();
cc.tween(btnLight) this.loadBundle(bundleInfo);
.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) initStoryBoxView(bundleInfo) {
btnSelected.on('click', () => { this.hideWWView();
this.hideMenu();
}); // 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;
if (data.has_child == '1') { this.syllabus_id = defaultBondle.children[0].id;
for (let i = 0; i < 10; i++) { this.loadBundleByConf(defaultBondle.children[0].conf, () => {
const optionNode = cc.find(`bubbleBase/bubbleBg/option_${i}`, node); const ExitBtn = cc.find("middleLayer/storyBox/ExitBtn");
console.log("optionNode = " + optionNode); ExitBtn.active = true;
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; this.menuItemNodeList = [];
const titleNode = cc.find('middleLayer/storyBox/menu/menuBase/title'); data.rows
titleNode.y = 30 + this.storyBoxMenuLength * 100; .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;
const storyBox = cc.find('middleLayer/storyBox'); this.menuItemNodeList.push(node);
storyBox.active = true;
this.initStoryBoxListener();
});
},
hideAllSubmenu() { const menuBase = cc.find("bubbleBase", node);
this.menuItemNodeList.forEach(node => {
const menuBase = cc.find('bubbleBase', node);
menuBase.active = false;
});
},
resetAllMenu() { const label = cc.find("label", node);
this.menuItemNodeList.forEach(node => { label.getComponent(cc.Label).string = data.name;
const btn = cc.find('btn', node); label.active = true;
const btnLight = cc.find('btnHightLight', node); const labelSelected = cc.find("labelSelected", node);
const btnSelected = cc.find('btnSelected', 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; btn.active = true;
btnLight.active = false; btnLight.active = false;
btnSelected.active = false; btnSelected.active = false;
const label = cc.find('label', node); btn.addComponent(cc.Button);
const labelSelected = cc.find('labelSelected', node); btn.on("click", () => {
label.active = true; console.log(data);
labelSelected.active = false; cc.tween(btn)
}); .to(0.1, { scale: 1.1 })
}, .to(0.1, { scale: 1.0 })
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(() => { .call(() => {
this.exit(); 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(); .start();
}); cc.tween(label)
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.1 })
.to(0.1, { scale: 1.0 }) .to(0.1, { scale: 1.0 })
.call(() => {
this.showMenu();
})
.start(); .start();
}); });
const lineBtnHide = cc.find('middleLayer/storyBox/menu/menuBase/lineBtnHide') btnLight.addComponent(cc.Button);
lineBtnHide.on('click', () => { btnLight.on("click", () => {
cc.tween(lineBtnHide) cc.tween(btnLight)
.to(0.1, { scale: 1.1 }) .to(0.1, { scale: 1.1 })
.to(0.1, { scale: 1.0 }) .to(0.1, { scale: 1.0 })
.call(() => { .call(() => {
this.hideMenu(); menuBase.active = false;
btn.active = true;
btnLight.active = false;
}) })
.start(); .start();
}); cc.tween(label)
}, .to(0.1, { scale: 1.1 })
.to(0.1, { scale: 1.0 })
showMenu() { .start();
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) {
this.currentBundleIndex = index;
const currentBundleInfo = this.bundleInfoList[this.currentBundleIndex];
const btnLeft = this.node.getChildByName('BtnLeft');
const btnRight = this.node.getChildByName('BtnRight');
btnLeft.active = true;
btnRight.active = true;
if (this.currentBundleIndex == 0) {
btnLeft.active = false;
}
if (this.currentBundleIndex == this.bundleInfoList.length - 1) {
btnRight.active = false; btnSelected.addComponent(cc.Button);
} btnSelected.on("click", () => {
this.hideMenu();
});
this.baseUrl = currentBundleInfo.baseUrl; if (data.has_child == "1") {
this.token = currentBundleInfo.token; for (let i = 0; i < 10; i++) {
this.homework_id = currentBundleInfo.homework_id; const optionNode = cc.find(
this.syllabus_id = currentBundleInfo.syllabus_id; `bubbleBase/bubbleBg/option_${i}`,
this.role = currentBundleInfo.role; 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.0 })
.call(() => {
this.hideMenu();
this.syllabus_id = menuData.children[0].id;
this.loadBundleByConf(menuData.children[0].conf);
})
.start();
});
});
}
});
this.loadBundle(currentBundleInfo); this.storyBoxMenuLength = this.menuItemNodeList.filter(
}, (node) => node.active
).length;
loadDefaultBundle() { 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();
}
);
},
const jsonStr = this.callNativeFunction({ name: 'loadScene', value: '' }); hideAllSubmenu() {
this.menuItemNodeList.forEach((node) => {
const menuBase = cc.find("bubbleBase", node);
menuBase.active = false;
});
},
const { resetAllMenu() {
sceneName, this.menuItemNodeList.forEach((node) => {
version, const btn = cc.find("btn", node);
bondleUrl, const btnLight = cc.find("btnHightLight", node);
token, const btnSelected = cc.find("btnSelected", node);
baseUrl,
homework_id, btn.active = true;
syllabus_id, btnLight.active = false;
role btnSelected.active = false;
} = JSON.parse(jsonStr);
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();
});
},
this.baseUrl = baseUrl; showMenu() {
this.token = token; const lineBtnShow = cc.find(
this.homework_id = homework_id; "middleLayer/storyBox/menu/menuBase/lineBtnShow"
this.syllabus_id = syllabus_id; );
this.role = role; const lineBtnHide = cc.find(
"middleLayer/storyBox/menu/menuBase/lineBtnHide"
);
this.loadBundle({ bondleUrl, version, sceneName }); lineBtnHide.active = true;
}, lineBtnShow.active = false;
initListener() { const canvas = cc.find("Canvas");
const exitBtn = this.node.getChildByName('ExitBtn'); console.log("canvas.width = " + canvas.width);
exitBtn.on('click', () => { console.log("canvas.height = " + canvas.height);
cc.tween(exitBtn)
.to(0.1, { scaleX: 0.9, scaleY: 1.1 }) const menuBase = cc.find("middleLayer/storyBox/menu/menuBase");
.to(0.1, { scaleX: 1.1, scaleY: 0.9 }) cc.tween(menuBase)
.to(0.1, { scaleX: 1, scaleY: 1 }) .to(
.call(() => { 1,
this.exit(); { y: this.storyBoxMenuLength * -100 - 80 },
}) { easing: "bounceOut" }
.start(); )
}); .start();
},
const btnLeft = this.node.getChildByName('BtnLeft'); hideMenu() {
btnLeft.on('click', () => { this.hideAllSubmenu();
if (this.currentBundleIndex - 1 < 0) { this.resetAllMenu();
return;
}
this.jumpToBundleByIndex(this.currentBundleIndex - 1);
});
const btnRight = this.node.getChildByName('BtnRight'); const lineBtnShow = cc.find(
btnRight.on('click', () => { "middleLayer/storyBox/menu/menuBase/lineBtnShow"
if (this.currentBundleIndex + 1 >= this.bundleInfoList.length) { );
return; const lineBtnHide = cc.find(
} "middleLayer/storyBox/menu/menuBase/lineBtnHide"
this.jumpToBundleByIndex(this.currentBundleIndex + 1); );
});
const btnClose = cc.find('middleLayer/ConsoleNode/BtnClose'); lineBtnShow.active = true;
const btnOpen = cc.find('middleLayer/ConsoleNode/BtnOpen'); lineBtnHide.active = false;
const consoleNode = cc.find('middleLayer/ConsoleNode/Console');
const consoleBg = cc.find('middleLayer/ConsoleNode/bg');
btnOpen.on('click', () => {
btnClose.active = true;
btnOpen.active = false;
consoleNode.active = true;
consoleBg.active = true;
});
btnClose.on('click', () => { const menuBase = cc.find("middleLayer/storyBox/menu/menuBase");
btnClose.active = false; cc.tween(menuBase).to(1, { y: 0 }, { easing: "cubicInOut" }).start();
btnOpen.active = true; },
consoleNode.active = false;
consoleBg.active = false;
});
},
log(str) {
const logStr = `${new Date().toLocaleString()}: ${str}`;
console.log(logStr);
const content = cc.instantiate(cc.find('middleLayer/ConsoleNode/content'));
content.active = true;
const label = content.getChildByName('label');
label.getComponent(cc.Label).string = logStr;
const consoleContent = cc.find('middleLayer/ConsoleNode/Console/content');
consoleContent.addChild(content);
consoleContent.getComponent(cc.Layout).updateLayout();
},
callNativeFunction(param) {
const paramStr = JSON.stringify(param);
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
return jsb.reflection.callStaticMethod('CocosMng', 'cocosWithNativeProtocol:', paramStr);
} 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);
} else {
console.error('非源生环境');
}
},
showWaitingLetters() {
const waitingLayer = cc.find('middleLayer/waitingLayer');
waitingLayer.active = true;
const colorList = this.getRainbowColorList();
const layout = cc.find('middleLayer/layout');
layout.removeAllChildren();
layout.active = true;
const str = 'Now Loading...';
str.split('').forEach((word, idx) => {
const node = new cc.Node();
const label = node.addComponent(cc.Label);
label.string = word;
node.parent = layout;
node.color = colorList[idx];
cc.tween(node)
.delay(idx / 4)
.by(0.3, { y: 50 }, { easing: 'sineOut' })
.by(0.3, { y: -50 }, { easing: 'sineIn' })
.delay((str.length - idx) / 4)
.union()
.repeatForever()
.start();
});
const totalWidth = layout.children.reduce((width, node, idx) => {
return width + node.width;
}, 0);
layout.width = totalWidth;
},
hideWaitingLetters() {
const layout = cc.find('middleLayer/layout');
layout.active = false;
const waitingLayer = cc.find('middleLayer/waitingLayer');
waitingLayer.active = false;
},
showLog(str) {
if (!this.logList) {
this.logList = [];
}
this.logList.push(str);
console.log(str);
if (this.logList.length == 1) { hideWWView() {
this.showOneLog(); 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) {
this.currentBundleIndex = index;
const currentBundleInfo = this.bundleInfoList[this.currentBundleIndex];
const btnLeft = this.node.getChildByName("BtnLeft");
const btnRight = this.node.getChildByName("BtnRight");
btnLeft.active = true;
btnRight.active = true;
if (this.currentBundleIndex == 0) {
btnLeft.active = false;
}
if (this.currentBundleIndex == this.bundleInfoList.length - 1) {
btnRight.active = false;
}
this.baseUrl = currentBundleInfo.baseUrl;
this.token = currentBundleInfo.token;
this.homework_id = currentBundleInfo.homework_id;
this.syllabus_id = currentBundleInfo.syllabus_id;
this.role = currentBundleInfo.role;
this.loadBundle(currentBundleInfo);
},
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 });
},
showOneLog() { initListener() {
const str = this.logList[0]; const exitBtn = this.node.getChildByName("ExitBtn");
if (str === undefined) { exitBtn.on("click", () => {
return; 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 btnLeft = this.node.getChildByName("BtnLeft");
btnLeft.on("click", () => {
if (this.currentBundleIndex - 1 < 0) {
return;
}
this.jumpToBundleByIndex(this.currentBundleIndex - 1);
});
const btnRight = this.node.getChildByName("BtnRight");
btnRight.on("click", () => {
if (this.currentBundleIndex + 1 >= this.bundleInfoList.length) {
return;
}
this.jumpToBundleByIndex(this.currentBundleIndex + 1);
});
const btnClose = cc.find("middleLayer/ConsoleNode/BtnClose");
const btnOpen = cc.find("middleLayer/ConsoleNode/BtnOpen");
const consoleNode = cc.find("middleLayer/ConsoleNode/Console");
const consoleBg = cc.find("middleLayer/ConsoleNode/bg");
btnOpen.on("click", () => {
btnClose.active = true;
btnOpen.active = false;
consoleNode.active = true;
consoleBg.active = true;
});
btnClose.on("click", () => {
btnClose.active = false;
btnOpen.active = true;
consoleNode.active = false;
consoleBg.active = false;
});
},
log(str) {
const logStr = `${new Date().toLocaleString()}: ${str}`;
console.log(logStr);
const content = cc.instantiate(cc.find("middleLayer/ConsoleNode/content"));
content.active = true;
const label = content.getChildByName("label");
label.getComponent(cc.Label).string = logStr;
const consoleContent = cc.find("middleLayer/ConsoleNode/Console/content");
consoleContent.addChild(content);
consoleContent.getComponent(cc.Layout).updateLayout();
},
callNativeFunction(param) {
const paramStr = JSON.stringify(param);
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
return jsb.reflection.callStaticMethod(
"CocosMng",
"cocosWithNativeProtocol:",
paramStr
);
} 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
);
} else {
console.error("非源生环境");
}
},
showWaitingLetters() {
const waitingLayer = cc.find("middleLayer/waitingLayer");
waitingLayer.active = true;
const colorList = this.getRainbowColorList();
const layout = cc.find("middleLayer/layout");
layout.removeAllChildren();
layout.active = true;
const str = "Now Loading...";
str.split("").forEach((word, idx) => {
const node = new cc.Node();
const label = node.addComponent(cc.Label);
label.string = word;
node.parent = layout;
node.color = colorList[idx];
cc.tween(node)
.delay(idx / 4)
.by(0.3, { y: 50 }, { easing: "sineOut" })
.by(0.3, { y: -50 }, { easing: "sineIn" })
.delay((str.length - idx) / 4)
.union()
.repeatForever()
.start();
});
const totalWidth = layout.children.reduce((width, node, idx) => {
return width + node.width;
}, 0);
layout.width = totalWidth;
},
hideWaitingLetters() {
const layout = cc.find("middleLayer/layout");
layout.active = false;
const waitingLayer = cc.find("middleLayer/waitingLayer");
waitingLayer.active = false;
},
showLog(str) {
if (!this.logList) {
this.logList = [];
}
this.logList.push(str);
console.log(str);
if (this.logList.length == 1) {
this.showOneLog();
}
},
showOneLog() {
const str = this.logList[0];
if (str === undefined) {
return;
}
const node = new cc.Node();
node.anchorX = 0.5;
const label = node.addComponent(cc.RichText);
label.string = `<outline color=black width=3>${str}</outline>`;
label.maxWidth = this.node.width / 2;
node.x = this.node.width / 4;
node.y = -this.node.height / 2;
node.parent = this.node;
cc.tween(node).to(5, { y: this.node.height }).removeSelf().start();
setTimeout(() => {
this.logList.shift();
this.showOneLog();
}, 1000);
},
loadBundle(conf, callback) {
this.showWaitingLetters();
cc.assetManager.loadBundle(
conf.bondleUrl,
{ version: conf.version },
async (err, bundle) => {
if (err) {
return this.asyncDelayLog(err);
} }
const node = new cc.Node(); bundle.loadScene(conf.sceneName, (err, scene) => {
node.anchorX = 0.5; if (err) {
const label = node.addComponent(cc.RichText); this.asyncDelayLog("err: ", err);
label.string = `<outline color=black width=3>${str}</outline>`; }
label.maxWidth = this.node.width / 2; cc.audioEngine.stopAll();
node.x = this.node.width / 4; cc.director.runScene(scene, null, () => {
node.y = -this.node.height / 2; console.log("sceneName = " + conf.sceneName);
node.parent = this.node; const canvas = cc.find("Canvas");
cc.tween(node) const middleLayer = cc.find("middleLayer");
.to(5, { y: this.node.height }) this.hideWaitingLetters();
.removeSelf() callback && callback();
.start(); if (this.bundleType == "StoryBox") {
setTimeout(() => { this.node.removeComponent(cc.Widget);
this.logList.shift(); this.updateScale();
this.showOneLog();
}, 1000);
},
loadBundle(conf, callback) {
this.showWaitingLetters();
cc.assetManager.loadBundle(conf.bondleUrl, { version: conf.version }, async (err, bundle) => {
if (err) {
return this.asyncDelayLog(err);
} }
bundle.loadScene(conf.sceneName, (err, scene) => { });
if (err) {
this.asyncDelayLog('err: ', err);
}
cc.audioEngine.stopAll();
cc.director.runScene(scene, null, () => {
console.log('sceneName = ' + conf.sceneName);
const canvas = cc.find('Canvas');
const middleLayer = cc.find('middleLayer');
this.hideWaitingLetters();
callback && callback();
if (this.bundleType == 'StoryBox') {
this.node.removeComponent(cc.Widget);
this.updateScale();
}
});
});
}); });
}, }
);
},
updateScale() { updateScale() {
console.log("updateScale"); console.log("updateScale");
...@@ -678,44 +717,43 @@ cc.Class({ ...@@ -678,44 +717,43 @@ cc.Class({
} }
}, },
loadBundleByConf(conf, callback) {
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
this.loadBundle(conf.ios, callback);
} else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) {
this.loadBundle(conf.android, callback);
} else {
this.loadBundle(conf.web_desktop, callback);
console.error("非源生环境");
}
},
loadBundleByConf(conf, callback) { exit() {
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) { cc.game.removePersistRootNode(this.node);
this.loadBundle(conf.ios, callback); cc.director.loadScene("emptyScene", () => {
} else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) { this.callNativeFunction({ name: "exit", value: "" });
this.loadBundle(conf.android, callback); });
} else { },
this.loadBundle(conf.web_desktop, callback);
console.error('非源生环境');
}
},
exit() { getRainbowColorList() {
cc.game.removePersistRootNode(this.node); return [
cc.director.loadScene("emptyScene", () => { cc.color(128, 0, 255),
this.callNativeFunction({ name: 'exit', value: '' }); cc.color(255, 0, 255),
}); cc.color(255, 0, 128),
},
cc.color(0, 0, 0),
getRainbowColorList() {
return [ cc.color(255, 0, 0),
cc.color(128, 0, 255), cc.color(255, 128, 0),
cc.color(255, 0, 255), cc.color(255, 255, 0),
cc.color(255, 0, 128), cc.color(128, 255, 0),
cc.color(0, 255, 0),
cc.color(0, 0, 0), cc.color(0, 255, 128),
cc.color(0, 255, 255),
cc.color(255, 0, 0),
cc.color(255, 128, 0), cc.color(0, 128, 255),
cc.color(255, 255, 0), cc.color(0, 0, 255),
cc.color(128, 255, 0), cc.color(128, 0, 255),
cc.color(0, 255, 0), ];
cc.color(0, 255, 128), },
cc.color(0, 255, 255),
cc.color(0, 128, 255),
cc.color(0, 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