- MVP架构重构聊天逻辑

- 优化聊天气泡体验
- 修复prompt bug
- 实现聊天次数限制功能(未接服务端)
- 实现情绪切视频功能
This commit is contained in:
2025-08-27 16:12:19 +08:00
parent 9004f77e8d
commit e57818d498
27 changed files with 1713 additions and 687 deletions
@@ -6,6 +6,7 @@ import {
Overflow,
Size,
UITransform,
view,
} from "cc";
import Tools from "../../utils/tools";
const { ccclass, property } = _decorator;
@@ -20,12 +21,36 @@ export class DialogBubble extends Component {
contentT: UITransform = null;
fixMaxWidth: number;
init(maxWidth: number = 650) {
this.fixMaxWidth = maxWidth;
private loadingAnimationId: number = null;
init(maxWidth?: number) {
// 如果没有提供maxWidth,使用屏幕宽度的80%
if (maxWidth === undefined) {
this.fixMaxWidth = view.getVisibleSize().width * 0.8;
} else {
this.fixMaxWidth = maxWidth;
}
}
updateBubbleContent(str: string, callback?: (actualHeight: number) => void) {
updateBubbleContent(str: string, callback?: (actualHeight: number) => void, isLoading: boolean = false) {
// 停止之前的加载动画
this.stopLoadingAnimation();
this.content.overflow = Overflow.NONE;
// 如果是加载状态,使用固定的"..."
if (isLoading && str === "...") {
this.content.string = "...";
// 设置固定尺寸用于加载显示
const contentWidth = 60;
this.contentT.setContentSize(new Size(contentWidth, 40));
this.bg.setContentSize(new Size(contentWidth + 30, 50));
if (callback) {
callback(40); // 返回固定高度
}
return;
}
// 设置文本内容
this.content.string = str;
@@ -77,4 +102,8 @@ export class DialogBubble extends Component {
const estimatedHeight = Math.max(lines.length * 35 + 20, 60); // 最小高度60
return estimatedHeight;
}
private stopLoadingAnimation() {
// 预留方法,当前实现中不需要动画,但保留接口以备将来使用
}
}