Files
KingMcDonalds 5c2328f975 new weapon menu
2025-01-25 16:27:07 -08:00

115 lines
2.8 KiB
Lua

-- This was created by scully for personal use and thinline resources ONLY! --
-- This does not have a license therefore you do not have permission to take it for your own use --
menuBuilder = {
process = false,
pool = NativeUI.CreatePool(),
menus = {}
}
function menuBuilder.open(menuId)
if not menuBuilder.pool:IsAnyMenuOpen() then
for id, menu in pairs(menuBuilder.menus) do
if id == menuId then
menu.handle:Visible(true)
break
end
end
end
end
function menuBuilder.create(data)
local menu = menuBuilder.menus[data.id]
if not menu then
if not data.parentMenu then
local handle = NativeUI.CreateMenu(data.label, data.description or '')
menu = {
handle = handle
}
menuBuilder.pool:Add(handle)
else
local handle, item = menuBuilder.pool:AddSubMenu(data.parentMenu, data.label, data.description or '')
item:RightLabel('>>>')
menu = {
handle = handle
}
end
end
menu.handle:Clear()
menu.options = {}
for i = 1, #data.options do
local option = data.options[i]
if option.type == 'select' then
option.handle = NativeUI.CreateItem(option.label, option.description or '')
menu.handle:AddItem(option.handle)
elseif option.type == 'list' then
option.handle = NativeUI.CreateListItem(option.label, option.list, option.index or 1, option.description or '')
menu.handle:AddItem(option.handle)
elseif option.type == 'submenu' then
option.parentMenu = menu.handle
menuBuilder.create(option)
end
menu.options[i] = option
end
local menuOptions = menu.options
function menu.handle.OnListChange(sender, item, index)
for i = 1, #menuOptions do
local option = menuOptions[i]
if item == option.handle then
option.handle:IndexToItem(index)
if option.onChange then
option.onChange(index)
end
break
end
end
end
function menu.handle.OnItemSelect(sender, item, index)
for i = 1, #menuOptions do
local option = menuOptions[i]
if item == option.handle then
option.onClick()
break
end
end
end
menuBuilder.pool:RefreshIndex()
menuBuilder.menus[data.id] = menu
end
CreateThread(function()
while true do
local sleep = 100
if menuBuilder.process then
sleep = 0
menuBuilder.pool:ProcessMenus()
end
Wait(sleep)
end
end)