2025-08-11 16:08:59 +08:00
|
|
|
|
import { find } from "cc";
|
|
|
|
|
|
import { ChatContentsLayout } from "../ui/components/ChatContentsLayout";
|
2025-08-13 11:31:21 +08:00
|
|
|
|
import { DemoData } from "../data/DialogData";
|
2025-08-11 16:08:59 +08:00
|
|
|
|
import { NavigationManager } from "./NavigationManager";
|
|
|
|
|
|
import Utils from "db://assets/Scripts/Main/Common/Utils";
|
2025-08-13 11:31:21 +08:00
|
|
|
|
import { InnerMsgCode } from "db://assets/Scripts/Main/Config/InnerMsgCode";
|
2025-08-11 16:08:59 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 对话管理器
|
2025-08-13 11:31:21 +08:00
|
|
|
|
*
|
2025-08-11 16:08:59 +08:00
|
|
|
|
* 专注于管理对话数据和对话流程,导航功能已迁移至NavigationManager
|
2025-08-13 11:31:21 +08:00
|
|
|
|
*
|
2025-08-11 16:08:59 +08:00
|
|
|
|
* @author AI Chat System
|
|
|
|
|
|
* @version 2.0.0
|
|
|
|
|
|
*/
|
|
|
|
|
|
export class DialogManager {
|
|
|
|
|
|
private static _instance: DialogManager;
|
2025-08-13 11:31:21 +08:00
|
|
|
|
|
2025-08-11 16:08:59 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取DialogManager的单例实例
|
2025-08-13 11:31:21 +08:00
|
|
|
|
*
|
2025-08-11 16:08:59 +08:00
|
|
|
|
* @returns {DialogManager} 对话管理器实例
|
|
|
|
|
|
* @static
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static getInstance(): DialogManager {
|
|
|
|
|
|
if (!this._instance) {
|
|
|
|
|
|
this._instance = new DialogManager();
|
|
|
|
|
|
}
|
|
|
|
|
|
return this._instance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private constructor() {
|
|
|
|
|
|
this.demoData = new DemoData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 对话数据实例 */
|
|
|
|
|
|
private demoData: DemoData;
|
2025-08-13 11:31:21 +08:00
|
|
|
|
|
2025-08-11 16:08:59 +08:00
|
|
|
|
/** 当前主题ID */
|
|
|
|
|
|
private themeId = -1;
|
2025-08-13 11:31:21 +08:00
|
|
|
|
|
2025-08-11 16:08:59 +08:00
|
|
|
|
/** 聊天内容布局组件引用 */
|
|
|
|
|
|
public layoutout: ChatContentsLayout;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 进入角色列表(委托给NavigationManager)
|
|
|
|
|
|
* @deprecated 请直接使用 NavigationManager.Instance.navigateToGirlList()
|
|
|
|
|
|
*/
|
|
|
|
|
|
public EnterGirlList(id: number = null): void {
|
2025-08-13 11:31:21 +08:00
|
|
|
|
console.warn(
|
|
|
|
|
|
"DemoManager.EnterGirlList is deprecated, use NavigationManager instead"
|
|
|
|
|
|
);
|
|
|
|
|
|
if (id != null) {
|
|
|
|
|
|
this.themeId = id;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.themeId !== -1) {
|
2025-08-11 16:08:59 +08:00
|
|
|
|
NavigationManager.Instance.navigateToGirlList(this.themeId);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-13 11:31:21 +08:00
|
|
|
|
|
2025-08-11 16:08:59 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 进入聊天页面(委托给NavigationManager)
|
|
|
|
|
|
* @deprecated 请直接使用 NavigationManager.Instance.navigateToChat()
|
|
|
|
|
|
*/
|
|
|
|
|
|
public EnterChat(id: number): void {
|
2025-08-13 11:31:21 +08:00
|
|
|
|
console.warn(
|
|
|
|
|
|
"DemoManager.EnterChat is deprecated, use NavigationManager instead"
|
|
|
|
|
|
);
|
2025-08-11 16:08:59 +08:00
|
|
|
|
NavigationManager.Instance.navigateToChat(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 进入角色详情页面(委托给NavigationManager)
|
|
|
|
|
|
* @deprecated 请直接使用 NavigationManager.Instance.navigateToGirlDetail()
|
|
|
|
|
|
*/
|
|
|
|
|
|
public EnterDetail(id: number): void {
|
2025-08-13 11:31:21 +08:00
|
|
|
|
console.warn(
|
|
|
|
|
|
"DemoManager.EnterDetail is deprecated, use NavigationManager instead"
|
|
|
|
|
|
);
|
2025-08-11 16:08:59 +08:00
|
|
|
|
NavigationManager.Instance.navigateToGirlDetail(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 更新对话内容
|
2025-08-13 11:31:21 +08:00
|
|
|
|
*
|
2025-08-11 16:08:59 +08:00
|
|
|
|
* @param {boolean} isPlayer - 是否为玩家消息
|
|
|
|
|
|
* @param {string} str - 消息内容
|
|
|
|
|
|
* @param {boolean} fromPlayer - 是否来自玩家输入(用于清理对话)
|
|
|
|
|
|
*/
|
2025-08-13 11:31:21 +08:00
|
|
|
|
public updateDialog(
|
|
|
|
|
|
isPlayer: boolean,
|
|
|
|
|
|
str: string,
|
|
|
|
|
|
fromPlayer: boolean = false
|
|
|
|
|
|
): void {
|
|
|
|
|
|
if (fromPlayer) {
|
2025-08-11 16:08:59 +08:00
|
|
|
|
this.demoData.cleanDialog();
|
|
|
|
|
|
}
|
|
|
|
|
|
this.demoData.pushDialog(isPlayer, str);
|
2025-08-13 11:31:21 +08:00
|
|
|
|
console.log("Dialog updated:", {
|
|
|
|
|
|
isPlayer,
|
|
|
|
|
|
content: str.substring(0, 50) + "...",
|
|
|
|
|
|
});
|
2025-08-11 16:08:59 +08:00
|
|
|
|
Utils.sendInnerMsg(InnerMsgCode.Chat_DialogRefresh);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取所有对话记录
|
2025-08-13 11:31:21 +08:00
|
|
|
|
*
|
2025-08-11 16:08:59 +08:00
|
|
|
|
* @returns {Dialog[]} 对话记录数组
|
|
|
|
|
|
*/
|
|
|
|
|
|
public getDialogs() {
|
|
|
|
|
|
return this.demoData.GetDialogs();
|
|
|
|
|
|
}
|
2025-08-13 11:31:21 +08:00
|
|
|
|
|
2025-08-11 16:08:59 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 清空当前对话记录
|
|
|
|
|
|
*/
|
|
|
|
|
|
public clearDialogs(): void {
|
|
|
|
|
|
this.demoData.cleanDialog();
|
|
|
|
|
|
console.log("All dialogs cleared");
|
|
|
|
|
|
Utils.sendInnerMsg(InnerMsgCode.Chat_DialogRefresh);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|