From 5580cc874524fcdb555d5664a724447ae26244dc Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 25 Feb 2020 14:23:31 +0000 Subject: [PATCH] Added a second set of binds for small keyboards Also changed the key lock key to L, as the "switch binds" key is now K --- cl_plate_reader.lua | 6 ++--- cl_radar.lua | 59 ++++++++++++++++++++++++++++++++-------- config.lua | 65 ++++++++++++++++++++++++++++++++------------- nui/radar.css | 6 ++--- nui/radar.html | 2 ++ nui/radar.js | 40 +++++++++++++++++++++++----- 6 files changed, 136 insertions(+), 42 deletions(-) diff --git a/cl_plate_reader.lua b/cl_plate_reader.lua index 896897a..c83e1c8 100644 --- a/cl_plate_reader.lua +++ b/cl_plate_reader.lua @@ -104,14 +104,14 @@ function READER:GetCamLocked( cam ) end -- Locks the given reader -function READER:LockCam( cam, playAudio ) +function READER:LockCam( cam, playAudio, isBolo ) -- Check that plate readers can actually be locked if ( PLY:VehicleStateValid() and self:CanPerformMainTask() ) then -- Toggle the lock state self.vars.cams[cam].locked = not self.vars.cams[cam].locked -- Tell the NUI side to show/hide the lock icon - SendNUIMessage( { _type = "lockPlate", cam = cam, state = self:GetCamLocked( cam ) } ) + SendNUIMessage( { _type = "lockPlate", cam = cam, state = self:GetCamLocked( cam ), isBolo = isBolo } ) -- Play a beep if ( self:GetCamLocked( cam ) ) then @@ -199,7 +199,7 @@ function READER:Main() -- Automatically lock the plate if the scanned plate matches the BOLO if ( plate == self:GetBoloPlate() ) then - self:LockCam( cam, false ) + self:LockCam( cam, false, true ) SendNUIMessage( { _type = "audio", name = "plate_hit", vol = RADAR:GetSettingValue( "plateAudio" ) } ) end diff --git a/cl_radar.lua b/cl_radar.lua index 6ca8003..7d556f6 100644 --- a/cl_radar.lua +++ b/cl_radar.lua @@ -204,7 +204,11 @@ RADAR.vars = threadWaitTime = 500, -- Key lock, when true, prevents any of the radar's key events from working, like the ELS key lock - keyLock = false + keyLock = false, + + -- Full keyboard, when true, the keybinds for the radar will be set to the keys on the numpad, when false, the + -- keybinds for the radar will be set to the number keys above WASD + fullKeyboard = true } -- Speed conversion values @@ -434,6 +438,32 @@ function RADAR:GetKeyLockState() return self.vars.keyLock end +-- Toggles between the full and small keybinds +function RADAR:ToggleFullKeyboard() + -- Check the player state is valid + if ( PLY:VehicleStateValid() ) then + -- Toggle the full keyboard state + self.vars.fullKeyboard = not self.vars.fullKeyboard + + -- Tell the NUI side to display the keybind message + SendNUIMessage( { _type = "displayKeybindChange", state = self:GetFullKeyboardState() } ) + end +end + +-- Returns the full keyboard state +function RADAR:GetFullKeyboardState() + return self.vars.fullKeyboard +end + +-- Returns which keybind set to use +function RADAR:GetKeybindType() + if ( self:GetFullKeyboardState() ) then + return "full" + else + return "small" + end +end + --[[---------------------------------------------------------------------------------- Radar menu functions @@ -1611,37 +1641,44 @@ end ) function RunControlManager() -- Make sure only the keyboard works if ( IsInputDisabled( 0 ) ) then - if ( not RADAR:GetKeyLockState() ) then + if ( not RADAR:GetKeyLockState() ) then + local keyType = RADAR:GetKeybindType() + -- Opens the remote control - if ( IsDisabledControlJustPressed( 1, CONFIG.remote_control_key ) ) then + if ( IsDisabledControlJustPressed( 1, CONFIG.keys.remote_control ) ) then RADAR:OpenRemote() end -- Locks speed from front antenna - if ( IsDisabledControlJustPressed( 1, CONFIG.front_lock_key ) ) then + if ( IsDisabledControlJustPressed( 1, CONFIG.keys[keyType].front_lock ) ) then RADAR:LockAntennaSpeed( "front" ) end -- Locks speed from rear antenna - if ( IsDisabledControlJustPressed( 1, CONFIG.rear_lock_key ) ) then + if ( IsDisabledControlJustPressed( 1, CONFIG.keys[keyType].rear_lock ) ) then RADAR:LockAntennaSpeed( "rear" ) end -- Locks front plate reader - if ( IsDisabledControlJustPressed( 1, CONFIG.plate_front_lock_key ) ) then - READER:LockCam( "front", true ) + if ( IsDisabledControlJustPressed( 1, CONFIG.keys[keyType].plate_front_lock ) ) then + READER:LockCam( "front", true, false ) end -- Locks front plate reader - if ( IsDisabledControlJustPressed( 1, CONFIG.plate_rear_lock_key ) ) then - READER:LockCam( "rear", true ) + if ( IsDisabledControlJustPressed( 1, CONFIG.keys[keyType].plate_rear_lock ) ) then + READER:LockCam( "rear", true, false ) end end -- Toggles the key lock state - if ( IsDisabledControlJustPressed( 1, CONFIG.key_lock_key ) ) then + if ( IsDisabledControlJustPressed( 1, CONFIG.keys.key_lock ) ) then RADAR:ToggleKeyLock() - end + end + + -- Toggles between the keybind types + if ( IsDisabledControlJustPressed( 1, CONFIG.keys.switch_keys ) ) then + RADAR:ToggleFullKeyboard() + end end -- Shortcut to restart the resource diff --git a/config.lua b/config.lua index ee7510b..6159544 100644 --- a/config.lua +++ b/config.lua @@ -8,29 +8,58 @@ -- Do not touch this CONFIG = {} --- Remote control key --- The default key to open the remote control is 166 (F5 - INPUT_SELECT_CHARACTER_MICHAEL) -CONFIG.remote_control_key = 166 +CONFIG.keys = +{ + -- Remote control key + -- The default key to open the remote control is 166 (F5 - INPUT_SELECT_CHARACTER_MICHAEL) + remote_control = 166, --- Radar front antenna lock/unlock Key --- The default key to lock/unlock the front antenna is 111 (Numpad 8 - INPUT_VEH_FLY_PITCH_UP_ONLY) -CONFIG.front_lock_key = 111 + -- Radar key lock key + -- The default key to enable/disable the radar key lock is 182 (L - INPUT_CELLPHONE_CAMERA_FOCUS_LOCK) + key_lock = 182, --- Radar rear antenna lock/unlock Key --- The default key to lock/unlock the rear antenna is 112 (Numpad 5 - INPUT_VEH_FLY_PITCH_DOWN_ONLY) -CONFIG.rear_lock_key = 112 + -- Radar keybinds switch + -- The default to key to switch the bind set is (K - INPUT_REPLAY_SHOWHOTKEY) + switch_keys = 311, --- Radar key lock key --- The default key to enable/disable the radar key lock is 311 (K - INPUT_REPLAY_SHOWHOTKEY) -CONFIG.key_lock_key = 311 + -- Keys for a full size keyboard + [ "full" ] = { + -- Radar front antenna lock/unlock Key + -- The default full keyboard key to lock/unlock the front antenna is 111 (Numpad 8 - INPUT_VEH_FLY_PITCH_UP_ONLY) + front_lock = 111, --- Plate reader front lock/unlock Key --- The default key to lock/unlock the front plate reader is 118 (Numpad 9 - INPUT_VEH_FLY_SELECT_TARGET_RIGHT) -CONFIG.plate_front_lock_key = 118 + -- Radar rear antenna lock/unlock Key + -- The default full keyboard key to lock/unlock the rear antenna is 112 (Numpad 5 - INPUT_VEH_FLY_PITCH_DOWN_ONLY) + rear_lock = 112, --- Plate reader rear lock/unlock Key --- The default key to lock/unlock the rear plate reader is 109 (Numpad 6 - INPUT_VEH_FLY_ROLL_RIGHT_ONLY) -CONFIG.plate_rear_lock_key = 109 + -- Plate reader front lock/unlock Key + -- The default full keyboard key to lock/unlock the front plate reader is 118 (Numpad 9 - INPUT_VEH_FLY_SELECT_TARGET_RIGHT) + plate_front_lock = 118, + + -- Plate reader rear lock/unlock Key + -- The default full keyboard key to lock/unlock the rear plate reader is 109 (Numpad 6 - INPUT_VEH_FLY_ROLL_RIGHT_ONLY) + plate_rear_lock = 109 + }, + + -- Keys for smaller keyboards + [ "small" ] = { + -- Radar front antenna lock/unlock Key + -- The default small keyboard key to lock/unlock the front antenna is 157 (1 - INPUT_SELECT_WEAPON_UNARMED) + front_lock = 157, + + -- Radar rear antenna lock/unlock Key + -- The default small keyboard key to lock/unlock the rear antenna is 158 (2 - INPUT_SELECT_WEAPON_MELEE) + rear_lock = 158, + + -- Plate reader front lock/unlock Key + -- The default small keyboard key to lock/unlock the front plate reader is 160 (3 - INPUT_SELECT_WEAPON_SHOTGUN) + plate_front_lock = 160, + + -- Plate reader rear lock/unlock Key + -- The default small keyboard key to lock/unlock the rear plate reader is 164 (4 - INPUT_SELECT_WEAPON_HEAVY) + plate_rear_lock = 164 + } +} -- Radar fast limit locking -- When enabled, the player will be able to define a fast limit within the radar's menu, when a vehicle diff --git a/nui/radar.css b/nui/radar.css index 519f6da..723cd4e 100644 --- a/nui/radar.css +++ b/nui/radar.css @@ -958,7 +958,7 @@ button:focus { outline: none; } padding: 0; } -#keyLockLabel { +#keyLockLabel, #keyBindsLabel { position: absolute; left: 0; right: 0; @@ -967,12 +967,12 @@ button:focus { outline: none; } text-align: center; font-size: 30px; - color: rgb( 200, 200, 200 ); + color: rgb(255, 255, 255); text-shadow: 3px 2px 5px rgb( 0, 0, 0 ); z-index: 5; } - #keyLockLabel span { + #keyLockLabel span, #keyBindsLabel span { font-size: 30px; } diff --git a/nui/radar.html b/nui/radar.html index bec5011..6a24aad 100644 --- a/nui/radar.html +++ b/nui/radar.html @@ -268,6 +268,8 @@

Radar key lock

+

Radar keybinds set for a

+
diff --git a/nui/radar.js b/nui/radar.js index 1ee09ca..8f96e3f 100644 --- a/nui/radar.js +++ b/nui/radar.js @@ -118,6 +118,11 @@ const elements = stateLabel: $( "#keyLockStateLabel" ) }, + keyBinds: { + label: $( "#keyBindsLabel" ), + stateLabel: $( "#keyBindsStateLabel" ) + }, + patrolSpeed: $( "#patrolSpeed" ), antennas: { @@ -196,6 +201,7 @@ elements.plateReader.hide(); elements.plateReaderBox.hide(); elements.uiSettingsBox.hide(); elements.keyLock.label.hide(); +elements.keyBinds.label.hide(); elements.helpWindow.hide(); // Sets the action for the "UI SETTINGS" button on the remote to open the UI settings box @@ -304,7 +310,7 @@ function setAntennaDirs( ant, dir, fastDir ) } // sets the plate lock light for the given plate reader -function setPlateLock( cam, state ) +function setPlateLock( cam, state, isBolo ) { // Get the plate reader lock object let obj = elements.plates[cam]; @@ -313,12 +319,15 @@ function setPlateLock( cam, state ) if ( state ) { obj.lock.addClass( "active" ); - // Make the hit plate flash for 3 seconds, acts as a visual aid - obj.plate.addClass( "plate_hit" ); + // Only flash the plate if it was a BOLO plate + if ( isBolo ) { + // Make the hit plate flash for 3 seconds, acts as a visual aid + obj.plate.addClass( "plate_hit" ); - setTimeout( function() { - obj.plate.removeClass( "plate_hit" ); - }, 3000 ); + setTimeout( function() { + obj.plate.removeClass( "plate_hit" ); + }, 3000 ); + } } else { obj.lock.removeClass( "active" ); } @@ -563,6 +572,20 @@ function displayKeyLock( state ) }, 2000 ); } +function displayKeybindState( state ) +{ +// Set the state label text to enabled or disabled + elements.keyBinds.stateLabel.html( state ? "full keyboard" : "small keyboard" ); + + // Fade in the label + elements.keyBinds.label.fadeIn(); + + // Make the label fade out after 2 seconds + setTimeout( function() { + elements.keyBinds.label.fadeOut(); + }, 2000 ); +} + // 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 ) { @@ -981,6 +1004,9 @@ window.addEventListener( "message", function( event ) { case "displayKeyLock": displayKeyLock( item.state ); break; + case "displayKeybindChange": + displayKeybindState( item.state ); + return; // Radar events case "openRemote": @@ -1026,7 +1052,7 @@ window.addEventListener( "message", function( event ) { setPlate( item.cam, item.plate, item.index ); break; case "lockPlate": - setPlateLock( item.cam, item.state ); + setPlateLock( item.cam, item.state, item.isBolo ); break; // Audio events