Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion _types.lua
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -10,6 +15,7 @@
---@field status? 'info' | 'warning' | 'success' | 'error'
---@field id? number


---@class ContextMenuItem
---@field title? string
---@field menu? string
Expand Down Expand Up @@ -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;
---@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
57 changes: 33 additions & 24 deletions client/radial/ox.lua
Original file line number Diff line number Diff line change
@@ -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
---Returns the current radial menu id.
function Radial.getCurrentId()
return lib.getCurrentRadialId()
end
119 changes: 63 additions & 56 deletions client/radial/qb.lua
Original file line number Diff line number Diff line change
@@ -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

---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