From 49124b2f4c81fbe7f7c0311c537ff9f8e2e5ba10 Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 22 Oct 2024 17:41:35 +0330 Subject: [PATCH] feat(radial): added canSelect functin and onEvent field --- resource/interface/client/radial.lua | 49 +++++++++++++++++++++------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/resource/interface/client/radial.lua b/resource/interface/client/radial.lua index 2649d73d3..0728a4821 100644 --- a/resource/interface/client/radial.lua +++ b/resource/interface/client/radial.lua @@ -3,6 +3,8 @@ ---@field label string ---@field menu? string ---@field onSelect? fun(currentMenu: string | nil, itemIndex: number) | string +---@field canSelect? fun() +---@field onEvent? string ---@field [string] any ---@field keepOpen? boolean ---@field iconWidth? number @@ -209,22 +211,45 @@ RegisterNUICallback('radialClick', function(index, cb) end local menuResource = currentRadial and currentRadial.resource or item.resource + local success, resp = true, "" + + if item.canSelect then + success, resp = pcall(item.canSelect, currentMenu, itemIndex) + if success and resp then + 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 + + 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 - 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 + item.onSelect(currentMenu, itemIndex) + end + else + error(resp) + end + else + 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 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 - if onSelect then - if type(onSelect) == 'string' then - return exports[menuResource][onSelect](0, currentMenu, itemIndex) + item.onSelect(currentMenu, itemIndex) end - - onSelect(currentMenu, itemIndex) end end)