mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(client/interface): initial lua radial menu implementation
linden pls don't kill me
This commit is contained in:
59
resource/interface/client/radial.lua
Normal file
59
resource/interface/client/radial.lua
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
local isOpen = false
|
||||||
|
local menuItems = {}
|
||||||
|
|
||||||
|
function lib.addRadialItem(items)
|
||||||
|
if table.type(items) == 'array' then
|
||||||
|
for i = 1, #items do
|
||||||
|
local itemOption = items[i]
|
||||||
|
menuItems[#menuItems+1] = itemOption
|
||||||
|
end
|
||||||
|
else
|
||||||
|
menuItems[#menuItems+1] = items
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- TODO: Interval canInteract checking and sending new items to NUI
|
||||||
|
local function openRadial()
|
||||||
|
isOpen = true
|
||||||
|
local items = {}
|
||||||
|
for i = 1, #menuItems do
|
||||||
|
local menuItem = menuItems[i]
|
||||||
|
if menuItem.canInteract == nil or menuItem.canInteract() then
|
||||||
|
items[#items+1] = {
|
||||||
|
icon = menuItem.icon,
|
||||||
|
label = menuItem.label
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
SendNUIMessage({
|
||||||
|
action = 'openRadialMenu',
|
||||||
|
data = {
|
||||||
|
items = items
|
||||||
|
}
|
||||||
|
})
|
||||||
|
SetNuiFocus(true, true)
|
||||||
|
SetNuiFocusKeepInput(true)
|
||||||
|
CreateThread(function()
|
||||||
|
while isOpen do
|
||||||
|
DisablePlayerFiring(cache.playerId, true)
|
||||||
|
DisableControlAction(0, 1, true)
|
||||||
|
DisableControlAction(0, 2, true)
|
||||||
|
Wait(0)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function closeRadial()
|
||||||
|
SendNUIMessage({
|
||||||
|
action = 'openRadialMenu',
|
||||||
|
data = false
|
||||||
|
})
|
||||||
|
SetNuiFocus(false, false)
|
||||||
|
isOpen = false
|
||||||
|
end
|
||||||
|
|
||||||
|
RegisterCommand('+ox_lib-radial', openRadial)
|
||||||
|
|
||||||
|
RegisterCommand('-ox_lib-radial', closeRadial)
|
||||||
|
|
||||||
|
RegisterKeyMapping('+ox_lib-radial', 'Open radial menu', 'keyboard', 'z')
|
||||||
@@ -62,7 +62,8 @@ const RadialMenu: React.FC = () => {
|
|||||||
sub: false,
|
sub: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
useNuiEvent('openRadialMenu', (data: { items: MenuItem[]; sub?: boolean }) => {
|
useNuiEvent('openRadialMenu', (data: { items: MenuItem[]; sub?: boolean } | false) => {
|
||||||
|
if (!data) return setVisible(false);
|
||||||
setMenu(data);
|
setMenu(data);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user