mirror of
https://github.com/Michatec/wk_wars2x.git
synced 2026-04-01 08:26:27 +02:00
Remote opens on F5, closes on Esc, updated functions and other stuff
This commit is contained in:
29
cl_radar.lua
29
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()
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</head>
|
||||
|
||||
<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="frame_border"></div>
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="rc" style="visibility: hidden;">
|
||||
<div id="rc">
|
||||
<!-- <div id="rc"> -->
|
||||
<button class="rounded_btn toggle_display">TOGGLE DISPLAY</button>
|
||||
|
||||
|
||||
73
nui/radar.js
73
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();
|
||||
}
|
||||
} );
|
||||
Reference in New Issue
Block a user