From 67708664bd9b23f7a2719d5a8f458e8d85bcd878 Mon Sep 17 00:00:00 2001 From: Ryan S Date: Mon, 28 Mar 2022 17:05:02 -0400 Subject: [PATCH] feat: Add support for multiple bolo plates --- cl_plate_reader.lua | 32 +++++++++++--------------------- nui/radar.css | 31 +++++++++++++++++++++---------- nui/radar.html | 11 +++++++---- nui/radar.js | 25 +++++++++++++++++-------- 4 files changed, 56 insertions(+), 43 deletions(-) diff --git a/cl_plate_reader.lua b/cl_plate_reader.lua index 87b43ac..f1d5b65 100644 --- a/cl_plate_reader.lua +++ b/cl_plate_reader.lua @@ -48,7 +48,7 @@ READER.vars = hidden = false, -- The BOLO plate - boloPlate = "", + boloPlates = {}, -- Cameras, this table contains all of the data needed for operation of the front and rear plate reader cams = { @@ -99,22 +99,19 @@ function READER:GetIndex( cam ) return self.vars.cams[cam].index end function READER:SetIndex( cam, index ) self.vars.cams[cam].index = index end -- Returns the bolo plate -function READER:GetBoloPlate() - if ( self.vars.boloPlate ~= nil ) then - return self.vars.boloPlate +function READER:GetBoloPlate( plate ) + for _,v in ipairs(self.vars.boloPlates) do + if v == plate then + return true + end end + return false end -- Sets the bolo plate to the given plate -function READER:SetBoloPlate( plate ) - self.vars.boloPlate = plate - UTIL:Notify( "BOLO plate set to: ~b~" .. plate ) -end - --- Clears the BOLO plate -function READER:ClearBoloPlate() - self.vars.boloPlate = nil - UTIL:Notify( "~b~BOLO plate cleared!" ) +function READER:SetBoloPlate( plates ) + self.vars.boloPlates = plates + UTIL:Notify( "~b~BOLO plates updated" ) end -- Returns if the given reader is locked @@ -216,13 +213,6 @@ RegisterNUICallback( "setBoloPlate", function( plate, cb ) cb( "ok" ) end ) --- Runs when the "Clear BOLO Plate" button is pressed on the plate reader box -RegisterNUICallback( "clearBoloPlate", function( plate, cb ) - -- Clear the BOLO plate - READER:ClearBoloPlate() - cb( "ok" ) -end ) - --[[---------------------------------------------------------------------------------- Plate reader threads @@ -275,7 +265,7 @@ function READER:Main() self:SetIndex( cam, index ) -- Automatically lock the plate if the scanned plate matches the BOLO - if ( plate == self:GetBoloPlate() ) then + if ( self:GetBoloPlate( plate ) ) then self:LockCam( cam, false, true ) SYNC:LockReaderCam( cam, READER:GetCameraDataPacket( cam ) ) diff --git a/nui/radar.css b/nui/radar.css index 742d102..70163a1 100644 --- a/nui/radar.css +++ b/nui/radar.css @@ -777,8 +777,8 @@ button:focus { outline: none; } } #plateReaderBox { - width: 225px; - height: 330px; + width: 235px; + height: min-content; position: absolute; margin: auto; @@ -807,10 +807,8 @@ button:focus { outline: none; } #plateReaderBox .container { width: 100%; - height: 200px; display: grid; - grid-template-rows: 60px 70px 60px; align-items: center; justify-items: center; } @@ -820,6 +818,7 @@ button:focus { outline: none; } border-radius: 10px; font-size: 16px; border: none; + margin: 10px 0px; } #plateReaderBox .container .btn:hover { background-color: rgb( 255, 255, 255 ); @@ -829,6 +828,21 @@ button:focus { outline: none; } background-color: rgb( 190, 190, 190 ); padding: 0; } + + #plateReaderBox .container #boloPlates { + border-spacing: 15px 5px; + } + + #plateReaderBox .container .plate_text { + width: 75%; + font-family: "Plate-Font"; + text-align: center; + font-size: 30px; + text-transform: uppercase; + padding: 0; + padding-bottom: 10px; + background-color: white; + } #plateReaderBox .container .plate_input { width: 75%; @@ -839,18 +853,15 @@ button:focus { outline: none; } text-transform: uppercase; padding: 0; padding-bottom: 15px; - margin-bottom: -15px; + margin: 10px 0px; } #plateReaderBox .close { width: 80px; height: 20px; - position: absolute; - left: 0; - right: 0; - bottom: 10px; - margin: auto; + + margin: 10px 0px; border-radius: 10px; border: none; diff --git a/nui/radar.html b/nui/radar.html index 77a92c2..9b2ba35 100644 --- a/nui/radar.html +++ b/nui/radar.html @@ -242,14 +242,17 @@
- +
+ +
+
- + - + +
-
diff --git a/nui/radar.js b/nui/radar.js index e906f12..ffb8ef8 100644 --- a/nui/radar.js +++ b/nui/radar.js @@ -88,8 +88,8 @@ const elements = plateReaderBtn: $( "#plateReaderBtn" ), plateReaderBox: $( "#plateReaderBox" ), boloText: $( "#boloText" ), + boloPlates: $( "#boloPlates" ), setBoloBtn: $( "#setBoloPlate" ), - clearBoloBtn: $( "#clearBoloPlate" ), closePrBtn: $( "#closePlateReaderSettings" ), openHelp: $( "#helpBtn" ), @@ -218,6 +218,9 @@ const dirs = away: 2 } +// Plate Reader +let boloPlates = []; + /*------------------------------------------------------------------------------------ Hide elements @@ -769,18 +772,23 @@ elements.setBoloBtn.click( function() { // Add the padding to the string let text = plate.padStart( plate.length + startSpace ); text = text.padEnd( text.length + endSpace ); + plate = text; + } - // Send the plate to the Lua side - sendData( "setBoloPlate", text ); - } else { - sendData( "setBoloPlate", plate ); + if ( !boloPlates.includes( plate ) ) { + boloPlates.push( plate ); + elements.boloPlates.append( `${plate}` ); } + + elements.boloText.val(""); } ) // Sets the on click function for the clear BOLO button -elements.clearBoloBtn.click( function() { - sendData( "clearBoloPlate", null ); -} ) +function clearBoloPlate( event ) { + const plate = event.target.parentElement.parentElement.dataset.plate; + event.target.parentElement.parentElement.remove(); + boloPlates = boloPlates.filter( e => e !== plate ); +} // Checks what the user is typing into the plate box function checkPlateInput( event ) @@ -844,6 +852,7 @@ elements.closeUiBtn.click( function() { // Close the plate reader settings window when the 'Close' button is pressed elements.closePrBtn.click( function() { setEleVisible( elements.plateReaderBox, false ); + sendData( "setBoloPlate", boloPlates ); } ) // Set the remote scale buttons to change the remote's scale