mirror of
https://github.com/Michatec/wk_wars2x.git
synced 2026-04-01 08:26:27 +02:00
Merge pull request #6 from Jamelele/callbacks
NUI Callback Improvements
This commit is contained in:
@@ -174,15 +174,17 @@ AddEventHandler( "wk:togglePlateLock", function( cam, beep, bolo )
|
|||||||
end )
|
end )
|
||||||
|
|
||||||
-- Runs when the "Toggle Display" button is pressed on the plate reder box
|
-- Runs when the "Toggle Display" button is pressed on the plate reder box
|
||||||
RegisterNUICallback( "togglePlateReaderDisplay", function()
|
RegisterNUICallback( "togglePlateReaderDisplay", function( data, cb )
|
||||||
-- Toggle the display state
|
-- Toggle the display state
|
||||||
READER:ToggleDisplayState()
|
READER:ToggleDisplayState()
|
||||||
|
cb('ok')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
-- Runs when the "Set BOLO Plate" button is pressed on the plate reader box
|
-- Runs when the "Set BOLO Plate" button is pressed on the plate reader box
|
||||||
RegisterNUICallback( "setBoloPlate", function( plate, cb )
|
RegisterNUICallback( "setBoloPlate", function( plate, cb )
|
||||||
-- Set the BOLO plate
|
-- Set the BOLO plate
|
||||||
READER:SetBoloPlate( plate )
|
READER:SetBoloPlate( plate )
|
||||||
|
cb('ok')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
-- This is the main function that runs and scans all vehicles in front and behind the patrol vehicle
|
-- This is the main function that runs and scans all vehicles in front and behind the patrol vehicle
|
||||||
|
|||||||
20
cl_radar.lua
20
cl_radar.lua
@@ -1419,25 +1419,28 @@ end
|
|||||||
NUI callback
|
NUI callback
|
||||||
----------------------------------------------------------------------------------]]--
|
----------------------------------------------------------------------------------]]--
|
||||||
-- Runs when the "Toggle Display" button is pressed on the remote control
|
-- Runs when the "Toggle Display" button is pressed on the remote control
|
||||||
RegisterNUICallback( "toggleRadarDisplay", function()
|
RegisterNUICallback( "toggleRadarDisplay", function( data, cb )
|
||||||
-- Toggle the display state
|
-- Toggle the display state
|
||||||
RADAR:ToggleDisplayState()
|
RADAR:ToggleDisplayState()
|
||||||
|
cb('ok')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
-- Runs when the user presses the power button on the radar ui
|
-- Runs when the user presses the power button on the radar ui
|
||||||
RegisterNUICallback( "togglePower", function()
|
RegisterNUICallback( "togglePower", function( data, cb )
|
||||||
-- Toggle the radar's power
|
-- Toggle the radar's power
|
||||||
RADAR:TogglePower()
|
RADAR:TogglePower()
|
||||||
|
cb('ok')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
-- Runs when the user presses the ESC or RMB when the remote is open
|
-- Runs when the user presses the ESC or RMB when the remote is open
|
||||||
RegisterNUICallback( "closeRemote", function()
|
RegisterNUICallback( "closeRemote", function( data, cb )
|
||||||
-- Remove focus to the NUI side
|
-- Remove focus to the NUI side
|
||||||
SetNuiFocus( false, false )
|
SetNuiFocus( false, false )
|
||||||
|
cb('ok')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
-- Runs when the user presses any of the antenna mode buttons on the remote
|
-- Runs when the user presses any of the antenna mode buttons on the remote
|
||||||
RegisterNUICallback( "setAntennaMode", function( data )
|
RegisterNUICallback( "setAntennaMode", function( data, cb )
|
||||||
-- Only run the codw if the radar has power and is not powering up
|
-- Only run the codw if the radar has power and is not powering up
|
||||||
if ( RADAR:IsPowerOn() and not RADAR:IsPoweringUp() ) then
|
if ( RADAR:IsPowerOn() and not RADAR:IsPoweringUp() ) then
|
||||||
-- As the mode buttons are used to exit the menu, we check for that
|
-- As the mode buttons are used to exit the menu, we check for that
|
||||||
@@ -1465,10 +1468,11 @@ RegisterNUICallback( "setAntennaMode", function( data )
|
|||||||
end )
|
end )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
cb('ok')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
-- Runs when the user presses either of the XMIT/HOLD buttons on the remote
|
-- Runs when the user presses either of the XMIT/HOLD buttons on the remote
|
||||||
RegisterNUICallback( "toggleAntenna", function( data )
|
RegisterNUICallback( "toggleAntenna", function( data, cb )
|
||||||
-- Only run the codw if the radar has power and is not powering up
|
-- Only run the codw if the radar has power and is not powering up
|
||||||
if ( RADAR:IsPowerOn() and not RADAR:IsPoweringUp() ) then
|
if ( RADAR:IsPowerOn() and not RADAR:IsPoweringUp() ) then
|
||||||
-- As the xmit/hold buttons are used to change settings in the menu, we check for that
|
-- As the xmit/hold buttons are used to change settings in the menu, we check for that
|
||||||
@@ -1489,10 +1493,11 @@ RegisterNUICallback( "toggleAntenna", function( data )
|
|||||||
end )
|
end )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
cb('ok')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
-- Runs when the user presses the menu button on the remote control
|
-- Runs when the user presses the menu button on the remote control
|
||||||
RegisterNUICallback( "menu", function()
|
RegisterNUICallback( "menu", function( data, cb )
|
||||||
-- Only run the codw if the radar has power and is not powering up
|
-- Only run the codw if the radar has power and is not powering up
|
||||||
if ( RADAR:IsPowerOn() and not RADAR:IsPoweringUp() ) then
|
if ( RADAR:IsPowerOn() and not RADAR:IsPoweringUp() ) then
|
||||||
-- As the menu button is a multipurpose button, we first check to see if the menu is already open
|
-- As the menu button is a multipurpose button, we first check to see if the menu is already open
|
||||||
@@ -1510,17 +1515,20 @@ RegisterNUICallback( "menu", function()
|
|||||||
-- Play the standard audio beep
|
-- Play the standard audio beep
|
||||||
SendNUIMessage( { _type = "audio", name = "beep", vol = RADAR:GetSettingValue( "beep" ) } )
|
SendNUIMessage( { _type = "audio", name = "beep", vol = RADAR:GetSettingValue( "beep" ) } )
|
||||||
end
|
end
|
||||||
|
cb('ok')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
-- Runs when the JavaScript side sends the UI data for saving
|
-- Runs when the JavaScript side sends the UI data for saving
|
||||||
RegisterNUICallback( "saveUiData", function( data, cb )
|
RegisterNUICallback( "saveUiData", function( data, cb )
|
||||||
UTIL:Log( "Saving updated UI settings data." )
|
UTIL:Log( "Saving updated UI settings data." )
|
||||||
SetResourceKvp( "wk_wars2x_ui_data", json.encode( data ) )
|
SetResourceKvp( "wk_wars2x_ui_data", json.encode( data ) )
|
||||||
|
cb('ok')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
-- Runs when the JavaScript side sends the quick start video has been watched
|
-- Runs when the JavaScript side sends the quick start video has been watched
|
||||||
RegisterNUICallback( "qsvWatched", function( data, cb )
|
RegisterNUICallback( "qsvWatched", function( data, cb )
|
||||||
SetResourceKvpInt( "wk_wars2x_new_user", 1 )
|
SetResourceKvpInt( "wk_wars2x_new_user", 1 )
|
||||||
|
cb('ok')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
15
nui/radar.js
15
nui/radar.js
@@ -257,7 +257,7 @@ elements.closeHelp.click( function() {
|
|||||||
// Sets the action for the "No" button on the new user popup to close the popup
|
// Sets the action for the "No" button on the new user popup to close the popup
|
||||||
elements.closeNewUser.click( function() {
|
elements.closeNewUser.click( function() {
|
||||||
setEleVisible( elements.newUser, false );
|
setEleVisible( elements.newUser, false );
|
||||||
sendData( "qsvWatched", null );
|
sendData( "qsvWatched", {} );
|
||||||
} )
|
} )
|
||||||
|
|
||||||
// Sets the action for the "Yes" button on the new user popup to open the quick start window and load the video
|
// Sets the action for the "Yes" button on the new user popup to open the quick start window and load the video
|
||||||
@@ -271,7 +271,7 @@ elements.openQsv.click( function() {
|
|||||||
elements.closeQsv.click( function() {
|
elements.closeQsv.click( function() {
|
||||||
setEleVisible( elements.qsvWindow, false );
|
setEleVisible( elements.qsvWindow, false );
|
||||||
loadQuickStartVideo( false );
|
loadQuickStartVideo( false );
|
||||||
sendData( "qsvWatched", null );
|
sendData( "qsvWatched", {} );
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
|
||||||
@@ -620,9 +620,16 @@ function displayKeyLock( state )
|
|||||||
}, 2000 );
|
}, 2000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepare headers for HTTP requests
|
||||||
|
$.ajaxSetup({
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// This function is used to send data back through to the LUA side
|
// This function is used to send data back through to the LUA side
|
||||||
function sendData( name, data ) {
|
function sendData( name, data ) {
|
||||||
$.post( "http://" + resourceName + "/" + name, JSON.stringify( data ), function( datab ) {
|
$.post( "https://" + resourceName + "/" + name, JSON.stringify( data ), function( datab ) {
|
||||||
if ( datab != "ok" ) {
|
if ( datab != "ok" ) {
|
||||||
console.log( datab );
|
console.log( datab );
|
||||||
}
|
}
|
||||||
@@ -1033,7 +1040,7 @@ $( "body" ).find( "button, div" ).each( function( i, obj ) {
|
|||||||
------------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------------*/
|
||||||
function closeRemote()
|
function closeRemote()
|
||||||
{
|
{
|
||||||
sendData( "closeRemote", null );
|
sendData( "closeRemote", {} );
|
||||||
|
|
||||||
setEleVisible( elements.plateReaderBox, false );
|
setEleVisible( elements.plateReaderBox, false );
|
||||||
setEleVisible( elements.uiSettingsBox, false );
|
setEleVisible( elements.uiSettingsBox, false );
|
||||||
|
|||||||
Reference in New Issue
Block a user