1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-03 19:35:29 +02:00
parent b0f9fbee65
commit d6480dfebd
2 changed files with 104 additions and 36 deletions

View file

@ -671,3 +671,43 @@ function OpenDJInterface()
end end
end) 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)

View file

@ -1284,9 +1284,9 @@ function stopResize() {
} }
function closeDJInterface() { 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('mousemove', handleDrag);
document.removeEventListener('mouseup', stopDrag); document.removeEventListener('mouseup', stopDrag);
document.removeEventListener('mousemove', handleResize); document.removeEventListener('mousemove', handleResize);
@ -1298,14 +1298,19 @@ function closeDJInterface() {
djInterfaceElement.classList.add('hidden'); djInterfaceElement.classList.add('hidden');
} }
// Benachrichtige FiveM // Wichtig: Benachrichtige FiveM BEVOR wir irgendwelche lokalen Variablen zurücksetzen
notifyFiveM('djInterfaceClosed', { 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'); console.log('DJ System: Interface closed, music continues playing');
} }
function stopAllAudio() { function stopAllAudio() {
// Stoppe YouTube-Player // Stoppe YouTube-Player
for (const deck of ['A', 'B']) { for (const deck of ['A', 'B']) {
@ -1333,24 +1338,34 @@ function stopAllAudio() {
} }
function showDJInterface() { function showDJInterface() {
console.log('DJ System: Showing interface');
const djInterfaceElement = document.getElementById('dj-interface'); const djInterfaceElement = document.getElementById('dj-interface');
if (djInterfaceElement) { if (!djInterfaceElement) {
djInterfaceElement.classList.remove('hidden'); console.error('DJ System: Interface element not found!');
notifyFiveM('error', {error: 'Interface element not found'});
// Position weiter rechts und unten return;
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();
} }
// 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 // Aktualisiere den Message Handler
window.addEventListener('message', function(event) { window.addEventListener('message', function(event) {
const data = event.data; const data = event.data;
@ -1453,32 +1468,45 @@ function extractYouTubeVideoId(url) {
return null; return null;
} }
// Verbesserte notifyFiveM-Funktion mit Callback-Unterstützung // Verbesserte notifyFiveM-Funktion mit Fehlerbehandlung
function notifyFiveM(event, data, callback) { function notifyFiveM(event, data, callback) {
const callbackId = callback ? Date.now().toString() + Math.random().toString(36).substr(2, 5) : null; try {
const callbackId = callback ? Date.now().toString() + Math.random().toString(36).substr(2, 5) : null;
if (callback) {
window.callbacks = window.callbacks || {}; if (callback) {
window.callbacks[callbackId] = callback; window.callbacks = window.callbacks || {};
} window.callbacks[callbackId] = callback;
}
fetch(`https://${GetParentResourceName()}/${event}`, {
method: 'POST', const payload = {
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
...data, ...data,
callbackId: callbackId 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) { if (callback) {
delete window.callbacks[callbackId]; callback({success: false, error: 'Internal error'});
} }
}); }
} }
// Callback-Handler // Callback-Handler
window.handleCallback = function(callbackId, data) { window.handleCallback = function(callbackId, data) {
if (window.callbacks && window.callbacks[callbackId]) { if (window.callbacks && window.callbacks[callbackId]) {