feat(client/radial): support refreshing menus

This commit is contained in:
Linden
2023-02-24 00:26:17 +11:00
parent 5428d1c768
commit 5f1678131c

View File

@@ -23,16 +23,6 @@ local menuHistory = {}
---@type RadialMenuProps? ---@type RadialMenuProps?
local currentRadial = nil local currentRadial = nil
---Registers a radial sub menu with predefined options.
---@param radial RadialMenuProps
function lib.registerRadial(radial)
menus[radial.id] = radial
end
function lib.getCurrentRadialId()
return currentRadial and currentRadial.id
end
---Open a registered radial submenu with the given id. ---Open a registered radial submenu with the given id.
---@param id string ---@param id string
local function showRadial(id) local function showRadial(id)
@@ -62,6 +52,36 @@ local function showRadial(id)
}) })
end end
---Refresh the global menu items or current submenu.
local function refreshRadial()
if not isOpen then return end
if currentRadial then
return showRadial(currentRadial.id)
end
SendNUIMessage({
action = 'refreshItems',
data = menuItems
})
end
---Registers a radial sub menu with predefined options.
---@param radial RadialMenuProps
function lib.registerRadial(radial)
menus[radial.id] = radial
if currentRadial and radial.id == currentRadial.id then
currentRadial = radial
refreshRadial()
end
end
function lib.getCurrentRadialId()
return currentRadial and currentRadial.id
end
function lib.hideRadial() function lib.hideRadial()
if not isOpen then return end if not isOpen then return end
@@ -96,10 +116,7 @@ function lib.addRadialItem(items)
end end
if isOpen and not currentRadial then if isOpen and not currentRadial then
SendNUIMessage({ refreshRadial()
action = 'refreshItems',
data = menuItems
})
end end
end end
@@ -149,10 +166,7 @@ function lib.removeRadialItem(id)
}) })
end end
else else
SendNUIMessage({ refreshRadial()
action = 'refreshItems',
data = menuItems
})
end end
end end
end end