Files
ox_lib/resource/interface/client/context.lua
Luke c21054280c fix(client/context): Allow using events to open context menus
There was an issue where if you wanted to open a second context menu using args from the first context menu's item with events, the nui focus would get stuck beacuse it would get set by the event.
2022-04-15 11:26:11 +02:00

51 lines
1.2 KiB
Lua

local contextMenus = {}
local openContextMenu = nil
function lib.showContext(id)
local data = contextMenus[id]
openContextMenu = id
SetNuiFocus(true, true)
SendNUIMessage({
action = 'showContext',
data = {
title = data.title,
menu = data.menu,
options = data.options
}
})
end
function lib.registerContext(context)
for k, v in pairs(context) do
if type(k) == 'number' then
contextMenus[v.id] = v
else
contextMenus[context.id] = context
break
end
end
end
function lib.getOpenContextMenu() return openContextMenu end
RegisterNUICallback('openContext', function(id, cb)
cb(1)
lib.showContext(id)
end)
RegisterNUICallback('clickContext', function(data, cb)
cb(1)
SetNuiFocus(false, false)
if data.event then TriggerEvent(data.event, data.args) end
if data.serverEvent then TriggerServerEvent(data.serverEvent, data.args) end
openContextMenu = nil
SendNUIMessage({
action = 'hideContext'
})
end)
RegisterNUICallback('closeContext', function(_, cb)
cb(1)
SetNuiFocus(false, false)
end)