Commit 8b9dd890 authored by Tt's avatar Tt

逻辑处理

parent 541a830e
This diff is collapsed.
...@@ -361,7 +361,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -361,7 +361,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 根据火苗编号调整消防车位置 // 根据火苗编号调整消防车位置
// fire_0~fire_2 消防车位置 x=-400,fire_3~fire_5 消防车位置 x=-185 // fire_0~fire_2 消防车位置 x=-400,fire_3~fire_5 消防车位置 x=-185
// 并根据当前页码进行偏移 // 并根据当前页码进行偏移
const baseXList = [-400, -420, -400, -175, -215, -175] const baseXList = [-420, -430, -400, -195, -225, -175]
const baseX = baseXList[fireIndex]; const baseX = baseXList[fireIndex];
const targetX = baseX + 1920 * currentPage; const targetX = baseX + 1920 * currentPage;
...@@ -414,7 +414,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -414,7 +414,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
onFireSuccess() { onFireSuccess() {
pg.hw.playLocalAudio('score_success');
const fireNode = this.currentFireNode; const fireNode = this.currentFireNode;
// 从活跃火苗列表中移除当前火苗 --- 答题后操作 // 从活跃火苗列表中移除当前火苗 --- 答题后操作
const index = this.activeFireNodes.indexOf(fireNode); const index = this.activeFireNodes.indexOf(fireNode);
...@@ -442,10 +441,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -442,10 +441,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
pg.view.playDBAnimation(this.node_firetruck_flush, '收水', 1); pg.view.playDBAnimation(this.node_firetruck_flush, '收水', 1);
setTimeout(() => { this.scheduleOnce(() => {
this.node_firetruck_flush.active = false; this.node_firetruck_flush.active = false;
}, 2000);
this.touching = false; this.touching = false;
}, 1);
// 检查当前页面是否所有火苗都已处理完毕 // 检查当前页面是否所有火苗都已处理完毕
if (this.activeFireNodes.length === 0) { if (this.activeFireNodes.length === 0) {
...@@ -457,7 +456,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -457,7 +456,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
onFireFail() { onFireFail() {
pg.hw.playLocalAudio('score_fail');
const fireNode = this.currentFireNode; const fireNode = this.currentFireNode;
// 将火苗节点重新添加到活跃列表中,以便再次尝试 // 将火苗节点重新添加到活跃列表中,以便再次尝试
...@@ -469,6 +467,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -469,6 +467,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (fireNode) { if (fireNode) {
fireNode.active = true; fireNode.active = true;
} }
pg.view.playDBAnimation(this.node_firetruck_flush, '收水', 1);
this.scheduleOnce(() => {
this.node_firetruck_flush.active = false;
this.touching = false;
}, 1);
} }
nextPage() { nextPage() {
// 切换到下一页 // 切换到下一页
...@@ -569,6 +572,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -569,6 +572,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 录音动画定时器 // 录音动画定时器
private _voiceAniTimer: any = null; private _voiceAniTimer: any = null;
/**
* 显示或隐藏卡片
* @param show 是否显示卡片,默认为true
* @param recordState 录音状态,默认为'init'
*/
showCard(show: boolean = true, recordState: string = 'init') { showCard(show: boolean = true, recordState: string = 'init') {
if (show) { if (show) {
// 显示卡片 // 显示卡片
...@@ -582,12 +590,51 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -582,12 +590,51 @@ export default class SceneComponent extends MyCocosSceneComponent {
let btn_stop = pg.view.find(this.layout_speak, 'btn_stop'); let btn_stop = pg.view.find(this.layout_speak, 'btn_stop');
let btn_record_replay = pg.view.find(this.layout_speak, 'btn_record_replay'); let btn_record_replay = pg.view.find(this.layout_speak, 'btn_record_replay');
let bg_card = pg.view.find(this.layout_speak, 'bg_card'); let bg_card = pg.view.find(this.layout_speak, 'bg_card');
// 渲染卡片内容(语音按钮、图标、文字、进度)
if (recordState == 'init') {
this.renderCardContent(bg_card, currentData);
// 绑定按钮事件
this.bindCardButtonEvents(btn_start, btn_start_reset, btn_stop, btn_record_replay);
}
// 根据录音状态设置按钮显示
this.updateButtonsByRecordState(recordState, btn_start, btn_stop, btn_start_reset, btn_record_replay);
} else {
// 隐藏录音界面
this.layout_speak.active = false;
// 停止录音动画
this.stopVoiceAni();
}
}
/**
* 渲染卡片内容(语音按钮、图标、文字、进度)
* @param bg_card 卡片背景节点
* @param currentData 当前题目数据
*/
private renderCardContent(bg_card, currentData) {
let btn_voice = pg.view.find(bg_card, 'btn_voice'); let btn_voice = pg.view.find(bg_card, 'btn_voice');
let icon = pg.view.find(bg_card, 'icon'); let icon = pg.view.find(bg_card, 'icon');
let word = pg.view.find(bg_card, 'word'); let word = pg.view.find(bg_card, 'word');
let label_progress = pg.view.find(bg_card, 'label_progress'); let label_progress = pg.view.find(bg_card, 'label_progress');
// 任务1: 处理btn_voice按钮显示和音频播放 // 处理btn_voice按钮显示和音频播放
this.renderVoiceButton(btn_voice, currentData);
// 处理icon和word的显示逻辑
this.renderIconAndWord(icon, word, currentData);
// 设置进度显示
this.renderProgressLabel(label_progress);
}
/**
* 处理语音按钮的显示和事件绑定
* @param btn_voice 语音按钮节点
* @param currentData 当前题目数据
*/
private renderVoiceButton(btn_voice, currentData) {
if (currentData.audioUrl) { if (currentData.audioUrl) {
// 如果数据中有audio,显示语音按钮 // 如果数据中有audio,显示语音按钮
pg.view.visible(btn_voice, true); pg.view.visible(btn_voice, true);
...@@ -600,8 +647,15 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -600,8 +647,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 没有音频则隐藏按钮 // 没有音频则隐藏按钮
pg.view.visible(btn_voice, false); pg.view.visible(btn_voice, false);
} }
}
// 任务2: 处理icon和word的显示逻辑 /**
* 处理图标和文字的显示逻辑
* @param icon 图标节点
* @param word 文字节点
* @param currentData 当前题目数据
*/
private renderIconAndWord(icon, word, currentData) {
if (currentData.type === 'img') { if (currentData.type === 'img') {
// 如果类型是img,显示图片,隐藏文字 // 如果类型是img,显示图片,隐藏文字
pg.view.visible(icon, true); pg.view.visible(icon, true);
...@@ -619,24 +673,44 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -619,24 +673,44 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.view.setString(word, currentData.txt); pg.view.setString(word, currentData.txt);
} }
} }
}
// 任务3: 设置进度显示 /**
* 设置进度标签显示
* @param label_progress 进度标签节点
*/
private renderProgressLabel(label_progress) {
// 获取当前正确答题的数量和总题目数量 // 获取当前正确答题的数量和总题目数量
// 使用player.right表示录音返回结果不是tryagain的答题数据数量 // 使用player.right表示录音返回结果不是tryagain的答题数据数量
const correctAnswers = Game.getIns().player.right; const correctAnswers = Game.getIns().player.right;
const totalQuestions = Game.getIns().total; const totalQuestions = Game.getIns().total;
// 设置进度文本 (正确答题数量)/(总数) // 设置进度文本 (正确答题数量)/(总数)
pg.view.setString(label_progress, `${correctAnswers + 1}/${totalQuestions}`); pg.view.setString(label_progress, `${correctAnswers + 1}/${totalQuestions}`);
}
/**
* 绑定卡片按钮事件
// 绑定按钮事件 * @param btn_start 开始按钮节点
* @param btn_start_reset 重新开始按钮节点
* @param btn_stop 停止按钮节点
* @param btn_record_replay 回放按钮节点
*/
private bindCardButtonEvents(btn_start, btn_start_reset, btn_stop, btn_record_replay) {
pg.view.touchOn(btn_start, this.onTouchRecord, this); pg.view.touchOn(btn_start, this.onTouchRecord, this);
pg.view.touchOn(btn_start_reset, this.onTouchRecord, this); pg.view.touchOn(btn_start_reset, this.onTouchRecord, this);
pg.view.touchOn(btn_stop, this.onTouchRecordEnd, this); pg.view.touchOn(btn_stop, this.onTouchRecordEnd, this);
pg.view.touchOn(btn_record_replay, this.onTouchPlayRecord, this); pg.view.touchOn(btn_record_replay, this.onTouchPlayRecord, this);
}
// 根据录音状态显示不同的按钮 /**
* 根据录音状态更新按钮显示
* @param recordState 录音状态
* @param btn_start 开始按钮节点
* @param btn_stop 停止按钮节点
* @param btn_start_reset 重新开始按钮节点
* @param btn_record_replay 回放按钮节点
*/
private updateButtonsByRecordState(recordState, btn_start, btn_stop, btn_start_reset, btn_record_replay) {
switch (recordState) { switch (recordState) {
case 'init': // 初始状态,未录制 case 'init': // 初始状态,未录制
pg.hw.playLocalAudio('pop_card'); pg.hw.playLocalAudio('pop_card');
...@@ -671,12 +745,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -671,12 +745,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 停止录音动画,显示初始状态 // 停止录音动画,显示初始状态
this.stopVoiceAni(); this.stopVoiceAni();
} }
} else {
// 隐藏录音界面
this.layout_speak.active = false;
// 停止录音动画
this.stopVoiceAni();
}
} }
onTouchSpeakClose() { onTouchSpeakClose() {
this.showCard(false); this.showCard(false);
...@@ -746,7 +814,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -746,7 +814,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
"fluency": 84, "fluency": 84,
"integrity": 100, "integrity": 100,
"kernel_version": "3.7.1", "kernel_version": "3.7.1",
"overall": 83, "overall": 8,
"pronunciation": 88, "pronunciation": 88,
"resource_version": "2.3.11", "resource_version": "2.3.11",
"rhythm": 46, "rhythm": 46,
...@@ -836,8 +904,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -836,8 +904,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.log("recrodEnd!!!!!") this.log("recrodEnd!!!!!")
// 将当前题目ID添加到录音数据中 // 将当前题目ID添加到录音数据中
data.questionId = this.touchData.id; data.questionId = this.touchData.id;
// 保存录音数据
Game.getIns().player.addVoice(data);
// 获取评分和检查单词正确性 // 获取评分和检查单词正确性
let score = data.result.overall; let score = data.result.overall;
...@@ -853,15 +919,25 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -853,15 +919,25 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (score >= 80) { if (score >= 80) {
// 80分及以上,显示优秀提示(3星) // 80分及以上,显示优秀提示(3星)
this.updateTips(TIPS_STATE.EXCELLENT); this.updateTips(TIPS_STATE.EXCELLENT);
pg.hw.playLocalAudio('score_success');
// 保存录音数据
Game.getIns().player.addVoice(data);
} else if (score >= 60) { } else if (score >= 60) {
// 60-80分,显示不错提示(2星) // 60-80分,显示不错提示(2星)
this.updateTips(TIPS_STATE.NICE); this.updateTips(TIPS_STATE.NICE);
pg.hw.playLocalAudio('score_success');
// 保存录音数据
Game.getIns().player.addVoice(data);
} else if (score >= 10) { } else if (score >= 10) {
// 10-60分,显示加油提示(1星) // 10-60分,显示加油提示(1星)
this.updateTips(TIPS_STATE.COMEON); this.updateTips(TIPS_STATE.COMEON);
pg.hw.playLocalAudio('score_success');
// 保存录音数据
Game.getIns().player.addVoice(data);
} else { } else {
// 10分以下,显示再试一次提示(0星) // 10分以下,显示再试一次提示(0星)
this.updateTips(TIPS_STATE.TRYAGAIN); this.updateTips(TIPS_STATE.TRYAGAIN);
pg.hw.playLocalAudio('score_fail');
} }
// 增加正确计数 // 增加正确计数
......
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