Files
bim_engine/src/managers/walk-control-manager.ts

143 lines
4.7 KiB
TypeScript
Raw Normal View History

/**
*
*
*/
import { BaseManager } from '../core/base-manager';
2025-12-25 15:47:57 +08:00
import { WalkControlPanel } from '../components/walk-control-panel';
import { WalkPathDialogManager } from './walk-path-dialog-manager';
/**
*
*
2025-12-25 15:47:57 +08:00
*/
export class WalkControlManager extends BaseManager {
/** 漫游控制面板实例 */
2025-12-25 15:47:57 +08:00
public panel: WalkControlPanel | null = null;
/** 路径漫游对话框管理器 */
2025-12-25 15:47:57 +08:00
private pathManager: WalkPathDialogManager | null = null;
constructor() {
super();
2025-12-25 15:47:57 +08:00
}
/** 初始化管理器 */
2025-12-25 15:47:57 +08:00
public init(): void {
this.pathManager = new WalkPathDialogManager();
2025-12-25 15:47:57 +08:00
this.pathManager.init();
}
/** 显示漫游控制面板 */
2025-12-25 15:47:57 +08:00
public show(): void {
if (!this.registry.toolbar) {
2025-12-25 15:47:57 +08:00
console.warn('Toolbar not initialized');
return;
}
this.registry.toolbar.hide();
2025-12-25 15:47:57 +08:00
this.panel = new WalkControlPanel({
onPlanViewToggle: (isActive) => {
console.log('[WalkControl] 地图:', isActive);
if (isActive) {
this.registry.map?.show();
2025-12-25 15:47:57 +08:00
} else {
this.registry.map?.hide();
2025-12-25 15:47:57 +08:00
}
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);
2025-12-25 15:47:57 +08:00
if (isActive) {
this.pathManager?.hide();
this.registry.engine3d?.activateFirstPersonMode();
} else {
this.registry.engine3d?.deactivateFirstPersonMode();
2025-12-25 15:47:57 +08:00
}
this.emit('walk:walk-mode-toggle', { isActive });
},
onSpeedChange: (speed) => {
console.log('[WalkControl] 速度变化:', speed);
// 将 UI 速度值转换为引擎速度值UI: 1-10, 引擎: 0.01-0.1
const engineSpeed = speed * 0.01;
this.registry.engine3d?.setWalkSpeed(engineSpeed);
2025-12-25 15:47:57 +08:00
this.emit('walk:speed-change', { speed });
},
onGravityToggle: (enabled) => {
console.log('[WalkControl] 重力:', enabled);
this.registry.engine3d?.setWalkGravity(enabled);
2025-12-25 15:47:57 +08:00
this.emit('walk:gravity-toggle', { enabled });
},
onCollisionToggle: (enabled) => {
console.log('[WalkControl] 碰撞:', enabled);
this.registry.engine3d?.setWalkCollision(enabled);
2025-12-25 15:47:57 +08:00
this.emit('walk:collision-toggle', { enabled });
},
onCharacterModelChange: (model) => {
console.log('[WalkControl] 角色模型:', model);
},
onWalkModeChange: (mode) => {
console.log('[WalkControl] 行走模式:', mode);
},
onExit: () => {
this.hide();
}
});
this.panel.init();
if (this.registry.map?.isOpen()) {
2025-12-25 15:47:57 +08:00
this.panel.setPlanViewActive(true);
}
this.subscribe('map:opened', () => {
2025-12-25 15:47:57 +08:00
this.panel?.setPlanViewActive(true);
});
this.subscribe('map:closed', () => {
2025-12-25 15:47:57 +08:00
this.panel?.setPlanViewActive(false);
});
if (this.registry.container) {
2025-12-25 15:47:57 +08:00
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.registry.container.appendChild(this.panel.element);
2025-12-25 15:47:57 +08:00
} else {
console.warn('[WalkControlManager] Container not found');
}
}
/** 隐藏漫游控制面板 */
2025-12-25 15:47:57 +08:00
public hide(): void {
this.pathManager?.hide();
if (this.panel) {
this.panel.destroy();
this.panel = null;
}
if (this.registry.toolbar) {
this.registry.toolbar.show();
2025-12-25 15:47:57 +08:00
}
}
/** 销毁管理器 */
2025-12-25 15:47:57 +08:00
public destroy(): void {
this.hide();
this.pathManager?.destroy();
this.pathManager = null;
super.destroy();
2025-12-25 15:47:57 +08:00
}
}