class UIManager { constructor(roomManager, wallManager) { this.roomManager = roomManager; this.wallManager = wallManager; this.selectedElement = null; } // Set selected element setSelectedElement(element) { this.selectedElement = element; this.updatePropertiesPanel(); } // Clear selection clearSelection() { this.selectedElement = null; this.updatePropertiesPanel(); } // Update properties panel updatePropertiesPanel() { const panel = document.getElementById('propertiesPanel'); if (this.selectedElement) { let propertiesHTML = this.getBasicPropertiesHTML(); if (this.selectedElement.type === 'wall') { propertiesHTML += this.getWallPropertiesHTML(); } else if (this.selectedElement.type === 'room') { propertiesHTML += this.getRoomPropertiesHTML(); } propertiesHTML += this.getDeleteButtonHTML(); panel.innerHTML = propertiesHTML; } else { panel.innerHTML = this.getDefaultPanelHTML(); } } // Get basic properties HTML getBasicPropertiesHTML() { return `
Type: ${this.selectedElement.type}
Material: ${this.selectedElement.material}
Color:
${this.selectedElement.color}
`; } // Get wall properties HTML getWallPropertiesHTML() { const wallProps = this.wallManager.getWallProperties(this.selectedElement); return `
Length: ${wallProps.length}px
Thickness: ${wallProps.thickness}px
`; } // Get room properties HTML getRoomPropertiesHTML() { const roomProps = this.roomManager.getRoomProperties(this.selectedElement); return `
Name:
Area: ${roomProps.area} sq px
Dimensions: ${roomProps.dimensions}
`; } // Get delete button HTML getDeleteButtonHTML() { return `
`; } // Get default panel HTML getDefaultPanelHTML() { return `

Select an element to edit properties

Keyboard Shortcuts:

G - Toggle Grid

M - Toggle Measurements

S - Toggle Snap to Grid

+/- - Zoom In/Out

0 - Reset Zoom

Ctrl+Drag - Pan Canvas

Delete - Delete Selected

`; } // Update tool button states updateToolButtons(currentTool) { // Update top toolbar buttons document.querySelectorAll('.toolbar-btn').forEach(btn => { btn.classList.remove('bg-blue-100'); btn.classList.add('hover:bg-gray-100'); }); const activeTopBtn = document.getElementById(currentTool + 'ToolTop'); if (activeTopBtn) { activeTopBtn.classList.add('bg-blue-100'); activeTopBtn.classList.remove('hover:bg-gray-100'); } // Update sidebar tool buttons if they exist document.querySelectorAll('.tool-btn').forEach(btn => { btn.classList.remove('bg-primary', 'text-white', 'border-primary'); btn.classList.add('bg-gray-100', 'hover:bg-gray-200', 'border-gray-300'); }); const activeBtn = document.getElementById(currentTool + 'Tool'); if (activeBtn) { activeBtn.classList.remove('bg-gray-100', 'hover:bg-gray-200', 'border-gray-300'); activeBtn.classList.add('bg-primary', 'text-white', 'border-primary'); } // Show/hide element properties in top toolbar this.updateTopToolbarProperties(currentTool); // Show/hide type selection sections in sidebar const doorSection = document.getElementById('doorTypeSection'); const windowSection = document.getElementById('windowTypeSection'); if (doorSection) doorSection.classList.toggle('hidden', currentTool !== 'door'); if (windowSection) windowSection.classList.toggle('hidden', currentTool !== 'window'); } // Update top toolbar element properties updateTopToolbarProperties(currentTool) { const doorProps = document.getElementById('doorPropsTop'); const windowProps = document.getElementById('windowPropsTop'); const wallProps = document.getElementById('wallPropsTop'); // Hide all property sections if (doorProps) doorProps.classList.add('hidden'); if (windowProps) windowProps.classList.add('hidden'); if (wallProps) wallProps.classList.add('hidden'); // Show relevant property section if (currentTool === 'door' && doorProps) { doorProps.classList.remove('hidden'); } else if (currentTool === 'window' && windowProps) { windowProps.classList.remove('hidden'); } else if (currentTool === 'wall' && wallProps) { wallProps.classList.remove('hidden'); } } // Update instruction text updateInstructionText(tool) { const instructionText = document.querySelector('.absolute.top-4.left-4 p'); if (instructionText) { const toolNames = { 'pointer': 'Pointer Tool Active: Click to select objects', 'hand': 'Hand Tool Active: Drag to pan the view', 'move': 'Move Tool Active: Drag to move objects', 'rotate': 'Rotate Tool Active: Drag to rotate objects', 'wall': 'Wall Tool Active: Click and drag to create walls', 'room': 'Room Tool Active: Click and drag to create rooms', 'door': 'Door Tool Active: Click to place doors', 'window': 'Window Tool Active: Click to place windows' }; instructionText.innerHTML = `${toolNames[tool] || 'Tool Active'}`; } } // Update instruction text for 3D view update3DInstructionText() { const instructionText = document.querySelector('.absolute.top-4.left-4 p'); if (instructionText) { instructionText.innerHTML = `3D View Active: Left-drag: rotate, Right-drag: pan, Scroll: zoom, R: reset camera`; } } // Update instruction text for 2D view update2DInstructionText(tool) { this.updateInstructionText(tool); } // Show modal showModal(title, body) { const modal = document.getElementById('modal'); const modalTitle = document.getElementById('modalTitle'); const modalBody = document.getElementById('modalBody'); if (modal && modalTitle && modalBody) { modalTitle.textContent = title; modalBody.innerHTML = body; modal.classList.remove('hidden'); } } // Hide modal hideModal() { const modal = document.getElementById('modal'); if (modal) { modal.classList.add('hidden'); } } // Show alert showAlert(message, type = 'info') { alert(message); // Simple implementation, could be enhanced with custom modal } // Show confirmation showConfirmation(message) { return confirm(message); } // Get selected element getSelectedElement() { return this.selectedElement; } // Update room name updateRoomName(newName) { if (this.selectedElement && this.roomManager.updateRoomName(this.selectedElement, newName)) { return true; } return false; } // Update wall thickness updateWallThickness(thickness) { if (this.selectedElement && this.wallManager.updateWallThickness(this.selectedElement, thickness)) { return true; } return false; } }