mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
refactor(client/radial): allow onSelect as string to call an export
e.g. onSelect = 'menuHandler'
exports('menuHandler', function(menu, item) end)
This commit is contained in:
@@ -4,7 +4,7 @@ type RadialItem = {
|
|||||||
id: string;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
icon: IconName | [IconPrefix, IconName];
|
icon: IconName | [IconPrefix, IconName];
|
||||||
onSelect?: (currentMenu: string | null, itemIndex: number) => void;
|
onSelect?: (currentMenu: string | null, itemIndex: number) => void | string;
|
||||||
menu?: string;
|
menu?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,13 @@
|
|||||||
---@field icon string
|
---@field icon string
|
||||||
---@field label string
|
---@field label string
|
||||||
---@field menu? string
|
---@field menu? string
|
||||||
---@field onSelect? fun(currentMenu: string | nil, itemIndex: number)
|
---@field onSelect? fun(currentMenu: string | nil, itemIndex: number) | string
|
||||||
---@field [string] any
|
---@field [string] any
|
||||||
|
|
||||||
---@class RadialMenuProps
|
---@class RadialMenuProps
|
||||||
---@field id string
|
---@field id string
|
||||||
---@field items RadialMenuItem[]
|
---@field items RadialMenuItem[]
|
||||||
|
---@field [string] any
|
||||||
|
|
||||||
local isOpen = false
|
local isOpen = false
|
||||||
|
|
||||||
@@ -98,6 +99,7 @@ end
|
|||||||
---@param radial RadialMenuProps
|
---@param radial RadialMenuProps
|
||||||
function lib.registerRadial(radial)
|
function lib.registerRadial(radial)
|
||||||
menus[radial.id] = radial
|
menus[radial.id] = radial
|
||||||
|
radial.resource = GetInvokingResource()
|
||||||
|
|
||||||
if currentRadial then
|
if currentRadial then
|
||||||
refreshRadial(radial.id)
|
refreshRadial(radial.id)
|
||||||
@@ -188,7 +190,15 @@ RegisterNUICallback('radialClick', function(index, cb)
|
|||||||
lib.hideRadial()
|
lib.hideRadial()
|
||||||
end
|
end
|
||||||
|
|
||||||
if item.onSelect then item.onSelect(currentMenu, itemIndex) end
|
local onSelect = item.onSelect
|
||||||
|
|
||||||
|
if onSelect then
|
||||||
|
if type(onSelect) == 'string' then
|
||||||
|
return exports[currentRadial and currentRadial.resource or item.resource][onSelect](0, currentMenu, itemIndex)
|
||||||
|
end
|
||||||
|
|
||||||
|
onSelect(currentMenu, itemIndex)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNUICallback('radialBack', function(_, cb)
|
RegisterNUICallback('radialBack', function(_, cb)
|
||||||
|
|||||||
Reference in New Issue
Block a user