Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(radial): added canSelect functin and onEvent / onExport field #658

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 21 additions & 8 deletions resource/interface/client/radial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
---@field icon string | {[1]: IconProp, [2]: string};
---@field label string
---@field menu? string
---@field onSelect? fun(currentMenu: string | nil, itemIndex: number) | string
---@field onSelect? fun(currentMenu: string | nil, itemIndex: number)
---@field canSelect? fun(currentMenu: string | nil, itemIndex: number)
---@field onEvent? string
---@field onExport? string
---@field [string] any
---@field keepOpen? boolean
---@field iconWidth? number
Expand Down Expand Up @@ -209,22 +212,32 @@ RegisterNUICallback('radialClick', function(index, cb)
end

local menuResource = currentRadial and currentRadial.resource or item.resource

if item.canSelect then
local success, resp = pcall(item.canSelect, currentMenu, itemIndex)
if not success then
return
end
end

if item.menu then
menuHistory[#menuHistory + 1] = { id = currentRadial and currentRadial.id, option = item.menu }
showRadial(item.menu)
elseif not item.keepOpen then
lib.hideRadial()
end

local onSelect = item.onSelect

if onSelect then
if type(onSelect) == 'string' then
return exports[menuResource][onSelect](0, currentMenu, itemIndex)

if item.onEvent then TriggerEvent(item.onEvent, currentMenu, itemIndex) end
if item.onSelect then
if type(item.onSelect) == 'string' then
return exports[menuResource][item.onSelect](0, currentMenu, itemIndex)
end

onSelect(currentMenu, itemIndex)
item.onSelect(currentMenu, itemIndex)
end

if item.onExport then
return exports[menuResource][item.onExport](0, currentMenu, itemIndex)
end
end)

Expand Down