From 6579d52c7c77230dd21fc074a514ebe5d340237b Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Sun, 25 Sep 2022 14:24:45 +0200 Subject: [PATCH 1/3] feat(web/menu/list): keyPressed on closeMenu --- web/src/features/menu/list/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/src/features/menu/list/index.tsx b/web/src/features/menu/list/index.tsx index 5e4622a5b..b32364cd8 100644 --- a/web/src/features/menu/list/index.tsx +++ b/web/src/features/menu/list/index.tsx @@ -37,10 +37,10 @@ const ListMenu: React.FC = () => { const [indexStates, setIndexStates] = useState>({}); const listRefs = useRef>([]); - const closeMenu = (ignoreFetch?: boolean) => { + const closeMenu = (ignoreFetch?: boolean, keyPressed?: string) => { if (menu.canClose === false) return; setVisible(false); - if (!ignoreFetch) fetchNui('closeMenu'); + if (!ignoreFetch) fetchNui('closeMenu', keyPressed); }; const moveMenu = (e: React.KeyboardEvent) => { @@ -111,7 +111,7 @@ const ListMenu: React.FC = () => { if (!visible) return; const keyHandler = (e: KeyboardEvent) => { - if (['Escape', 'Backspace'].includes(e.code)) closeMenu(); + if (['Escape', 'Backspace'].includes(e.code)) closeMenu(false, e.code); }; window.addEventListener('keydown', keyHandler); From c47741a7854ae68b852a6fc563fdbbb27bb9c975 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Sun, 25 Sep 2022 14:25:26 +0200 Subject: [PATCH 2/3] feat(package/interface/menu): onClose keyPressed --- package/client/resource/interface/menu.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package/client/resource/interface/menu.ts b/package/client/resource/interface/menu.ts index 623aca61e..480ae1436 100644 --- a/package/client/resource/interface/menu.ts +++ b/package/client/resource/interface/menu.ts @@ -18,7 +18,8 @@ interface MenuProps { options: MenuOptions[]; position?: MenuPosition; disableInput?: boolean; - onClose?: () => void; + canClose?: boolean; + onClose?: (keyPressed?: 'Escape' | 'Backspace') => void; onSelected?: ChangeFunction; onSideScroll?: ChangeFunction; } From 615a3cc073484f489f09a1005b02d068271e7dc3 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Sun, 25 Sep 2022 14:26:04 +0200 Subject: [PATCH 3/3] feat(interface/menu): onClose keyPressed --- resource/interface/client/menu.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/resource/interface/client/menu.lua b/resource/interface/client/menu.lua index 361f96d23..215767a76 100644 --- a/resource/interface/client/menu.lua +++ b/resource/interface/client/menu.lua @@ -1,4 +1,6 @@ +---@type { [string]: MenuProps } local registeredMenus = {} +---@type MenuProps | nil local openMenu = nil local keepInput = IsNuiFocusKeepingInput() @@ -19,7 +21,8 @@ local keepInput = IsNuiFocusKeepingInput() ---@field options MenuOptions[] ---@field position? MenuPosition ---@field disableInput? boolean ----@field onClose? fun() +---@field canClose? boolean +---@field onClose? fun(keyPressed?: 'Escape' | 'Backspace') ---@field onSelected? MenuChangeFunction ---@field onSideScroll? MenuChangeFunction @@ -45,7 +48,7 @@ function lib.showMenu(id, startIndex) if not openMenu then CreateThread(function() while openMenu do - if not openMenu.disableInput then + if openMenu.disableInput == nil or openMenu.disableInput then DisablePlayerFiring(cache.playerId, true) HudWeaponWheelIgnoreSelection() DisableControlAction(0, 140, true) @@ -165,6 +168,6 @@ RegisterNUICallback('closeMenu', function(data, cb) openMenu = nil if menu.onClose then - menu.onClose() + menu.onClose(data --[[@as 'Escape' | 'Backspace' | nil]]) end -end) \ No newline at end of file +end)