forked from Simnation/Main
ed
This commit is contained in:
parent
b0f9fbee65
commit
d6480dfebd
2 changed files with 104 additions and 36 deletions
|
@ -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)
|
||||
|
|
|
@ -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,22 +1338,32 @@ function stopAllAudio() {
|
|||
}
|
||||
|
||||
function showDJInterface() {
|
||||
console.log('DJ System: Showing interface');
|
||||
|
||||
const djInterfaceElement = document.getElementById('dj-interface');
|
||||
if (djInterfaceElement) {
|
||||
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
|
||||
// Position weiter rechts und unten, falls keine gespeicherte Position
|
||||
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
|
||||
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
|
||||
|
@ -1453,8 +1468,9 @@ function extractYouTubeVideoId(url) {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Verbesserte notifyFiveM-Funktion mit Callback-Unterstützung
|
||||
// Verbesserte notifyFiveM-Funktion mit Fehlerbehandlung
|
||||
function notifyFiveM(event, data, callback) {
|
||||
try {
|
||||
const callbackId = callback ? Date.now().toString() + Math.random().toString(36).substr(2, 5) : null;
|
||||
|
||||
if (callback) {
|
||||
|
@ -1462,22 +1478,34 @@ function notifyFiveM(event, data, callback) {
|
|||
window.callbacks[callbackId] = callback;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
...data,
|
||||
callbackId: callbackId
|
||||
};
|
||||
|
||||
console.log(`DJ System: Sending ${event} to FiveM`, payload);
|
||||
|
||||
fetch(`https://${GetParentResourceName()}/${event}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...data,
|
||||
callbackId: callbackId
|
||||
})
|
||||
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) {
|
||||
callback({success: false, error: 'Internal error'});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Callback-Handler
|
||||
window.handleCallback = function(callbackId, data) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue