Files
bim_engine/src/managers/walk-control-manager.ts
2025-12-25 15:47:57 +08:00

152 lines
4.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { BimComponent } from '../core/component';
import { BimEngine } from '../bim-engine';
import { WalkControlPanel } from '../components/walk-control-panel';
import { WalkPathDialogManager } from './walk-path-dialog-manager';
/**
* 漫游控制管理器
*/
export class WalkControlManager extends BimComponent {
public panel: WalkControlPanel | null = null;
private pathManager: WalkPathDialogManager | null = null;
constructor(engine: BimEngine) {
super(engine);
}
public init(): void {
// 初始化子 manager
this.pathManager = new WalkPathDialogManager(this.engine);
this.pathManager.init();
}
/**
* 显示漫游控制面板
*/
public show(): void {
if (!this.engine.toolbar) {
console.warn('Toolbar not initialized');
return;
}
// 隐藏 toolbar
this.engine.toolbar.hide();
// 创建漫游控制面板
this.panel = new WalkControlPanel({
onPlanViewToggle: (isActive) => {
console.log('[WalkControl] 地图:', isActive);
if (isActive) {
this.engine.map?.show();
} else {
this.engine.map?.hide();
}
// 触发事件
this.emit('walk:plan-view-toggle', { isActive });
},
onPathModeToggle: (isActive) => {
console.log('[WalkControl] 路径漫游:', isActive);
if (isActive) {
this.pathManager?.show();
} 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();
}
});
this.panel.init();
// 如果地图已经打开,同步按钮状态
if (this.engine.map?.isOpen()) {
this.panel.setPlanViewActive(true);
}
// 监听地图事件,同步漫游面板中的地图按钮状态
this.engine.on('map:opened', () => {
this.panel?.setPlanViewActive(true);
});
this.engine.on('map:closed', () => {
this.panel?.setPlanViewActive(false);
});
// 将面板添加到主容器中定位在底部中间类似toolbar的位置
if (this.engine.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);
} 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();
}
}
/**
* 销毁管理器
*/
public destroy(): void {
this.hide();
this.pathManager?.destroy();
this.pathManager = null;
}
}