Files
community_bridge/modules/menu/_oxlib.lua
T

53 lines
1.6 KiB
Lua
Raw Normal View History

2025-01-18 05:31:33 -06:00
if GetResourceState('ox_lib') ~= 'started' or (BridgeClientConfig.MenuSystem ~= "ox" and BridgeClientConfig.MenuSystem ~= "auto") then return end
2025-01-16 00:53:51 -06:00
Menus = Menus or {}
2025-01-14 09:44:30 -06:00
--- Converts a QB menu to an Ox menu.
---@param id string The menu ID.
---@param menu table The QB menu data.
---@return table The Ox menu data.
local function QBToOxMenu(id, menu)
local oxMenu = {
id = id,
title = "",
canClose = true,
options = {},
}
for i, v in pairs(menu) do
if v.isMenuHeader then
if oxMenu.title == "" then
oxMenu.title = v.header
end
else
local option = {
title = v.header,
description = v.txt,
icon = v.icon,
args = v.params.args,
onSelect = function(selected, secondary, args)
local params = menu[id]?.options?[selected]?.params
if not params then return end
local event = params.event
local isServer = params.isServer
if not event then return end
if isServer then
return TriggerServerEvent(event, args)
end
return TriggerEvent(event, args)
end
}
table.insert(oxMenu.options, option)
end
end
return oxMenu
end
OpenMenu = function(id, data, useQBinput)
if useQBinput then
data = QBToOxMenu(id, data)
end
2025-02-15 21:16:44 -06:00
lib.registerContext(data)
2025-01-16 00:53:51 -06:00
lib.showContext(id)
2025-01-14 12:30:29 -06:00
return data
2025-01-14 09:44:30 -06:00
end