Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dg18_tianci
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
dg18_tianci
Commits
ba3576ae
Commit
ba3576ae
authored
Jan 03, 2024
by
limingzhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 文本自适应
parent
bb4d34b6
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
388 additions
and
87 deletions
+388
-87
dg18_tianci.fire
assets/dg18_tianci/scene/dg18_tianci.fire
+283
-87
dg18_tianci.ts
assets/dg18_tianci/scene/dg18_tianci.ts
+105
-0
No files found.
assets/dg18_tianci/scene/dg18_tianci.fire
View file @
ba3576ae
This diff is collapsed.
Click to expand it.
assets/dg18_tianci/scene/dg18_tianci.ts
View file @
ba3576ae
...
@@ -167,12 +167,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -167,12 +167,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
lastY
=
null
;
lastY
=
null
;
}
}
if
(
data
.
itemType
==
'
text
'
)
{
if
(
data
.
itemType
==
'
text
'
)
{
data
.
text
+=
'
aaa bbb cc dd
'
;
let
item
=
pg
.
view
.
clone
(
this
.
item_battery_text
)
let
item
=
pg
.
view
.
clone
(
this
.
item_battery_text
)
item
.
active
=
true
;
item
.
active
=
true
;
item
.
x
=
0
;
item
.
x
=
0
;
let
item_text
=
pg
.
view
.
find
(
item
,
'
item_text
'
);
let
item_text
=
pg
.
view
.
find
(
item
,
'
item_text
'
);
pg
.
view
.
setString
(
pg
.
view
.
find
(
item_text
,
'
text
'
),
data
.
text
)
pg
.
view
.
setString
(
pg
.
view
.
find
(
item_text
,
'
text
'
),
data
.
text
)
this
.
setItemText
(
item_text
,
data
.
text
);
pg
.
view
.
setColor
(
pg
.
view
.
find
(
item_text
,
'
text
'
),
"
#FEFE24
"
)
pg
.
view
.
setColor
(
pg
.
view
.
find
(
item_text
,
'
text
'
),
"
#FEFE24
"
)
pg
.
view
.
setColor
(
pg
.
view
.
find
(
item_text
,
'
text_1
'
),
"
#FEFE24
"
)
pg
.
view
.
setColor
(
pg
.
view
.
find
(
item_text
,
'
text_2
'
),
"
#FEFE24
"
)
for
(
let
n
=
1
;
n
<=
6
;
n
++
)
{
for
(
let
n
=
1
;
n
<=
6
;
n
++
)
{
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
'
bg/img_battery
'
+
n
),
false
)
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
'
bg/img_battery
'
+
n
),
false
)
...
@@ -337,6 +344,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -337,6 +344,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
node
.
y
=
targetData
.
pos
.
y
;
node
.
y
=
targetData
.
pos
.
y
;
let
text
=
pg
.
view
.
find
(
node
,
'
text
'
);
let
text
=
pg
.
view
.
find
(
node
,
'
text
'
);
text
.
active
=
true
;
let
text1
=
pg
.
view
.
find
(
node
,
'
text_1
'
);
let
text2
=
pg
.
view
.
find
(
node
,
'
text_2
'
);
text1
.
active
=
false
;
text2
.
active
=
false
;
pg
.
view
.
setColor
(
text
,
'
#1D8B38
'
)
pg
.
view
.
setColor
(
text
,
'
#1D8B38
'
)
text
.
getComponent
(
cc
.
Label
).
fontSize
=
targetData
.
fontSize
;
text
.
getComponent
(
cc
.
Label
).
fontSize
=
targetData
.
fontSize
;
text
.
getComponent
(
cc
.
Label
).
overflow
=
cc
.
Label
.
Overflow
.
NONE
;
text
.
getComponent
(
cc
.
Label
).
overflow
=
cc
.
Label
.
Overflow
.
NONE
;
...
@@ -453,6 +467,97 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -453,6 +467,97 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
});
})
})
}
}
async
setItemText
(
itemText
,
text
)
{
const
maxW
=
180
;
const
disH
=
26
;
const
baseY
=
4
;
const
labelNode1
=
cc
.
find
(
"
text_1
"
,
itemText
);
const
labelNode2
=
cc
.
find
(
"
text_2
"
,
itemText
);
const
label1
=
labelNode1
.
getComponent
(
cc
.
Label
);
const
label2
=
labelNode2
.
getComponent
(
cc
.
Label
);
const
textArr
=
text
.
split
(
'
'
);
let
isLabel1Max
=
false
;
let
isLabel2Max
=
false
;
const
checkLabelWidthMax
=
async
(
label
,
text
)
=>
{
label
.
string
=
text
;
await
asyncDelay
(
0.01
);
const
labelWidth
=
label
.
node
.
getBoundingBox
().
width
;
console
.
log
(
'
labelWidth:
'
,
labelWidth
);
if
(
labelWidth
>
maxW
)
{
return
true
;
}
return
false
;
}
const
checkPutTextByScale
=
async
(
scale
)
=>
{
label1
.
node
.
scale
=
scale
;
label2
.
node
.
scale
=
scale
;
isLabel1Max
=
false
;
isLabel2Max
=
false
;
let
label1Text
=
''
;
let
label2Text
=
''
;
for
(
let
i
=
0
;
i
<
textArr
.
length
;
i
++
)
{
let
checkText
=
textArr
[
i
];
if
(
!
isLabel1Max
&&
label1Text
!=
''
)
{
checkText
=
label1Text
+
'
'
+
checkText
;
}
let
isCurMax1
=
await
checkLabelWidthMax
(
label1
,
checkText
);
if
(
!
isLabel1Max
&&
!
isCurMax1
)
{
label1Text
=
checkText
;
}
else
{
isLabel1Max
=
true
;
label1
.
string
=
label1Text
;
checkText
=
textArr
[
i
];
if
(
label2Text
!=
''
)
{
checkText
=
label2Text
+
'
'
+
checkText
;
}
let
isCurMax2
=
await
checkLabelWidthMax
(
label2
,
checkText
);
if
(
!
isLabel2Max
&&
!
isCurMax2
)
{
label2Text
=
checkText
;
label2
.
string
=
label2Text
;
}
else
{
return
false
;
}
}
}
return
true
;
}
const
testScale
=
[
1
,
0.9
,
0.8
,
0.7
,
0.6
,
0.5
,
0.4
,
0.3
,
0.2
,
0.1
];
for
(
let
i
=
0
;
i
<
testScale
.
length
;
i
++
)
{
const
scale
=
testScale
[
i
];
const
isCanPut
=
await
checkPutTextByScale
(
scale
);
if
(
isCanPut
)
{
if
(
!
isLabel1Max
)
{
label1
.
node
.
y
=
baseY
;
label2
.
node
.
active
=
false
;
}
else
{
label1
.
node
.
y
=
baseY
+
disH
*
0.5
+
disH
*
scale
*
0.5
;
label2
.
node
.
y
=
baseY
-
disH
*
0.5
-
disH
*
scale
*
0.5
;
label2
.
node
.
active
=
true
;
}
break
;
}
}
}
}
}
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