From 49124b2f4c81fbe7f7c0311c537ff9f8e2e5ba10 Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 22 Oct 2024 17:41:35 +0330 Subject: [PATCH 1/4] 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) From aa00808c48d2e57552736daa56728156e6e47a89 Mon Sep 17 00:00:00 2001 From: Amir Date: Sat, 25 Jan 2025 00:05:12 +0330 Subject: [PATCH 2/4] Fix(ox_lib/radial): Remove duplicate codes --- resource/interface/client/radial.lua | 52 ++++++++-------------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/resource/interface/client/radial.lua b/resource/interface/client/radial.lua index 0728a4821..0e61e8c04 100644 --- a/resource/interface/client/radial.lua +++ b/resource/interface/client/radial.lua @@ -2,9 +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 canSelect? fun() +---@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 @@ -211,46 +212,21 @@ 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 - - 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 - - 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 + local success, resp = pcall(item.canSelect, currentMenu, itemIndex) + if not success then return end + end - item.onSelect(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 + if item.onEvent then TriggerEvent(item.onEvent, currentMenu, itemIndex) end + if item.onSelect then item.onSelect(currentMenu, itemIndex) end + if item.onExport then return exports[menuResource][item.onExport](0, currentMenu, itemIndex) end end) RegisterNUICallback('radialBack', function(_, cb) From 36ab286daee9b82cfa2e99d576d6665b1f6e63bf Mon Sep 17 00:00:00 2001 From: Amir Date: Sat, 25 Jan 2025 00:08:54 +0330 Subject: [PATCH 3/4] Fix(ox_lib/radial): Remove duplicate codes --- resource/interface/client/radial.lua | 53 ++++++++++------------------ 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/resource/interface/client/radial.lua b/resource/interface/client/radial.lua index 0728a4821..4c07b4afc 100644 --- a/resource/interface/client/radial.lua +++ b/resource/interface/client/radial.lua @@ -211,45 +211,28 @@ 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 - - item.onSelect(currentMenu, itemIndex) - end - else - error(resp) + local success, resp = pcall(item.canSelect, currentMenu, itemIndex) + if not success then + return 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 - - 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 + end - item.onSelect(currentMenu, itemIndex) + 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 + + item.onSelect(currentMenu, itemIndex) end end) From f8f6202005c44fc571f2b8773d9f316ddbd9c31b Mon Sep 17 00:00:00 2001 From: Amir Date: Sat, 25 Jan 2025 00:11:18 +0330 Subject: [PATCH 4/4] feat(ox_lib/radial): added onExport --- resource/interface/client/radial.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resource/interface/client/radial.lua b/resource/interface/client/radial.lua index 66601af7d..903721e5d 100644 --- a/resource/interface/client/radial.lua +++ b/resource/interface/client/radial.lua @@ -235,6 +235,10 @@ RegisterNUICallback('radialClick', function(index, cb) item.onSelect(currentMenu, itemIndex) end + + if item.onExport then + return exports[menuResource][item.onExport](0, currentMenu, itemIndex) + end end) RegisterNUICallback('radialBack', function(_, cb)