Commit 44973cb8 authored by 范雪寒's avatar 范雪寒

feat: 适配ui尺寸

parent 963fe620
......@@ -295,25 +295,25 @@
"__id__": 20
},
{
"__id__": 138
"__id__": 137
},
{
"__id__": 173
"__id__": 172
},
{
"__id__": 177
"__id__": 176
},
{
"__id__": 179
"__id__": 178
}
],
"_active": true,
"_components": [
{
"__id__": 190
"__id__": 189
},
{
"__id__": 191
"__id__": 190
}
],
"_prefab": null,
......@@ -1013,11 +1013,7 @@
}
],
"_active": true,
"_components": [
{
"__id__": 137
}
],
"_components": [],
"_prefab": null,
"_opacity": 255,
"_color": {
......@@ -1029,8 +1025,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 1280,
"height": 720
"width": 1120,
"height": 510
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -6784,33 +6780,6 @@
"_N$reverse": false,
"_id": "bc3W7j5EVJRaoW20bSToA3"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 20
},
"_enabled": true,
"alignMode": 2,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 1280,
"_originalHeight": 720,
"_id": "c87OiuHMRI7YOL5SUoikbx"
},
{
"__type__": "cc.Node",
"_name": "ConsoleNode",
......@@ -6820,25 +6789,25 @@
},
"_children": [
{
"__id__": 139
"__id__": 138
},
{
"__id__": 145
"__id__": 144
},
{
"__id__": 148
"__id__": 147
},
{
"__id__": 156
"__id__": 155
},
{
"__id__": 164
"__id__": 163
}
],
"_active": true,
"_components": [
{
"__id__": 172
"__id__": 171
}
],
"_prefab": null,
......@@ -6894,20 +6863,20 @@
"_name": "content",
"_objFlags": 0,
"_parent": {
"__id__": 138
"__id__": 137
},
"_children": [
{
"__id__": 140
"__id__": 139
}
],
"_active": false,
"_components": [
{
"__id__": 143
"__id__": 142
},
{
"__id__": 144
"__id__": 143
}
],
"_prefab": null,
......@@ -6963,16 +6932,16 @@
"_name": "label",
"_objFlags": 0,
"_parent": {
"__id__": 139
"__id__": 138
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 141
"__id__": 140
},
{
"__id__": 142
"__id__": 141
}
],
"_prefab": null,
......@@ -7028,7 +6997,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 140
"__id__": 139
},
"_enabled": true,
"_materials": [
......@@ -7061,7 +7030,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 140
"__id__": 139
},
"_enabled": true,
"alignMode": 1,
......@@ -7088,7 +7057,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 139
"__id__": 138
},
"_enabled": true,
"_layoutSize": {
......@@ -7120,7 +7089,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 139
"__id__": 138
},
"_enabled": true,
"alignMode": 2,
......@@ -7147,16 +7116,16 @@
"_name": "bg",
"_objFlags": 0,
"_parent": {
"__id__": 138
"__id__": 137
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 146
"__id__": 145
},
{
"__id__": 147
"__id__": 146
}
],
"_prefab": null,
......@@ -7212,7 +7181,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 145
"__id__": 144
},
"_enabled": true,
"_materials": [
......@@ -7244,7 +7213,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 145
"__id__": 144
},
"_enabled": true,
"alignMode": 1,
......@@ -7271,15 +7240,18 @@
"_name": "Console",
"_objFlags": 0,
"_parent": {
"__id__": 138
"__id__": 137
},
"_children": [
{
"__id__": 149
"__id__": 148
}
],
"_active": false,
"_components": [
{
"__id__": 151
},
{
"__id__": 152
},
......@@ -7288,9 +7260,6 @@
},
{
"__id__": 154
},
{
"__id__": 155
}
],
"_prefab": null,
......@@ -7346,16 +7315,16 @@
"_name": "content",
"_objFlags": 0,
"_parent": {
"__id__": 148
"__id__": 147
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 150
"__id__": 149
},
{
"__id__": 151
"__id__": 150
}
],
"_prefab": null,
......@@ -7411,7 +7380,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 149
"__id__": 148
},
"_enabled": true,
"_layoutSize": {
......@@ -7443,7 +7412,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 149
"__id__": 148
},
"_enabled": true,
"alignMode": 1,
......@@ -7470,7 +7439,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 148
"__id__": 147
},
"_enabled": true,
"alignMode": 2,
......@@ -7497,7 +7466,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 148
"__id__": 147
},
"_enabled": true,
"_materials": [
......@@ -7517,7 +7486,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 148
"__id__": 147
},
"_enabled": true,
"horizontal": false,
......@@ -7529,10 +7498,10 @@
"scrollEvents": [],
"cancelInnerEvents": true,
"_N$content": {
"__id__": 149
"__id__": 148
},
"content": {
"__id__": 149
"__id__": 148
},
"_id": "43wBGhGBpFP7OYyNM+j0Ho"
},
......@@ -7541,7 +7510,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 148
"__id__": 147
},
"_enabled": true,
"_layoutSize": {
......@@ -7573,20 +7542,20 @@
"_name": "BtnClose",
"_objFlags": 0,
"_parent": {
"__id__": 138
"__id__": 137
},
"_children": [
{
"__id__": 157
"__id__": 156
}
],
"_active": false,
"_components": [
{
"__id__": 162
"__id__": 161
},
{
"__id__": 163
"__id__": 162
}
],
"_prefab": null,
......@@ -7642,20 +7611,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 156
"__id__": 155
},
"_children": [
{
"__id__": 158
"__id__": 157
}
],
"_active": true,
"_components": [
{
"__id__": 160
"__id__": 159
},
{
"__id__": 161
"__id__": 160
}
],
"_prefab": null,
......@@ -7711,13 +7680,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 157
"__id__": 156
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 159
"__id__": 158
}
],
"_prefab": null,
......@@ -7773,7 +7742,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 158
"__id__": 157
},
"_enabled": true,
"_materials": [
......@@ -7806,7 +7775,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 157
"__id__": 156
},
"_enabled": true,
"_materials": [
......@@ -7838,7 +7807,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 157
"__id__": 156
},
"_enabled": true,
"alignMode": 0,
......@@ -7865,7 +7834,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 156
"__id__": 155
},
"_enabled": true,
"_normalMaterial": null,
......@@ -7938,7 +7907,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 157
"__id__": 156
},
"_id": "54SC9WcmBAZ6cTznyI0o+3"
},
......@@ -7947,7 +7916,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 156
"__id__": 155
},
"_enabled": true,
"alignMode": 1,
......@@ -7974,20 +7943,20 @@
"_name": "BtnOpen",
"_objFlags": 0,
"_parent": {
"__id__": 138
"__id__": 137
},
"_children": [
{
"__id__": 165
"__id__": 164
}
],
"_active": false,
"_components": [
{
"__id__": 170
"__id__": 169
},
{
"__id__": 171
"__id__": 170
}
],
"_prefab": null,
......@@ -8043,20 +8012,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 164
"__id__": 163
},
"_children": [
{
"__id__": 166
"__id__": 165
}
],
"_active": true,
"_components": [
{
"__id__": 168
"__id__": 167
},
{
"__id__": 169
"__id__": 168
}
],
"_prefab": null,
......@@ -8112,13 +8081,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 165
"__id__": 164
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 167
"__id__": 166
}
],
"_prefab": null,
......@@ -8174,7 +8143,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 166
"__id__": 165
},
"_enabled": true,
"_materials": [
......@@ -8207,7 +8176,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 165
"__id__": 164
},
"_enabled": true,
"_materials": [
......@@ -8239,7 +8208,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 165
"__id__": 164
},
"_enabled": true,
"alignMode": 0,
......@@ -8266,7 +8235,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 164
"__id__": 163
},
"_enabled": true,
"_normalMaterial": null,
......@@ -8339,7 +8308,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 165
"__id__": 164
},
"_id": "81HoUuRyJOppi+n4Av/u0p"
},
......@@ -8348,7 +8317,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 164
"__id__": 163
},
"_enabled": true,
"alignMode": 1,
......@@ -8375,7 +8344,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 138
"__id__": 137
},
"_enabled": true,
"alignMode": 1,
......@@ -8408,13 +8377,13 @@
"_active": false,
"_components": [
{
"__id__": 174
"__id__": 173
},
{
"__id__": 175
"__id__": 174
},
{
"__id__": 176
"__id__": 175
}
],
"_prefab": null,
......@@ -8470,7 +8439,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 173
"__id__": 172
},
"_enabled": true,
"alignMode": 2,
......@@ -8497,7 +8466,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 173
"__id__": 172
},
"_enabled": true,
"_normalMaterial": null,
......@@ -8565,7 +8534,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 173
"__id__": 172
},
"_enabled": true,
"_materials": [
......@@ -8603,7 +8572,7 @@
"_active": true,
"_components": [
{
"__id__": 178
"__id__": 177
}
],
"_prefab": null,
......@@ -8659,7 +8628,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 177
"__id__": 176
},
"_enabled": true,
"_layoutSize": {
......@@ -8695,10 +8664,10 @@
},
"_children": [
{
"__id__": 180
"__id__": 179
},
{
"__id__": 183
"__id__": 182
}
],
"_active": false,
......@@ -8756,16 +8725,16 @@
"_name": "loading",
"_objFlags": 0,
"_parent": {
"__id__": 179
"__id__": 178
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 181
"__id__": 180
},
{
"__id__": 182
"__id__": 181
}
],
"_prefab": null,
......@@ -8821,7 +8790,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 180
"__id__": 179
},
"_enabled": true,
"_materials": [
......@@ -8853,7 +8822,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 180
"__id__": 179
},
"_enabled": true,
"_defaultClip": {
......@@ -8872,24 +8841,24 @@
"_name": "progress",
"_objFlags": 0,
"_parent": {
"__id__": 179
"__id__": 178
},
"_children": [
{
"__id__": 184
"__id__": 183
}
],
"_active": true,
"_components": [
{
"__id__": 187
"__id__": 186
},
{
"__id__": 188
"__id__": 187
}
],
"_prefab": {
"__id__": 189
"__id__": 188
},
"_opacity": 255,
"_color": {
......@@ -8943,17 +8912,17 @@
"_name": "bar",
"_objFlags": 0,
"_parent": {
"__id__": 183
"__id__": 182
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 185
"__id__": 184
}
],
"_prefab": {
"__id__": 186
"__id__": 185
},
"_opacity": 255,
"_color": {
......@@ -9007,7 +8976,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 184
"__id__": 183
},
"_enabled": true,
"_materials": [
......@@ -9037,7 +9006,7 @@
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 183
"__id__": 182
},
"asset": {
"__uuid__": "3d356c4d-cb23-4239-aa5f-8a913f420fa4"
......@@ -9050,7 +9019,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 183
"__id__": 182
},
"_enabled": true,
"_materials": [
......@@ -9082,7 +9051,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 183
"__id__": 182
},
"_enabled": true,
"_id": "3eMT/DXoJNGZT/8Z3nuTUH"
......@@ -9090,7 +9059,7 @@
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 183
"__id__": 182
},
"asset": {
"__uuid__": "3d356c4d-cb23-4239-aa5f-8a913f420fa4"
......
import { initAir } from './air';
import { initAir } from "./air";
cc.Class({
extends: cc.Component,
properties: {
},
properties: {},
callNetworkApiPost(baseUrl, uri, data, callBack) {
this.getBaseUrl((baseUrl) => {
const xhr = new XMLHttpRequest();
const url = `${baseUrl}${uri}`;
xhr.open("POST", url, true);
xhr.setRequestHeader('content-type', 'application/json');
xhr.setRequestHeader("content-type", "application/json");
xhr.onreadystatechange = () => {
if (xhr.readyState == 4) {
callBack(JSON.parse(xhr.responseText));
}
}
};
xhr.send(JSON.stringify(data));
});
},
callNetworkApiGet(baseUrl, uri, data, callBack) {
this.getBaseUrl((baseUrl) => {
let queryStr = '?';
let queryStr = "?";
const params = [];
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
......@@ -32,19 +30,19 @@ cc.Class({
queryStr += params.join("&");
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status < 400) {
callBack(xhr.responseText);
}
};
const url = `${baseUrl}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
console.log("url = " + url);
xhr.open("GET", url, true);
xhr.send();
});
},
callNetworkApiGetLocal(baseUrl, uri, data, callBack) {
let queryStr = '?';
let queryStr = "?";
const params = [];
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
......@@ -54,13 +52,13 @@ cc.Class({
queryStr += params.join("&");
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status < 400) {
callBack(xhr.responseText);
}
};
const url = `${baseUrl}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
console.log("url = " + url);
xhr.open("GET", url, true);
xhr.send();
},
......@@ -78,18 +76,18 @@ cc.Class({
},
getBaseUrl(callback) {
if(window.air.engineInfo){
if(window.air.engineInfo.isDev==1){
callback('https://staging-teach.ireadabc.com');
}else{
callback('https://iteachabc.com');
}
}else{
window.courseware.getEngineInfo(()=>{
if(window.air.engineInfo.isDev==1){
callback('https://staging-teach.ireadabc.com');
}else{
callback('https://iteachabc.com');
if (window.air.engineInfo) {
if (window.air.engineInfo.isDev == 1) {
callback("https://staging-teach.ireadabc.com");
} else {
callback("https://iteachabc.com");
}
} else {
window.courseware.getEngineInfo(() => {
if (window.air.engineInfo.isDev == 1) {
callback("https://staging-teach.ireadabc.com");
} else {
callback("https://iteachabc.com");
}
});
}
......@@ -100,26 +98,36 @@ cc.Class({
cc.game.addPersistRootNode(this.node);
this.initListener();
const addressText = cc.find('middleLayer/ui/address');
const str = cc.sys.localStorage.getItem('ip');
console.log('str = ' + str);
const addressText = cc.find("middleLayer/ui/address");
const str = cc.sys.localStorage.getItem("ip");
console.log("str = " + str);
if (str) {
addressText.getComponent(cc.EditBox).string = str;
}
const nameText = cc.find('middleLayer/ui/bundleName');
const bundleName = cc.sys.localStorage.getItem('bundleName');
const nameText = cc.find("middleLayer/ui/bundleName");
const bundleName = cc.sys.localStorage.getItem("bundleName");
if (bundleName) {
nameText.getComponent(cc.EditBox).string = bundleName;
}
const courseIdNode = cc.find('middleLayer/ui/courseId');
const courseId = cc.sys.localStorage.getItem('courseId');
const courseIdNode = cc.find("middleLayer/ui/courseId");
const courseId = cc.sys.localStorage.getItem("courseId");
if (courseId) {
courseIdNode.getComponent(cc.EditBox).string = courseId;
}
global.middleLayer = cc.find('middleLayer').getComponent('middleLayer');
const uiNode = cc.find("middleLayer/ui");
uiNode.parent.getComponent(cc.Widget).updateAlignment();
const scale = Math.min(
uiNode.parent.width / uiNode.width,
uiNode.parent.height / uiNode.height
);
console.log('scale = ' + scale);
uiNode.scale = scale;
global.middleLayer = cc.find("middleLayer").getComponent("middleLayer");
middleLayer.log("middleLayer.log('像这样在这里打log')");
},
......@@ -131,42 +139,57 @@ cc.Class({
}
window.preloadBundleAndSourcesFlag = true;
cc.find("middleLayer/ui/ProgressLabel").active = true;
cc.find('middleLayer/ui/loadingProgress').active = true;
cc.find("middleLayer/ui/loadingProgress").active = true;
let platform = "web_desktop";
if (cc.sys.os == cc.sys.OS_IOS) {
platform = "ios";
} else if (cc.sys.os == cc.sys.OS_ANDROID) {
platform = "android";
}
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allbundles`, { orgid: 483, platform }, (datastr) => {
this.callNetworkApiGet(
`http://staging-teach.ireadabc.com`,
`/api/syllabus/v1/allbundles`,
{ orgid: 483, platform },
(datastr) => {
const data = JSON.parse(datastr);
if (data.rows && data.rows.length > 0) {
this.preloadCount += data.rows.length;
}
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allresources`, { orgid: 483 }, (datastr1) => {
this.callNetworkApiGet(
`http://staging-teach.ireadabc.com`,
`/api/syllabus/v1/allresources`,
{ orgid: 483 },
(datastr1) => {
const data1 = JSON.parse(datastr1);
if (data1.rows && data1.rows.length > 0) {
this.preloadCount += data1.rows.length;
}
console.log('data.rows = ' + JSON.stringify(data.rows));
console.log("data.rows = " + JSON.stringify(data.rows));
this.batchPreloadScene(data.rows);
this.preloadSource(data1.rows);
});
});
}
);
}
);
},
preloadSourceImman() {
// 测试用
cc.find("middleLayer/ui/ProgressLabel").active = true;
cc.find('middleLayer/ui/loadingProgress').active = true;
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/courseware/v1/getresources`, { courseid: 20894 }, (datastr1) => {
cc.find("middleLayer/ui/loadingProgress").active = true;
this.callNetworkApiGet(
`http://staging-teach.ireadabc.com`,
`/api/courseware/v1/getresources`,
{ courseid: 20894 },
(datastr1) => {
const data1 = JSON.parse(datastr1);
if (data1.rows && data1.rows.length > 0) {
this.preloadCount += data1.rows.length;
}
this.log('data1.rows = ' + JSON.stringify(data1.rows));
this.log("data1.rows = " + JSON.stringify(data1.rows));
this.preloadSource(data1.rows);
});
}
);
},
batchPreloadScene(scenes = []) {
......@@ -189,7 +212,10 @@ cc.Class({
}
return;
}
cc.assetManager.loadBundle(scene.bondleUrl, { version: scene.version }, (err, bundle) => {
cc.assetManager.loadBundle(
scene.bondleUrl,
{ version: scene.version },
(err, bundle) => {
console.log(`${scene.bondleUrl}---场景开始loadBundle----`);
if (!bundle) {
_this.loadedCount++;
......@@ -202,7 +228,10 @@ cc.Class({
}
return;
}
bundle.preloadScene(scene.sceneName, () => { }, () => {
bundle.preloadScene(
scene.sceneName,
() => {},
() => {
console.log(`${scene.sceneName}场景预加载结束`);
_this.loadedCount++;
_this.updateProcessBar();
......@@ -212,9 +241,11 @@ cc.Class({
load();
}, 1);
}
});
});
}
);
}
);
};
if (scenes && scenes.length > 0) {
load();
......@@ -229,7 +260,7 @@ cc.Class({
for (let i = 0; i < tempArr.length; i++) {
cc.assetManager.loadRemote(tempArr[i], (err, texture) => {
if (err) {
console.log(err)
console.log(err);
}
this.loadedCount++;
this.updateProcessBar();
......@@ -238,20 +269,23 @@ cc.Class({
}
});
}
}
};
batchLoad();
},
updateProcessBar() {
const label = cc.find("middleLayer/ui/ProgressLabel").getComponent(cc.Label);
const loadingProgress = cc.find('middleLayer/ui/loadingProgress');
const label = cc
.find("middleLayer/ui/ProgressLabel")
.getComponent(cc.Label);
const loadingProgress = cc.find("middleLayer/ui/loadingProgress");
label.string = `正在加载:${this.loadedCount} / ${this.preloadCount}`;
if (this.loadedCount > this.preloadCount * 0.99) {
cc.find("middleLayer/ui/ProgressLabel").active = false;
loadingProgress.active = false;
this.showLog("资源全部加载完成");
}
loadingProgress.getComponent(cc.ProgressBar).progress = this.loadedCount / this.preloadCount;
loadingProgress.getComponent(cc.ProgressBar).progress =
this.loadedCount / this.preloadCount;
},
asyncDelayLog(str) {
......@@ -264,10 +298,10 @@ cc.Class({
},
initListener() {
const exitBtn = cc.find('middleLayer/ExitBtn');
exitBtn.on('click', () => {
cc.find('middleLayer/BtnRight').active = false;
cc.find('middleLayer/BtnLeft').active = false;
const exitBtn = cc.find("middleLayer/ExitBtn");
exitBtn.on("click", () => {
cc.find("middleLayer/BtnRight").active = false;
cc.find("middleLayer/BtnLeft").active = false;
cc.tween(exitBtn)
.to(0.1, { scaleX: 0.4, scaleY: 0.6 })
......@@ -279,60 +313,58 @@ cc.Class({
// cc.director.getScene().destroy();
cc.audioEngine.stopAll();
window.courseware.freeAllOcMethod();
cc.director.loadScene("debug_shell", null, null, (err, scene) => {
});
cc.director.loadScene("debug_shell", null, null, (err, scene) => {});
})
.start();
});
cc.find('middleLayer/BtnRight').on('click', () => {
cc.find("middleLayer/BtnRight").on("click", () => {
this.goNextPage();
});
cc.find('middleLayer/BtnLeft').on('click', () => {
cc.find("middleLayer/BtnLeft").on("click", () => {
this.goPrePage();
});
cc.find('middleLayer/ui/BtnOpenOsmo').on('click', () => {
cc.find("middleLayer/ui/BtnOpenOsmo").on("click", () => {
window.courseware.openOsmo();
});
cc.find('middleLayer/ui/BtnCloseOsmo').on('click', () => {
cc.find("middleLayer/ui/BtnCloseOsmo").on("click", () => {
window.courseware.closeOsmo();
});
cc.find('middleLayer/ui/BtnOpenRecord').on('click', () => {
cc.find("middleLayer/ui/BtnOpenRecord").on("click", () => {
window.courseware.startRecord(1);
});
cc.find('middleLayer/ui/BtnCloseRecord').on('click', () => {
window.courseware.stopRecord(res => {
this.log('--------录音返回结果 stopRecord ------------');
this.log(JSON.stringify(res))
this.log('------------------------------');
cc.find("middleLayer/ui/BtnCloseRecord").on("click", () => {
window.courseware.stopRecord((res) => {
this.log("--------录音返回结果 stopRecord ------------");
this.log(JSON.stringify(res));
this.log("------------------------------");
});
});
cc.find('middleLayer/ui/BtnOpenTest').on('click', () => {
window.courseware.startTest('');
cc.find("middleLayer/ui/BtnOpenTest").on("click", () => {
window.courseware.startTest("");
});
cc.find('middleLayer/ui/BtnCloseTest').on('click', () => {
window.courseware.stopTest(res => {
this.log('--------录音评测返回结果 stopTest ---------');
this.log(JSON.stringify(res))
this.log('------------------------------');
cc.find("middleLayer/ui/BtnCloseTest").on("click", () => {
window.courseware.stopTest((res) => {
this.log("--------录音评测返回结果 stopTest ---------");
this.log(JSON.stringify(res));
this.log("------------------------------");
});
});
const BtnStartLocal = cc.find('middleLayer/ui/BtnStartLocal');
BtnStartLocal.on('click', () => {
const addressText = cc.find('middleLayer/ui/address');
const BtnStartLocal = cc.find("middleLayer/ui/BtnStartLocal");
BtnStartLocal.on("click", () => {
const addressText = cc.find("middleLayer/ui/address");
const str = addressText.getComponent(cc.EditBox).string;
cc.sys.localStorage.setItem('ip', str);
const address = str.split(':')[0];
const port = str.split(':')[0] | 8081;
cc.sys.localStorage.setItem("ip", str);
const address = str.split(":")[0];
const port = str.split(":")[0] | 8081;
this.localMode = true;
this.loadLocalBundle(address, port);
this.showWaitingLetters();
......@@ -340,46 +372,46 @@ cc.Class({
this.showDebugUI();
});
const BtnStartOnline = cc.find('middleLayer/ui/BtnStartOnline');
BtnStartOnline.on('click', () => {
const nameText = cc.find('middleLayer/ui/bundleName');
const BtnStartOnline = cc.find("middleLayer/ui/BtnStartOnline");
BtnStartOnline.on("click", () => {
const nameText = cc.find("middleLayer/ui/bundleName");
const bundleName = nameText.getComponent(cc.EditBox).string;
cc.sys.localStorage.setItem('bundleName', bundleName);
cc.sys.localStorage.setItem("bundleName", bundleName);
this.loadOnlineBundle(bundleName);
this.showDebugUI();
});
const BtnStartCourseWare = cc.find('middleLayer/ui/BtnStartCourseWare');
BtnStartCourseWare.on('click', () => {
const courseIdNode = cc.find('middleLayer/ui/courseId');
const BtnStartCourseWare = cc.find("middleLayer/ui/BtnStartCourseWare");
BtnStartCourseWare.on("click", () => {
const courseIdNode = cc.find("middleLayer/ui/courseId");
const courseId = courseIdNode.getComponent(cc.EditBox).string;
cc.sys.localStorage.setItem('courseId', courseId);
cc.sys.localStorage.setItem("courseId", courseId);
this.loadOnlineCourseWare(courseId);
this.showDebugUI();
});
const BtnLoad = cc.find('middleLayer/ui/BtnLoad');
BtnLoad.on('click', () => {
const BtnLoad = cc.find("middleLayer/ui/BtnLoad");
BtnLoad.on("click", () => {
this.preloadCount = 0;
this.loadedCount = 0;
cc.find("middleLayer/ui/ProgressLabel").active = true;
cc.find('middleLayer/ui/loadingProgress').active = true;
cc.find("middleLayer/ui/loadingProgress").active = true;
// this.preloadAll();
this.preloadSourceImman();
});
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', () => {
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.on("click", () => {
btnClose.active = false;
btnOpen.active = true;
consoleNode.active = false;
......@@ -394,7 +426,12 @@ cc.Class({
this.goTarIndexPage(this.courseIndex + 1);
},
goTarIndexPage(index) {
if (!this.courses || index == this.courseIndex || index < 0 || index > this.courses.length - 1) {
if (
!this.courses ||
index == this.courseIndex ||
index < 0 ||
index > this.courses.length - 1
) {
return;
}
......@@ -403,35 +440,39 @@ cc.Class({
this.courseIndex = index;
this.courseItem = this.courses[this.courseIndex];
if (this.courseIndex == 0) {
cc.find('middleLayer/BtnLeft').active = false;
cc.find("middleLayer/BtnLeft").active = false;
} else {
cc.find('middleLayer/BtnLeft').active = false;
cc.find("middleLayer/BtnLeft").active = false;
}
if (this.courseIndex == this.courses.length - 1) {
cc.find('middleLayer/BtnRight').active = false;
cc.find("middleLayer/BtnRight").active = false;
} else {
cc.find('middleLayer/BtnRight').active = true;
cc.find("middleLayer/BtnRight").active = true;
}
this.loadPageBundle();
},
log(str) {
const logStr = `${new Date().toLocaleString()}: ${str}`;
console.log(logStr);
const content = cc.instantiate(cc.find('middleLayer/ConsoleNode/content'));
const content = cc.instantiate(cc.find("middleLayer/ConsoleNode/content"));
content.active = true;
const label = content.getChildByName('label');
const label = content.getChildByName("label");
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.getComponent(cc.Layout).updateLayout();
},
hideUI() {
cc.find('middleLayer/ui').active = false;
cc.find("middleLayer/ui").active = false;
},
loadOnlineBundle(bundleName) {
this.hideUI();
this.showWaitingLetters();
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/template/v1/${bundleName}`, {}, (datastr) => {
this.callNetworkApiGet(
`http://staging-teach.ireadabc.com`,
`/api/template/v1/${bundleName}`,
{},
(datastr) => {
const data = JSON.parse(datastr);
let configData = null;
if (cc.sys.os == cc.sys.OS_IOS) {
......@@ -445,7 +486,8 @@ cc.Class({
const version = configData.version;
const bondleUrl = configData.bondleUrl;
this.loadBundle(sceneName, version, bondleUrl);
});
}
);
},
courses: null,
courseIndex: 0,
......@@ -458,29 +500,42 @@ cc.Class({
if (linkFlag === true) {
api = `/api/courseware/v1/${courseId}/eq/level/list`;
}
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, api, {}, (datastr) => {
this.callNetworkApiGet(
`http://staging-teach.ireadabc.com`,
api,
{},
(datastr) => {
const data = JSON.parse(datastr);
if (data.rows && data.rows.length > 0) {
this.courses = data.rows;
this.courseIndex = data.index || 0;
this.courseItem = data.rows[this.courseIndex];
}
if (this.courses && this.courses.length > 1 && this.courseIndex <= this.courses.length - 1) {
cc.find('middleLayer/BtnRight').active = true;
if (
this.courses &&
this.courses.length > 1 &&
this.courseIndex <= this.courses.length - 1
) {
cc.find("middleLayer/BtnRight").active = true;
}
if (this.courseIndex > 0) {
cc.find('middleLayer/BtnLeft').active = false;
cc.find("middleLayer/BtnLeft").active = false;
}
this.reWriteAir();
this.loadPageBundle();
});
}
);
},
loadLocalBundle(address, port) {
this.callNetworkApiGetLocal(`http://${address}:${port}`, '/dist/config.json', {}, (datastr) => {
this.callNetworkApiGetLocal(
`http://${address}:${port}`,
"/dist/config.json",
{},
(datastr) => {
const data = JSON.parse(datastr);
let sceneName = '';
let version = '';
let bondleUrl = '';
let sceneName = "";
let version = "";
let bondleUrl = "";
if (cc.sys.os == cc.sys.OS_IOS) {
sceneName = data.ios.sceneName;
version = data.ios.version;
......@@ -495,10 +550,13 @@ cc.Class({
bondleUrl = `http://${address}:${port}/dist/web_desktop/`;
}
this.loadBundle(sceneName, version, bondleUrl);
});
}
);
},
loadPageBundle() {
let sceneName, version, bondleUrl = "";
let sceneName,
version,
bondleUrl = "";
if (cc.sys.os == cc.sys.OS_IOS) {
sceneName = this.courseItem.conf.ios.sceneName;
version = this.courseItem.conf.ios.version;
......@@ -519,20 +577,23 @@ cc.Class({
this.currentBundleInfo = { sceneName, version, bondleUrl };
this.showMask();
this.showWaitingLetters();
cc.assetManager.loadBundle(bondleUrl, { version: version }, async (err, bundle) => {
cc.assetManager.loadBundle(
bondleUrl,
{ version: version },
async (err, bundle) => {
if (err) {
return this.asyncDelayLog(err);
}
bundle.loadScene(sceneName, null, null, (err, scene) => {
if (err) {
this.asyncDelayLog('err: ', err);
this.asyncDelayLog("err: ", err);
}
cc.audioEngine.stopAll();
cc.director.runScene(scene, null, () => {
console.log('sceneName = ' + sceneName);
const Canvas = cc.find('Canvas');
const middleLayer = cc.find('middleLayer');
cc.find('middleLayer/ExitBtn').active = true;
console.log("sceneName = " + sceneName);
const Canvas = cc.find("Canvas");
const middleLayer = cc.find("middleLayer");
cc.find("middleLayer/ExitBtn").active = true;
this.hideWaitingLetters();
this.hideMask();
Canvas.getComponent(cc.Widget).updateAlignment();
......@@ -540,7 +601,8 @@ cc.Class({
// this.showLog('middleLayer.scale = ' + middleLayer.scale);
});
});
});
}
);
},
reloadBundle() {
......@@ -550,16 +612,13 @@ cc.Class({
},
showMask() {
const mask = cc.find('middleLayer/mask');
const mask = cc.find("middleLayer/mask");
mask.active = true;
cc.tween(mask)
.set({ opacity: 0 })
.to(0.5, { opacity: 0 })
.start();
cc.tween(mask).set({ opacity: 0 }).to(0.5, { opacity: 0 }).start();
},
hideMask() {
const mask = cc.find('middleLayer/mask');
const mask = cc.find("middleLayer/mask");
mask.stopAllActions();
cc.tween(mask)
.set({ opacity: 0 })
......@@ -578,82 +637,102 @@ cc.Class({
}
this.log("===成功调用getData===" + this.courseItem.data);
callback && callback(data);
}
};
window.courseware.nextPage = () => {
this.goNextPage();
}
};
window.courseware.beforePage = () => {
this.goPrePage();
}
};
window.courseware.sendAnswer = (answerObj) => {
this.log("===成功调用sendAnswer===" + JSON.stringify(answerObj));
this.callNetworkApiPost(`http://staging-teach.ireadabc.com`, `/api/oxford/courseware/v1/${this.courseItem.id}/saveanswer`, answerObj, (data) => {
this.callNetworkApiPost(
`http://staging-teach.ireadabc.com`,
`/api/oxford/courseware/v1/${this.courseItem.id}/saveanswer`,
answerObj,
(data) => {
answerObj.callback && answerObj.callback(JSON.stringify(data.row));
});
}
);
};
window.courseware.getAnswer = (queryObj, callback) => {
this.log("===成功调用getAnswer===" + JSON.stringify(queryObj));
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/oxford/courseware/v1/${this.courseItem.id}/getanswer`, queryObj, (datastr) => {
this.callNetworkApiGet(
`http://staging-teach.ireadabc.com`,
`/api/oxford/courseware/v1/${this.courseItem.id}/getanswer`,
queryObj,
(datastr) => {
const data = JSON.parse(datastr);
callback && callback(JSON.stringify(data.rows));
});
}
);
};
},
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);
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);
return jsb.reflection.callStaticMethod(
"com/iplayabc/cocos/AppActivity",
"cocosWithNativeProtocol",
"(Ljava/lang/String;)Ljava/lang/String;",
paramStr
);
} else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_WINDOWS) {
console.log('汪汪汪')
console.log("汪汪汪");
} else {
console.error('非源生环境');
console.error("非源生环境");
}
},
showWaitingLetters() {
if (this.isShowWaiting) {
return;
}
this.isShowWaiting = true;
const layout = cc.find('middleLayer/layout');
const layout = cc.find("middleLayer/layout");
layout.removeAllChildren();
const canvas = cc.find("Canvas");
const bg = layout.addComponent(cc.Graphics);
bg.fillRect(-canvas.width / 2, -canvas.height / 2, canvas.width, canvas.height);
const laodingLayer = cc.find('middleLayer/loadingLayer');
bg.fillRect(
-canvas.width / 2,
-canvas.height / 2,
canvas.width,
canvas.height
);
const laodingLayer = cc.find("middleLayer/loadingLayer");
laodingLayer.active = true;
const loading = cc.find('middleLayer/loadingLayer/loading');
const anim = loading.getComponent(cc.Animation)
anim.play('loading')
const loading = cc.find("middleLayer/loadingLayer/loading");
const anim = loading.getComponent(cc.Animation);
anim.play("loading");
const script = cc.find('middleLayer/loadingLayer/progress').getComponent('progressScript');
const script = cc
.find("middleLayer/loadingLayer/progress")
.getComponent("progressScript");
script.setProgress(0);
const id = setInterval(() => {
console.log('changeObj.value: ', changeObj.value);
console.log("changeObj.value: ", changeObj.value);
script.setProgress(changeObj.value);
}, 1);
const changeObj = {value: 0};
const changeObj = { value: 0 };
cc.tween(changeObj)
.to(5, {value: 0.9})
.to(5, { value: 0.9 })
.call(() => {
clearInterval(id);
})
.start();
// const colorList = this.getRainbowColorList();
// const layout = cc.find('middleLayer/layout');
// layout.removeAllChildren();
......@@ -678,15 +757,13 @@ cc.Class({
// return width + node.width;
// }, 0);
// layout.width = totalWidth;
},
hideWaitingLetters() {
const layout = cc.find('middleLayer/layout');
const layout = cc.find("middleLayer/layout");
layout.active = false;
const laodingLayer = cc.find('middleLayer/loadingLayer');
const laodingLayer = cc.find("middleLayer/loadingLayer");
laodingLayer.active = false;
},
......@@ -703,7 +780,7 @@ cc.Class({
},
showDebugUI() {
cc.find('middleLayer/ConsoleNode/BtnOpen').active = true;
cc.find("middleLayer/ConsoleNode/BtnOpen").active = true;
},
showOneLog() {
......@@ -719,10 +796,7 @@ cc.Class({
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();
cc.tween(node).to(5, { y: this.node.height }).removeSelf().start();
setTimeout(() => {
this.logList.shift();
this.showOneLog();
......@@ -732,9 +806,9 @@ cc.Class({
exit() {
cc.game.removePersistRootNode(this.node);
cc.director.loadScene("emptyScene", () => {
this.callNativeFunction({ name: 'exit', value: '' });
this.callNativeFunction({ name: "exit", value: "" });
});
},
},
getRainbowColorList() {
return [
......@@ -756,5 +830,5 @@ cc.Class({
cc.color(255, 128, 0),
cc.color(255, 255, 0),
];
}
},
});
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