- MVP架构重构聊天逻辑
- 优化聊天气泡体验 - 修复prompt bug - 实现聊天次数限制功能(未接服务端) - 实现情绪切视频功能
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
Node,
|
||||
UITransform,
|
||||
Vec3,
|
||||
view,
|
||||
} from "cc";
|
||||
import { DialogManager } from "../../manager/DialogManager";
|
||||
import { DialogBubble } from "./DialogBubble";
|
||||
@@ -31,7 +32,7 @@ export class ChatContentsLayout extends Component {
|
||||
protected start(): void {
|
||||
this.lBubble.node.active = false;
|
||||
this.rBubble.node.active = false;
|
||||
this.fixMaxWidth = this.node.getComponent(UITransform).contentSize.y * 0.6;
|
||||
this.fixMaxWidth = view.getVisibleSize().width * 0.8;
|
||||
}
|
||||
|
||||
protected onEnable(): void {
|
||||
@@ -92,7 +93,7 @@ export class ChatContentsLayout extends Component {
|
||||
? instantiate(this.rBubble.node)
|
||||
: instantiate(this.lBubble.node);
|
||||
newBubble = newBubbleNode.getComponent(DialogBubble);
|
||||
newBubble.init(this.fixMaxWidth);
|
||||
newBubble.init();
|
||||
newBubbleNode.setParent(this.node);
|
||||
}
|
||||
|
||||
@@ -109,7 +110,7 @@ export class ChatContentsLayout extends Component {
|
||||
if (pendingUpdates === 0) {
|
||||
updateNextBubble(index - 1);
|
||||
}
|
||||
});
|
||||
}, dialog.isLoading || false);
|
||||
|
||||
this.bubbles.push(newBubble);
|
||||
};
|
||||
|
||||
@@ -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() {
|
||||
// 预留方法,当前实现中不需要动画,但保留接口以备将来使用
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user