Commit 528f51a3 authored by Tt's avatar Tt

feat(play): 添加检查按钮并根据选择状态更新

parent 6f6e8bc1
...@@ -143,6 +143,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -143,6 +143,7 @@ export class PlayComponent implements OnInit, OnDestroy {
m_moveElementArray = [] m_moveElementArray = []
m_gameOver = false; // 游戏结束标志 m_gameOver = false; // 游戏结束标志
selectList = []; // 选中的项目列表 selectList = []; // 选中的项目列表
checkBtnElement = null; // 检查按钮元素引用
// ------------------------------------ // ------------------------------------
...@@ -357,6 +358,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -357,6 +358,7 @@ export class PlayComponent implements OnInit, OnDestroy {
this.initListItem(); this.initListItem();
this.initCheckBtn();
// 渲染layout_page // 渲染layout_page
this.render(layoutPage.ref, zIndexMap.card); this.render(layoutPage.ref, zIndexMap.card);
...@@ -387,6 +389,9 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -387,6 +389,9 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
} }
// 更新按钮状态
this.updateCheckBtnState();
console.log('当前选中项目:', this.selectList); console.log('当前选中项目:', this.selectList);
} }
...@@ -402,7 +407,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -402,7 +407,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 设置背景图片位置 - 水平居中,垂直在顶部 // 设置背景图片位置 - 水平居中,垂直在顶部
titleBgElement.ref.x = this.g_canvasWidth / 2; titleBgElement.ref.x = this.g_canvasWidth / 2;
titleBgElement.ref.y = 40 * this.g_mapScale; // 距离顶部100像素 titleBgElement.ref.y = 40 * this.g_mapScale; // 距离顶部100像素
// 创建标题文字元素 // 创建标题文字元素
const titleTextElement = this.g_cartoon.createCartoonElement('page_title_text', 'Label'); const titleTextElement = this.g_cartoon.createCartoonElement('page_title_text', 'Label');
...@@ -422,7 +427,73 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -422,7 +427,73 @@ export class PlayComponent implements OnInit, OnDestroy {
this.render(titleBgElement.ref, zIndexMap.background + 1); this.render(titleBgElement.ref, zIndexMap.background + 1);
this.render(titleTextElement.ref, zIndexMap.background + 2); this.render(titleTextElement.ref, zIndexMap.background + 2);
} }
initCheckBtn() {
// 创建按钮元素
const checkBtnElement = this.g_cartoon.createCartoonElement('check_btn', 'MySprite');
// 根据selectList长度决定显示的按钮图片和文字
const updateButtonState = () => {
if (this.selectList.length >= 2) {
// 显示"开始游戏"按钮
checkBtnElement.ref.init(this.g_cartoon.images.get('kai_shi'));
} else {
// 显示"选择单词"按钮
checkBtnElement.ref.init(this.g_cartoon.images.get('xuan_ze'));
}
};
// 初始化按钮状态
updateButtonState();
// 设置按钮缩放
checkBtnElement.ref.scaleX = this.g_mapScale;
checkBtnElement.ref.scaleY = this.g_mapScale;
// 设置按钮位置 - 屏幕右下角
// kai_shi和xuan_ze的尺寸都是209x65
const buttonWidth = 209 * this.g_mapScale;
const buttonHeight = 65 * this.g_mapScale;
checkBtnElement.ref.x = this.g_canvasWidth - buttonWidth / 2 - 50 * this.g_mapScale; // 距离右边50像素
checkBtnElement.ref.y = this.g_canvasHeight - buttonHeight / 2 - 50 * this.g_mapScale; // 距离底部50像素
// 添加点击事件
this.m_mapDownQueue['check_btn'] = () => {
// 播放点击音效
this.g_cartoon.playAudio('sm-click');
if (this.selectList.length >= 2) {
// 开始游戏逻辑
console.log('开始游戏,选中的项目:', this.selectList);
// 这里可以添加开始游戏的具体逻辑
} else {
// 提示需要选择更多单词
console.log('请至少选择2个单词');
// 这里可以添加提示逻辑
}
};
// 保存按钮引用,用于状态更新
this.checkBtnElement = checkBtnElement;
// 渲染按钮
this.render(checkBtnElement.ref, zIndexMap.card + 2);
}
/**
* 更新检查按钮状态
* 根据selectList的长度更新按钮显示
*/
updateCheckBtnState() {
if (this.checkBtnElement) {
if (this.selectList.length >= 2) {
// 显示"开始游戏"按钮
this.checkBtnElement.ref.init(this.g_cartoon.images.get('kai_shi'));
} else {
// 显示"选择单词"按钮
this.checkBtnElement.ref.init(this.g_cartoon.images.get('xuan_ze'));
}
}
}
initListItem() { initListItem() {
// // 创建list_item节点作为滑动列表容器 // // 创建list_item节点作为滑动列表容器
......
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