refactor: 重构 Manager 架构,引入 ManagerRegistry 和 BaseManager 基类
- 新增 ManagerRegistry 单例注册表,统一管理所有 Manager 实例 - 新增 BaseManager 基类,自动管理事件订阅清理 - 新增 BaseDialogManager 基类,统一对话框生命周期管理 - 重构 15 个 Manager 使用新基类 - 重构 Toolbar 按钮和 Menu 按钮移除 engine 参数依赖 - 删除 BimComponent 基类(已不再使用) - 为所有 Manager 和核心模块添加中文 JSDoc 注释
This commit is contained in:
@@ -1,47 +1,48 @@
|
||||
import { BimComponent } from '../core/component';
|
||||
import { BimEngine } from '../bim-engine';
|
||||
/**
|
||||
* 漫游控制管理器
|
||||
* 负责管理漫游模式的控制面板和相关交互
|
||||
*/
|
||||
import { BaseManager } from '../core/base-manager';
|
||||
import { WalkControlPanel } from '../components/walk-control-panel';
|
||||
import { WalkPathDialogManager } from './walk-path-dialog-manager';
|
||||
|
||||
/**
|
||||
* 漫游控制管理器
|
||||
* 提供第一人称漫游、路径漫游等功能的控制界面
|
||||
*/
|
||||
export class WalkControlManager extends BimComponent {
|
||||
export class WalkControlManager extends BaseManager {
|
||||
/** 漫游控制面板实例 */
|
||||
public panel: WalkControlPanel | null = null;
|
||||
/** 路径漫游对话框管理器 */
|
||||
private pathManager: WalkPathDialogManager | null = null;
|
||||
|
||||
constructor(engine: BimEngine) {
|
||||
super(engine);
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/** 初始化管理器 */
|
||||
public init(): void {
|
||||
// 初始化子 manager
|
||||
this.pathManager = new WalkPathDialogManager(this.engine);
|
||||
this.pathManager = new WalkPathDialogManager();
|
||||
this.pathManager.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示漫游控制面板
|
||||
*/
|
||||
/** 显示漫游控制面板 */
|
||||
public show(): void {
|
||||
if (!this.engine.toolbar) {
|
||||
if (!this.registry.toolbar) {
|
||||
console.warn('Toolbar not initialized');
|
||||
return;
|
||||
}
|
||||
|
||||
// 隐藏 toolbar
|
||||
this.engine.toolbar.hide();
|
||||
this.registry.toolbar.hide();
|
||||
|
||||
// 创建漫游控制面板
|
||||
this.panel = new WalkControlPanel({
|
||||
onPlanViewToggle: (isActive) => {
|
||||
console.log('[WalkControl] 地图:', isActive);
|
||||
if (isActive) {
|
||||
this.engine.map?.show();
|
||||
this.registry.map?.show();
|
||||
} else {
|
||||
this.engine.map?.hide();
|
||||
this.registry.map?.hide();
|
||||
}
|
||||
// 触发事件
|
||||
this.emit('walk:plan-view-toggle', { isActive });
|
||||
},
|
||||
onPathModeToggle: (isActive) => {
|
||||
@@ -51,40 +52,32 @@ export class WalkControlManager extends BimComponent {
|
||||
} else {
|
||||
this.pathManager?.hide();
|
||||
}
|
||||
// 触发事件
|
||||
this.emit('walk:path-mode-toggle', { isActive });
|
||||
},
|
||||
onWalkModeToggle: (isActive) => {
|
||||
console.log('[WalkControl] 漫游模式:', isActive);
|
||||
// 切换到漫游模式时,关闭路径漫游弹窗
|
||||
if (isActive) {
|
||||
this.pathManager?.hide();
|
||||
}
|
||||
// 触发事件
|
||||
this.emit('walk:walk-mode-toggle', { isActive });
|
||||
},
|
||||
onSpeedChange: (speed) => {
|
||||
console.log('[WalkControl] 速度变化:', speed);
|
||||
// 触发事件
|
||||
this.emit('walk:speed-change', { speed });
|
||||
},
|
||||
onGravityToggle: (enabled) => {
|
||||
console.log('[WalkControl] 重力:', enabled);
|
||||
// 触发事件
|
||||
this.emit('walk:gravity-toggle', { enabled });
|
||||
},
|
||||
onCollisionToggle: (enabled) => {
|
||||
console.log('[WalkControl] 碰撞:', enabled);
|
||||
// 触发事件
|
||||
this.emit('walk:collision-toggle', { enabled });
|
||||
},
|
||||
onCharacterModelChange: (model) => {
|
||||
console.log('[WalkControl] 角色模型:', model);
|
||||
// TODO: 实现角色模型变化逻辑
|
||||
},
|
||||
onWalkModeChange: (mode) => {
|
||||
console.log('[WalkControl] 行走模式:', mode);
|
||||
// TODO: 实现行走模式变化逻辑
|
||||
},
|
||||
onExit: () => {
|
||||
this.hide();
|
||||
@@ -92,60 +85,50 @@ export class WalkControlManager extends BimComponent {
|
||||
});
|
||||
this.panel.init();
|
||||
|
||||
// 如果地图已经打开,同步按钮状态
|
||||
if (this.engine.map?.isOpen()) {
|
||||
if (this.registry.map?.isOpen()) {
|
||||
this.panel.setPlanViewActive(true);
|
||||
}
|
||||
|
||||
// 监听地图事件,同步漫游面板中的地图按钮状态
|
||||
this.engine.on('map:opened', () => {
|
||||
this.subscribe('map:opened', () => {
|
||||
this.panel?.setPlanViewActive(true);
|
||||
});
|
||||
|
||||
this.engine.on('map:closed', () => {
|
||||
this.subscribe('map:closed', () => {
|
||||
this.panel?.setPlanViewActive(false);
|
||||
});
|
||||
|
||||
// 将面板添加到主容器中,定位在底部中间(类似toolbar的位置)
|
||||
if (this.engine.container) {
|
||||
// 添加定位样式
|
||||
if (this.registry.container) {
|
||||
this.panel.element.style.position = 'absolute';
|
||||
this.panel.element.style.bottom = '20px';
|
||||
this.panel.element.style.left = '50%';
|
||||
this.panel.element.style.transform = 'translateX(-50%)';
|
||||
this.panel.element.style.zIndex = '1000';
|
||||
|
||||
this.engine.container.appendChild(this.panel.element);
|
||||
this.registry.container.appendChild(this.panel.element);
|
||||
} else {
|
||||
console.warn('[WalkControlManager] Container not found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏漫游控制面板
|
||||
*/
|
||||
/** 隐藏漫游控制面板 */
|
||||
public hide(): void {
|
||||
// 关闭路径漫游弹窗(但不关闭地图,因为地图可能是用户单独打开的)
|
||||
this.pathManager?.hide();
|
||||
|
||||
// 销毁面板
|
||||
if (this.panel) {
|
||||
this.panel.destroy();
|
||||
this.panel = null;
|
||||
}
|
||||
|
||||
// 显示 toolbar
|
||||
if (this.engine.toolbar) {
|
||||
this.engine.toolbar.show();
|
||||
if (this.registry.toolbar) {
|
||||
this.registry.toolbar.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁管理器
|
||||
*/
|
||||
/** 销毁管理器 */
|
||||
public destroy(): void {
|
||||
this.hide();
|
||||
this.pathManager?.destroy();
|
||||
this.pathManager = null;
|
||||
super.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user