2026-01-22 15:23:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 漫游控制管理器
|
|
|
|
|
|
* 负责管理漫游模式的控制面板和相关交互
|
|
|
|
|
|
*/
|
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 漫游控制管理器
|
2026-01-22 15:23:57 +08:00
|
|
|
|
* 提供第一人称漫游、路径漫游等功能的控制界面
|
2025-12-25 15:47:57 +08:00
|
|
|
|
*/
|
2026-01-22 15:23:57 +08:00
|
|
|
|
export class WalkControlManager extends BaseManager {
|
|
|
|
|
|
/** 漫游控制面板实例 */
|
2025-12-25 15:47:57 +08:00
|
|
|
|
public panel: WalkControlPanel | null = null;
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 路径漫游对话框管理器 */
|
2025-12-25 15:47:57 +08:00
|
|
|
|
private pathManager: WalkPathDialogManager | null = null;
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
constructor() {
|
|
|
|
|
|
super();
|
2025-12-25 15:47:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 初始化管理器 */
|
2025-12-25 15:47:57 +08:00
|
|
|
|
public init(): void {
|
2026-01-22 15:23:57 +08:00
|
|
|
|
this.pathManager = new WalkPathDialogManager();
|
2025-12-25 15:47:57 +08:00
|
|
|
|
this.pathManager.init();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 显示漫游控制面板 */
|
2025-12-25 15:47:57 +08:00
|
|
|
|
public show(): void {
|
2026-01-22 15:23:57 +08:00
|
|
|
|
if (!this.registry.toolbar) {
|
2025-12-25 15:47:57 +08:00
|
|
|
|
console.warn('Toolbar not initialized');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
this.registry.toolbar.hide();
|
2025-12-25 15:47:57 +08:00
|
|
|
|
|
|
|
|
|
|
this.panel = new WalkControlPanel({
|
|
|
|
|
|
onPlanViewToggle: (isActive) => {
|
|
|
|
|
|
console.log('[WalkControl] 地图:', isActive);
|
|
|
|
|
|
if (isActive) {
|
2026-01-22 15:23:57 +08:00
|
|
|
|
this.registry.map?.show();
|
2025-12-25 15:47:57 +08:00
|
|
|
|
} else {
|
2026-01-22 15:23:57 +08:00
|
|
|
|
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) => {
|
2026-01-28 11:24:33 +08:00
|
|
|
|
console.log('[WalkControl] 第一人称漫游:', isActive);
|
2025-12-25 15:47:57 +08:00
|
|
|
|
if (isActive) {
|
|
|
|
|
|
this.pathManager?.hide();
|
2026-01-28 11:24:33 +08:00
|
|
|
|
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);
|
2026-01-28 11:24:33 +08:00
|
|
|
|
// 将 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);
|
2026-01-28 11:24:33 +08:00
|
|
|
|
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);
|
2026-01-28 11:24:33 +08:00
|
|
|
|
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();
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
if (this.registry.map?.isOpen()) {
|
2025-12-25 15:47:57 +08:00
|
|
|
|
this.panel.setPlanViewActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
this.subscribe('map:opened', () => {
|
2025-12-25 15:47:57 +08:00
|
|
|
|
this.panel?.setPlanViewActive(true);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
this.subscribe('map:closed', () => {
|
2025-12-25 15:47:57 +08:00
|
|
|
|
this.panel?.setPlanViewActive(false);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
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';
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
this.registry.container.appendChild(this.panel.element);
|
2025-12-25 15:47:57 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
console.warn('[WalkControlManager] Container not found');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 隐藏漫游控制面板 */
|
2025-12-25 15:47:57 +08:00
|
|
|
|
public hide(): void {
|
|
|
|
|
|
this.pathManager?.hide();
|
|
|
|
|
|
|
|
|
|
|
|
if (this.panel) {
|
|
|
|
|
|
this.panel.destroy();
|
|
|
|
|
|
this.panel = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
if (this.registry.toolbar) {
|
|
|
|
|
|
this.registry.toolbar.show();
|
2025-12-25 15:47:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
|
/** 销毁管理器 */
|
2025-12-25 15:47:57 +08:00
|
|
|
|
public destroy(): void {
|
|
|
|
|
|
this.hide();
|
|
|
|
|
|
this.pathManager?.destroy();
|
|
|
|
|
|
this.pathManager = null;
|
2026-01-22 15:23:57 +08:00
|
|
|
|
super.destroy();
|
2025-12-25 15:47:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|