Files
18xchat/assets/Scripts/chat18x/manager/NavigationManager.ts
T

186 lines
4.8 KiB
TypeScript
Raw Normal View History

2025-08-11 16:08:59 +08:00
import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
2025-08-25 20:15:42 +08:00
import { UITransitionHelper } from "../utils/UITransitionHelper";
2025-09-09 14:31:47 +08:00
import GameRootUI from "../../Main/Common/GameRootUI";
2025-08-11 16:08:59 +08:00
/**
* 导航管理器
2025-09-09 14:31:47 +08:00
*
2025-08-11 16:08:59 +08:00
* 负责管理游戏中的页面导航和路由,将导航逻辑从业务逻辑中分离出来
2025-09-09 14:31:47 +08:00
*
* @author AI Chat System
2025-08-11 16:08:59 +08:00
* @version 1.0.0
*/
export class NavigationManager {
2025-09-09 14:31:47 +08:00
private static _instance: NavigationManager;
2025-08-11 16:08:59 +08:00
2025-09-09 14:31:47 +08:00
/**
* 获取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;
}
GameRootUI.I.hideDefaultView();
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;
2025-08-11 16:08:59 +08:00
}
2025-09-09 14:31:47 +08:00
console.log(`Navigating to chat with role ID: ${roleId}`);
ViewManager.I.openBundlesView("ChatPanel", roleId);
}
2025-08-11 16:08:59 +08:00
2025-09-09 14:31:47 +08:00
/**
* 带过渡动画进入聊天页面
* 从GirlDetailPanel平滑过渡到ChatPanel
*
* @param {number} roleId - 角色ID
* @param {any} currentPanel - 当前面板实例(GirlDetailPanel
*
* @example
* ```typescript
* NavigationManager.Instance.navigateToChatWithTransition(10001, this);
* ```
*/
public navigateToChatWithTransition(
roleId: number,
currentPanel?: any
): void {
if (roleId == null || roleId <= 0) {
console.warn(
"Invalid role ID for chat navigation with transition:",
roleId
);
return;
2025-08-11 16:08:59 +08:00
}
2025-09-09 14:31:47 +08:00
console.log(`Navigating to chat with transition, role ID: ${roleId}`);
2025-08-11 16:08:59 +08:00
2025-09-09 14:31:47 +08:00
// 打开ChatPanel,同时标记需要执行滑入动画
ViewManager.I.openBundlesView(
"ChatPanel",
{
roleId: roleId,
withSlideTransition: true,
},
(chatNode) => {
// ChatPanel打开后,如果有当前面板,执行滑出动画
if (currentPanel && currentPanel.node && currentPanel.node.isValid) {
UITransitionHelper.slideOutToLeft(currentPanel.node, 0.3, () => {
// 滑出动画完成后关闭原面板
if (
currentPanel.onClose &&
typeof currentPanel.onClose === "function"
) {
currentPanel.onClose();
2025-08-25 20:15:42 +08:00
}
2025-09-09 14:31:47 +08:00
});
2025-08-11 16:08:59 +08:00
}
2025-09-09 14:31:47 +08:00
}
);
}
2025-08-11 16:08:59 +08:00
2025-09-09 14:31:47 +08:00
/**
* 进入角色详情页面
*
* @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;
2025-08-11 16:08:59 +08:00
}
2025-09-09 14:31:47 +08:00
console.log(`Navigating to girl detail with role ID: ${roleId}`);
ViewManager.I.openBundlesView("GirlDetailPanel", roleId);
}
2025-08-11 16:08:59 +08:00
2025-09-09 14:31:47 +08:00
/**
* 返回主界面
*
* @example
* ```typescript
* NavigationManager.Instance.navigateToMainMenu();
* ```
*/
public navigateToMainMenu(): void {
console.log("Navigating to main menu");
// TODO: 实现返回主界面的逻辑
// ViewManager.I.openBundlesView("MainMenu");
}
2025-08-11 16:08:59 +08:00
2025-09-09 14:31:47 +08:00
/**
* 检查是否可以导航到指定页面
*
* @param {string} pageName - 页面名称
* @returns {boolean} 是否可以导航
*/
public canNavigateTo(pageName: string): boolean {
const allowedPages = ["GirlListPanel", "ChatPanel", "GirlDetailPanel"];
return allowedPages.indexOf(pageName) >= 0;
}
2025-08-11 16:08:59 +08:00
2025-09-09 14:31:47 +08:00
/**
* 获取当前页面的导航历史(预留功能)
*
* @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");
}
}