代码结构整理
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import { find } from "cc";
|
||||
import { ChatContentsLayout } from "../ui/components/ChatContentsLayout";
|
||||
import { DemoData } from "../utils/DemoData";
|
||||
import { NavigationManager } from "./NavigationManager";
|
||||
import Utils from "db://assets/Scripts/Main/Common/Utils";
|
||||
import {InnerMsgCode} from "db://assets/Scripts/Main/Config/InnerMsgCode";
|
||||
|
||||
/**
|
||||
* 对话管理器
|
||||
*
|
||||
* 专注于管理对话数据和对话流程,导航功能已迁移至NavigationManager
|
||||
*
|
||||
* @author AI Chat System
|
||||
* @version 2.0.0
|
||||
*/
|
||||
export class DialogManager {
|
||||
private static _instance: DialogManager;
|
||||
|
||||
/**
|
||||
* 获取DialogManager的单例实例
|
||||
*
|
||||
* @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;
|
||||
|
||||
/** 当前主题ID */
|
||||
private themeId = -1;
|
||||
|
||||
/** 聊天内容布局组件引用 */
|
||||
public layoutout: ChatContentsLayout;
|
||||
|
||||
/**
|
||||
* 进入角色列表(委托给NavigationManager)
|
||||
* @deprecated 请直接使用 NavigationManager.Instance.navigateToGirlList()
|
||||
*/
|
||||
public EnterGirlList(id: number = null): void {
|
||||
console.warn("DemoManager.EnterGirlList is deprecated, use NavigationManager instead");
|
||||
if(id != null) { this.themeId = id; }
|
||||
if(this.themeId !== -1) {
|
||||
NavigationManager.Instance.navigateToGirlList(this.themeId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入聊天页面(委托给NavigationManager)
|
||||
* @deprecated 请直接使用 NavigationManager.Instance.navigateToChat()
|
||||
*/
|
||||
public EnterChat(id: number): void {
|
||||
console.warn("DemoManager.EnterChat is deprecated, use NavigationManager instead");
|
||||
NavigationManager.Instance.navigateToChat(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入角色详情页面(委托给NavigationManager)
|
||||
* @deprecated 请直接使用 NavigationManager.Instance.navigateToGirlDetail()
|
||||
*/
|
||||
public EnterDetail(id: number): void {
|
||||
console.warn("DemoManager.EnterDetail is deprecated, use NavigationManager instead");
|
||||
NavigationManager.Instance.navigateToGirlDetail(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新对话内容
|
||||
*
|
||||
* @param {boolean} isPlayer - 是否为玩家消息
|
||||
* @param {string} str - 消息内容
|
||||
* @param {boolean} fromPlayer - 是否来自玩家输入(用于清理对话)
|
||||
*/
|
||||
public updateDialog(isPlayer: boolean, str: string, fromPlayer: boolean = false): void {
|
||||
if(fromPlayer) {
|
||||
this.demoData.cleanDialog();
|
||||
}
|
||||
this.demoData.pushDialog(isPlayer, str);
|
||||
console.log("Dialog updated:", { isPlayer, content: str.substring(0, 50) + "..." });
|
||||
Utils.sendInnerMsg(InnerMsgCode.Chat_DialogRefresh);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有对话记录
|
||||
*
|
||||
* @returns {Dialog[]} 对话记录数组
|
||||
*/
|
||||
public getDialogs() {
|
||||
return this.demoData.GetDialogs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空当前对话记录
|
||||
*/
|
||||
public clearDialogs(): void {
|
||||
this.demoData.cleanDialog();
|
||||
console.log("All dialogs cleared");
|
||||
Utils.sendInnerMsg(InnerMsgCode.Chat_DialogRefresh);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c766f939-d2bd-4dab-8229-4303fb7e2e1c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
|
||||
|
||||
/**
|
||||
* 导航管理器
|
||||
*
|
||||
* 负责管理游戏中的页面导航和路由,将导航逻辑从业务逻辑中分离出来
|
||||
*
|
||||
* @author AI Chat System
|
||||
* @version 1.0.0
|
||||
*/
|
||||
export class NavigationManager {
|
||||
private static _instance: NavigationManager;
|
||||
|
||||
/**
|
||||
* 获取NavigationManager的单例实例
|
||||
*
|
||||
* @returns {NavigationManager} 导航管理器实例
|
||||
* @static
|
||||
*/
|
||||
public static get Instance(): NavigationManager {
|
||||
if (!this._instance) {
|
||||
this._instance = new NavigationManager();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
private constructor() {}
|
||||
|
||||
/**
|
||||
* 进入角色列表页面
|
||||
*
|
||||
* @param {number} themeId - 主题ID,用于筛选角色
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* NavigationManager.Instance.navigateToGirlList(1);
|
||||
* ```
|
||||
*/
|
||||
public navigateToGirlList(themeId: number): void {
|
||||
if (themeId == null || themeId < 0) {
|
||||
console.warn("Invalid theme ID for girl list navigation:", themeId);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Navigating to girl list with theme ID: ${themeId}`);
|
||||
ViewManager.I.openBundlesView("GirlListPanel", themeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入聊天页面
|
||||
*
|
||||
* @param {number} roleId - 角色ID
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* NavigationManager.Instance.navigateToChat(10001);
|
||||
* ```
|
||||
*/
|
||||
public navigateToChat(roleId: number): void {
|
||||
if (roleId == null || roleId <= 0) {
|
||||
console.warn("Invalid role ID for chat navigation:", roleId);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Navigating to chat with role ID: ${roleId}`);
|
||||
ViewManager.I.openBundlesView("ChatPanel", roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入角色详情页面
|
||||
*
|
||||
* @param {number} roleId - 角色ID
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* NavigationManager.Instance.navigateToGirlDetail(10001);
|
||||
* ```
|
||||
*/
|
||||
public navigateToGirlDetail(roleId: number): void {
|
||||
if (roleId == null || roleId <= 0) {
|
||||
console.warn("Invalid role ID for detail navigation:", roleId);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Navigating to girl detail with role ID: ${roleId}`);
|
||||
ViewManager.I.openBundlesView("GirlDetailPanel", roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回主界面
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* NavigationManager.Instance.navigateToMainMenu();
|
||||
* ```
|
||||
*/
|
||||
public navigateToMainMenu(): void {
|
||||
console.log("Navigating to main menu");
|
||||
// TODO: 实现返回主界面的逻辑
|
||||
// ViewManager.I.openBundlesView("MainMenu");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否可以导航到指定页面
|
||||
*
|
||||
* @param {string} pageName - 页面名称
|
||||
* @returns {boolean} 是否可以导航
|
||||
*/
|
||||
public canNavigateTo(pageName: string): boolean {
|
||||
const allowedPages = ["GirlListPanel", "ChatPanel", "GirlDetailPanel"];
|
||||
return allowedPages.indexOf(pageName)>=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前页面的导航历史(预留功能)
|
||||
*
|
||||
* @returns {string[]} 导航历史数组
|
||||
*/
|
||||
public getNavigationHistory(): string[] {
|
||||
// TODO: 实现导航历史记录功能
|
||||
console.log("Navigation history feature not implemented yet");
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回上一页(预留功能)
|
||||
*/
|
||||
public goBack(): void {
|
||||
// TODO: 实现返回上一页功能
|
||||
console.log("Go back feature not implemented yet");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "88dbed6f-be79-465f-9b29-302c3e46dda0",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user