Skip to content

Commit

Permalink
feat(client/radial): return currentMenu and itemIndex onSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Feb 25, 2023
1 parent 60e3a12 commit 29022e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package/client/resource/interface/radial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type RadialItem = {
id: string;
label: string;
icon: IconName | [IconPrefix, IconName];
onSelect?: () => void;
onSelect?: (currentMenu: string | null, itemIndex: number) => void;
menu?: string;
};

Expand Down
14 changes: 11 additions & 3 deletions resource/interface/client/radial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---@field icon string
---@field label string
---@field menu? string
---@field onSelect? function
---@field onSelect? fun(currentMenu: string | nil, itemIndex: number)
---@field [string] any

---@class RadialMenuProps
Expand Down Expand Up @@ -168,7 +168,15 @@ end
RegisterNUICallback('radialClick', function(index, cb)
cb(1)

local item = (currentRadial and currentRadial.items or menuItems)[index + 1]
local itemIndex = index + 1
local item, currentMenu

if currentRadial then
item = currentRadial.items[itemIndex]
currentMenu = currentRadial.id
else
item = menuItems[itemIndex]
end

if item.menu then
if currentRadial then
Expand All @@ -180,7 +188,7 @@ RegisterNUICallback('radialClick', function(index, cb)
lib.hideRadial()
end

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

RegisterNUICallback('radialBack', function(_, cb)
Expand Down

0 comments on commit 29022e1

Please sign in to comment.