diff --git a/game.js b/game.js index a3e37ce..1b5c8ae 100644 --- a/game.js +++ b/game.js @@ -1,5 +1,48 @@ (() => { // ==================== КОНФИГУРАЦИЯ СЕРВЕРА ==================== +// === Custom modal functions === +function customAlert(msg) { + const overlay = document.createElement("div"); + overlay.className = "custom-modal-overlay"; + const box = document.createElement("div"); + box.className = "custom-modal-box"; + const text = document.createElement("div"); + text.textContent = msg; + text.style.marginBottom = "16px"; + const btn = document.createElement("button"); + btn.className = "btn-ok"; + btn.textContent = "OK"; + btn.onclick = () => overlay.remove(); + box.appendChild(text); + box.appendChild(btn); + overlay.appendChild(box); + document.querySelector("#game").appendChild(overlay); +} +function customConfirm(msg, onYes) { + const overlay = document.createElement("div"); + overlay.className = "custom-modal-overlay"; + const box = document.createElement("div"); + box.className = "custom-modal-box"; + const text = document.createElement("div"); + text.textContent = msg; + text.style.marginBottom = "16px"; + const btns = document.createElement("div"); + btns.className = "modal-btns"; + const yesBtn = document.createElement("button"); + yesBtn.className = "btn-yes"; + yesBtn.textContent = "Да"; + yesBtn.onclick = () => { overlay.remove(); onYes(); }; + const noBtn = document.createElement("button"); + noBtn.className = "btn-no"; + noBtn.textContent = "Отмена"; + noBtn.onclick = () => overlay.remove(); + btns.appendChild(yesBtn); + btns.appendChild(noBtn); + box.appendChild(text); + box.appendChild(btns); + overlay.appendChild(box); + document.querySelector("#game").appendChild(overlay); +} // Возможность переопределить сервер через query string const urlParams = new URLSearchParams(window.location.search); const SERVER_URL = urlParams.get('server') || 'https://apigrech.mkn8n.ru'; @@ -1255,14 +1298,14 @@ const voiceBtn = document.createElement('div'); voiceBtn.innerHTML = '🎤/'; voiceBtn.title = 'Голосовой чат (выкл)'; - voiceBtn.style.cssText = 'position:absolute;top:74px;right:170px;width:52px;height:52px;border-radius:12px;background:#555;z-index:200;display:flex;align-items:center;justify-content:center;font-size:24px;cursor:pointer;border:2px solid rgba(255,255,255,0.9);box-shadow:0 4px 0 rgba(0,0,0,0.5);pointer-events:auto;'; + voiceBtn.style.cssText = 'position:absolute;top:74px;right:130px;width:52px;height:52px;border-radius:12px;background:#555;z-index:200;display:flex;align-items:center;justify-content:center;font-size:24px;cursor:pointer;border:2px solid rgba(255,255,255,0.9);box-shadow:0 4px 0 rgba(0,0,0,0.5);pointer-events:auto;'; document.querySelector('.ui').appendChild(voiceBtn); // Кнопка режима голоса (близко / весь мир) const voiceModeBtn = document.createElement('div'); voiceModeBtn.innerHTML = '📢'; voiceModeBtn.title = 'Режим: рядом (600px)'; - voiceModeBtn.style.cssText = 'position:absolute;top:74px;right:112px;width:48px;height:52px;border-radius:12px;background:#3498db;z-index:200;display:flex;align-items:center;justify-content:center;font-size:20px;cursor:pointer;border:2px solid rgba(255,255,255,0.7);box-shadow:0 4px 0 rgba(0,0,0,0.5);pointer-events:auto;color:#fff;font-weight:bold;'; + voiceModeBtn.style.cssText = 'position:absolute;top:74px;right:190px;width:48px;height:52px;border-radius:12px;background:#3498db;z-index:200;display:flex;align-items:center;justify-content:center;font-size:20px;cursor:pointer;border:2px solid rgba(255,255,255,0.7);box-shadow:0 4px 0 rgba(0,0,0,0.5);pointer-events:auto;color:#fff;font-weight:bold;'; document.querySelector('.ui').appendChild(voiceModeBtn); voiceModeBtn.onclick = () => { if (voiceMode === 'near') { @@ -1640,13 +1683,13 @@ saveBtn.onclick = () => { playSound('click'); saveGame(); - alert('Игра сохранена!'); + customAlert('Игра сохранена!'); }; // Кнопка сброса игры (удаление сохранения и создание нового мира) const resetBtn = document.getElementById('resetBtn'); resetBtn.onclick = () => { - if (confirm('Вы уверены, что хотите удалить сохранение и начать новую игру?')) { + customConfirm('Вы уверены, что хотите удалить сохранение и начать новую игру?', () => { playSound('click'); // Удаляем сохранение из localStorage @@ -1680,7 +1723,7 @@ // Перезагружаем страницу location.reload(); - } + }); }; // Показываем кнопку сохранения только если играем одни diff --git a/index.html b/index.html index cffd717..fae2b2f 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@