diff --git a/fxmanifest.lua b/fxmanifest.lua index 975faf3..3596c3f 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -53,7 +53,7 @@ client_scripts { 'modules/progressbar/**/client.lua', 'modules/clothing/**/client.lua', 'modules/input/**/client.lua', - 'modules/menu/*.lua', + 'modules/menu/**/client.lua', 'modules/helptext/**/client.lua', 'modules/notify/**/client.lua', 'modules/dialogue/**/client/*.lua', diff --git a/modules/menu/client.lua b/modules/menu/_defualt/client.lua similarity index 91% rename from modules/menu/client.lua rename to modules/menu/_defualt/client.lua index c5a497f..730e90c 100644 --- a/modules/menu/client.lua +++ b/modules/menu/_defualt/client.lua @@ -12,6 +12,10 @@ function Menu.Open(data, useQb) 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 diff --git a/modules/menu/lation_ui/client.lua b/modules/menu/lation_ui/client.lua new file mode 100644 index 0000000..5d06ed7 --- /dev/null +++ b/modules/menu/lation_ui/client.lua @@ -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 \ No newline at end of file diff --git a/modules/menu/_oxlib.lua b/modules/menu/ox_lib/client.lua similarity index 94% rename from modules/menu/_oxlib.lua rename to modules/menu/ox_lib/client.lua index 02603fe..5899892 100644 --- a/modules/menu/_oxlib.lua +++ b/modules/menu/ox_lib/client.lua @@ -44,11 +44,15 @@ local function QBToOxMenu(id, menu) return oxMenu end -OpenMenu = function(id, data, useQBinput) +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 \ No newline at end of file diff --git a/modules/menu/_qb-menu.lua b/modules/menu/qb-menu/client.lua similarity index 92% rename from modules/menu/_qb-menu.lua rename to modules/menu/qb-menu/client.lua index 31aa56e..035489b 100644 --- a/modules/menu/_qb-menu.lua +++ b/modules/menu/qb-menu/client.lua @@ -36,10 +36,14 @@ function OxToQBMenu(id, menu) return qbMenu end -OpenMenu = function(id, data, useQBinput) +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 \ No newline at end of file diff --git a/modules/progressbar/lation_ui/client.lua b/modules/progressbar/lation_ui/client.lua index 4b23e8d..2a7aad0 100644 --- a/modules/progressbar/lation_ui/client.lua +++ b/modules/progressbar/lation_ui/client.lua @@ -14,16 +14,16 @@ local function convertFromQB(options) local prop2 = options.propTwo or {} local props = { { - model = prop1.model, - bone = prop1.bone, - pos = prop1.coords, - rot = prop1.rotation, + model = prop1?.model, + bone = prop1?.bone, + pos = prop1?.coords, + rot = prop1?.rotation, }, { - model = prop2.model, - bone = prop2.bone, - pos = prop2.coords, - rot = prop2.rotation, + model = prop2?.model, + bone = prop2?.bone, + pos = prop2?.coords, + rot = prop2?.rotation, } } return { diff --git a/settings/sharedConfig.lua b/settings/sharedConfig.lua index 2fd78c3..5415b88 100644 --- a/settings/sharedConfig.lua +++ b/settings/sharedConfig.lua @@ -1,7 +1,7 @@ BridgeSharedConfig = {} BridgeSharedConfig.Lang = "auto" -- Change this to your preferred language (must match the locale file name ex. en or fr etc) BridgeSharedConfig.DebugLevel = 0 -- Change this to your Debug level, 0 for none, 1 for some, 2 for all data -BridgeSharedConfig.Notify = "auto" -- [ auto | ox_lib | r_notify | okokNotify | mythic_notify | pNotify | t-notify | wasabi_notify | brutal_notify] +BridgeSharedConfig.Notify = "auto" -- [ auto | ox_lib | r_notify | wasabi_notify | lation_ui | okokNotify | mythic_notify | pNotify | t-notify | brutal_notify] BridgeSharedConfig.HelpText = "auto" -- [ auto | ox_lib | jg-textui | cd_drawtextui | lab-HintUI | okokTextUI] BridgeSharedConfig.Phone = "auto" -- [ auto | qs-smartphone | lb-phone | gksphone] BridgeSharedConfig.Skills = "auto" -- [ auto | OT_skills | evolent_skills | pickle_xp]