Files
ox_lib/resource/interface/client/context.lua

46 lines
1.0 KiB
Lua
Raw Normal View History

2022-04-01 21:22:14 +02:00
local contextMenus = {}
function lib.showContext(id)
2022-04-01 21:22:14 +02:00
local data = contextMenus[id]
SetNuiFocus(true, true)
SendNUIMessage({
action = 'showContext',
data = {
title = data.title,
menu = data.menu,
options = data.options
}
})
end
function lib.registerContext(context)
2022-04-01 21:22:14 +02:00
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
2022-04-11 16:14:32 +02:00
RegisterNUICallback('openContext', function(id, cb)
cb(1)
lib.showContext(id)
2022-04-01 21:22:14 +02:00
end)
2022-04-11 16:14:32 +02:00
RegisterNUICallback('clickContext', function(data, cb)
cb(1)
2022-04-01 21:22:14 +02:00
if data.event then TriggerEvent(data.event, data.args) end
if data.serverEvent then TriggerServerEvent(data.serverEvent, data.args) end
SetNuiFocus(false, false)
SendNUIMessage({
action = 'hideContext'
})
end)
2022-04-11 16:14:32 +02:00
RegisterNUICallback('closeContext', function(_, cb)
cb(1)
2022-04-01 21:22:14 +02:00
SetNuiFocus(false, false)
end)