diff --git a/src/mining.html b/src/mining.html index 48b6836..697c6bd 100644 --- a/src/mining.html +++ b/src/mining.html @@ -30,6 +30,10 @@ METADATA:{ width: 100%; height: 100%; display: block; + position: absolute; + top: 0; + left: 0; + z-index: 0; } .mining-ui { @@ -40,7 +44,7 @@ METADATA:{ font-family: 'Minecraft', monospace; /* Fallback */ pointer-events: none; text-shadow: 2px 2px 0 #000; - z-index: 10; + z-index: 100; } .mining-stat { @@ -59,8 +63,26 @@ METADATA:{ padding: 5px; border-radius: 5px; pointer-events: auto; + overflow-x: auto; + max-width: 95%; + white-space: nowrap; + -webkit-overflow-scrolling: touch; + z-index: 100; + } + /* Scrollbar styling for inventory */ + .inventory-container::-webkit-scrollbar { + height: 6px; + } + .inventory-container::-webkit-scrollbar-track { + background: rgba(0,0,0,0.3); + border-radius: 3px; + } + .inventory-container::-webkit-scrollbar-thumb { + background: rgba(255,255,255,0.3); + border-radius: 3px; } .inventory-slot { + flex: 0 0 auto; /* Don't shrink */ width: 40px; height: 40px; background: rgba(255, 255, 255, 0.1); @@ -96,6 +118,22 @@ METADATA:{ padding: 5px; border-radius: 5px; pointer-events: auto; /* Allow clicking */ + overflow-y: auto; + max-height: 60vh; + -webkit-overflow-scrolling: touch; + z-index: 100; + } + /* Scrollbar styling for crafting */ + .crafting-container::-webkit-scrollbar { + width: 6px; + } + .crafting-container::-webkit-scrollbar-track { + background: rgba(0,0,0,0.3); + border-radius: 3px; + } + .crafting-container::-webkit-scrollbar-thumb { + background: rgba(255,255,255,0.3); + border-radius: 3px; } .crafting-slot { width: 40px; @@ -151,21 +189,24 @@ METADATA:{ padding: 5px 10px; font-family: 'Minecraft', monospace; cursor: pointer; - z-index: 20; + z-index: 100; } .shop-container { position: absolute; - top: 50%; + top: 10%; left: 50%; - transform: translate(-50%, -50%); + transform: translateX(-50%); background: rgba(0, 0, 0, 0.9); border: 2px solid #555; padding: 20px; color: white; font-family: 'Minecraft', monospace; display: none; - z-index: 30; + z-index: 101; min-width: 300px; + max-height: 80vh; + overflow-y: auto; + -webkit-overflow-scrolling: touch; } .shop-section { margin-bottom: 20px; @@ -224,6 +265,35 @@ METADATA:{ .shop-container .close-btn:hover { background: #f44336; } + + .fullscreen-btn { + position: absolute; + top: 10px; + right: 80px; + background: #2196F3; + color: white; + border: 2px solid #1976D2; + padding: 5px 10px; + font-family: 'Minecraft', monospace; + cursor: pointer; + z-index: 100; + } + .fullscreen-btn:hover { + background: #42A5F5; + } + + .mining-container:fullscreen { + width: 100vw; + height: 100vh; + max-width: none; + aspect-ratio: auto; + border: none; + background: #87CEEB; /* Match sky color */ + } + .mining-container:fullscreen #game-canvas { + width: 100vw; + height: 100vh; + } @@ -245,15 +315,16 @@ METADATA:{
Depth: 0
Score: 0
+ -
+ diff --git a/website/mining.js b/website/mining.js index 15cca8a..c0878ee 100644 --- a/website/mining.js +++ b/website/mining.js @@ -51,7 +51,7 @@ document.addEventListener('DOMContentLoaded', () => { camera.updateProjectionMatrix(); const renderer = new THREE.WebGLRenderer({ canvas: canvas, alpha: false, antialias: true }); - renderer.setSize(canvas.clientWidth, canvas.clientHeight); + renderer.setSize(canvas.clientWidth, canvas.clientHeight, false); renderer.setPixelRatio(window.devicePixelRatio); // renderer.outputEncoding = THREE.sRGBEncoding; // We use GammaCorrectionShader instead renderer.shadowMap.enabled = true; @@ -993,12 +993,9 @@ document.addEventListener('DOMContentLoaded', () => { vector.project(camera); const canvas = renderer.domElement; - const rect = canvas.getBoundingClientRect(); - const scrollX = window.scrollX || window.pageXOffset; - const scrollY = window.scrollY || window.pageYOffset; - - const x = (vector.x + 1) / 2 * rect.width + rect.left + scrollX; - const y = -(vector.y - 1) / 2 * rect.height + rect.top + scrollY; + // Use relative coordinates for the container + const x = (vector.x + 1) / 2 * canvas.clientWidth; + const y = -(vector.y - 1) / 2 * canvas.clientHeight; // Create 2D floating item createFloatingItem(drop.userData.type, x - 16, y - 16, drop.userData.count || 1); @@ -1721,9 +1718,16 @@ document.addEventListener('DOMContentLoaded', () => { } // Handle resize - window.addEventListener('resize', () => { - const aspect = canvas.clientWidth / canvas.clientHeight; - const d = 5; + const resizeObserver = new ResizeObserver(() => { + const width = canvas.clientWidth; + const height = canvas.clientHeight; + + if (width === 0 || height === 0) return; + + const aspect = width / height; + // Dynamic view size based on grid size + const d = 5 + (upgrades.grid_size || 0); + camera.left = -d * aspect; camera.right = d * aspect; camera.top = d; @@ -1731,9 +1735,11 @@ document.addEventListener('DOMContentLoaded', () => { camera.updateProjectionMatrix(); renderer.setPixelRatio(window.devicePixelRatio); - renderer.setSize(canvas.clientWidth, canvas.clientHeight, false); - composer.setSize(canvas.clientWidth, canvas.clientHeight); + renderer.setSize(width, height, false); + composer.setSize(width, height); + if (ssaoPass) ssaoPass.setSize(width, height); }); + resizeObserver.observe(canvas); // Start initGame(); @@ -1877,6 +1883,18 @@ document.addEventListener('DOMContentLoaded', () => { return geometry; } + // Fullscreen + window.toggleFullscreen = function() { + const elem = document.querySelector('.mining-container'); + if (!document.fullscreenElement) { + elem.requestFullscreen().catch(err => { + console.error(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`); + }); + } else { + document.exitFullscreen(); + } + }; + // Shop System window.toggleShop = function() { const shop = document.getElementById('shop-modal'); @@ -2287,20 +2305,21 @@ document.addEventListener('DOMContentLoaded', () => { img.style.pointerEvents = 'none'; img.style.zIndex = '1000'; - document.body.appendChild(img); + const container = document.querySelector('.mining-container'); + container.appendChild(img); - // Find target - const scrollX = window.scrollX || window.pageXOffset; - const scrollY = window.scrollY || window.pageYOffset; - - let targetX = (window.innerWidth / 2) + scrollX; - let targetY = (window.innerHeight - 50) + scrollY; + // Find target relative to container + const containerRect = container.getBoundingClientRect(); + + // Default target (center bottom if slot not found) + let targetX = containerRect.width / 2; + let targetY = containerRect.height - 50; const slot = document.querySelector(`.inventory-slot[data-type="${type}"]`); if (slot) { const rect = slot.getBoundingClientRect(); - targetX = rect.left + rect.width / 2 - 16 + scrollX; - targetY = rect.top + rect.height / 2 - 16 + scrollY; + targetX = rect.left - containerRect.left + rect.width / 2 - 16; + targetY = rect.top - containerRect.top + rect.height / 2 - 16; } // Control point for Bezier curve @@ -2337,7 +2356,7 @@ document.addEventListener('DOMContentLoaded', () => { requestAnimationFrame(animate); } else { if (img.parentNode) { - document.body.removeChild(img); + img.parentNode.removeChild(img); } addToInventory(type, count); }