import { BimComponent } from '../core/component'; import { BimEngine } from '../bim-engine'; import { BimDialog } from '../components/dialog'; import { WalkPathPanel } from '../components/walk-path-panel'; /** * 路径漫游弹窗管理器 */ export class WalkPathDialogManager extends BimComponent { private dialogId = 'walk-path-dialog'; private dialog: BimDialog | null = null; private panel: WalkPathPanel | null = null; constructor(engine: BimEngine) { super(engine); } public init(): void { // 可以在这里监听事件 } /** * 显示弹窗 */ public show(): void { if (!this.engine.dialog || !this.engine.container) { console.warn('Dialog manager or container is not initialized'); return; } // 如果已打开,先销毁 this.destroy(); // 创建面板(暂时空内容) this.panel = new WalkPathPanel(); this.panel.init(); const dialogWidth = 300; const dialogHeight = 400; const paddingRight = 20; const container = this.engine.container; const containerHeight = container.clientHeight; const containerWidth = container.clientWidth; // 右边中间:right: 20px, 垂直居中 const x = containerWidth - dialogWidth - paddingRight; const y = (containerHeight - dialogHeight) / 2; this.dialog = this.engine.dialog.create({ id: this.dialogId, title: 'walkControl.path.dialogTitle', width: dialogWidth, height: dialogHeight, position: { x, y }, draggable: true, resizable: false, content: this.panel.element, onClose: () => { // 通知主控制面板更新状态 if (this.engine.walkControl && this.engine.walkControl.panel) { this.engine.walkControl.panel.setPathModeActive(false); } this.hide(); } }); this.dialog.init(); } /** * 隐藏弹窗 */ public hide(): void { this.destroy(); } /** * 销毁弹窗和面板 */ public destroy(): void { // 先保存 dialog 引用,避免在回调中重复调用 const dialog = this.dialog; // 立即清空引用,防止递归 this.dialog = null; // 关闭弹窗 if (dialog) { dialog.destroy(); } // 销毁面板 if (this.panel) { this.panel.destroy(); this.panel = null; } } }