diff --git a/cl_radar.lua b/cl_radar.lua
index 8e63ed0..6d35ea9 100644
--- a/cl_radar.lua
+++ b/cl_radar.lua
@@ -17,15 +17,14 @@ local pairs = pairs
Resource Rename Fix - for those muppets who rename the resource and
complain that the NUI aspect doesn't work!
------------------------------------------------------------------------]]--
-Citizen.CreateThread( function()
- -- Wait for a short period of time to give the resource time to load
- Citizen.Wait( 10000 )
-
+Citizen.SetTimeout( 5000, function()
-- Get the name of the resource, for example the default name is 'wk_wrs2'
- local resourceName = GetCurrentResourceName()
+ local name = GetCurrentResourceName()
+
+ print( "WK_WARS2X: Sending resource name (" .. name .. ") to JavaScript side." )
-- Send a message through the NUI system to the JavaScript file to give the name of the resource
- SendNUIMessage( { resourcename = resourceName } )
+ SendNUIMessage( { pathName = name } )
end )
@@ -640,10 +639,16 @@ end
-- Num7 = 117 - INPUT_VEH_FLY_SELECT_TARGET_LEFT
-- Num8 = 111 - INPUT_VEH_FLY_PITCH_UP_ONLY
-- Num9 = 118 - INPUT_VEH_FLY_SELECT_TARGET_RIGHT
+-- F5 = 166 - INPUT_SELECT_CHARACTER_MICHAEL
function RADAR:RunControlManager()
-- 'Z' key, toggles debug mode
if ( IsDisabledControlJustPressed( 1, 20 ) ) then
self.config.debug_mode = not self.config.debug_mode
+ end
+
+ if ( IsDisabledControlJustPressed( 1, 166 ) ) then
+ SendNUIMessage( { activateRemote = true } )
+ SetNuiFocus( true, true )
end
-- 'X' key, change the sort mode
@@ -675,6 +680,16 @@ function RADAR:RunControlManager()
end
+--[[------------------------------------------------------------------------
+ NUI callback
+------------------------------------------------------------------------]]--
+RegisterNUICallback( "remote", function( data, cb )
+ if ( data == "close" ) then
+ SetNuiFocus( false, false )
+ end
+end )
+
+
--[[------------------------------------------------------------------------
Main function
------------------------------------------------------------------------]]--
@@ -738,6 +753,8 @@ end )
-- Main thread
Citizen.CreateThread( function()
+ SetNuiFocus( false, false )
+
while ( true ) do
RADAR:Main()
diff --git a/nui/radar.css b/nui/radar.css
index 7a4e822..68ced45 100644
--- a/nui/radar.css
+++ b/nui/radar.css
@@ -19,6 +19,9 @@
box-sizing: border-box;
}
+/* Removes the outline when buttons have been clicked */
+button:focus { outline: none; }
+
.unit_frame {
width: 715px;
height: 230px;
diff --git a/nui/radar.html b/nui/radar.html
index a94b025..2d261ef 100644
--- a/nui/radar.html
+++ b/nui/radar.html
@@ -4,7 +4,7 @@
-
+
@@ -112,7 +112,7 @@
-
+
diff --git a/nui/radar.js b/nui/radar.js
index ba4549b..e01f1b0 100644
--- a/nui/radar.js
+++ b/nui/radar.js
@@ -8,60 +8,93 @@
-------------------------------------------------------------------------*/
+// Variables
+var resourceName;
+
// Setup the main const element structure, this way we can easily access elements without having the mess
// that was in the JS file for WraithRS
const elements =
{
- radar: $( "radarFrame" ),
- patrolSpeed: $( "patrolSpeed" ),
+ radar: $( "#radarFrame" ),
+ remote: $( "#rc" ),
+
+ patrolSpeed: $( "#patrolSpeed" ),
antennas: {
front: {
- targetSpeed: $( "frontSpeed" ),
+ targetSpeed: $( "#frontSpeed" ),
dirs: {
- forward: $( "frontDirAway" ),
- backward: $( "frontDirTowards" )
+ forward: $( "#frontDirAway" ),
+ backward: $( "#frontDirTowards" )
},
modes: {
- same: $( "frontSame" ),
- opp: $( "frontOpp" ),
- xmit: $( "frontXmit" )
+ same: $( "#frontSame" ),
+ opp: $( "#frontOpp" ),
+ xmit: $( "#frontXmit" )
},
fast: {
- speed: $( "frontFastSpeed" ),
- fastLabel: $( "frontFastLabel" ),
- lockLabel: $( "frontFastLockLabel" )
+ speed: $( "#frontFastSpeed" ),
+ fastLabel: $( "#frontFastLabel" ),
+ lockLabel: $( "#frontFastLockLabel" )
}
},
rear: {
- targetSpeed: $( "rearSpeed" ),
+ targetSpeed: $( "#rearSpeed" ),
dirs: {
- forward: $( "rearDirTowards" ),
- backward: $( "rearDirAway" )
+ forward: $( "#rearDirTowards" ),
+ backward: $( "#rearDirAway" )
},
modes: {
- same: $( "rearSame" ),
- opp: $( "rearOpp" ),
- xmit: $( "rearXmit" )
+ same: $( "#rearSame" ),
+ opp: $( "#rearOpp" ),
+ xmit: $( "#rearXmit" )
},
fast: {
- speed: $( "rearFastSpeed" ),
- fastLabel: $( "rearFastLabel" ),
- lockLabel: $( "rearFastLockLabel" )
+ speed: $( "#rearFastSpeed" ),
+ fastLabel: $( "#rearFastLabel" ),
+ lockLabel: $( "#rearFastLockLabel" )
}
}
}
}
+// 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();
+
+// 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 ) {
+ if ( datab != "ok" ) {
+ console.log( datab );
+ }
+ } );
+}
+
+// Close the remote when the user presses the 'Escape' key
+document.onkeyup = function ( event ) {
+ if ( event.keyCode == 27 )
+ {
+ sendData( "remote", "close" );
+ $( "#rc" ).toggle();
+ }
+}
+
// 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
window.addEventListener( "message", function( event ) {
var item = event.data;
+
+ if ( item.pathName ) {
+ resourceName = item.pathName;
+ } else if ( item.activateRemote ) {
+ $( "#rc" ).toggle();
+ }
} );
\ No newline at end of file