Commit c5832a8f authored by 李维's avatar 李维

Done

parent ab33b3cf
......@@ -5,16 +5,24 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
@property({type: cc.Node, displayName: "开始按钮"})
startBtn: cc.Node = null;
@property({type: cc.Node, displayName: "结束按钮"})
stopBtn: cc.Node = null;
@property({type: cc.Node, displayName: "复制信息"})
copyInfoBtn: cc.Node = null;
@property({type: cc.Node, displayName: "信息输出"})
outputBox: cc.Node = null;
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
this._imageResList.push({ url: this.data.pic_url });
this._imageResList.push({ url: this.data.pic_url_2 });
}
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
this._audioResList.push({ url: this.data.audio_url });
}
addPreloadAnima() {
......@@ -23,22 +31,21 @@ export default class SceneComponent extends MyCocosSceneComponent {
async onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView();
this.initListener();
}
_cantouch = null;
initData() {
// 所有全局变量 默认都是null
this._cantouch = true;
}
comTotal = null;
comSuccess = null;
comFail = null;
initView() {
this.initBg();
this.initPic();
this.initBtn();
this.initIcon();
this.comTotal = cc.find("Canvas/rightSummaryInfo/total").getComponent(cc.Label);
this.comSuccess = cc.find("Canvas/rightSummaryInfo/success").getComponent(cc.Label);
this.comFail = cc.find("Canvas/rightSummaryInfo/fail").getComponent(cc.Label);
this.initData();
}
initBg() {
......@@ -51,131 +58,70 @@ export default class SceneComponent extends MyCocosSceneComponent {
initPic() {
const canvas = cc.find('Canvas');
const maxW = canvas.width * 0.7;
this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
const picNode1 = sprNode;
picNode1.scale = maxW / picNode1.width;
picNode1.baseX = picNode1.x;
canvas.addChild(picNode1);
this.pic1 = picNode1;
const labelNode = new cc.Node();
labelNode.color = cc.Color.YELLOW;
const label = labelNode.addComponent(cc.Label);
label.string = this.data.text;
label.fontSize = 60;
label.lineHeight = 60;
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
picNode1.addChild(labelNode);
});
this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
const picNode2 = sprNode;
picNode2.scale = maxW / picNode2.width;
canvas.addChild(picNode2);
picNode2.x = canvas.width;
picNode2.baseX = picNode2.x;
this.pic2 = picNode2;
const labelNode = new cc.Node();
const label = labelNode.addComponent(cc.RichText);
const size = 60
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
label.lineHeight = size;
picNode2.addChild(labelNode);
});
}
initIcon() {
const iconNode = this.getSprNode('icon');
iconNode.zIndex = 5;
iconNode.anchorX = 1;
iconNode.anchorY = 1;
iconNode.parent = cc.find('Canvas');
iconNode.x = iconNode.parent.width / 2 - 10;
iconNode.y = iconNode.parent.height / 2 - 10;
iconNode.on(cc.Node.EventType.TOUCH_START, () => {
this.playAudioByUrl(this.data.audio_url);
initBtn() {
this.startBtn.on("click", ()=>{
this.startCheck();
})
}
curPage = null;
initBtn() {
this.curPage = 0;
const bottomPart = cc.find('Canvas/bottomPart');
bottomPart.zIndex = 5; // 提高层级
bottomPart.x = bottomPart.parent.width / 2;
bottomPart.y = -bottomPart.parent.height / 2;
const leftBtnNode = bottomPart.getChildByName('btn_left');
//节点中添加了button组件 则可以添加click事件监听
leftBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 0) {
return;
initData() {
console.log(this.data);
}
this.curPage = 0
this.leftMove();
this.playLocalAudio('btn');
async startCheck() {
const audioUrl = [];
this.data.forEach(item => {
audioUrl.push({
id: item.id,
type: "cn",
name: item.text_cn,
audio_url: item.audio_cn_url
})
audioUrl.push({
id: item.id,
type: "en",
name: item.text_en,
audio_url: item.audio_url
})
});
const rightBtnNode = bottomPart.getChildByName('btn_right');
//节点中添加了button组件 则可以添加click事件监听
rightBtnNode.on('click', () => {
if (!this._cantouch) {
return;
this.summaryInfo_now = 0;
this.summaryInfo_total = audioUrl.length;
this.summaryInfo_success = 0;
this.summaryInfo_fail = 0;
this.updateSummaryInfo()
for(let i=0; i<audioUrl.length; i++) {
const res = await this.testAudioPlay(audioUrl[i].audio_url)
if(res) {
this.inputText(`播放成功! id:${audioUrl[i].id} 资源名:${audioUrl[i].name}`);
this.summaryInfo_success ++;
} else {
this.inputText(`播放失败! id:${audioUrl[i].id} 资源名:${audioUrl[i].name}`);
console.log(`Fail: id=${audioUrl[i].id} type=${audioUrl[i].type}`)
this.summaryInfo_fail ++;
}
if (this.curPage == 1) {
return;
this.updateSummaryInfo()
}
this.curPage = 1
this.rightMove();
// 游戏结束时需要调用这个方法通知系统作业完成
onHomeworkFinish();
this.playLocalAudio('btn');
})
this.inputText(`检测完成,总计【${this.summaryInfo_total}】 成功【${this.summaryInfo_success}】 失败【${this.summaryInfo_fail}】`);
}
leftMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
// 输入文字
inputText(str) {
this.outputBox.getComponent(cc.Label).string = str;
}
rightMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
summaryInfo_now = 0;
summaryInfo_total = 0;
summaryInfo_success = 0;
summaryInfo_fail = 0;
updateSummaryInfo() {
this.comTotal.string = `进度:${this.summaryInfo_now}/${this.summaryInfo_total}`
this.comSuccess.string = `成功:${this.summaryInfo_success}`
this.comFail.string = `失败:${this.summaryInfo_fail}`
}
// update (dt) {},
......@@ -192,4 +138,33 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
})
}
_intervalId = null;
testAudioPlay(audio_url) {
return new Promise((resovle, reject) => {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
if(this._intervalId != null) {
clearInterval(this._intervalId);
this._intervalId = null;
}
let count = 0;
this._intervalId = setInterval(() => {
if(cc.audioEngine.getCurrentTime(audioId) > 0) {
clearInterval(this._intervalId);
this._intervalId = null;
resovle(true)
} else {
if(count > 50) {
clearInterval(this._intervalId);
this._intervalId = null;
resovle(false)
} else {
count++
}
}
}, 200);
});
})
}
}
{
"ver": "2.3.5",
"uuid": "efa5fa09-a4dd-4bfc-ab7e-17c19f85408f",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 366,
"height": 336,
"platformSettings": {},
"subMetas": {
"1orange": {
"ver": "1.0.4",
"uuid": "43d1e79d-6de8-4dcb-b8ce-d767df7913aa",
"rawTextureUuid": "efa5fa09-a4dd-4bfc-ab7e-17c19f85408f",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": -0.5,
"trimX": 0,
"trimY": 1,
"width": 366,
"height": 335,
"rawWidth": 366,
"rawHeight": 336,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "9a79969a-0506-48d4-bc98-3c05d109b027",
"uuid": "75197063-3a11-4d30-b364-6677df12ca0f",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 61,
"height": 67,
"width": 1920,
"height": 1080,
"platformSettings": {},
"subMetas": {
"btn_left": {
"bg_dark": {
"ver": "1.0.4",
"uuid": "ce19457d-e8f3-4c38-ae3e-d4b99208ddb5",
"rawTextureUuid": "9a79969a-0506-48d4-bc98-3c05d109b027",
"uuid": "d1add30b-0179-4a8b-8826-d6738d26f18f",
"rawTextureUuid": "75197063-3a11-4d30-b364-6677df12ca0f",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 61,
"height": 67,
"rawWidth": 61,
"rawHeight": 67,
"width": 1920,
"height": 1080,
"rawWidth": 1920,
"rawHeight": 1080,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
{
"ver": "2.3.5",
"uuid": "d582359e-924e-4ee9-9964-1fc4bb417e71",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 61,
"height": 67,
"platformSettings": {},
"subMetas": {
"btn_right": {
"ver": "1.0.4",
"uuid": "e5a2dbaa-a677-4a32-90d7-a1b057d7fb59",
"rawTextureUuid": "d582359e-924e-4ee9-9964-1fc4bb417e71",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -0.5,
"offsetY": 0.5,
"trimX": 0,
"trimY": 0,
"width": 60,
"height": 66,
"rawWidth": 61,
"rawHeight": 67,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "18d07592-51a9-421e-8972-0f67b68d29e1",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 144,
"height": 144,
"platformSettings": {},
"subMetas": {
"icon": {
"ver": "1.0.4",
"uuid": "6fbc30a8-3c49-44ae-8ba4-7f56f385b78a",
"rawTextureUuid": "18d07592-51a9-421e-8972-0f67b68d29e1",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": -0.5,
"trimX": 3,
"trimY": 2,
"width": 138,
"height": 141,
"rawWidth": 144,
"rawHeight": 144,
"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