mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
feat(client/interface): menu close arg on button
This commit is contained in:
@@ -36,13 +36,14 @@ function lib.getOpenMenu() return openMenu end
|
|||||||
|
|
||||||
RegisterNUICallback('confirmSelected', function(data, cb)
|
RegisterNUICallback('confirmSelected', function(data, cb)
|
||||||
cb(1)
|
cb(1)
|
||||||
SetNuiFocus(false, false)
|
local selected = type(data) == 'number' and data+1 or data[1]
|
||||||
local selected = data
|
local menu = registeredMenus[openMenu]
|
||||||
local args = registeredMenus[openMenu].options[type(selected) == 'number' and selected+1 or selected[1]].args
|
if menu.options[selected].close ~= false then SetNuiFocus(false, false) end
|
||||||
if type(selected) == 'number' then
|
local args = menu.options[selected].args
|
||||||
registeredMenus[openMenu].cb(selected, nil, args)
|
if type(data) == 'number' then
|
||||||
|
registeredMenus[openMenu].cb(data, nil, args)
|
||||||
else
|
else
|
||||||
registeredMenus[openMenu].cb(selected[1], selected[2], args)
|
registeredMenus[openMenu].cb(data[1], data[2], args)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -78,16 +79,16 @@ RegisterCommand('testMenu', function()
|
|||||||
title = 'Nicer menu',
|
title = 'Nicer menu',
|
||||||
position = 'top-right',
|
position = 'top-right',
|
||||||
onClose = function()
|
onClose = function()
|
||||||
lib.setMenuOptions('epic_menu', {
|
--lib.setMenuOptions('epic_menu', {
|
||||||
{label = 'Nice 1'},
|
-- {label = 'Nice 1'},
|
||||||
{label = 'Nice 2', icon = {'fab', 'bitcoin'}},
|
-- {label = 'Nice 2', icon = {'fab', 'bitcoin'}},
|
||||||
{label = 'Nice 3', icon = 'biohazard', values={'option 1', 'option 2', 'option 3'}, defaultIndex = 2}
|
-- {label = 'Nice 3', icon = 'biohazard', values={'option 1', 'option 2', 'option 3'}, defaultIndex = 2}
|
||||||
})
|
--})
|
||||||
lib.setMenuOptions('epic_menu', {label = 'Not nice'}, 1)
|
--lib.setMenuOptions('epic_menu', {label = 'Not nice'}, 1)
|
||||||
lib.showMenu('epic_menu')
|
--lib.showMenu('epic_menu')
|
||||||
end,
|
end,
|
||||||
options = {
|
options = {
|
||||||
{label = 'Extra nice option', args = 'Hello there'},
|
{label = 'Extra nice option', args = 'Hello there', close = false},
|
||||||
{label = 'Giga nice option'},
|
{label = 'Giga nice option'},
|
||||||
{label = 'Omega nice option'},
|
{label = 'Omega nice option'},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export interface MenuItem {
|
|||||||
description?: string;
|
description?: string;
|
||||||
icon?: IconProp;
|
icon?: IconProp;
|
||||||
defaultIndex?: number;
|
defaultIndex?: number;
|
||||||
|
close?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MenuSettings {
|
interface MenuSettings {
|
||||||
@@ -109,7 +110,7 @@ const ListMenu: React.FC = () => {
|
|||||||
"confirmSelected",
|
"confirmSelected",
|
||||||
Array.isArray(menu.items[selected].values) ? [selected, indexStates[selected]] : selected
|
Array.isArray(menu.items[selected].values) ? [selected, indexStates[selected]] : selected
|
||||||
);
|
);
|
||||||
setVisible(false);
|
if (menu.items[selected].close === undefined || menu.items[selected].close) setVisible(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user