Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SSIWB2504
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
SSIWB2504
Commits
6f6e8bc1
Commit
6f6e8bc1
authored
Aug 04, 2025
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(play): 添加列表项选择功能并优化页面标题
parent
ba561eae
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
28 deletions
+100
-28
play.component.ts
src/app/play/play.component.ts
+100
-28
No files found.
src/app/play/play.component.ts
View file @
6f6e8bc1
...
@@ -142,6 +142,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -142,6 +142,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// ------------ 游戏逻辑数据 ------------
// ------------ 游戏逻辑数据 ------------
m_moveElementArray
=
[]
m_moveElementArray
=
[]
m_gameOver
=
false
;
// 游戏结束标志
m_gameOver
=
false
;
// 游戏结束标志
selectList
=
[];
// 选中的项目列表
// ------------------------------------
// ------------------------------------
...
@@ -261,10 +262,10 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -261,10 +262,10 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
initBackground
()
this
.
initBackground
()
this
.
initListPage
();
this
.
initListPage
();
// 初始化退出按钮
// this.initBtnBack();
// // 初始化标题
// // 初始化标题
// this.initTitle();
// this.initTitle();
// // 初始化退出按钮
// this.initBtnBack();
// const partXList = this.g_formData.type == 0 ? [300 * this.g_mapScale, 700 * this.g_mapScale, 1100 * this.g_mapScale] : [700 * this.g_mapScale, 300 * this.g_mapScale, 1100 * this.g_mapScale];
// const partXList = this.g_formData.type == 0 ? [300 * this.g_mapScale, 700 * this.g_mapScale, 1100 * this.g_mapScale] : [700 * this.g_mapScale, 300 * this.g_mapScale, 1100 * this.g_mapScale];
// // 初始化第一部分内容(字母块)
// // 初始化第一部分内容(字母块)
// this.initPart1(partXList[0]);
// this.initPart1(partXList[0]);
...
@@ -352,6 +353,78 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -352,6 +353,78 @@ export class PlayComponent implements OnInit, OnDestroy {
layoutPage
.
ref
.
y
=
this
.
g_canvasHeight
/
2
;
layoutPage
.
ref
.
y
=
this
.
g_canvasHeight
/
2
;
layoutPage
.
ref
.
fillColor
=
'
rgba(0, 0, 0, 0)
'
;
layoutPage
.
ref
.
fillColor
=
'
rgba(0, 0, 0, 0)
'
;
this
.
initPageTitle
();
this
.
initListItem
();
// 渲染layout_page
this
.
render
(
layoutPage
.
ref
,
zIndexMap
.
card
);
}
/**
* 切换项目的选中状态
* @param itemNode 项目节点
* @param dataIndex 数据索引
*/
toggleItemSelection
(
itemNode
,
dataIndex
)
{
const
isSelected
=
itemNode
.
ref
.
isSelected
||
false
;
const
selectMark
=
itemNode
.
ref
.
selectMark
;
if
(
!
isSelected
)
{
// 选中状态:显示选择标记,添加到selectList
selectMark
.
visible
=
true
;
itemNode
.
ref
.
isSelected
=
true
;
if
(
!
this
.
selectList
.
includes
(
dataIndex
))
{
this
.
selectList
.
push
(
dataIndex
);
}
}
else
{
// 取消选中:隐藏选择标记,从selectList移除
selectMark
.
visible
=
false
;
itemNode
.
ref
.
isSelected
=
false
;
const
index
=
this
.
selectList
.
indexOf
(
dataIndex
);
if
(
index
>
-
1
)
{
this
.
selectList
.
splice
(
index
,
1
);
}
}
console
.
log
(
'
当前选中项目:
'
,
this
.
selectList
);
}
initPageTitle
()
{
// 创建标题背景图片元素
const
titleBgElement
=
this
.
g_cartoon
.
createCartoonElement
(
'
page_title_bg
'
,
'
MySprite
'
);
// 使用bg_title作为背景图片资源
titleBgElement
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
'
bg_title
'
));
// 设置背景图片的缩放比例
titleBgElement
.
ref
.
scaleX
=
this
.
g_mapScale
;
titleBgElement
.
ref
.
scaleY
=
this
.
g_mapScale
;
// 设置背景图片位置 - 水平居中,垂直在顶部
titleBgElement
.
ref
.
x
=
this
.
g_canvasWidth
/
2
;
titleBgElement
.
ref
.
y
=
40
*
this
.
g_mapScale
;
// 距离顶部100像素
// 创建标题文字元素
const
titleTextElement
=
this
.
g_cartoon
.
createCartoonElement
(
'
page_title_text
'
,
'
Label
'
);
// 设置文字内容
titleTextElement
.
ref
.
text
=
'
请选择本次的练习目标
'
;
// 设置字体大小
titleTextElement
.
ref
.
fontSize
=
32
*
this
.
g_mapScale
;
// 设置字体颜色为深色
titleTextElement
.
ref
.
fontColor
=
'
#FFFFFF
'
;
// 设置文字位置与背景图片相同
titleTextElement
.
ref
.
x
=
titleBgElement
.
ref
.
x
+
15
;
titleTextElement
.
ref
.
y
=
titleBgElement
.
ref
.
y
+
10
;
// 设置文本对齐方式为居中
titleTextElement
.
ref
.
textAlign
=
'
center
'
;
// 渲染背景图片和文字元素
this
.
render
(
titleBgElement
.
ref
,
zIndexMap
.
background
+
1
);
this
.
render
(
titleTextElement
.
ref
,
zIndexMap
.
background
+
2
);
}
initListItem
()
{
// // 创建list_item节点作为滑动列表容器
// // 创建list_item节点作为滑动列表容器
const
listItem
=
this
.
g_cartoon
.
createCartoonElement
(
'
list_item
'
,
'
ShapeRectNew
'
);
const
listItem
=
this
.
g_cartoon
.
createCartoonElement
(
'
list_item
'
,
'
ShapeRectNew
'
);
// 设置固定高度为800
// 设置固定高度为800
...
@@ -396,6 +469,10 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -396,6 +469,10 @@ export class PlayComponent implements OnInit, OnDestroy {
// 使用bg_danci作为卡片背景资源
// 使用bg_danci作为卡片背景资源
itemNode
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
'
bg_danci
'
));
itemNode
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
'
bg_danci
'
));
// 存储数据索引和选中状态
itemNode
.
ref
.
dataIndex
=
i
;
itemNode
.
ref
.
isSelected
=
false
;
// 计算子节点位置 - 基于左锚点的坐标计算
// 计算子节点位置 - 基于左锚点的坐标计算
// X坐标:从左到右排列,考虑间距,基于listItem的左边界
// X坐标:从左到右排列,考虑间距,基于listItem的左边界
const
itemX
=
listItem
.
ref
.
x
+
(
column
*
(
itemWidth
+
itemSpacing
))
+
(
itemWidth
/
2
);
const
itemX
=
listItem
.
ref
.
x
+
(
column
*
(
itemWidth
+
itemSpacing
))
+
(
itemWidth
/
2
);
...
@@ -421,26 +498,38 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -421,26 +498,38 @@ export class PlayComponent implements OnInit, OnDestroy {
// 设置文本对齐方式为居中
// 设置文本对齐方式为居中
textElement
.
ref
.
textAlign
=
'
center
'
;
textElement
.
ref
.
textAlign
=
'
center
'
;
// 添加选择标记(dui_hao图片)
const
selectMarkElement
=
this
.
g_cartoon
.
createCartoonElement
(
`list_item_select_
${
i
}
`
,
'
MySprite
'
);
selectMarkElement
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
'
dui_hao
'
));
// 放置在右下角位置(根据bg_danci尺寸280x185和dui_hao尺寸89x64计算)
selectMarkElement
.
ref
.
x
=
itemWidth
*
0.35
;
// 相对于itemNode的右下角
selectMarkElement
.
ref
.
y
=
itemHeight
*
0.25
;
selectMarkElement
.
ref
.
scaleX
=
itemWidth
/
itemNode
.
ref
.
width
;
selectMarkElement
.
ref
.
scaleY
=
itemHeight
/
itemNode
.
ref
.
height
;
selectMarkElement
.
ref
.
visible
=
false
;
// 初始时隐藏
itemNode
.
ref
.
selectMark
=
selectMarkElement
.
ref
;
// 保存引用
// 为子节点添加点击事件
// 为子节点添加点击事件
this
.
m_mapDownQueue
[
`list_item_
${
i
}
`
]
=
()
=>
{
this
.
m_mapDownQueue
[
`list_item_
${
i
}
`
]
=
()
=>
{
if
(
!
isDragging
)
{
if
(
!
isDragging
)
{
// 播放音效
// 播放音效
this
.
g_cartoon
.
playAudio
(
'
click
'
);
this
.
g_cartoon
.
playAudio
(
'
click
'
);
// 添加果冻动画效果
// 切换选中状态
this
.
toggleItemSelection
(
itemNode
,
i
);
}
}
};
};
// 渲染子节点和文字
// 渲染子节点、文字和选择标记
itemNode
.
ref
.
addChild
(
textElement
.
ref
)
itemNode
.
ref
.
addChild
(
textElement
.
ref
);
itemNode
.
ref
.
addChild
(
selectMarkElement
.
ref
);
listItem
.
ref
.
addChild
(
itemNode
.
ref
);
listItem
.
ref
.
addChild
(
itemNode
.
ref
);
// this.render(itemNode.ref, zIndexMap.card);
// this.render(textElement.ref, zIndexMap.card + 1);
}
}
// 添加滑动功能
// 添加滑动功能
// 订阅按下事件
// 订阅按下事件
this
.
subscribeMapDownEvent
(
'
list_item
'
,
(
e
)
=>
{
this
.
subscribeMapDownEvent
(
'
list_item
'
,
(
e
)
=>
{
console
.
log
(
"
list_item_down
"
,
e
);
//
console.log("list_item_down", e);
isDragging
=
false
;
isDragging
=
false
;
isPressed
=
true
;
// 设置按下状态为true
isPressed
=
true
;
// 设置按下状态为true
startX
=
this
.
g_clickX
;
startX
=
this
.
g_clickX
;
...
@@ -459,7 +548,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -459,7 +548,7 @@ export class PlayComponent implements OnInit, OnDestroy {
if
(
!
isPressed
)
{
if
(
!
isPressed
)
{
return
;
return
;
}
}
console
.
log
(
"
list_item_move
"
,
e
)
//
console.log("list_item_move", e)
// 计算移动距离
// 计算移动距离
const
deltaX
=
this
.
g_clickX
-
startX
;
const
deltaX
=
this
.
g_clickX
-
startX
;
...
@@ -480,7 +569,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -480,7 +569,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 更新list_item位置
// 更新list_item位置
listItem
.
ref
.
x
=
newX
;
listItem
.
ref
.
x
=
newX
;
console
.
log
(
"
listItem.ref.x
"
,
listItem
.
ref
.
x
)
//
console.log("listItem.ref.x", listItem.ref.x)
}
}
// 重新启用移动事件
// 重新启用移动事件
this
.
g_enableMapMove
=
true
;
this
.
g_enableMapMove
=
true
;
...
@@ -488,7 +577,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -488,7 +577,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 订阅抬起事件
// 订阅抬起事件
this
.
subscribeMapUpEvent
(
'
list_item
'
,
(
e
)
=>
{
this
.
subscribeMapUpEvent
(
'
list_item
'
,
(
e
)
=>
{
console
.
log
(
"
list_item_up
"
,
e
)
//
console.log("list_item_up", e)
isDragging
=
false
;
isDragging
=
false
;
isPressed
=
false
;
// 设置按下状态为false,停止move事件处理
isPressed
=
false
;
// 设置按下状态为false,停止move事件处理
// 重新启用事件处理
// 重新启用事件处理
...
@@ -497,8 +586,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -497,8 +586,6 @@ export class PlayComponent implements OnInit, OnDestroy {
// 渲染list_item
// 渲染list_item
this
.
render
(
listItem
.
ref
,
zIndexMap
.
card
);
this
.
render
(
listItem
.
ref
,
zIndexMap
.
card
);
// 渲染layout_page
this
.
render
(
layoutPage
.
ref
,
zIndexMap
.
card
);
}
}
/**
/**
...
@@ -1082,21 +1169,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -1082,21 +1169,6 @@ export class PlayComponent implements OnInit, OnDestroy {
btnElement
.
ref
.
scaleX
=
this
.
g_mapScale
;
btnElement
.
ref
.
scaleX
=
this
.
g_mapScale
;
btnElement
.
ref
.
scaleY
=
this
.
g_mapScale
;
btnElement
.
ref
.
scaleY
=
this
.
g_mapScale
;
// 确保标题背景元素存在
if
(
this
.
m_titleBgElement
)
{
// 计算按钮位置(标题背景的最左侧)
// 标题背景左边缘 = 标题背景X坐标 - 标题背景宽度/2
const
titleLeftEdge
=
this
.
m_titleBgElement
.
ref
.
x
-
this
.
m_titleBgElement
.
ref
.
width
*
this
.
m_titleBgElement
.
ref
.
scaleX
/
2
;
// 设置按钮的X坐标位置(按钮中心位于标题背景左边缘加上按钮宽度的一半) 额外偏移30像素
btnElement
.
ref
.
x
=
titleLeftEdge
+
btnElement
.
ref
.
width
*
btnElement
.
ref
.
scaleX
/
2
-
30
*
this
.
g_mapScale
;
// 设置按钮的Y坐标位置(与标题背景Y坐标相同)
btnElement
.
ref
.
y
=
this
.
m_titleBgElement
.
ref
.
y
;
}
else
{
// 如果标题背景元素不存在,使用默认位置
btnElement
.
ref
.
x
=
50
*
this
.
g_mapScale
+
btnElement
.
ref
.
width
*
btnElement
.
ref
.
scaleX
/
2
;
btnElement
.
ref
.
y
=
50
*
this
.
g_mapScale
+
btnElement
.
ref
.
height
*
btnElement
.
ref
.
scaleY
/
2
;
}
// 渲染按钮元素(使用比标题背景更高的zIndex确保按钮显示在上层)
// 渲染按钮元素(使用比标题背景更高的zIndex确保按钮显示在上层)
this
.
render
(
btnElement
.
ref
,
zIndexMap
.
background
+
2
);
this
.
render
(
btnElement
.
ref
,
zIndexMap
.
background
+
2
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment