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

feat: 选项

parent c2159e42
......@@ -128,5 +128,8 @@
}
}
},
"defaultProject": "ng-template-generator"
"defaultProject": "ng-template-generator",
"cli": {
"analytics": false
}
}
\ No newline at end of file
{
"ver": "1.1.0",
"uuid": "c551970e-b095-45f3-9f1d-25cde8b8deb1",
"uuid": "73588b7a-9fa6-4401-a693-8cb0a6c4e8e4",
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
......@@ -91,6 +91,84 @@ cc.Class({
if (this._onLoadFinishFunc && typeof (this._onLoadFinishFunc) == 'function') {
this._onLoadFinishFunc();
}
this.showQuestion();
},
initStatus() {
this.status = {
currentQuestionIdx: 0
}
},
initNodes() {
const tittleLabelNode = cc.find('Canvas/bgFrount/leef/TittleLabelNode');
tittleLabelNode.getComponent(cc.Label).string = this.data.tittleTxt;
},
initListeners() {
addButtonListener(cc.find('Canvas/BtnNode/BtnBefore'), () => {
if (this.status.currentQuestionIdx <= 0) {
return;
}
this.status.currentQuestionIdx--;
this.showQuestion();
});
addButtonListener(cc.find('Canvas/BtnNode/BtnNext'), () => {
if (this.status.currentQuestionIdx + 1 >= this.data.questionList.length) {
return;
}
this.status.currentQuestionIdx++;
this.showQuestion();
});
addButtonListener(cc.find('Canvas/BtnNode/BtnRefresh'), () => {
this.showQuestion();
});
},
updateBgSize() {
},
async showQuestion() {
this.showOptions();
await this.questionBoardDown();
},
showOptions() {
for (let i = 0; i < 4; i++) {
const optionNode = cc.find(`Canvas/optionNode_${i}`);
if (optionNode) {
optionNode.removeFromParent();
}
}
const optionList = this.data.questionList[this.status.currentQuestionIdx].optionList;
optionList.forEach(async (data, idx) => {
const optionNode = cc.instantiate(cc.find(`OptionNodeBase_${optionList.length}`));
optionNode.name = `optionNode_${idx}`;
optionNode.parent = cc.find('Canvas');
const posNode = cc.find(`Canvas/OptionPosListBase/Option_${optionList.length}_${idx}`)
optionNode.x = posNode.x;
optionNode.y = posNode.y;
const animeNode = await asyncLoadDragonBoneAnime(cc.find('OptionDragonBoneBaseNode', optionNode), data.optionDragonBone);
// await asyncPlayDragonBoneAnimation(cc.find('OptionDragonBoneBaseNode', optionNode), 'normal', 1);
});
},
async questionBoardDown() {
const questionLabel = cc.find('Canvas/QuestionLabelBg/QuestionLabelNode').getComponent(cc.Label);
questionLabel.string = this.data.questionList[this.status.currentQuestionIdx].questionTxt;
const labelBgNode = cc.find('Canvas/QuestionLabelBg');
await asyncTweenTo(labelBgNode, 1, { y: 263 });
},
async questionBoardUp() {
const labelBgNode = cc.find('Canvas/QuestionLabelBg');
await asyncTweenTo(labelBgNode, 1, { y: 463 });
},
});
module.exports = {
"tittleAudio": "http://staging-teach.cdn.ireadabc.com/23376490a9ba0f4a3fe0618fc1c935e1.mp3",
"tittleTxt": "I can do everything",
"questionList": [{
"questionAudio": "http://staging-teach.cdn.ireadabc.com/17edcaecd09a72a64a77480673cdc232.mp3",
"questionTxt": "I can stand up.",
"rightOptionIdx": 1,
"optionList": [{
"optionDragonBone": {
"skeJsonData": { "url": "" },
"texJsonData": { "url": "" },
"texPngData": { "url": "" }
},
"optionAudio": "http://staging-teach.cdn.ireadabc.com/17edcaecd09a72a64a77480673cdc232.mp3"
}, {
"optionDragonBone": {
"skeJsonData": { "url": "" },
"texJsonData": { "url": "" },
"texPngData": { "url": "" }
},
"optionAudio": "http://staging-teach.cdn.ireadabc.com/17edcaecd09a72a64a77480673cdc232.mp3"
}, {
"optionDragonBone": {
"skeJsonData": { "url": "" },
"texJsonData": { "url": "" },
"texPngData": { "url": "" }
},
"optionAudio": "http://staging-teach.cdn.ireadabc.com/17edcaecd09a72a64a77480673cdc232.mp3"
}]
}, {
"questionAudio": "http://staging-teach.cdn.ireadabc.com/17edcaecd09a72a64a77480673cdc232.mp3",
"questionTxt": "I can stand up.",
"rightOptionIdx": 1,
"optionList": [{
"optionDragonBone": {
"skeJsonData": { "url": "" },
"texJsonData": { "url": "" },
"texPngData": { "url": "" }
},
"optionAudio": "http://staging-teach.cdn.ireadabc.com/17edcaecd09a72a64a77480673cdc232.mp3"
}, {
"optionDragonBone": {
"skeJsonData": { "url": "" },
"texJsonData": { "url": "" },
"texPngData": { "url": "" }
},
"optionAudio": "http://staging-teach.cdn.ireadabc.com/17edcaecd09a72a64a77480673cdc232.mp3"
}, {
"optionDragonBone": {
"skeJsonData": { "url": "" },
"texJsonData": { "url": "" },
"texPngData": { "url": "" }
},
"optionAudio": "http://staging-teach.cdn.ireadabc.com/17edcaecd09a72a64a77480673cdc232.mp3"
}, {
"optionDragonBone": {
"skeJsonData": { "url": "" },
"texJsonData": { "url": "" },
"texPngData": { "url": "" }
},
"optionAudio": "http://staging-teach.cdn.ireadabc.com/17edcaecd09a72a64a77480673cdc232.mp3"
}]
}]
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "6a081092-5433-4e92-b7af-7734f74a9c2c",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.8",
"uuid": "ef71d5e0-2ae1-48aa-b6c0-27634345db4c",
"isPlugin": true,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -231,3 +231,105 @@ export async function asyncLoadImgByUrl(node, url) {
loadImgByUrl(node, url, resolve);
});
}
export function addButtonListener(btnNode, func) {
btnNode.on('click', async (btn) => {
if (btnNode.canNotClick) {
return;
}
btnNode.canNotClick = true;
playEffect('按钮');
await jelly(btnNode);
await func(btn);
btnNode.canNotClick = false;
});
}
export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJsonDataUrl }, texJsonData: { url: texJsonDataUrl }, texPngData: { url: texPngDataUrl } }) {
if (!texPngDataUrl || !texJsonDataUrl || !texPngDataUrl) {
return;
}
return new Promise((resolve, reject) => {
if (node.animaNode) {
node.animaNode.removeFromParent();
}
const animaNode = new cc.Node();
animaNode.name = 'animaNode';
animaNode.parent = node;
animaNode.active = true;
node.animaNode = animaNode;
const dragonDisplay = animaNode.addComponent(dragonBones.ArmatureDisplay);
// cc.assetManager.loadRemote(texPngDataUrl, (error, texture) => {
// cc.assetManager.loadAny({ url: texJsonDataUrl }, (error, atlasJson) => {
// cc.assetManager.loadAny({ url: skeJsonDataUrl }, (error, dragonBonesJson) => {
// const atlas = new dragonBones.DragonBonesAtlasAsset();
// atlas.atlasJson = JSON.stringify(atlasJson);
// atlas.texture = texture;
// const asset = new dragonBones.DragonBonesAsset();
// asset.dragonBonesJson = JSON.stringify(dragonBonesJson);
// dragonDisplay.dragonAtlasAsset = atlas;
// dragonDisplay.dragonAsset = asset;
// let armatureNames = dragonBonesJson.armature.map(data => data.name);
// if (armatureNames.length > 0) {
// dragonDisplay.armatureName = armatureNames[0];
// }
// resolve(animaNode);
// });
// });
// });
const loadTexture = new Promise((resolve, reject) => {
cc.assetManager.loadRemote(texPngDataUrl, (error, texture) => {
if (error) {
reject(error);
}
resolve(texture);
});
});
const loadTexJsonData = new Promise((resolve, reject) => {
cc.assetManager.loadAny({ url: texJsonDataUrl }, (error, atlasJson) => {
if (error) {
reject(error);
}
resolve(atlasJson);
});
});
const loadSkeJsonData = new Promise((resolve, reject) => {
cc.assetManager.loadAny({ url: skeJsonDataUrl }, (error, dragonBonesJson) => {
if (error) {
reject(error);
}
resolve(dragonBonesJson);
});
});
Promise.all([loadTexture, loadTexJsonData, loadSkeJsonData]).then(([texture, atlasJson, dragonBonesJson]) => {
const atlas = new dragonBones.DragonBonesAtlasAsset();
atlas.atlasJson = JSON.stringify(atlasJson);
atlas.texture = texture;
const asset = new dragonBones.DragonBonesAsset();
asset.dragonBonesJson = JSON.stringify(dragonBonesJson);
dragonDisplay.dragonAtlasAsset = atlas;
dragonDisplay.dragonAsset = asset;
let armatureNames = dragonBonesJson.armature.map(data => data.name);
if (armatureNames.length > 0) {
dragonDisplay.armatureName = armatureNames[0];
}
resolve(animaNode);
});
});
}
\ No newline at end of file
......@@ -11,7 +11,7 @@
"height": 154,
"platformSettings": {},
"subMetas": {
"option": {
"option_3": {
"ver": "1.0.4",
"uuid": "08a24fc8-782c-40d4-be3e-5123f1695dfb",
"rawTextureUuid": "e9bcc801-4c45-45ef-9761-a569328686c9",
......
{
"ver": "2.3.5",
"uuid": "7c942112-0d58-4846-a60c-0dd73b7abbd6",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 322,
"height": 115,
"platformSettings": {},
"subMetas": {
"option_4": {
"ver": "1.0.4",
"uuid": "8471267b-453c-4c90-9bcd-d086725c0376",
"rawTextureUuid": "7c942112-0d58-4846-a60c-0dd73b7abbd6",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 322,
"height": 115,
"rawWidth": 322,
"rawHeight": 115,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
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