Commit 8bc4d5d6 authored by liujiangnan's avatar liujiangnan

feat

parent 4f4ed69a
......@@ -57,7 +57,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.rootAttrTree = this.getComponent('Attributes');
this.initBg();
this.initUnitViewPager();
await this.createFiniteStateMachines();
this.createFiniteStateMachines();
const BackViewButtons = this.rootAttrTree.querySelectorAll('.back-view');
BackViewButtons.forEach(b => {
buttonOnClick(b, ()=> {
......@@ -227,175 +227,176 @@ export default class SceneComponent extends MyCocosSceneComponent {
cc.audioEngine.playMusic(audio, true);
}
createFiniteStateMachines() {
return new Promise((resolve) => {
let pid = 21228; // 本地测试用
let pname = 'level 1'; // 本地测试用
const middleLayer = cc.find('middleLayer');
if(middleLayer) {
pid = middleLayer.getComponent('middleLayer').getData('NJ_MonkyTree');
pname = middleLayer.getComponent('middleLayer').getData('NJ_MonkyTree_name');
if (pname) {
pname = pname.toLowerCase().trim();
}
let pid = 21228; // 本地测试用
let pname = 'level 1'; // 本地测试用
const middleLayer = cc.find('middleLayer');
if(middleLayer) {
pid = middleLayer.getComponent('middleLayer').getData('NJ_MonkyTree');
pname = middleLayer.getComponent('middleLayer').getData('NJ_MonkyTree_name');
if (pname) {
pname = pname.toLowerCase().trim();
}
// 根据不同级别渲染图片
this.drawLevelItemPic(pname);
const operationState = {
id: 'operation',
initial: 'UnitView',
context: {
UnitViewData: null,
currentDataset: null,
},
states: {
UnitView: {
entry: (ctx, event) => {
console.log('entry UnitView stage');
this.UnitView.active = true;
if (pname == 'level 1') {
this.playBgMusic(this.bgMusic2);
} else if (pname == 'level 2') {
this.playBgMusic(this.bgMusic3);
} else if (pname == 'level 3') {
this.playBgMusic(this.bgMusic4);
}
// 根据不同级别渲染图片
this.drawLevelItemPic(pname);
const operationState = {
id: 'operation',
initial: 'UnitView',
context: {
UnitViewData: null,
currentDataset: null,
},
states: {
UnitView: {
entry: (ctx, event) => {
console.log('entry UnitView stage');
this.UnitView.active = true;
if (pname == 'level 1') {
this.playBgMusic(this.bgMusic2);
} else if (pname == 'level 2') {
this.playBgMusic(this.bgMusic3);
} else if (pname == 'level 3') {
this.playBgMusic(this.bgMusic4);
}
const lessonsBtn = this.rootAttrTree.querySelectorAll('.lesson-button');
lessonsBtn.forEach((b, idx) => {
const attr: Attributes = b.getComponent('Attributes');
const lock = cc.find('icon_key', b);
lock.active = true;
const titleNode = attr.querySelector('.title');
const outline = '#000';
const name = "";
const richText = titleNode.getComponent(cc.RichText);
if ( !richText.fontSizeBase ) {
richText.fontSizeBase = richText.fontSize;
}
const lessonsBtn = this.rootAttrTree.querySelectorAll('.lesson-button');
lessonsBtn.forEach((b, idx) => {
const attr: Attributes = b.getComponent('Attributes');
const lock = cc.find('icon_key', b);
lock.active = true;
const titleNode = attr.querySelector('.title');
const outline = '#000';
const name = "";
const richText = titleNode.getComponent(cc.RichText);
if ( !richText.fontSizeBase ) {
richText.fontSizeBase = richText.fontSize;
}
richText.fontSize = richText.fontSizeBase;
if (name.length > 14) {
richText.fontSize = richText.fontSizeBase * 0.7;
}
richText.font = cc.find("Canvas/res/font/BRLNSDB").getComponent(cc.Label).font;
titleNode.getComponent(cc.RichText).string = `<outline align=top color=${outline}
width=4>${name}</outline>`
// const pos = exchangeNodePos(b, titleNode);
// titleNode.x = pos.x;
// titleNode.y = pos.y;
// titleNode.parent = b;
// const textPng = this.getSprNode("Game");
// titleNode.addChild(textPng);
// textPng.y = -titleNode.height;
// textPng.active = false;
// titleNode.textPng = textPng;
});
callNetworkApiGet('/api/syllabus/v2/tree', { pid, deep: 1 }, (resp: any) => {
resp = JSON.parse(resp);
if (resp.msg == 'success') {
let { rows } = resp;
const list = rows.reduce((result, next) => {
const { children } = next;
// has_courseware true 是文件夹
let childrenList = children.filter(r => r.has_courseware)
if (childrenList.length > 3) {
childrenList.length = 3
richText.fontSize = richText.fontSizeBase;
if (name.length > 14) {
richText.fontSize = richText.fontSizeBase * 0.7;
}
richText.font = cc.find("Canvas/res/font/BRLNSDB").getComponent(cc.Label).font;
titleNode.getComponent(cc.RichText).string = `<outline align=top color=${outline}
width=4>${name}</outline>`
// const pos = exchangeNodePos(b, titleNode);
// titleNode.x = pos.x;
// titleNode.y = pos.y;
// titleNode.parent = b;
// const textPng = this.getSprNode("Game");
// titleNode.addChild(textPng);
// textPng.y = -titleNode.height;
// textPng.active = false;
// titleNode.textPng = textPng;
});
callNetworkApiGet('/api/syllabus/v2/tree', { pid, deep: 1 }, (resp: any) => {
resp = JSON.parse(resp);
if (resp.msg == 'success') {
let { rows } = resp;
const list = rows.reduce((result, next) => {
const { children } = next;
// has_courseware true 是文件夹
let childrenList = children.filter(r => r.has_courseware)
if (childrenList.length > 3) {
childrenList.length = 3
}
result = [...result, ...childrenList]
return result
}, []);
// rows = rows.filter(r => !r.has_courseware)
lessonsBtn.forEach((b, idx) => {
const attr: Attributes = b.getComponent('Attributes');
const index = attr.attrMap['index'];
const lesson = list[index];
const lock = cc.find('icon_key', b);
// console.log("===liu2===", index);
// if (index == 0) {
// lock.active = false;
// } else {
lock.active = true;
// }
const titleNode = attr.querySelector('.title');
if (!lesson) {
return;
}
b.attr({ 'data_id': lesson.id });
b.attr({ 'data_pid': lesson.pid });
if (index == 0 || ( this.kidInfo && this.kidInfo.unlock_syllabuses?.includes(lesson.id+"") && (index-0) % 3 === 0)) {
lock.active = false;
const outline = this.drawTextBorder(pname, b.name);
const name = lesson.name;
const richText = titleNode.getComponent(cc.RichText);
if ( !richText.fontSizeBase ) {
richText.fontSizeBase = richText.fontSize;
}
result = [...result, ...childrenList]
return result
}, []);
// rows = rows.filter(r => !r.has_courseware)
lessonsBtn.forEach((b, idx) => {
const attr: Attributes = b.getComponent('Attributes');
const index = attr.attrMap['index'];
const lesson = list[index];
const lock = cc.find('icon_key', b);
// console.log("===liu2===", index);
// if (index == 0) {
// lock.active = false;
// } else {
lock.active = true;
// }
const titleNode = attr.querySelector('.title');
if (!lesson) {
return;
richText.fontSize = richText.fontSizeBase;
if (name.length > 14) {
richText.fontSize = richText.fontSizeBase * 0.7;
}
b.attr({ 'data_id': lesson.id });
b.attr({ 'data_pid': lesson.pid });
if (index == 0 || ( this.kidInfo && this.kidInfo.unlock_syllabuses?.includes(lesson.id+"") && (index-0) % 3 === 0)) {
lock.active = false;
const outline = this.drawTextBorder(pname, b.name);
richText.font = cc.find("Canvas/res/font/BRLNSDB").getComponent(cc.Label).font;
const name = lesson.name;
const richText = titleNode.getComponent(cc.RichText);
if ( !richText.fontSizeBase ) {
richText.fontSizeBase = richText.fontSize;
}
richText.fontSize = richText.fontSizeBase;
if (name.length > 14) {
richText.fontSize = richText.fontSizeBase * 0.7;
}
richText.font = cc.find("Canvas/res/font/BRLNSDB").getComponent(cc.Label).font;
titleNode.getComponent(cc.RichText).string = `<outline align=top color=${outline}
width=4>${name}</outline>`;
titleNode.getComponent(cc.RichText).string = `<outline align=top color=${outline}
width=4>${name}</outline>`;
const pos = exchangeNodePos(b, titleNode);
titleNode.x = pos.x;
titleNode.y = pos.y;
titleNode.parent = b;
const pos = exchangeNodePos(b, titleNode);
titleNode.x = pos.x;
titleNode.y = pos.y;
titleNode.parent = b;
// delayCall(1, () => {
// delayCall(1, () => {
// console.log('idx: ', idx);
// console.log("传入按钮名2:", name);
// console.log('idx: ', idx);
// console.log("传入按钮名2:", name);
// titleNode.getComponent(cc.RichText).string = `<outline align=top color=${outline}
// width=4>${name}</outline>`;
// console.log("显示按钮名2:", titleNode.getComponent(cc.RichText).string);
// titleNode.getComponent(cc.RichText).string = `<outline align=top color=${outline}
// width=4>${name}</outline>`;
// console.log("显示按钮名2:", titleNode.getComponent(cc.RichText).string);
// })
}
// })
}
});
ctx.UnitViewData = list;
ctx.currentDataset = list;
}
});
ctx.UnitViewData = list;
ctx.currentDataset = list;
}
resolve();
});
},
exit: () => {
// console.log('exit UnitView stage');
},
invoke: {
src: (ctx, event) => {
if (window && window["air"]) {
window["air"].hideAirClassLoading();
}
},
},
}
};
});
const operationMachine = createMachine(operationState);
},
exit: () => {
// console.log('exit UnitView stage');
},
invoke: {
src: (ctx, event) => {
}
},
},
}
};
this.gameMachineService = interpret(operationMachine).onTransition((state) => {
console.log(1, state);
});
const operationMachine = createMachine(operationState);
this.gameMachineService = interpret(operationMachine).onTransition((state) => {
console.log(1, state);
});
}
......
......@@ -89,17 +89,7 @@ export class MyCocosSceneComponent extends cc.Component {
const preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList);
cc.assetManager.loadAny(preloadArr, null, null, async (err, data) => {
if (window && window["air"]) {
// window["air"].onCourseInScreen = (next) => {
// window["air"].isCourseInScreen = true;
// this.onLoadEnd();
// next();
// };
await this.onLoadEnd();
window["air"].hideAirClassLoading();
} else {
this.onLoadEnd();
}
this.onLoadEnd();
cc.debug.setDisplayStats(false);
});
......
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