mirror of
https://github.com/Michatec/wk_wars2x.git
synced 2026-04-01 00:16:27 +02:00
JS switch/case, xmit light, speed display setting, reduced player vehicle check rate
This commit is contained in:
@@ -29,9 +29,9 @@ button:focus { outline: none; }
|
||||
position: absolute;
|
||||
margin: auto;
|
||||
/* top: 0; */
|
||||
right: 0;
|
||||
bottom: 15px;
|
||||
left: 0;
|
||||
right: 10px;
|
||||
bottom: 10px;
|
||||
/* left: 0; */
|
||||
|
||||
background-image: url( "frame.png" );
|
||||
}
|
||||
|
||||
@@ -119,31 +119,31 @@
|
||||
|
||||
<div class="antenna_btns_container">
|
||||
<div class="btns btns_top">
|
||||
<button id="frontOppMode" data-action="setAntennaMode" data-value="front" data-mode="2" class="zone_btn top_left">OPP LK/REL</button>
|
||||
<button id="frontOppMode" data-nuitype="setAntennaMode" data-value="front" data-mode="2" class="zone_btn top_left">OPP LK/REL</button>
|
||||
|
||||
<div class="xmit_wrap">
|
||||
<div class="xmit_btn xmit_top">
|
||||
<div class="arrow"></div>
|
||||
<button id="frontXmitToggle" class="top_middle">XMIT HOLD</button>
|
||||
<button id="frontXmitToggle" data-nuitype="toggleAntenna" data-value="front" class="top_middle">XMIT HOLD</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button id="frontSameMode" data-action="setAntennaMode" data-value="front" data-mode="1" class="zone_btn top_right">SAME LK/REL</button>
|
||||
<button id="frontSameMode" data-nuitype="setAntennaMode" data-value="front" data-mode="1" class="zone_btn top_right">SAME LK/REL</button>
|
||||
</div>
|
||||
|
||||
<div class="breaker"></div>
|
||||
|
||||
<div class="btns btns_bottom">
|
||||
<button id="rearOppMode" data-action="setAntennaMode" data-value="rear" data-mode="2" class="zone_btn bottom_left">LK/REL OPP</button>
|
||||
<button id="rearOppMode" data-nuitype="setAntennaMode" data-value="rear" data-mode="2" class="zone_btn bottom_left">LK/REL OPP</button>
|
||||
|
||||
<div class="xmit_wrap">
|
||||
<div class="xmit_btn xmit_bottom">
|
||||
<div class="arrow arrow_bottom"></div>
|
||||
<button id="rearXmitToggle" class="bottom_middle">HOLD XMIT</button>
|
||||
<button id="rearXmitToggle" data-nuitype="toggleAntenna" data-value="rear" class="bottom_middle">HOLD XMIT</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button id="rearSameMode" data-action="setAntennaMode" data-value="rear" data-mode="1" class="zone_btn bottom_right">LK/REL SAME</button>
|
||||
<button id="rearSameMode" data-nuitype="setAntennaMode" data-value="rear" data-mode="1" class="zone_btn bottom_right">LK/REL SAME</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
92
nui/radar.js
92
nui/radar.js
@@ -90,13 +90,14 @@ const remoteButtons =
|
||||
|
||||
const antennaModes =
|
||||
{
|
||||
same: 0,
|
||||
opp: 1,
|
||||
both: 2
|
||||
off: 0,
|
||||
same: 1,
|
||||
opp: 2,
|
||||
both: 3
|
||||
}
|
||||
|
||||
// Hide the radar and remote, this way we can bypass setting a style of 'display: none;' in the HTML file
|
||||
elements.radar.hide();
|
||||
// elements.radar.hide();
|
||||
elements.remote.hide();
|
||||
|
||||
// Create the onclick event for the toggle display button
|
||||
@@ -109,7 +110,39 @@ function toggleRemote()
|
||||
elements.remote.toggle();
|
||||
}
|
||||
|
||||
// function toggleLabel( )
|
||||
function setLight( ant, cat, item, state )
|
||||
{
|
||||
let obj = elements.antennas[ant][cat][item];
|
||||
|
||||
if ( state ) {
|
||||
obj.addClass( "active" );
|
||||
} else {
|
||||
obj.removeClass( "active" );
|
||||
}
|
||||
}
|
||||
|
||||
function setAntennaXmit( ant, state )
|
||||
{
|
||||
setLight( ant, "modes", "xmit", state );
|
||||
|
||||
if ( !state ) {
|
||||
elements.antennas[ant].targetSpeed.html( "¦¦¦" );
|
||||
elements.antennas[ant].fast.speed.html( "HLd" );
|
||||
}
|
||||
}
|
||||
|
||||
function updateDisplays( ps, ants )
|
||||
{
|
||||
elements.patrolSpeed.html( ps );
|
||||
|
||||
if ( ants["front"].speed != null ) {
|
||||
elements.antennas["front"].targetSpeed.html( ants["front"].speed );
|
||||
}
|
||||
|
||||
if ( ants["front"].fast != null ) {
|
||||
elements.antennas["front"].fast.speed.html( ants["front"].fast );
|
||||
}
|
||||
}
|
||||
|
||||
// This function is used to send data back through to the LUA side
|
||||
function sendData( name, data ) {
|
||||
@@ -121,20 +154,17 @@ function sendData( name, data ) {
|
||||
}
|
||||
|
||||
// This runs when the JS file is loaded, loops through all of the remote buttons and assigns them an onclick function
|
||||
function remoteInit()
|
||||
{
|
||||
elements.remote.find( "button" ).each( function( i, obj ) {
|
||||
if ( $( this ).attr( "data-action" ) && $( this ).attr( "data-value" ) ) {
|
||||
$( this ).click( function() {
|
||||
let action = $( this ).data( "action" );
|
||||
let value = $( this ).data( "value" );
|
||||
let mode = $( this ).data( "mode" );
|
||||
elements.remote.find( "button" ).each( function( i, obj ) {
|
||||
if ( $( this ).attr( "data-nuitype" ) && $( this ).attr( "data-value" ) ) {
|
||||
$( this ).click( function() {
|
||||
let type = $( this ).data( "nuitype" );
|
||||
let value = $( this ).data( "value" );
|
||||
let mode = $( this ).attr( "data-mode" ) ? $( this ).data( "mode" ) : null;
|
||||
|
||||
sendData( action, { value, mode } );
|
||||
} )
|
||||
}
|
||||
} );
|
||||
}
|
||||
sendData( type, { value, mode } );
|
||||
} )
|
||||
}
|
||||
} );
|
||||
|
||||
// Close the remote when the user presses the 'Escape' key
|
||||
document.onkeyup = function ( event ) {
|
||||
@@ -145,16 +175,26 @@ document.onkeyup = function ( event ) {
|
||||
}
|
||||
}
|
||||
|
||||
remoteInit();
|
||||
|
||||
// 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;
|
||||
var item = event.data;
|
||||
var type = event.data._type;
|
||||
|
||||
if ( item.pathName ) {
|
||||
resourceName = item.pathName;
|
||||
} else if ( item.activateRemote ) {
|
||||
toggleRemote();
|
||||
}
|
||||
switch ( type ) {
|
||||
case "updatePathName":
|
||||
resourceName = item.pathName
|
||||
break;
|
||||
case "openRemote":
|
||||
toggleRemote();
|
||||
break;
|
||||
case "update":
|
||||
updateDisplays( item.speed, item.antennas );
|
||||
break;
|
||||
case "antennaXmit":
|
||||
setAntennaXmit( item.ant, item.on );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} );
|
||||
Reference in New Issue
Block a user