This commit is contained in:
2025-07-22 16:43:10 +08:00
parent a90dce06f3
commit 52bae0735f
36 changed files with 10224 additions and 1658 deletions
+36 -2
View File
@@ -1,4 +1,5 @@
import { _decorator, Component, Label, Node, Size, UITransform } from "cc";
import Tools from "./tools";
const { ccclass, property } = _decorator;
@ccclass("DialogBubble")
@@ -11,13 +12,46 @@ export class DialogBubble extends Component {
contentT: UITransform = null;
updateBubbleContent(str: string) {
const lines = str.split("\n");
let len = 0;
let index = 0;
for (let i = 0; i < lines.length; i++) {
const element = lines[i];
if (element.length > len) {
len = element.length;
index = i;
}
}
let finalLen = 0;
// for (let i = 0; i < lines[index].length; i++) {
// const element = lines[index][i];
// if ("\u4e00" <= element[i] && element[i] <= "\u9fff") {
// finalLen += 35;
// } else {
// finalLen += 18;
// }
// }
if (Tools.IsChinese(lines[index])) {
finalLen = 35 * lines[index].length;
} else {
finalLen = 21 * lines[index].length;
}
this.content.string = str;
this.contentT.setContentSize(
new Size(Math.min(finalLen, 950), this.contentT.contentSize.y)
);
this.content.updateRenderData();
this.bg.setContentSize(
new Size(this.contentT.contentSize.x + 5, this.contentT.contentSize.y + 5)
new Size(
this.contentT.contentSize.x + 30,
this.contentT.contentSize.y + 20
)
);
return this.bg.contentSize.y / 2;
return this.bg.contentSize.y;
}
}