Files
community_bridge/modules/menu/ox_lib/client.lua
T

58 lines
1.7 KiB
Lua
Raw Normal View History

2025-03-04 22:15:29 -05:00
local resourceName = "ox_lib"
local configValue = BridgeClientConfig.MenuSystem
if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end
2025-01-16 00:53:51 -06:00
Menus = Menus or {}
---Converts a QB menu to an Ox menu.
2025-01-14 09:44:30 -06:00
---@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,
2025-07-29 05:22:55 -05:00
onSelect = v.action or function(selected, secondary, args)
2025-01-14 09:44:30 -06:00
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
function OpenMenu(id, data, useQBinput)
2025-02-20 15:10:42 -05:00
if useQBinput then
2025-01-14 09:44:30 -06:00
data = QBToOxMenu(id, data)
2025-02-20 15:10:42 -05:00
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
end
GetMenuResourceName = function()
return resourceName
end