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

@@ -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;

View File

@@ -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>

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
// 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();
}
} );