mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46: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 contextMenus = {}
|
||||||
local openContextMenu = nil
|
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)
|
function lib.showContext(id)
|
||||||
if not contextMenus[id] then return error('No context menu of such id found.') end
|
if not contextMenus[id] then return error('No context menu of such id found.') end
|
||||||
local data = contextMenus[id]
|
local data = contextMenus[id]
|
||||||
@@ -29,11 +37,7 @@ end
|
|||||||
|
|
||||||
function lib.getOpenContextMenu() return openContextMenu end
|
function lib.getOpenContextMenu() return openContextMenu end
|
||||||
|
|
||||||
function lib.hideContext()
|
function lib.hideContext(onExit) return closeContext(nil, nil, onExit) end
|
||||||
SetNuiFocus(false, false)
|
|
||||||
SendNUIMessage({action = 'hideContext'})
|
|
||||||
openContextMenu = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
RegisterNUICallback('openContext', function(id, cb)
|
RegisterNUICallback('openContext', function(id, cb)
|
||||||
cb(1)
|
cb(1)
|
||||||
@@ -58,8 +62,4 @@ RegisterNUICallback('clickContext', function(id, cb)
|
|||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNUICallback('closeContext', function(_, cb)
|
RegisterNUICallback('closeContext', closeContext)
|
||||||
cb(1)
|
|
||||||
SetNuiFocus(false, false)
|
|
||||||
openContextMenu = nil
|
|
||||||
end)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user