feat: exit the operator menu on remote close

This commit is contained in:
Dan
2021-03-14 15:03:16 +00:00
parent 46a19221fb
commit 55b5a90a28

View File

@@ -756,6 +756,24 @@ function RADAR:SetMenuState( state )
end end
end end
-- Closes the operator menu
function RADAR:CloseMenu( playAudio )
-- Set the internal menu state to be closed (false)
RADAR:SetMenuState( false )
-- Send a setting update to the NUI side
RADAR:SendSettingUpdate()
-- Play a menu done beep
if ( playAudio or playAudio == nil ) then
SendNUIMessage( { _type = "audio", name = "done", vol = RADAR:GetSettingValue( "beep" ) } )
end
-- Save the operator menu values
local omData = json.encode( RADAR.vars.settings )
SetResourceKvp( "wk_wars2x_om_data", omData )
end
-- Returns if the operator menu is open -- Returns if the operator menu is open
function RADAR:IsMenuOpen() function RADAR:IsMenuOpen()
return self.vars.menuActive return self.vars.menuActive
@@ -1725,7 +1743,13 @@ end )
RegisterNUICallback( "closeRemote", function( data, cb ) RegisterNUICallback( "closeRemote", function( data, cb )
-- Remove focus to the NUI side -- Remove focus to the NUI side
SetNuiFocus( false, false ) SetNuiFocus( false, false )
if ( RADAR:IsMenuOpen() ) then
RADAR:CloseMenu( false )
end
SYNC:SetRemoteOpenState( false ) SYNC:SetRemoteOpenState( false )
cb( "ok" ) cb( "ok" )
end ) end )
@@ -1736,18 +1760,7 @@ RegisterNUICallback( "setAntennaMode", function( data, cb )
if ( RADAR:IsPowerOn() and not RADAR:IsPoweringUp() ) then if ( RADAR:IsPowerOn() and not RADAR:IsPoweringUp() ) then
-- As the mode buttons are used to exit the menu, we check for that -- As the mode buttons are used to exit the menu, we check for that
if ( RADAR:IsMenuOpen() ) then if ( RADAR:IsMenuOpen() ) then
-- Set the internal menu state to be closed (false) RADAR:CloseMenu()
RADAR:SetMenuState( false )
-- Send a setting update to the NUI side
RADAR:SendSettingUpdate()
-- Play a menu done beep
SendNUIMessage( { _type = "audio", name = "done", vol = RADAR:GetSettingValue( "beep" ) } )
-- Save the operator menu values
local omData = json.encode( RADAR.vars.settings )
SetResourceKvp( "wk_wars2x_om_data", omData )
else else
-- Change the mode for the designated antenna, pass along a callback which contains data from this NUI callback -- Change the mode for the designated antenna, pass along a callback which contains data from this NUI callback
RADAR:SetAntennaMode( data.value, tonumber( data.mode ) ) RADAR:SetAntennaMode( data.value, tonumber( data.mode ) )