This commit is contained in:
Nordi98 2025-08-06 16:37:06 +02:00
parent 510e3ffcf2
commit f43cf424cf
305 changed files with 34683 additions and 0 deletions

View file

@ -0,0 +1,30 @@
Menus = Menus or {}
Menu = {}
---Opens a menu based on the configuration.
---@param data table The menu data.
---@param useQb boolean Whether to use QB menu syntax.
---@return id string The menu ID.
function Menu.Open(data, useQb)
local id = data.id or Ids.CreateUniqueId(Menus, nil, nil)
Menus[id] = OpenMenu(id, data, useQb)
data.id = id
return id
end
function Menu.GetResourceName()
return GetMenuResourceName()
end
---Event to handle callback from menu selection.
---@param _args table The arguments passed to the callback.
---@return nil
RegisterNetEvent('community_bridge:client:MenuCallback', function(_args)
local id = _args.id
local onSelect = _args.onSelect
local args = _args.args
Menus[id] = nil
onSelect(args)
end)
return Menu

View file

@ -0,0 +1,96 @@
local resourceName = "lation_ui"
local configValue = BridgeClientConfig.MenuSystem
if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end
Menus = Menus or {}
local function runCheckForImageIcon(icon)
local iconStr = tostring(icon):lower()
if iconStr:match("^https?://") or iconStr:match("^nui://") or iconStr:match("^file://") then
return true
end
local extensions = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg", ".webp", ".ico"}
for _, ext in pairs(extensions) do
if iconStr:match(ext .. "$") then
return true
end
end
return false
end
---Converts a QB menu to an Lation menu.
---@param id string The menu ID.
---@param menu table The QB menu data.
---@return table The Lation menu data.
local function QBToLationMenu(id, menu)
local lationMenu = {
id = id,
title = "",
canClose = true,
options = {},
}
for i, v in pairs(menu) do
if v.isMenuHeader then
if lationMenu.title == "" then
lationMenu.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(lationMenu.options, option)
end
end
return lationMenu
end
local function OxToLationMenu(data)
local repack = {
id = data.id,
title = data.title or "",
canClose = data.canClose ~= false,
options = {}
}
-- Handle icon colors: remove for image icons, convert strings to hex for others
for k, v in pairs(data.options) do
if v.iconColor then
if v.icon and runCheckForImageIcon(v.icon) then
v.iconColor = nil
end
end
table.insert(repack.options, v)
end
return repack
end
function OpenMenu(id, data, useQBinput)
if useQBinput then
data = QBToLationMenu(id, data)
else
data = OxToLationMenu(data)
end
exports.lation_ui:registerMenu(data)
exports.lation_ui:showMenu(id)
return data
end
function GetMenuResourceName()
return resourceName
end

View file

@ -0,0 +1,58 @@
local resourceName = "ox_lib"
local configValue = BridgeClientConfig.MenuSystem
if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end
Menus = Menus or {}
---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
function OpenMenu(id, data, useQBinput)
if useQBinput then
data = QBToOxMenu(id, data)
end
lib.registerContext(data)
lib.showContext(id)
return data
end
GetMenuResourceName = function()
return resourceName
end

View file

@ -0,0 +1,49 @@
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.
---@param id string The menu ID.
---@param menu table The Ox menu data.
---@return table The QB menu data.
function OxToQBMenu(id, menu)
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,
disabled = v.disabled,
}
if v.onSelect then
button.params = {
event = "community_bridge:client:MenuCallback",
args = {id = id, selected = i, args = v.args, onSelect = v.onSelect},
}
else
button.params = {} -- should fix nil errors when no onSelect is provided
end
table.insert(qbMenu, button)
end
return qbMenu
end
function OpenMenu(id, data, useQBinput)
if not useQBinput then
data = OxToQBMenu(id, data)
end
exports['qb-menu']:openMenu(data)
return data
end
GetMenuResourceName = function()
return resourceName
end