Message
Message
currentMenu = nil
menus = {}
isMenuOpen = false
currentUI = "FUI"
function menulib.addSeparator(label)
table.insert(currentMenu.items, {id = #currentMenu.items + 1, type =
"separator", label = label})
end
function menulib.addLine()
table.insert(currentMenu.items, {id = #currentMenu.items + 1, type = "line"})
end
table.insert(currentMenu.items, button)
updateButtonDisplay(button)
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if currentMenu then
for _, item in ipairs(currentMenu.items) do
if item.type == "button" and item.condition then
updateButtonDisplay(item)
end
end
end
end
end)
function updateButtonDisplay(button)
if not button.condition then return end
SendNUIMessage({
eventName = "update_button",
metadata = {
id = button.id,
label = button.label,
rightLabel = rightLabel
}
})
end
function menulib.closeMenu()
if currentMenu then
SendNUIMessage({eventName = "close_menu"})
SetNuiFocus(false, false)
SetNuiFocusKeepInput(false)
isMenuOpen = false
currentMenu = nil
end
end
function menulib.openParentMenu()
if currentMenu and currentMenu.parent then
menulib.openMenu(currentMenu.parent)
else
menulib.closeMenu()
end
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if isMenuOpen then
local scrollDirection = nil
if IsControlJustPressed(0, 172) then
scrollDirection = "up"
PlaySound(Audio.UpDown.audioName, Audio.UpDown.audioRef)
elseif IsControlJustPressed(0, 173) then
scrollDirection = "down"
PlaySound(Audio.UpDown.audioName, Audio.UpDown.audioRef)
end
if scrollDirection then
SendNUIMessage({eventName = "start_accelerated_scroll", metadata =
{direction = scrollDirection}})
end
function updateMenuDisplay()
if currentMenu then
local itemsToSend = {}
for i, item in ipairs(currentMenu.items) do
local itemToSend = {
id = item.id,
type = item.type,
label = item.label,
rightLabel = item.rightLabel,
description = item.description,
list = item.list,
checked = item.checked,
info = item.info
}
table.insert(itemsToSend, itemToSend)
end
SendNUIMessage({
eventName = "update_menu",
metadata = {
id = currentMenu.id,
title = currentMenu.title,
subtitle = currentMenu.subtitle,
items = itemsToSend
}
})
end
end
function changeUi(ui)
currentUI = ui
SetResourceKvp("menu_ui_theme", ui)
SendNUIMessage({
eventName = "change_ui",
metadata = {
ui = ui
}
})
end