From d2c36884c3636ee4a3996cbc3e0ce9f252708140 Mon Sep 17 00:00:00 2001 From: Xirvin Date: Mon, 27 Nov 2023 22:09:54 +1100 Subject: [PATCH 1/2] radial init --- _types.lua | 26 +++++++++++++- client/modules/radial/ox.lua | 37 +++++++++++++++++++ client/modules/radial/qb.lua | 69 ++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 client/modules/radial/ox.lua create mode 100644 client/modules/radial/qb.lua diff --git a/_types.lua b/_types.lua index 7287d64..480c79a 100644 --- a/_types.lua +++ b/_types.lua @@ -1,4 +1,9 @@ +---======================================================== + -- Big thanks to Overextended, we decided to use all of their table structure since it gave the most flexibility. + -- So other frameworks that isnt 'ox' might have missing methods, or unused fields. +---======================================================== + ---@alias NotificationPosition 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left' | 'center-right' | 'center-left' @@ -8,4 +13,23 @@ ---@field duration? number ---@field position? NotificationPosition ---@field status? 'info' | 'warning' | 'success' | 'error' ----@field id? number \ No newline at end of file +---@field id? number + + +---@alias IconProp 'fas' | 'far' | 'fal' | 'fat' | 'fad' | 'fab' | 'fak' | 'fass' + +---@class RadialItem +---@field icon string | {[1]: string, [2]: string}; +---@field label string +---@field menu? string +---@field onSelect? fun(currentMenu: string | nil, itemIndex: number) | string +---@field [string] any +---@field keepOpen? boolean + +---@class RadialMenuItem: RadialItem +---@field id string + +---@class RadialMenuProps +---@field id string +---@field items RadialItem[] +---@field [string] any \ No newline at end of file diff --git a/client/modules/radial/ox.lua b/client/modules/radial/ox.lua new file mode 100644 index 0000000..d9b2163 --- /dev/null +++ b/client/modules/radial/ox.lua @@ -0,0 +1,37 @@ +---@diagnostic disable: duplicate-set-field + + +Radial = {} + +---@param items RadialMenuItem | RadialMenuItem[] +function Radial.addOption(items) + lib.addRadialItem(items) +end + +---@param id string +function Radial.removeOption(id) + lib.removeRadialItem(id) +end + +---Registers a radial sub menu with predefined options. +---@param radial RadialMenuProps +function Radial.registerRadial(radial) + lib.registerRadial(radial) +end + +---Removes all items from the global radial menu. +function Radial.clear() + lib.clearRadialItems() +end + + +---Disables the global radial menu. +---@param state boolean +function Radial.disable(state) + lib.disableRadial(state) +end + +---Returns the current radial menu id. +function Radial.getCurrentId() + return lib.getCurrentRadialId() +end \ No newline at end of file diff --git a/client/modules/radial/qb.lua b/client/modules/radial/qb.lua new file mode 100644 index 0000000..d625328 --- /dev/null +++ b/client/modules/radial/qb.lua @@ -0,0 +1,69 @@ +---@diagnostic disable: duplicate-set-field + + +Radial = {} + +local qbRadial = exports['qb-radialmenu'] + + +local overRideData = { + id = { + originalMethod = 'id', + }, + txt = { + originalMethod = 'description', + }, + icon = { + originalMethod = 'icon', + }, + menu = { + originalMethod = 'menu', + }, + label = { + originalMethod = 'title', + }, +} + +---@param items RadialMenuItem | RadialMenuItem[] +function Radial.addOption(items) + + if type(items) == 'table' then + for _, item in ipairs(items) do + local id = item.id + + qbRadial:AddOption(item, id) + end + else + local id = items.id + + qbRadial:AddOption(items, id) + end +end + +---@param id string +function Radial.removeOption(id) + qbRadial:RemoveOption(id) +end + +---Registers a radial sub menu with predefined options. +---@param radial RadialMenuProps +function Radial.registerRadial(radial) + lib.registerRadial(radial) +end + +---Removes all items from the global radial menu. +function Radial.clear() + lib.clearRadialItems() +end + + +---Disables the global radial menu. +---@param state boolean +function Radial.disable(state) + lib.disableRadial(state) +end + +---Returns the current radial menu id. +function Radial.getCurrentId() + return lib.getCurrentRadialId() +end \ No newline at end of file From aa14cde5bb0f52d73b9405c88603ec1575068312 Mon Sep 17 00:00:00 2001 From: Xirvin Date: Mon, 22 Jan 2024 13:37:29 +1100 Subject: [PATCH 2/2] kind of working qb radiual????? --- client/modules/radial/qb.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/client/modules/radial/qb.lua b/client/modules/radial/qb.lua index d625328..094d119 100644 --- a/client/modules/radial/qb.lua +++ b/client/modules/radial/qb.lua @@ -31,11 +31,19 @@ function Radial.addOption(items) for _, item in ipairs(items) do local id = item.id + for key, value in pairs(overRideData) do + if item[key] then + item[value.originalMethod] = item[key] + item[key] = nil + end + end + qbRadial:AddOption(item, id) end else local id = items.id + qbRadial:AddOption(items, id) end end @@ -48,22 +56,26 @@ end ---Registers a radial sub menu with predefined options. ---@param radial RadialMenuProps function Radial.registerRadial(radial) - lib.registerRadial(radial) + -- lib.registerRadial(radial) + return end ---Removes all items from the global radial menu. function Radial.clear() - lib.clearRadialItems() + -- lib.clearRadialItems() + return end ---Disables the global radial menu. ---@param state boolean function Radial.disable(state) - lib.disableRadial(state) + -- lib.disableRadial(state) + return end ---Returns the current radial menu id. function Radial.getCurrentId() - return lib.getCurrentRadialId() + -- return lib.getCurrentRadialId() + return end \ No newline at end of file