mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(web/menu): radial sub menu chaining
still some quirks to figure out but it's working well
This commit is contained in:
@@ -1,5 +1,25 @@
|
||||
local isOpen = false
|
||||
local menus = {}
|
||||
local menuItems = {}
|
||||
local currentRadial = nil
|
||||
|
||||
|
||||
function lib.registerRadial(radial)
|
||||
menus[radial.id] = radial
|
||||
end
|
||||
|
||||
function lib.showRadial(id)
|
||||
local radial = menus[id]
|
||||
if not radial then return error('No radial menu with such id found.') end
|
||||
currentRadial = radial
|
||||
SendNUIMessage({
|
||||
action = 'openRadialMenu',
|
||||
data = {
|
||||
items = radial.items,
|
||||
sub = true
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
function lib.addRadialItem(items)
|
||||
if table.type(items) == 'array' then
|
||||
@@ -28,6 +48,29 @@ function lib.removeRadialItem(key)
|
||||
end
|
||||
end
|
||||
|
||||
RegisterNUICallback('radialClick', function(index, cb)
|
||||
cb(1)
|
||||
local item = not currentRadial and menuItems[index + 1] or currentRadial.items[index + 1]
|
||||
if item.menu then lib.showRadial(item.menu) end
|
||||
if item.onSelect then item.onSelect() end
|
||||
end)
|
||||
|
||||
-- TODO: fix transition?
|
||||
RegisterNUICallback('radialBack', function(_, cb)
|
||||
cb(1)
|
||||
if currentRadial.menu then
|
||||
lib.showRadial(currentRadial.menu)
|
||||
else
|
||||
currentRadial = nil
|
||||
SendNUIMessage({
|
||||
action = 'openRadialMenu',
|
||||
data = {
|
||||
items = menuItems
|
||||
}
|
||||
})
|
||||
end
|
||||
end)
|
||||
|
||||
local function openRadial()
|
||||
isOpen = true
|
||||
SendNUIMessage({
|
||||
@@ -38,6 +81,7 @@ local function openRadial()
|
||||
})
|
||||
SetNuiFocus(true, true)
|
||||
SetNuiFocusKeepInput(true)
|
||||
SetCursorLocation(0.5, 0.5)
|
||||
CreateThread(function()
|
||||
while isOpen do
|
||||
DisablePlayerFiring(cache.playerId, true)
|
||||
@@ -55,6 +99,7 @@ local function closeRadial()
|
||||
})
|
||||
SetNuiFocus(false, false)
|
||||
isOpen = false
|
||||
if currentRadial then currentRadial = nil end
|
||||
end
|
||||
|
||||
RegisterCommand('+ox_lib-radial', openRadial)
|
||||
|
||||
Reference in New Issue
Block a user