Skip to content

Commit cb68e9a

Browse files
committed
fix: hide menu when there's no visible option #6
1 parent a6849d0 commit cb68e9a

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

interactionMenu/lua/client/interact.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ exports("refresh", refresh)
340340

341341
function Render.generic(data, metadata, callbacks)
342342
if not data then return end
343-
StateManager.set('active', true)
343+
if not IsMenuVisible(data) then return end
344344

345+
StateManager.set('active', true)
345346
-- onEnter callback
346347
if callbacks.onEnter then
347348
if not callbacks.onEnter(data, metadata) then return end

interactionMenu/lua/client/menuContainer.lua

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,6 @@ local function navigateMenu(wheelDirection, menus, selected)
839839
local validOptionCount = #validOptions
840840
-- no valid options (if this happens something is wrong!)
841841
if validOptionCount == 0 then return 1, 0 end
842-
843842
-- find the `current selected index` and its `position`
844843
local currentIndex = nil
845844
for i, option in ipairs(validOptions) do
@@ -871,13 +870,10 @@ local function updateSelectedItem(menus, selected, nextSelectedIndex)
871870
end
872871

873872
function Container.changeMenuItem(scaleform, menuData, wheelDirection)
874-
if not hasValidMenuOption(menuData) then
875-
return
876-
end
873+
if not hasValidMenuOption(menuData) then return end
877874

878875
local selected = menuData.selected
879876
local menus = menuData.menus
880-
881877
-- Ignore if list is empty, selected is not present, or menus are absent
882878
if not selected or not menus or not next(menus) then
883879
return
@@ -1247,6 +1243,24 @@ function Container.syncData(scaleform, menuData, refreshUI)
12471243
end
12481244
end
12491245

1246+
function IsMenuVisible(menu_data)
1247+
local is_visible = false
1248+
for _, menu in pairs(menu_data.menus) do
1249+
local menu_id = menu.id
1250+
local original_menu_data = Container.get(menu_id)
1251+
1252+
if original_menu_data and not original_menu_data.flags.deleted then
1253+
for _, option in ipairs(menu.options) do
1254+
if option.flags.hide == false then
1255+
is_visible = true
1256+
end
1257+
end
1258+
end
1259+
end
1260+
1261+
return is_visible
1262+
end
1263+
12501264
-- Validate and synchronize the selected option. If it's the first encounter with the menu,
12511265
-- choose a valid option; otherwise, restore the state on top of revalidating it
12521266
---@param scaleform table

0 commit comments

Comments
 (0)