Button click events set, antenna mode set working

This commit is contained in:
Dan
2019-11-27 11:24:33 +00:00
parent 9585ce5851
commit f404890e10
3 changed files with 60 additions and 103 deletions

View File

@@ -58,7 +58,7 @@ RADAR.vars =
-- Variables for the front antenna -- Variables for the front antenna
[ "front" ] = { [ "front" ] = {
xmit = false, -- Whether the antenna is on or off xmit = false, -- Whether the antenna is on or off
mode = 1, -- Current antenna mode, 1 = same, 2 = opp, 3 = same and opp mode = 0, -- Current antenna mode, 0 = none, 1 = same, 2 = opp, 3 = same and opp
speed = 0, -- Speed of the vehicle caught by the front antenna speed = 0, -- Speed of the vehicle caught by the front antenna
dir = nil, -- Direction the caught vehicle is going, 0 = towards, 1 = away dir = nil, -- Direction the caught vehicle is going, 0 = towards, 1 = away
fastMode = 1, -- Current fast mode, 1 = polling, 2 = lock on at first fast vehicle fastMode = 1, -- Current fast mode, 1 = polling, 2 = lock on at first fast vehicle
@@ -69,7 +69,7 @@ RADAR.vars =
[ "rear" ] = { [ "rear" ] = {
xmit = false, -- Whether the antenna is on or off xmit = false, -- Whether the antenna is on or off
mode = 1, -- Current antenna mode, 1 = same, 2 = opp, 3 = same and opp mode = 0, -- Current antenna mode, 0 = none, 1 = same, 2 = opp, 3 = same and opp
speed = 0, -- Speed of the vehicle caught by the front antenna speed = 0, -- Speed of the vehicle caught by the front antenna
dir = nil, -- Direction the caught vehicle is going, 0 = towards, 1 = away dir = nil, -- Direction the caught vehicle is going, 0 = towards, 1 = away
fastMode = 1, -- Current fast mode, 1 = polling, 2 = lock on at first fast vehicle fastMode = 1, -- Current fast mode, 1 = polling, 2 = lock on at first fast vehicle
@@ -367,7 +367,9 @@ end
Radar antenna functions Radar antenna functions
------------------------------------------------------------------------]]-- ------------------------------------------------------------------------]]--
function RADAR:ToggleAntenna( ant ) function RADAR:ToggleAntenna( ant )
self.vars.antennas[ant].xmit = not self.vars.antennas[ant].xmit if ( self:IsPowerOn() ) then
self.vars.antennas[ant].xmit = not self.vars.antennas[ant].xmit
end
end end
function RADAR:IsAntennaTransmitting( ant ) function RADAR:IsAntennaTransmitting( ant )
@@ -441,36 +443,6 @@ function RADAR:SetAntennaFastLock( ant, state )
end end
--[[------------------------------------------------------------------------
Radar sort mode functions
------------------------------------------------------------------------]]--
--[[ function RADAR:GetSortModeText()
return self.sorting[self.vars.sortMode].name
end
function RADAR:GetSortModeFunc()
return self.sorting[self.vars.sortMode].func
end
function RADAR:IsSortModeFastest()
if ( self.vars.sortMode == 2 ) then
return true
end
return false
end
function RADAR:ToggleSortMode()
if ( self.vars.sortMode < #self.sorting ) then
self.vars.sortMode = self.vars.sortMode + 1
else
self.vars.sortMode = 1
end
UTIL:Notify( "Radar mode set to " .. self:GetSortModeText() )
end ]]
--[[------------------------------------------------------------------------ --[[------------------------------------------------------------------------
Radar captured vehicle functions Radar captured vehicle functions
------------------------------------------------------------------------]]-- ------------------------------------------------------------------------]]--
@@ -491,7 +463,7 @@ function RADAR:InsertCapturedVehicleData( t, rt )
end end
end end
function RADAR:RemoveDuplicateCapturedVehicles() --[[ function RADAR:RemoveDuplicateCapturedVehicles()
for k, vehTable in pairs( self.capturedVehicles ) do for k, vehTable in pairs( self.capturedVehicles ) do
local veh = vehTable.veh local veh = vehTable.veh
local rt = vehTable.rayType local rt = vehTable.rayType
@@ -500,7 +472,7 @@ function RADAR:RemoveDuplicateCapturedVehicles()
if ( v.veh == veh and k ~= b and rt == v.rayType ) then table.remove( self.capturedVehicles, b ) end if ( v.veh == veh and k ~= b and rt == v.rayType ) then table.remove( self.capturedVehicles, b ) end
end end
end end
end end ]]
--[[------------------------------------------------------------------------ --[[------------------------------------------------------------------------
@@ -651,11 +623,6 @@ function RADAR:RunControlManager()
SetNuiFocus( true, true ) SetNuiFocus( true, true )
end end
-- 'X' key, change the sort mode
--[[ if ( IsDisabledControlJustPressed( 1, 105 ) ) then
self:ToggleSortMode()
end ]]
if ( IsDisabledControlJustPressed( 1, 117 ) ) then if ( IsDisabledControlJustPressed( 1, 117 ) ) then
self:TogglePower() self:TogglePower()
UTIL:Notify( "Radar power toggled." ) UTIL:Notify( "Radar power toggled." )
@@ -683,10 +650,14 @@ end
--[[------------------------------------------------------------------------ --[[------------------------------------------------------------------------
NUI callback NUI callback
------------------------------------------------------------------------]]-- ------------------------------------------------------------------------]]--
RegisterNUICallback( "remote", function( data, cb ) RegisterNUICallback( "closeRemote", function( data )
if ( data == "close" ) then SetNuiFocus( false, false )
SetNuiFocus( false, false ) end )
end
RegisterNUICallback( "setAntennaMode", function( data )
RADAR:SetAntennaMode( data.value, tostring( data.mode ) )
print( "Set antenna: " .. data.value .. " to mode " .. tostring( data.mode ) )
end ) end )
@@ -701,11 +672,11 @@ function RADAR:Main()
local plyVeh = GetVehiclePedIsIn( ped, false ) local plyVeh = GetVehiclePedIsIn( ped, false )
-- Check to make sure the player is in the driver's seat, and also that the vehicle has a class of VC_EMERGENCY (18) -- Check to make sure the player is in the driver's seat, and also that the vehicle has a class of VC_EMERGENCY (18)
if ( DoesEntityExist( plyVeh ) and GetPedInVehicleSeat( plyVeh, -1 ) == ped and GetVehicleClass( plyVeh ) == 18 and ( self:IsPowerOn() and self:IsEitherAntennaOn() ) ) then if ( DoesEntityExist( plyVeh ) and GetPedInVehicleSeat( plyVeh, -1 ) == ped and GetVehicleClass( plyVeh ) == 18 and self:IsPowerOn() ) then
local plyVehPos = GetEntityCoords( plyVeh ) local plyVehPos = GetEntityCoords( plyVeh )
-- First stage of the radar - get all of the vehicles hit by the radar -- First stage of the radar - get all of the vehicles hit by the radar
if ( self:GetRadarStage() == 0 ) then if ( self:GetRadarStage() == 0 --[[ and self:IsEitherAntennaOn() ]] ) then
if ( self:GetRayTraceState() == 0 ) then if ( self:GetRayTraceState() == 0 ) then
local vehs = self:GetVehiclePool() local vehs = self:GetVehiclePool()
@@ -717,41 +688,14 @@ function RADAR:Main()
end end
elseif ( self:GetRadarStage() == 1 ) then elseif ( self:GetRadarStage() == 1 ) then
-- self:RemoveDuplicateCapturedVehicles() -- self:RemoveDuplicateCapturedVehicles()
-- Only grab data to send if there have actually been vehicles captured by the radar
if ( not UTIL:IsTableEmpty( self:GetCapturedVehicles() ) ) then if ( not UTIL:IsTableEmpty( self:GetCapturedVehicles() ) ) then
local vehsForDisplay = self:GetVehiclesForAntenna() local vehsForDisplay = self:GetVehiclesForAntenna()
self:SetActiveVehicles( vehsForDisplay ) -- self:SetActiveVehicles( vehsForDisplay ) -- not really any point in setting this
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 else
self:SetActiveVehicles( { nil, nil, nil, nil } ) -- self:SetActiveVehicles( { nil, nil, nil, nil } )
end end
self:ResetRadarStage() self:ResetRadarStage()
@@ -778,7 +722,7 @@ Citizen.CreateThread( function()
while ( true ) do while ( true ) do
RADAR:Main() RADAR:Main()
Citizen.Wait( 50 ) Citizen.Wait( 100 )
end end
end ) end )

View File

@@ -113,14 +113,13 @@
</div> </div>
<div id="rc"> <div id="rc">
<!-- <div id="rc"> -->
<button id="toggleDisplay" class="rounded_btn toggle_display">TOGGLE DISPLAY</button> <button id="toggleDisplay" class="rounded_btn toggle_display">TOGGLE DISPLAY</button>
<p class="label">FRONT ANTENNA</p> <p class="label">FRONT ANTENNA</p>
<div class="antenna_btns_container"> <div class="antenna_btns_container">
<div class="btns btns_top"> <div class="btns btns_top">
<button id="frontOppMode" class="zone_btn top_left">OPP LK/REL</button> <button id="frontOppMode" data-action="setAntennaMode" data-value="front" data-mode="2" class="zone_btn top_left">OPP LK/REL</button>
<div class="xmit_wrap"> <div class="xmit_wrap">
<div class="xmit_btn xmit_top"> <div class="xmit_btn xmit_top">
@@ -129,7 +128,7 @@
</div> </div>
</div> </div>
<button id="frontSameMode" class="zone_btn top_right">SAME LK/REL</button> <button id="frontSameMode" data-action="setAntennaMode" data-value="front" data-mode="1" class="zone_btn top_right">SAME LK/REL</button>
</div> </div>
<div class="breaker"></div> <div class="breaker"></div>

View File

@@ -88,6 +88,13 @@ const remoteButtons =
} }
} }
const antennaModes =
{
same: 0,
opp: 1,
both: 2
}
// Hide the radar and remote, this way we can bypass setting a style of 'display: none;' in the HTML file // Hide the radar and remote, this way we can bypass setting a style of 'display: none;' in the HTML file
elements.radar.hide(); elements.radar.hide();
elements.remote.hide(); elements.remote.hide();
@@ -97,6 +104,13 @@ remoteButtons.toggleDisplay.click( function() {
elements.radar.fadeToggle(); elements.radar.fadeToggle();
} ) } )
function toggleRemote()
{
elements.remote.toggle();
}
// function toggleLabel( )
// 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( "http://" + resourceName + "/" + name, JSON.stringify( data ), function( datab ) {
@@ -106,15 +120,33 @@ function sendData( name, data ) {
} ); } );
} }
// This runs when the JS file is loaded, loops through all of the remote buttons and assigns them an onclick function
function remoteInit()
{
elements.remote.find( "button" ).each( function( i, obj ) {
if ( $( this ).attr( "data-action" ) && $( this ).attr( "data-value" ) ) {
$( this ).click( function() {
let action = $( this ).data( "action" );
let value = $( this ).data( "value" );
let mode = $( this ).data( "mode" );
sendData( action, { value, mode } );
} )
}
} );
}
// Close the remote when the user presses the 'Escape' key // Close the remote when the user presses the 'Escape' key
document.onkeyup = function ( event ) { document.onkeyup = function ( event ) {
if ( event.keyCode == 27 ) if ( event.keyCode == 27 )
{ {
sendData( "remote", "close" ); sendData( "closeRemote", null );
$( "#rc" ).toggle(); toggleRemote();
} }
} }
remoteInit();
// The main event listener, this is what the NUI messages sent by the LUA side arrive at, they are // The main event listener, this is what the NUI messages sent by the LUA side arrive at, they are
// then handled properly via a switch/case that runs the relevant code // then handled properly via a switch/case that runs the relevant code
window.addEventListener( "message", function( event ) { window.addEventListener( "message", function( event ) {
@@ -123,24 +155,6 @@ window.addEventListener( "message", function( event ) {
if ( item.pathName ) { if ( item.pathName ) {
resourceName = item.pathName; resourceName = item.pathName;
} else if ( item.activateRemote ) { } else if ( item.activateRemote ) {
$( "#rc" ).toggle(); toggleRemote();
} 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( "¦¦¦" );
}
} ); } );