This commit is contained in:
2025-10-13 17:09:39 +08:00
parent 347a7292cc
commit 104e7f566c
9 changed files with 376 additions and 230 deletions
@@ -14,6 +14,7 @@ import {
import "../../utils/polyfills";
import { DialogManager } from "../../manager/DialogManager";
import { ChatController, IChatPanelCallback } from "../../core/ChatController";
import { ChatAIService } from "../../core/ChatAIService";
import li_BaseView from "db://assets/Scripts/Main/Common/li_BaseView";
import Utils from "db://assets/Scripts/Main/Common/Utils";
import { InnerMsgCode } from "db://assets/Scripts/Main/Config/InnerMsgCode";
@@ -73,6 +74,7 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
private waitingAI: Node;
nameKey: string;
private currentEmotion: VideoEmotion | null = null;
private isActive: boolean = false; // 标记Panel是否处于活跃状态
private onLanguageChangeCallback = () => {
if (!this.girlName) return;
@@ -388,10 +390,14 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
protected onEnable(): void {
if (!this.manager) this.manager = DialogManager.getInstance();
this.isActive = true; // 设置为活跃状态
ChatAIService.Instance.setShouldShowErrorTips(true); // 启用错误提示
this.base.active = false;
this.refresh();
}
protected onDisable(): void {
this.isActive = false; // 设置为非活跃状态,停止响应异步操作
ChatAIService.Instance.setShouldShowErrorTips(false); // 禁用错误提示,避免在其他页面显示
this.base.active = true;
}
@@ -404,12 +410,20 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
}
if (this.isWaiting) {
TipsPanel.show(LanguageUtils.getText("chat_error_code_1003"));
return; // 修复:添加return,避免重复发送
}
// 通过ChatController发送消息
this.isWaiting = true;
this.waitingAI.active = true;
const succeed = await this.chatController.sendMessage(str);
// 检查Panel是否仍然活跃,如果已经关闭则不处理结果
if (!this.isActive) {
logger.log("ChatPanel已关闭,忽略AI响应结果");
return;
}
if (succeed) {
// 清空输入框
this.editBox.string = "";