/** * 漫游控制管理器 * 负责管理漫游模式的控制面板和相关交互 */ import { BaseManager } from '../core/base-manager'; import { ManagerRegistry } from '../core/manager-registry'; import { WalkControlPanel } from '../components/walk-control-panel'; import { WalkPathDialogManager } from './walk-path-dialog-manager'; /** * 漫游控制管理器 * 提供第一人称漫游、路径漫游等功能的控制界面 */ export class WalkControlManager extends BaseManager { /** 漫游控制面板实例 */ public panel: WalkControlPanel | null = null; /** 路径漫游对话框管理器 */ private pathManager: WalkPathDialogManager | null = null; constructor(registry: ManagerRegistry) { super(registry); } /** 初始化管理器 */ public init(): void { this.pathManager = new WalkPathDialogManager(this.registry); this.pathManager.init(); } /** 显示漫游控制面板 */ public show(): void { if (!this.registry.toolbar) { console.warn('Toolbar not initialized'); return; } this.registry.toolbar.hide(); // 打开漫游面板时,默认激活第一人称模式 console.log('[WalkControl] 打开漫游面板,激活第一人称模式'); this.engineComponent?.activateFirstPersonMode(); this.panel = new WalkControlPanel({ onPlanViewToggle: (isActive) => { console.log('[WalkControl] 小地图:', isActive); this.engineComponent?.toggleMiniMap(); // 同步工具栏地图按钮的激活状态 this.registry.toolbar?.setBtnActive('map', isActive); 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(); alert('第三人称功能开发中'); } this.emit('walk:walk-mode-toggle', { isActive }); }, onSpeedChange: (speed) => { console.log('[WalkControl] 速度变化:', speed); const engineSpeed = speed * 0.1; this.engineComponent?.setWalkSpeed(engineSpeed); this.emit('walk:speed-change', { speed }); }, onGravityToggle: (enabled) => { console.log('[WalkControl] 重力:', enabled); this.engineComponent?.setWalkGravity(enabled); this.emit('walk:gravity-toggle', { enabled }); }, onCollisionToggle: (enabled) => { console.log('[WalkControl] 碰撞:', enabled); this.engineComponent?.setWalkCollision(enabled); this.emit('walk:collision-toggle', { enabled }); }, onCharacterModelChange: (model) => { console.log('[WalkControl] 角色模型:', model); }, onWalkModeChange: (mode) => { console.log('[WalkControl] 行走模式:', mode); }, onExit: () => { this.hide(); } }); this.panel.init(); // 同步当前地图状态到漫游面板 const mapState = this.engineComponent?.getMiniMapState() ?? false; this.panel.setPlanViewActive(mapState); 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.registry.container.appendChild(this.panel.element); } else { console.warn('[WalkControlManager] Container not found'); } } /** 隐藏漫游控制面板 */ public hide(): void { this.pathManager?.hide(); // 如果小地图开着,先关闭它 if (this.engineComponent?.getMiniMapState()) { this.engineComponent.toggleMiniMap(); } console.log('[WalkControl] 关闭漫游面板,退出第一人称模式'); this.engineComponent?.deactivateFirstPersonMode(); if (this.panel) { this.panel.destroy(); this.panel = null; } // 同步工具栏地图按钮的激活状态 this.registry.toolbar?.setBtnActive('map', false); if (this.registry.toolbar) { this.registry.toolbar.show(); } } /** 销毁管理器 */ public destroy(): void { this.hide(); this.pathManager?.destroy(); this.pathManager = null; super.destroy(); } }