tweak(interface/menu): SetNuiFocusKeepInput

Default to allow input; disable with "disableInput = true" during registration.
This commit is contained in:
Linden
2022-08-08 18:07:30 +10:00
parent 2e77817c41
commit c3726ed924

View File

@@ -1,5 +1,6 @@
local registeredMenus = {} local registeredMenus = {}
local openMenu = nil local openMenu = nil
local keepInput = IsNuiFocusKeepingInput()
function lib.registerMenu(data, cb) function lib.registerMenu(data, cb)
if not data.id then return error('No menu id was provided.') end if not data.id then return error('No menu id was provided.') end
@@ -10,30 +11,56 @@ function lib.registerMenu(data, cb)
end end
function lib.showMenu(id) function lib.showMenu(id)
openMenu = registeredMenus[id] local menu = registeredMenus[id]
if not menu then
return error(('No menu with id %s was found'):format(id))
end
if not openMenu then if not openMenu then
return error(('No menu with id %s was found'):format(id)) CreateThread(function()
while openMenu do
if not openMenu.disableInput then
DisablePlayerFiring(cache.playerId, true)
HudWeaponWheelIgnoreSelection()
DisableControlAction(0, 140, true)
end
Wait(0)
end
end)
end
openMenu = menu
keepInput = IsNuiFocusKeepingInput()
if not menu.disableInput then
SetNuiFocusKeepInput(true)
end end
SetNuiFocus(true, false) SetNuiFocus(true, false)
SendNUIMessage({ SendNUIMessage({
action = 'setMenu', action = 'setMenu',
data = { data = {
position = openMenu.position, position = menu.position,
title = openMenu.title, title = menu.title,
items = openMenu.options items = menu.options
} }
}) })
end end
local function resetFocus()
SetNuiFocus(false, false)
SetNuiFocusKeepInput(keepInput)
end
function lib.hideMenu(onExit) function lib.hideMenu(onExit)
if onExit and openMenu.onClose then if onExit and openMenu.onClose then
openMenu.onClose() openMenu.onClose()
end end
openMenu = nil openMenu = nil
SetNuiFocus(false, false) resetFocus()
SendNUIMessage({ SendNUIMessage({
action = 'closeMenu' action = 'closeMenu'
}) })
@@ -58,7 +85,7 @@ RegisterNUICallback('confirmSelected', function(data, cb)
end end
if openMenu.options[data[1]].close ~= false then if openMenu.options[data[1]].close ~= false then
SetNuiFocus(false, false) resetFocus()
end end
if openMenu.cb then if openMenu.cb then
@@ -96,7 +123,7 @@ end)
RegisterNUICallback('closeMenu', function(data, cb) RegisterNUICallback('closeMenu', function(data, cb)
cb(1) cb(1)
SetNuiFocus(false, false) resetFocus()
if openMenu.onClose then if openMenu.onClose then
openMenu.onClose() openMenu.onClose()