diff --git a/resources/[tools]/nordi_dj/client/main.lua b/resources/[tools]/nordi_dj/client/main.lua index 38c471943..2342f51c2 100644 --- a/resources/[tools]/nordi_dj/client/main.lua +++ b/resources/[tools]/nordi_dj/client/main.lua @@ -671,3 +671,43 @@ function OpenDJInterface() end end) end + + +-- Callback-Handler für NUI +RegisterNUICallback('callback', function(data, cb) + if data.callbackId then + SendNUIMessage({ + type = 'callbackResponse', + callbackId = data.callbackId, + response = data.response or {} + }) + end + cb('ok') +end) + +-- Verbesserte Error-Handling +RegisterNUICallback('error', function(data, cb) + print("DJ System Error: " .. (data.error or "Unknown error")) + cb('ok') + + -- Benachrichtige Spieler + lib.notify({ + title = 'DJ System Error', + description = data.error or "Ein unbekannter Fehler ist aufgetreten", + type = 'error' + }) +end) + +-- Debug-Funktion für NUI-Status +function DebugNUIStatus() + local nuiFocus = {GetNuiFocus()} + print("NUI Focus:", json.encode(nuiFocus)) + print("isUIOpen:", isUIOpen) + print("isDJBooth:", isDJBooth) + print("nearestBooth:", nearestBooth) +end + +-- Debug-Befehl +RegisterCommand('djdebug', function() + DebugNUIStatus() +end, false) diff --git a/resources/[tools]/nordi_dj/html/script.js b/resources/[tools]/nordi_dj/html/script.js index bdb97306d..0a387b5f8 100644 --- a/resources/[tools]/nordi_dj/html/script.js +++ b/resources/[tools]/nordi_dj/html/script.js @@ -1284,9 +1284,9 @@ function stopResize() { } function closeDJInterface() { - + console.log('DJ System: Closing interface...'); - // Entferne Event-Listener + // Entferne Event-Listener für Drag und Resize document.removeEventListener('mousemove', handleDrag); document.removeEventListener('mouseup', stopDrag); document.removeEventListener('mousemove', handleResize); @@ -1298,14 +1298,19 @@ function closeDJInterface() { djInterfaceElement.classList.add('hidden'); } - // Benachrichtige FiveM + // Wichtig: Benachrichtige FiveM BEVOR wir irgendwelche lokalen Variablen zurücksetzen notifyFiveM('djInterfaceClosed', { - stopMusic: false // Wichtig: Teile FiveM mit, dass die Musik weiterlaufen soll + stopMusic: false // Musik weiterlaufen lassen }); + // Setze Drag & Resize Status zurück + isDragging = false; + isResizing = false; + console.log('DJ System: Interface closed, music continues playing'); } + function stopAllAudio() { // Stoppe YouTube-Player for (const deck of ['A', 'B']) { @@ -1333,24 +1338,34 @@ function stopAllAudio() { } function showDJInterface() { + console.log('DJ System: Showing interface'); + const djInterfaceElement = document.getElementById('dj-interface'); - if (djInterfaceElement) { - djInterfaceElement.classList.remove('hidden'); - - // Position weiter rechts und unten - if (!localStorage.getItem('djInterfacePosition')) { - interfacePosition = { - x: (window.innerWidth - interfaceSize.width) / 2 + 200, // 200px weiter rechts - y: (window.innerHeight - interfaceSize.height) / 2 + 150 // 150px weiter unten - }; - } - - // Wende gespeicherte Einstellungen an - applyInterfaceSettings(); + if (!djInterfaceElement) { + console.error('DJ System: Interface element not found!'); + notifyFiveM('error', {error: 'Interface element not found'}); + return; } + + // Entferne hidden-Klasse + djInterfaceElement.classList.remove('hidden'); + + // Position weiter rechts und unten, falls keine gespeicherte Position + if (!localStorage.getItem('djInterfacePosition')) { + interfacePosition = { + x: (window.innerWidth - interfaceSize.width) / 2, + y: (window.innerHeight - interfaceSize.height) / 2 + }; + } + + // Wende gespeicherte Einstellungen an + applyInterfaceSettings(); + + console.log('DJ System: Interface shown'); } + // Aktualisiere den Message Handler window.addEventListener('message', function(event) { const data = event.data; @@ -1453,32 +1468,45 @@ function extractYouTubeVideoId(url) { return null; } -// Verbesserte notifyFiveM-Funktion mit Callback-Unterstützung +// Verbesserte notifyFiveM-Funktion mit Fehlerbehandlung function notifyFiveM(event, data, callback) { - const callbackId = callback ? Date.now().toString() + Math.random().toString(36).substr(2, 5) : null; - - if (callback) { - window.callbacks = window.callbacks || {}; - window.callbacks[callbackId] = callback; - } - - fetch(`https://${GetParentResourceName()}/${event}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ + try { + const callbackId = callback ? Date.now().toString() + Math.random().toString(36).substr(2, 5) : null; + + if (callback) { + window.callbacks = window.callbacks || {}; + window.callbacks[callbackId] = callback; + } + + const payload = { ...data, callbackId: callbackId - }) - }).catch(err => { - console.error('DJ System: Failed to notify FiveM:', err); + }; + + console.log(`DJ System: Sending ${event} to FiveM`, payload); + + fetch(`https://${GetParentResourceName()}/${event}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(payload) + }).catch(err => { + console.error('DJ System: Failed to notify FiveM:', err); + if (callback) { + delete window.callbacks[callbackId]; + callback({success: false, error: 'Failed to communicate with FiveM'}); + } + }); + } catch (error) { + console.error('DJ System: Error in notifyFiveM:', error); if (callback) { - delete window.callbacks[callbackId]; + callback({success: false, error: 'Internal error'}); } - }); + } } + // Callback-Handler window.handleCallback = function(callbackId, data) { if (window.callbacks && window.callbacks[callbackId]) {