Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for multiple bolo plates #30

Open
wants to merge 1 commit into
base: upcoming
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions cl_plate_reader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ) )
Expand Down
31 changes: 21 additions & 10 deletions nui/radar.css
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,8 @@ button:focus { outline: none; }
}

#plateReaderBox {
width: 225px;
height: 330px;
width: 235px;
height: min-content;

position: absolute;
margin: auto;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 );
Expand All @@ -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%;
Expand All @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions nui/radar.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,17 @@
<div class="container">
<button id="togglePlateReader" data-nuitype="togglePlateReaderDisplay" class="btn">Toggle Display</button>

<input id="boloText" type="text" maxlength="8" placeholder="12ABC345" onkeypress="checkPlateInput(event)" class="plate_input"/>
<div style="height: 315px; overflow: auto;">
<table id ="boloPlates">
</table>
</div>

<button id="setBoloPlate" class="btn">Set BOLO Plate</button>
<input id="boloText" type="text" maxlength="8" placeholder="12ABC345" onkeypress="checkPlateInput(event)" class="plate_input"/>

<button id="clearBoloPlate" class="btn">Clear BOLO Plate</button>
<button id="setBoloPlate" class="btn">Add BOLO Plate</button>
<button id="closePlateReaderSettings" class="close">CLOSE</button>
</div>

<button id="closePlateReaderSettings" class="close">CLOSE</button>
</div>

<div id="uiSettingsBox">
Expand Down
25 changes: 17 additions & 8 deletions nui/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ const elements =
plateReaderBtn: $( "#plateReaderBtn" ),
plateReaderBox: $( "#plateReaderBox" ),
boloText: $( "#boloText" ),
boloPlates: $( "#boloPlates" ),
setBoloBtn: $( "#setBoloPlate" ),
clearBoloBtn: $( "#clearBoloPlate" ),
closePrBtn: $( "#closePlateReaderSettings" ),

openHelp: $( "#helpBtn" ),
Expand Down Expand Up @@ -218,6 +218,9 @@ const dirs =
away: 2
}

// Plate Reader
let boloPlates = [];


/*------------------------------------------------------------------------------------
Hide elements
Expand Down Expand Up @@ -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( `<tr data-plate="${plate}"><td class="plate_text">${plate}</td><td><button class="btn" style="width: unset;" onclick="clearBoloPlate(event)">Remove</button></td></tr>` );
}

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 )
Expand Down Expand Up @@ -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
Expand Down