mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
feat(interface/context): onExit function
Allows defining a function in the menu that must be called onExit which is going to execute every time the user exits the context menu with ESC
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
local contextMenus = {}
|
||||
local openContextMenu = nil
|
||||
|
||||
local function closeContext(_, cb, onExit)
|
||||
if cb then cb(1) end
|
||||
if (cb or onExit) and contextMenus[openContextMenu].onExit then contextMenus[openContextMenu].onExit() end
|
||||
SetNuiFocus(false, false)
|
||||
if not cb then SendNUIMessage({action = 'hideContext'}) end
|
||||
openContextMenu = nil
|
||||
end
|
||||
|
||||
function lib.showContext(id)
|
||||
if not contextMenus[id] then return error('No context menu of such id found.') end
|
||||
local data = contextMenus[id]
|
||||
@@ -29,11 +37,7 @@ end
|
||||
|
||||
function lib.getOpenContextMenu() return openContextMenu end
|
||||
|
||||
function lib.hideContext()
|
||||
SetNuiFocus(false, false)
|
||||
SendNUIMessage({action = 'hideContext'})
|
||||
openContextMenu = nil
|
||||
end
|
||||
function lib.hideContext(onExit) return closeContext(nil, nil, onExit) end
|
||||
|
||||
RegisterNUICallback('openContext', function(id, cb)
|
||||
cb(1)
|
||||
@@ -58,8 +62,4 @@ RegisterNUICallback('clickContext', function(id, cb)
|
||||
})
|
||||
end)
|
||||
|
||||
RegisterNUICallback('closeContext', function(_, cb)
|
||||
cb(1)
|
||||
SetNuiFocus(false, false)
|
||||
openContextMenu = nil
|
||||
end)
|
||||
RegisterNUICallback('closeContext', closeContext)
|
||||
|
||||
Reference in New Issue
Block a user