diff --git a/_types.lua b/_types.lua index 407f82b..7145fd0 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 IconProp 'fas' | 'far' | 'fal' | 'fat' | 'fad' | 'fab' | 'fak' | 'fass' ---@alias NotificationPosition 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left' | 'center-right' | 'center-left' @@ -10,6 +15,7 @@ ---@field status? 'info' | 'warning' | 'success' | 'error' ---@field id? number + ---@class ContextMenuItem ---@field title? string ---@field menu? string @@ -43,4 +49,23 @@ ---@field position? 'right-center' | 'left-center' | 'top-center'; ---@field icon? string | {[1]: IconProp, [2]: string}; ---@field iconColor? string; ----@field style? string | table; \ No newline at end of file +---@field style? string | table; + + +---@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/radial/ox.lua b/client/radial/ox.lua index 9c7a188..d9b2163 100644 --- a/client/radial/ox.lua +++ b/client/radial/ox.lua @@ -1,28 +1,37 @@ -local Radial = {} - - -function Radial.addOptions(optionId, data) - local id = require'utils'.await('UUID', false, 8) - local lib = exports.ox_lib - - local title, icon, items in data - lib:registerRadial({ - id = id, - items = items - }) - - lib:addRadialItem({ - { - id = optionId, - label = title or 'Unknown', - icon = icon or 'hand', - menu = id - }, - }) +---@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 -function Radial.removeOption(onExit) - +---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 -return Radial \ No newline at end of file +---Returns the current radial menu id. +function Radial.getCurrentId() + return lib.getCurrentRadialId() +end \ No newline at end of file diff --git a/client/radial/qb.lua b/client/radial/qb.lua index eeaa19b..094d119 100644 --- a/client/radial/qb.lua +++ b/client/radial/qb.lua @@ -1,74 +1,81 @@ -local menuName = 'qb-radialmenu' -if GetResourceState(menuName) ~= 'started' then - error(menuName..' isn\'t starting') - return -end +---@diagnostic disable: duplicate-set-field + + +Radial = {} + +local qbRadial = exports['qb-radialmenu'] -local qb_radial = exports[menuName] -local Radial = {} -local Utils = require 'utils' -local eventIndex = 0 -local storedEvents = {} local overRideData = { - title = { - originalMethod = 'label', + id = { + originalMethod = 'id', + }, + txt = { + originalMethod = 'description', }, icon = { originalMethod = 'icon', }, - id = { + menu = { originalMethod = 'menu', }, - shouldClose = { - originalMethod = 'keepOpen', - modifier = { - executeFun = true, - effect = function(value) - return type(value) ~= 'boolean' and true or not value - end - } - }, - event = { - originalMethod = 'onSelect', - modifier = { - executeFun = true, - effect = function(value) - local eventName = ("bl_bridge:client:radialId%s"):format(eventIndex) - eventIndex+= 1 - return {eventName = eventName, eventId = AddEventHandler(eventName, value)} - end - } + label = { + originalMethod = 'title', }, } -function Radial.addOptions(optionId, data) - local id = Utils.await('UUID', false, 8) - - local title, icon, items in data - items = Utils.retreiveNumberIndexedData(items, overRideData) - for _,v in ipairs(items) do - v.type = 'client' - - if v.event then - local eventName, eventId in v.event - local menuId = v.menu or #storedEvents+1 - storedEvents[menuId] = eventId - - v.menu = menuId - v.event = eventName +---@param items RadialMenuItem | RadialMenuItem[] +function Radial.addOption(items) + + if type(items) == 'table' then + 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 - qb_radial:AddOption({ - id = optionId, - title = title or 'Unknown', - icon = icon or 'hand', - items = items - }, id) end -function Radial.removeOption(onExit) - +---@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) + return +end + +---Removes all items from the global radial menu. +function Radial.clear() + -- lib.clearRadialItems() + return end -return Radial \ No newline at end of file + +---Disables the global radial menu. +---@param state boolean +function Radial.disable(state) + -- lib.disableRadial(state) + return +end + +---Returns the current radial menu id. +function Radial.getCurrentId() + -- return lib.getCurrentRadialId() + return +end \ No newline at end of file