Remote opens on F5, closes on Esc, updated functions and other stuff

This commit is contained in:
Dan
2019-11-26 10:56:52 +00:00
parent 897ced6c2d
commit 21e9fc9b6b
4 changed files with 81 additions and 28 deletions

View File

@@ -17,15 +17,14 @@ local pairs = pairs
Resource Rename Fix - for those muppets who rename the resource and Resource Rename Fix - for those muppets who rename the resource and
complain that the NUI aspect doesn't work! complain that the NUI aspect doesn't work!
------------------------------------------------------------------------]]-- ------------------------------------------------------------------------]]--
Citizen.CreateThread( function() Citizen.SetTimeout( 5000, function()
-- Wait for a short period of time to give the resource time to load
Citizen.Wait( 10000 )
-- Get the name of the resource, for example the default name is 'wk_wrs2' -- 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 -- 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 ) end )
@@ -640,10 +639,16 @@ end
-- Num7 = 117 - INPUT_VEH_FLY_SELECT_TARGET_LEFT -- Num7 = 117 - INPUT_VEH_FLY_SELECT_TARGET_LEFT
-- Num8 = 111 - INPUT_VEH_FLY_PITCH_UP_ONLY -- Num8 = 111 - INPUT_VEH_FLY_PITCH_UP_ONLY
-- Num9 = 118 - INPUT_VEH_FLY_SELECT_TARGET_RIGHT -- Num9 = 118 - INPUT_VEH_FLY_SELECT_TARGET_RIGHT
-- F5 = 166 - INPUT_SELECT_CHARACTER_MICHAEL
function RADAR:RunControlManager() function RADAR:RunControlManager()
-- 'Z' key, toggles debug mode -- 'Z' key, toggles debug mode
if ( IsDisabledControlJustPressed( 1, 20 ) ) then if ( IsDisabledControlJustPressed( 1, 20 ) ) then
self.config.debug_mode = not self.config.debug_mode self.config.debug_mode = not self.config.debug_mode
end
if ( IsDisabledControlJustPressed( 1, 166 ) ) then
SendNUIMessage( { activateRemote = true } )
SetNuiFocus( true, true )
end end
-- 'X' key, change the sort mode -- 'X' key, change the sort mode
@@ -675,6 +680,16 @@ function RADAR:RunControlManager()
end end
--[[------------------------------------------------------------------------
NUI callback
------------------------------------------------------------------------]]--
RegisterNUICallback( "remote", function( data, cb )
if ( data == "close" ) then
SetNuiFocus( false, false )
end
end )
--[[------------------------------------------------------------------------ --[[------------------------------------------------------------------------
Main function Main function
------------------------------------------------------------------------]]-- ------------------------------------------------------------------------]]--
@@ -738,6 +753,8 @@ end )
-- Main thread -- Main thread
Citizen.CreateThread( function() Citizen.CreateThread( function()
SetNuiFocus( false, false )
while ( true ) do while ( true ) do
RADAR:Main() RADAR:Main()

View File

@@ -19,6 +19,9 @@
box-sizing: border-box; box-sizing: border-box;
} }
/* Removes the outline when buttons have been clicked */
button:focus { outline: none; }
.unit_frame { .unit_frame {
width: 715px; width: 715px;
height: 230px; height: 230px;

View File

@@ -4,7 +4,7 @@
</head> </head>
<body onselectstart="return false;" ondragstart="return false;"> <body onselectstart="return false;" ondragstart="return false;">
<div id="radarFrame" class="unit_frame" style="visibility: hidden;"> <div id="radarFrame" class="unit_frame">
<!-- <div class="unit_frame"> --> <!-- <div class="unit_frame"> -->
<div class="frame_border"></div> <div class="frame_border"></div>
@@ -112,7 +112,7 @@
</div> </div>
</div> </div>
<div id="rc" style="visibility: hidden;"> <div id="rc">
<!-- <div id="rc"> --> <!-- <div id="rc"> -->
<button class="rounded_btn toggle_display">TOGGLE DISPLAY</button> <button class="rounded_btn toggle_display">TOGGLE DISPLAY</button>

View File

@@ -8,60 +8,93 @@
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
// Variables
var resourceName;
// Setup the main const element structure, this way we can easily access elements without having the mess // 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 // that was in the JS file for WraithRS
const elements = const elements =
{ {
radar: $( "radarFrame" ), radar: $( "#radarFrame" ),
patrolSpeed: $( "patrolSpeed" ), remote: $( "#rc" ),
patrolSpeed: $( "#patrolSpeed" ),
antennas: { antennas: {
front: { front: {
targetSpeed: $( "frontSpeed" ), targetSpeed: $( "#frontSpeed" ),
dirs: { dirs: {
forward: $( "frontDirAway" ), forward: $( "#frontDirAway" ),
backward: $( "frontDirTowards" ) backward: $( "#frontDirTowards" )
}, },
modes: { modes: {
same: $( "frontSame" ), same: $( "#frontSame" ),
opp: $( "frontOpp" ), opp: $( "#frontOpp" ),
xmit: $( "frontXmit" ) xmit: $( "#frontXmit" )
}, },
fast: { fast: {
speed: $( "frontFastSpeed" ), speed: $( "#frontFastSpeed" ),
fastLabel: $( "frontFastLabel" ), fastLabel: $( "#frontFastLabel" ),
lockLabel: $( "frontFastLockLabel" ) lockLabel: $( "#frontFastLockLabel" )
} }
}, },
rear: { rear: {
targetSpeed: $( "rearSpeed" ), targetSpeed: $( "#rearSpeed" ),
dirs: { dirs: {
forward: $( "rearDirTowards" ), forward: $( "#rearDirTowards" ),
backward: $( "rearDirAway" ) backward: $( "#rearDirAway" )
}, },
modes: { modes: {
same: $( "rearSame" ), same: $( "#rearSame" ),
opp: $( "rearOpp" ), opp: $( "#rearOpp" ),
xmit: $( "rearXmit" ) xmit: $( "#rearXmit" )
}, },
fast: { fast: {
speed: $( "rearFastSpeed" ), speed: $( "#rearFastSpeed" ),
fastLabel: $( "rearFastLabel" ), fastLabel: $( "#rearFastLabel" ),
lockLabel: $( "rearFastLockLabel" ) 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 // 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 // then handled properly via a switch/case that runs the relevant code
window.addEventListener( "message", function( event ) { window.addEventListener( "message", function( event ) {
var item = event.data; var item = event.data;
if ( item.pathName ) {
resourceName = item.pathName;
} else if ( item.activateRemote ) {
$( "#rc" ).toggle();
}
} ); } );