Remote const structure, test speed display

This commit is contained in:
Dan
2019-11-26 14:56:08 +00:00
parent 21e9fc9b6b
commit 1eef251ce8
5 changed files with 104 additions and 24 deletions

View File

@@ -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 )

View File

@@ -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

View File

@@ -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;

View File

@@ -114,50 +114,50 @@
<div id="rc">
<!-- <div id="rc"> -->
<button 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>
<div class="antenna_btns_container">
<div class="btns btns_top">
<button class="zone_btn top_left">OPP LK/REL</button>
<button id="frontOppMode" class="zone_btn top_left">OPP LK/REL</button>
<div class="xmit_wrap">
<div class="xmit_btn xmit_top">
<div class="arrow"></div>
<button class="top_middle">XMIT HOLD</button>
<button id="frontXmitToggle" class="top_middle">XMIT HOLD</button>
</div>
</div>
<button class="zone_btn top_right">SAME LK/REL</button>
<button id="frontSameMode" class="zone_btn top_right">SAME LK/REL</button>
</div>
<div class="breaker"></div>
<div class="btns btns_bottom">
<button class="zone_btn bottom_left">LK/REL OPP</button>
<button id="rearOppMode" class="zone_btn bottom_left">LK/REL OPP</button>
<div class="xmit_wrap">
<div class="xmit_btn xmit_bottom">
<div class="arrow arrow_bottom"></div>
<button class="bottom_middle">HOLD XMIT</button>
<button id="rearXmitToggle" class="bottom_middle">HOLD XMIT</button>
</div>
</div>
<button class="zone_btn bottom_right">LK/REL SAME</button>
<button id="rearSameMode" class="zone_btn bottom_right">LK/REL SAME</button>
</div>
</div>
<p class="label">REAR ANTENNA</p>
<button class="circle_btn menu blue">MENU</button>
<button id="menuButton" class="circle_btn menu blue">MENU</button>
<div class="vol_ps_container">
<button class="vol_and_test blue">VOLUME <span class="hold">TEST</span></button>
<button class="ps_blank blue">PS BLANK</button>
<button id="volAndTest" class="vol_and_test blue">VOLUME <span class="hold">TEST</span></button>
<button id="psBlank" class="ps_blank blue">PS BLANK</button>
</div>
<button class="rounded_btn light blue">UI SETTINGS</button>
<button id="uiSettings" class="rounded_btn light blue">UI SETTINGS</button>
<p class="logo"><span class="large">Wraith</span> ARS 2X</p>
</div>

View File

@@ -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( "¦¦¦" );
}
} );