diff --git a/cl_radar.lua b/cl_radar.lua index 6d35ea9..4193702 100644 --- a/cl_radar.lua +++ b/cl_radar.lua @@ -17,7 +17,7 @@ local pairs = pairs Resource Rename Fix - for those muppets who rename the resource and complain that the NUI aspect doesn't work! ------------------------------------------------------------------------]]-- -Citizen.SetTimeout( 5000, function() +Citizen.SetTimeout( 1000, function() -- Get the name of the resource, for example the default name is 'wk_wrs2' local name = GetCurrentResourceName() @@ -621,7 +621,7 @@ function RADAR:GetVehiclesForAntenna() table.sort( vehs[ant], self:GetFastestSortFunc() ) for k, v in pairs( vehs[ant] ) do - if ( self:CheckVehicleDataFitsMode( ant, v.rayType ) and v.veh ~= results[ant][1].veh and v.size + 1.0 < results[ant][1].size ) then + if ( self:CheckVehicleDataFitsMode( ant, v.rayType ) and v.veh ~= results[ant][1].veh and v.size + 0.5 < results[ant][1].size ) then results[ant][2] = v break end @@ -723,23 +723,44 @@ function RADAR:Main() local vehsForDisplay = self:GetVehiclesForAntenna() self:SetActiveVehicles( vehsForDisplay ) + + if ( vehsForDisplay[1] ~= nil ) then + local test = UTIL:FormatSpeed( UTIL:Round( self:GetVehSpeedFormatted( vehsForDisplay[1].speed ), 0 ) ) + SendNUIMessage( { test1 = test } ) + elseif ( vehsForDisplay[1] == nil ) then + SendNUIMessage( { test1 = -1 } ) + end + + if ( vehsForDisplay[2] ~= nil ) then + local test = UTIL:FormatSpeed( UTIL:Round( self:GetVehSpeedFormatted( vehsForDisplay[2].speed ), 0 ) ) + SendNUIMessage( { test2 = test } ) + elseif ( vehsForDisplay[2] == nil ) then + SendNUIMessage( { test2 = -1 } ) + end + + if ( vehsForDisplay[3] ~= nil ) then + local test = UTIL:FormatSpeed( UTIL:Round( self:GetVehSpeedFormatted( vehsForDisplay[3].speed ), 0 ) ) + SendNUIMessage( { test3 = test } ) + elseif ( vehsForDisplay[3] == nil ) then + SendNUIMessage( { test3 = -1 } ) + end + + if ( vehsForDisplay[4] ~= nil ) then + local test = UTIL:FormatSpeed( UTIL:Round( self:GetVehSpeedFormatted( vehsForDisplay[4].speed ), 0 ) ) + SendNUIMessage( { test4 = test } ) + elseif ( vehsForDisplay[4] == nil ) then + SendNUIMessage( { test4 = -1 } ) + end else self:SetActiveVehicles( { nil, nil, nil, nil } ) end - self:IncreaseRadarStage() - elseif ( self:GetRadarStage() == 2 ) then self:ResetRadarStage() self:ResetRayTraceState() end end end --- This will be the main function that handles all of the radar's operation -function RADAR:Controller() - -end - -- Update the vehicle pool every 3 seconds Citizen.CreateThread( function() while ( true ) do @@ -758,7 +779,7 @@ Citizen.CreateThread( function() while ( true ) do RADAR:Main() - Citizen.Wait( 100 ) + Citizen.Wait( 50 ) end end ) @@ -777,7 +798,7 @@ end ) ------------------------------ DEBUG ------------------------------ local types = { "FRONT", "FRONT FAST", "REAR", "REAR FAST" } -Citizen.CreateThread( function() +--[[ Citizen.CreateThread( function() while ( true ) do -- Caught veh debug printing local av = RADAR:GetActiveVehicles() @@ -820,7 +841,7 @@ Citizen.CreateThread( function() Citizen.Wait( 0 ) end -end ) +end ) ]] -- Commands for debugging RegisterCommand( "rdr", function( src, args, raw ) diff --git a/cl_utils.lua b/cl_utils.lua index 3aacbec..2feeebf 100644 --- a/cl_utils.lua +++ b/cl_utils.lua @@ -15,6 +15,19 @@ end -- return string.format( "%03d", speed ) -- end +function UTIL:FormatSpeed( speed ) + if ( speed < 0 or speed > 999 ) then return "Err" end + + local text = tostring( speed ) + local pipes = "" + + for i = 1, 3 - string.len( text ) do + pipes = pipes .. "¦" + end + + return pipes .. text +end + function UTIL:Clamp( val, min, max ) if ( val < min ) then return min diff --git a/nui/radar.css b/nui/radar.css index 68ced45..cf61330 100644 --- a/nui/radar.css +++ b/nui/radar.css @@ -212,7 +212,7 @@ button:focus { outline: none; } font-size: 70px; text-align: center; - line-height: 111%; + line-height: 113%; margin: 0 auto; letter-spacing: 10px; diff --git a/nui/radar.html b/nui/radar.html index 2d261ef..4020d64 100644 --- a/nui/radar.html +++ b/nui/radar.html @@ -114,50 +114,50 @@
- +

FRONT ANTENNA

- +
- +
- +
- +
- +
- +

REAR ANTENNA

- +
- - + +
- +
diff --git a/nui/radar.js b/nui/radar.js index e01f1b0..5688346 100644 --- a/nui/radar.js +++ b/nui/radar.js @@ -65,10 +65,38 @@ const elements = } } +const remoteButtons = +{ + toggleDisplay: $( "#toggleDisplay" ), + menu: $( "#menuButton" ), + volAndTest: $( "#volAndTest" ), + psBlank: $( "#psBlank" ), + uiSettings: $( "#uiSettings" ), + + antennas: { + front: { + sameMode: $( "#frontSameMode" ), + oppMode: $( "#frontOppMode" ), + xmitToggle: $( "#frontXmitToggle" ) + }, + + rear: { + sameMode: $( "#rearSameMode" ), + oppMode: $( "#rearOppMode" ), + xmitToggle: $( "#rearXmitToggle" ) + } + } +} + // Hide the radar and remote, this way we can bypass setting a style of 'display: none;' in the HTML file elements.radar.hide(); elements.remote.hide(); +// Create the onclick event for the toggle display button +remoteButtons.toggleDisplay.click( function() { + elements.radar.fadeToggle(); +} ) + // This function is used to send data back through to the LUA side function sendData( name, data ) { $.post( "http://" + resourceName + "/" + name, JSON.stringify( data ), function( datab ) { @@ -96,5 +124,23 @@ window.addEventListener( "message", function( event ) { resourceName = item.pathName; } else if ( item.activateRemote ) { $( "#rc" ).toggle(); + } else if ( item.test1 ) { + elements.antennas.front.targetSpeed.html( item.test1 ); + } else if ( item.test2 ) { + elements.antennas.front.fast.speed.html( item.test2 ); + } else if ( item.test3 ) { + elements.antennas.rear.targetSpeed.html( item.test3 ); + } else if ( item.test4 ) { + elements.antennas.rear.fast.speed.html( item.test4 ); + } + + if ( item.test1 == -1 ) { + elements.antennas.front.targetSpeed.html( "¦¦¦" ); + } else if ( item.test2 == -1 ) { + elements.antennas.front.fast.speed.html( "¦¦¦" ); + } else if ( item.test3 == -1 ) { + elements.antennas.rear.targetSpeed.html( "¦¦¦" ); + } else if ( item.test4 == -1 ) { + elements.antennas.rear.fast.speed.html( "¦¦¦" ); } } ); \ No newline at end of file