Files
community_bridge/modules/menu/qb-menu/client.lua
T

49 lines
1.3 KiB
Lua
Raw Normal View History

2025-03-04 22:15:29 -05:00
local resourceName = "qb-menu"
local configValue = BridgeClientConfig.MenuSystem
if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end
---Converts an Ox menu to a QB menu.
2025-01-14 09:44:30 -06:00
---@param id string The menu ID.
---@param menu table The Ox menu data.
---@return table The QB menu data.
2025-01-14 12:30:29 -06:00
function OxToQBMenu(id, menu)
2025-01-14 09:44:30 -06:00
local qbMenu = {
{
header = menu.title,
isMenuHeader = true,
}
}
for i, v in pairs(menu.options) do
local button = {
header = v.title,
txt = v.description,
icon = v.icon,
2025-04-03 08:52:47 +01:00
disabled = v.disabled,
2025-01-14 09:44:30 -06:00
}
2025-02-20 15:10:42 -05:00
2025-01-14 12:30:29 -06:00
if v.onSelect then
2025-01-14 09:44:30 -06:00
button.params = {
2025-02-20 15:10:42 -05:00
event = "community_bridge:client:MenuCallback",
2025-01-14 09:44:30 -06:00
args = {id = id, selected = i, args = v.args, onSelect = v.onSelect},
}
2025-06-13 07:44:21 -04:00
else
button.params = {} -- should fix nil errors when no onSelect is provided
2025-01-14 09:44:30 -06:00
end
2025-01-14 12:30:29 -06:00
2025-01-14 09:44:30 -06:00
table.insert(qbMenu, button)
end
2025-02-20 15:10:42 -05:00
2025-01-14 09:44:30 -06:00
return qbMenu
end
function OpenMenu(id, data, useQBinput)
2025-02-20 15:10:42 -05:00
if not useQBinput then
2025-01-14 09:44:30 -06:00
data = OxToQBMenu(id, data)
2025-02-20 15:10:42 -05:00
end
2025-01-14 12:30:29 -06:00
exports['qb-menu']:openMenu(data)
return data
end
GetMenuResourceName = function()
return resourceName
2025-01-14 09:44:30 -06:00
end