diff --git a/fxmanifest.lua b/fxmanifest.lua index 9884559..f4ceaf4 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,13 +4,13 @@ lua54 'yes' use_experimental_fxv2_oal 'yes' author 'The Order of the Sacred Framework' description 'A bridge made for the community to use as a base for their own projects. This bridge will allow a single format to work with nearly all commonly used systems while still offering expandability.' -version '0.1.3' +version '0.1.4' shared_scripts { 'settings/sharedConfig.lua', 'use/*.lua', - 'modules/Utility/shared/*.lua', - 'modules/Math/*.lua', + 'modules/utility/shared/*.lua', + 'modules/math/*.lua', 'modules/locales/*.lua', } @@ -18,34 +18,34 @@ server_scripts { '@oxmysql/lib/MySQL.lua', 'settings/serverConfig.lua', 'modules/locales/shared.lua', - 'modules/Utility/server/*.lua', - 'modules/Framework/**/server.lua', - 'modules/Inventory/**/server.lua', - 'modules/Doorlock/**/server.lua', - 'modules/Phone/**/server.lua', - 'modules/Notify/server.lua', - 'modules/Managment/**/server.lua', + 'modules/utility/server/*.lua', + 'modules/framework/**/server.lua', + 'modules/inventory/**/server.lua', + 'modules/doorlock/**/server.lua', + 'modules/phone/**/server.lua', + 'modules/notify/server.lua', + 'modules/managment/**/server.lua', 'init.lua', } client_scripts { 'settings/clientConfig.lua', 'modules/locales/shared.lua', - 'modules/Utility/client/*.lua', - 'modules/Framework/**/client.lua', - 'modules/Inventory/**/client.lua', - 'modules/Doorlock/**/client.lua', - 'modules/Phone/**/client.lua', - 'modules/Notify/client.lua', - 'modules/Weather/**/client.lua', - 'modules/VehicleKey/**/client.lua', - 'modules/Fuel/**/client.lua', - 'modules/Target/**/client.lua', - 'modules/Dispatch/**/client.lua', - 'modules/Progressbar/**/client.lua', - 'modules/Clothing/**/client.lua', - 'modules/Input/client.lua', - 'modules/menu/client.lua', + 'modules/utility/client/*.lua', + 'modules/framework/**/client.lua', + 'modules/inventory/**/client.lua', + 'modules/doorlock/**/client.lua', + 'modules/phone/**/client.lua', + 'modules/notify/client.lua', + 'modules/weather/**/client.lua', + 'modules/vehicleKey/**/client.lua', + 'modules/fuel/**/client.lua', + 'modules/target/**/client.lua', + 'modules/dispatch/**/client.lua', + 'modules/progressbar/**/client.lua', + 'modules/clothing/**/client.lua', + 'modules/input/*.lua', + 'modules/menu/*.lua', 'init.lua', } diff --git a/init.lua b/init.lua index 01a01eb..bc8f512 100644 --- a/init.lua +++ b/init.lua @@ -33,6 +33,7 @@ Bridge.RegisterModule("Target", Target) Bridge.RegisterModule("Table", Table) Bridge.RegisterModule("Math", Math) Bridge.RegisterModule("Prints", Prints) +Bridge.RegisterModule("Callback", Callback) CreateThread(function() diff --git a/modules/menu/_oxlib.lua b/modules/menu/_oxlib.lua new file mode 100644 index 0000000..9ad495c --- /dev/null +++ b/modules/menu/_oxlib.lua @@ -0,0 +1,51 @@ +if GetResourceState('ox_lib') ~= 'started' then return end + +--- 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 + return exports['qb-menu']:openMenu(data) +end diff --git a/modules/menu/_qb-menu.lua b/modules/menu/_qb-menu.lua new file mode 100644 index 0000000..987cde2 --- /dev/null +++ b/modules/menu/_qb-menu.lua @@ -0,0 +1,36 @@ +if GetResourceState('qb-menu') ~= 'started' 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. +local 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, + } + + if v.onSelect and type(v.onSelect) == 'function' then + button.params = { + event = "community_bridge:client:MenuCallback", + args = {id = id, selected = i, args = v.args, onSelect = v.onSelect}, + } + end + table.insert(qbMenu, button) + end + return qbMenu +end + +OpenMenu = function(id, data, useQBinput) + if not useQBinput then + data = OxToQBMenu(id, data) + end + return exports['qb-menu']:openMenu(data) +end \ No newline at end of file diff --git a/modules/menu/client.lua b/modules/menu/client.lua index dc3ff8a..bbd74cf 100644 --- a/modules/menu/client.lua +++ b/modules/menu/client.lua @@ -3,75 +3,9 @@ Menu = {} if GetResourceState('ox_lib') ~= 'started' and GetResourceState('qb-menu') ~= 'started' then return end ---- 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. -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 ---- 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, - } - if v.onSelect and type(v.onSelect) == 'function' then - button.params = { - event = "community_bridge:client:MenuCallback", - args = {id = id, selected = i, args = v.args, onSelect = v.onSelect}, - } - end - table.insert(qbMenu, button) - end - return qbMenu -end --- Opens a menu based on the configuration. ---@param data table The menu data. @@ -81,29 +15,7 @@ function Menu.Open(data, useQb) --local id = data.id or CreateUniqueId(Menus) local id = data.id or Ids.CreateUniqueId(Menus, nil, nil) local menuExists = Menus[id] - if useQb then - if BridgeClientConfig.MenuSystem == "ox" then - if not menuExists then - Menus[id] = QBToOxMenu(id, data) - lib.registerContext(Menus[id]) - end - return lib.showContext(id) - elseif BridgeClientConfig.MenuSystem == "qb" then - Menus[id] = data - return exports['qb-menu']:openMenu(Menus[id]) - end - else - if BridgeClientConfig.MenuSystem == "ox" then - if not menuExists then - Menus[id] = data - lib.registerContext(Menus[id]) - end - return lib.showContext(id) - elseif BridgeClientConfig.MenuSystem == "qb" then - Menus[id] = OxToQBMenu(id, data) - return exports['qb-menu']:openMenu(Menus[id]) - end - end + OpenMenu(id, data, useQb) return id end