聊天记录展示

This commit is contained in:
2025-10-15 18:55:01 +08:00
parent d984cb1457
commit 5714ae08bb
8 changed files with 285 additions and 137 deletions
@@ -44,16 +44,14 @@ export class DialogManager {
*
* @param {boolean} isPlayer - 是否为玩家消息
* @param {string} str - 消息内容
* @param {boolean} fromPlayer - 是否来自玩家输入(用于清理对话
* @param {boolean} fromPlayer - 是否来自玩家输入(已废弃,保留参数兼容性
*/
public updateDialog(
isPlayer: boolean,
str: string,
fromPlayer: boolean = false
): void {
if (fromPlayer) {
this.dialogData.cleanDialog();
}
// 移除清空逻辑,改为追加模式以支持历史记录显示
this.dialogData.pushDialog(isPlayer, str);
}
@@ -62,16 +60,14 @@ export class DialogManager {
*
* @param {boolean} isPlayer - 是否为玩家消息
* @param {string} str - 消息内容
* @param {boolean} fromPlayer - 是否来自玩家输入(用于清理对话
* @param {boolean} fromPlayer - 是否来自玩家输入(已废弃,保留参数兼容性
*/
public updateDialogWithSegments(
isPlayer: boolean,
str: string,
fromPlayer: boolean = false
): void {
if (fromPlayer) {
this.dialogData.cleanDialog();
}
// 移除清空逻辑,改为追加模式以支持历史记录显示
// 如果是玩家消息,直接添加单个气泡
if (isPlayer) {
@@ -182,4 +178,43 @@ export class DialogManager {
logger.log("DialogManager: Synced dialogs from ChatModel");
}
/**
* 加载历史对话记录(用于初始化显示)
* @param dialogs 历史对话数组
*/
public loadHistoryDialogs(dialogs: Dialog[]): void {
// 清空当前对话
this.dialogData.cleanDialog();
// 遍历历史对话,对AI消息进行分段处理
let totalSegments = 0;
dialogs.forEach((dialog) => {
if (dialog.isPlayer) {
// 玩家消息直接添加
this.dialogData.pushDialog(dialog.isPlayer, dialog.content);
totalSegments++;
} else {
// AI消息进行分段处理
const segments = this.splitMessageIntoSegments(dialog.content);
if (segments.length <= 1) {
// 单段消息直接添加
this.dialogData.pushDialog(dialog.isPlayer, dialog.content);
totalSegments++;
} else {
// 多段消息,每段作为独立气泡
segments.forEach((segment) => {
this.dialogData.pushDialog(dialog.isPlayer, segment);
totalSegments++;
});
}
}
});
logger.log(
`DialogManager: Loaded ${dialogs.length} history dialogs (expanded to ${totalSegments} segments)`
);
// 通知UI更新
Utils.sendInnerMsg(InnerMsgCode.Chat_DialogRefresh);
}
}