refactor(client/radial): ditch canInteract

This commit is contained in:
Luke
2023-02-03 13:24:55 +01:00
parent a44142333e
commit 86318d5fe4

View File

@@ -1,21 +1,5 @@
local isOpen = false local isOpen = false
local menuItems = {} local menuItems = {}
local activeItems = {}
local function getActiveItems()
activeItems = {}
for i = 1, #menuItems do
local item = menuItems[i]
if item.canInteract == nil or item.canInteract() then
activeItems[#activeItems+1] = {
icon = item.icon,
label = item.label,
key = item.key
}
end
end
return activeItems
end
function lib.addRadialItem(items) function lib.addRadialItem(items)
if table.type(items) == 'array' then if table.type(items) == 'array' then
@@ -33,35 +17,23 @@ function lib.removeRadialItem(key)
local item = menuItems[i] local item = menuItems[i]
if item.key == key then if item.key == key then
table.remove(menuItems, i) table.remove(menuItems, i)
break
end end
end end
if isOpen then if isOpen then
local refresh = false
for i = 1, #activeItems do
local activeItem = activeItems[i]
if activeItem.key == key then
table.remove(activeItems, i)
refresh = true
end
end
if refresh then
local items = getActiveItems()
SendNUIMessage({ SendNUIMessage({
action = 'refreshItems', action = 'refreshItems',
data = items data = menuItems
}) })
end end
end
end end
-- TODO: Interval canInteract checking and sending new items to NUI
local function openRadial() local function openRadial()
isOpen = true isOpen = true
local items = getActiveItems()
SendNUIMessage({ SendNUIMessage({
action = 'openRadialMenu', action = 'openRadialMenu',
data = { data = {
items = items items = menuItems
} }
}) })
SetNuiFocus(true, true) SetNuiFocus(true, true)