local f0_local0 = module local f0_local1, f0_local2 = ... f0_local0( f0_local1, package.seeall ) LUI.FlowManager.modal_priority = 500 PushAndPopsTable = {} function new() local f1_local0 = {} setmetatable( f1_local0, { __index = _M } ) f1_local0.menuInfoStack = {} f1_local0.debug = true f1_local0.flowEvents = {} f1_local0.menuInfoData = {} f1_local0.antiSpam = { lastOpenedMenu = 0, countOpenedMenusRecently = 0, openMenuDelay = 0 } setmetatable( f1_local0.menuInfoData, { __mode = "k" } ) return f1_local0 end function RegisterStackPushBehaviour( f2_arg0, f2_arg1 ) PushAndPopsTable[f2_arg0] = PushAndPopsTable[f2_arg0] or {} PushAndPopsTable[f2_arg0].pushFunc = f2_arg1 or PushAndPopsTable[f2_arg0].pushFunc end function RegisterStackPopBehaviour( f3_arg0, f3_arg1 ) PushAndPopsTable[f3_arg0] = PushAndPopsTable[f3_arg0] or {} PushAndPopsTable[f3_arg0].popFunc = f3_arg1 or PushAndPopsTable[f3_arg0].popFunc end function ResetAntiSpam( f4_arg0 ) f4_arg0.antiSpam = { lastOpenedMenu = 0, countOpenedMenusRecently = 0, openMenuDelay = 0 } end function ShouldDelayAgainstSpam( f5_arg0 ) if Engine.InFrontend() or not Engine.IsMultiplayer() then return false end local f5_local0 = f5_arg0.flowManager.antiSpam local f5_local1 = Engine.GetMilliseconds() if f5_local1 - f5_local0.lastOpenedMenu > 1000 then f5_local0.countOpenedMenusRecently = 0 f5_local0.openMenuDelay = 0 elseif f5_local0.countOpenedMenusRecently <= 3 then f5_local0.openMenuDelay = 200 else f5_local0.openMenuDelay = 750 end return f5_local1 - f5_local0.lastOpenedMenu < f5_local0.openMenuDelay end function tryAddMouseCursor( f6_arg0 ) if Engine.UsesMouseCursor() and not f6_arg0:getChildById( "mouse_cursor" ) then f6_arg0:addElement( LUI.UIMouseCursor.new( { material = RegisterMaterial( "ui_cursor" ) } ) ) end end function GetMenuBuildProps( f7_arg0, f7_arg1 ) local f7_local0 = {} if f7_arg0.menuInfoData[f7_arg1] and f7_arg0.menuInfoData[f7_arg1].buildData then f7_local0 = f7_arg0.menuInfoData[f7_arg1].buildData end f7_local0.exclusiveController = f7_arg1.exclusiveControllerIndex return f7_local0 end function SetMenuBuildProps( f8_arg0, f8_arg1, f8_arg2 ) f8_arg0.menuInfoData[f8_arg1] = f8_arg0.menuInfoData[f8_arg1] or {} f8_arg0.menuInfoData[f8_arg1].buildData = f8_arg2 end function GetMenuScopedData( f9_arg0, f9_arg1 ) if not f9_arg0.menuInfoData[f9_arg1] then f9_arg0.menuInfoData[f9_arg1] = {} end if not f9_arg0.menuInfoData[f9_arg1].scopedData then f9_arg0.menuInfoData[f9_arg1].scopedData = {} end return f9_arg0.menuInfoData[f9_arg1].scopedData end function GetMenuScopedDataFromElement( f10_arg0 ) if f10_arg0._scoped then return f10_arg0._scoped else local f10_local0 = f10_arg0:getParent() if f10_local0 then return GetMenuScopedDataFromElement( f10_local0 ) else DebugPrint( "WARNING: could not find scoped data for supplied menu element. This is expected if you've just hit LUI Reload, otherwise not so much." ) return {} end end end function GetMenuScopedDataByMenuName( f11_arg0 ) local f11_local0 = Engine.GetLuiRoot() f11_local0 = f11_local0.flowManager for f11_local1 = #f11_local0.menuInfoStack, 1, -1 do local f11_local4 = f11_local0.menuInfoStack[f11_local1] if f11_local4.name == f11_arg0 then return f11_local0:GetMenuScopedData( f11_local4 ) end end if f11_arg0 then DebugPrint( "WARNING: could not find scoped data for menu named " .. f11_arg0 .. ". This is expected if you've just hit LUI Reload, otherwise not so much." ) end return {} end function IsTopSignInMenu( f12_arg0 ) local f12_local0 = false if not LUI.UIRoot.IsButtonInputBlocked( f12_arg0 ) then local f12_local1 = f12_arg0.flowManager if f12_local1.menuInfoStack then local f12_local2 = f12_local1.menuInfoStack[#f12_local1.menuInfoStack] if f12_local2 and f12_local2.menu and f12_local2.menu.isSignInMenu then local f12_local3 = LUI.FlowManager.GetMenuScopedDataFromElement( f12_local2.menu ) if f12_local3 and f12_local3.focusedPage and f12_local3.focusedPage > 2 then else f12_local0 = true end end end end return f12_local0 end function PushMenuInfo( f13_arg0, f13_arg1, f13_arg2 ) if f13_arg1.isModal or #f13_arg0.menuInfoStack == 0 then table.insert( f13_arg0.menuInfoStack, f13_arg1 ) else local f13_local0 = #f13_arg0.menuInfoStack + 1 while f13_local0 > 1 and f13_arg0.menuInfoStack[f13_local0 - 1].isModal do f13_local0 = f13_local0 - 1 end if f13_arg2 then f13_local0 = math.max( 1, f13_local0 - 1 ) end table.insert( f13_arg0.menuInfoStack, f13_local0, f13_arg1 ) end if Engine.InFrontend() and #f13_arg0.menuInfoStack == 1 then PersistentBackground.Init() end if PushAndPopsTable[f13_arg1.name] and PushAndPopsTable[f13_arg1.name].pushFunc then PushAndPopsTable[f13_arg1.name].pushFunc() end if f13_arg0.debug then f13_arg0:printStack() end end function PopMenuInfo( f14_arg0, f14_arg1 ) local f14_local0 = nil local f14_local1 = #f14_arg0.menuInfoStack while f14_local1 >= 1 and (not (f14_arg1 or not f14_arg0.menuInfoStack[f14_local1].isModal) or f14_arg1 and f14_arg0.menuInfoStack[f14_local1] ~= f14_arg1) do f14_local1 = f14_local1 - 1 end if f14_local1 >= 1 then f14_local0 = f14_arg0.menuInfoStack[f14_local1] if f14_local0 then if PushAndPopsTable[f14_local0.name] and PushAndPopsTable[f14_local0.name].popFunc then PushAndPopsTable[f14_local0.name].popFunc() end table.remove( f14_arg0.menuInfoStack, f14_local1 ) end end if f14_local0 and #f14_arg0.menuInfoStack == 0 then local f14_local2 = Engine.GetLuiRoot() f14_local2:processEvent( { name = "empty_menu_stack" } ) if Engine.IsAliensMode() then ResetAntiSpam( f14_arg0 ) else f14_arg0.antiSpam.lastOpenedMenu = Engine.GetMilliseconds() end end if f14_arg0.debug then f14_arg0:printStack() end return f14_local0 end function GetTopMenuInfo( f15_arg0 ) local f15_local0 = nil local f15_local1 = #f15_arg0 while 1 <= f15_local1 and f15_arg0[f15_local1].isModal do f15_local1 = f15_local1 - 1 end if 1 <= f15_local1 then f15_local0 = f15_arg0[f15_local1] end return f15_local0 end f0_local0 = function ( f16_arg0 ) local f16_local0 = false local f16_local1 = f16_arg0[#f16_arg0] if f16_local1 and f16_local1.isModal then f16_local0 = true end return f16_local0 end function IsTopMenuModal() local f17_local0 = Engine.GetLuiRoot() if not f17_local0 then return false else return f0_local0( f17_local0.flowManager.menuInfoStack ) end end function IsElementAChildOf( f18_arg0, f18_arg1 ) if not f18_arg0 or not f18_arg1 then return false end while f18_arg0 do if f18_arg0 == f18_arg1 then return true end f18_arg0 = f18_arg0:getParent() end return false end function CloseMenuInfo( f19_arg0, f19_arg1, f19_arg2 ) if f19_arg1.menu then if not f19_arg2 then f19_arg1.menu:processEvent( { name = "lose_focus" } ) f19_arg1.menu:processEvent( { name = "menu_close", dispatchChildren = true, controller = f19_arg1.exclusiveControllerIndex } ) end f19_arg1.menu:clearSavedState() f19_arg1.menu:closeTree() f19_arg1.menu:close() f19_arg1.menu = nil end end function RestoreMenuInfo( f20_arg0, f20_arg1, f20_arg2, f20_arg3 ) local f20_local0 = false if not f20_arg1.menu then LUI.ActiveScoped = f20_arg0:GetMenuScopedData( f20_arg1 ) f20_arg1.menu = LUI.MenuBuilder.buildMenu( f20_arg1.name, f20_arg0:GetMenuBuildProps( f20_arg1 ) ) tryAddMouseCursor( f20_arg2 ) f20_arg0.menuRoot:addElement( f20_arg1.menu ) f20_arg1.menu:processEvent( { name = "menu_create", dispatchChildren = true, controller = f20_arg1.exclusiveControllerIndex } ) f20_local0 = true LUI.ActiveScoped = nil end if not f0_local0( f20_arg0.menuInfoStack ) then if f20_arg3 then f20_arg1.menu:processEvent( { name = "popup_inactive", dispatchChildren = true } ) end local f20_local1, f20_local2 = f20_arg1.menu:restoreState() if not f20_local1 or f20_local2 == 0 then DebugPrint( "LUI Warning: no saved state found for menu " .. f20_arg1.name ) f20_arg1.menu:processEvent( { name = "gain_focus" } ) end elseif f20_local0 then f20_arg1.menu:processEvent( { name = "popup_active", dispatchChildren = true } ) end return f20_arg1.menu end function CloseAllModalMenus( f21_arg0 ) for f21_local0 = #f21_arg0.menuInfoStack, 1, -1 do local f21_local3 = f21_arg0.menuInfoStack[f21_local0] if f21_local3.menu and f21_local3.isModal then f21_arg0:CloseMenuInfo( f21_local3 ) f21_arg0:PopMenuInfo( f21_local3 ) end end end function CloseVisibleInStack( f22_arg0, f22_arg1 ) local f22_local0 = true for f22_local1 = #f22_arg0.menuInfoStack, 1, -1 do local f22_local4 = f22_arg0.menuInfoStack[f22_local1] if f22_local4.menu and not f22_local4.isModal then if f22_local0 then if f22_arg1 then f22_local4.menu:clearSavedState() else f22_local4.menu:saveState() end f22_local4.menu:processEvent( { name = "lose_focus" } ) end f22_local4.menu:processEvent( { name = "menu_close", dispatchChildren = true, controller = f22_local4.exclusiveControllerIndex } ) f22_local4.menu:closeTree() f22_local4.menu:close() f22_local4.menu = nil f22_local0 = false end end end f0_local1 = function ( f23_arg0, f23_arg1, f23_arg2 ) local f23_local0 = { name = f23_arg0, menu = f23_arg1, isOldMenu = f23_arg2 } setmetatable( f23_local0, { __mode = "v" } ) return f23_local0 end function printStack( f24_arg0 ) DebugPrint( "----MENU STACK TOP----" ) for f24_local0 = #f24_arg0.menuInfoStack, 1, -1 do local f24_local3 = f24_arg0.menuInfoStack[f24_local0] DebugPrint( f24_local0 .. ") " .. f24_local3.name .. " (" .. (f24_local3.menu and "Built" or "Not built") .. (f24_local3.isOldMenu and ", old menu" or "") .. ")" ) end DebugPrint( "---MENU STACK BOTTOM---" ) end function setupRoot( f25_arg0, f25_arg1 ) f25_arg0.menuRoot = f25_arg1 f25_arg0.menuRoot = LUI.UIElement.new( { leftAnchor = true, topAnchor = true, rightAnchor = true, bottomAnchor = true, left = 0, top = 0, right = 0, bottom = 0 } ) if not Engine.UsingSplitscreenUpscaling() then f25_arg0.menuRoot:setupLetterboxElement() end if f25_arg1 == LUI.primaryRoot then f25_arg0.menuRoot:setUseStencil( true ) end f25_arg0.menuRoot:setPriority( LUI.UIRoot.childPriorities.menuRoot ) f25_arg1:addElement( f25_arg0.menuRoot ) for f25_local3, f25_local4 in pairs( m_flowEvents ) do f25_arg1:registerEventHandler( f25_local3, f25_local4 ) end end function RequestOldMenu( f26_arg0, f26_arg1, f26_arg2, f26_arg3 ) local f26_local0 = { name = "openOldMenu", menu = f26_arg1, replaceTop = f26_arg2, controller = f26_arg3 } local f26_local1 = Engine.GetLuiRoot() LUI.UIRoot.BlockButtonInput( f26_local1, true, "RequestOldMenu" ) LUI.UIRoot.ProcessEvent( f26_local1, f26_local0 ) end function RequestAddMenu( f27_arg0, f27_arg1, f27_arg2, f27_arg3, f27_arg4, f27_arg5 ) local f27_local0 = { name = "addmenu", menu = f27_arg1, exclusiveController = f27_arg2, controller = f27_arg3, replaceTop = f27_arg4, data = f27_arg5 } local f27_local1 = Engine.GetLuiRoot() LUI.UIRoot.BlockButtonInput( f27_local1, true, "RequestAddMenu" ) LUI.UIRoot.ProcessEvent( f27_local1, f27_local0 ) end function RequestPopupMenu( f28_arg0, f28_arg1, f28_arg2, f28_arg3, f28_arg4, f28_arg5, f28_arg6, f28_arg7, f28_arg8 ) local f28_local0 = { name = "popupmenu", menu = f28_arg1, exclusiveController = f28_arg2, controller = f28_arg3, replaceTop = f28_arg4, data = f28_arg5 } if f28_arg8 ~= nil then f28_local0.immediate = f28_arg8 else f28_local0.immediate = true end f28_local0.isModal = f28_arg7 local f28_local1 = Engine.GetLuiRoot() LUI.UIRoot.BlockButtonInput( f28_local1, true, "RequestPopupMenu " .. f28_arg1 ) LUI.UIRoot.ProcessEvent( f28_local1, f28_local0 ) end function RequestLeaveMenu( f29_arg0, f29_arg1 ) local f29_local0 = { name = "leavemenu", element = f29_arg0, immediate = f29_arg1 } local f29_local1 = Engine.GetLuiRoot() LUI.UIRoot.BlockButtonInput( f29_local1, true, "RequestLeaveMenu" ) LUI.UIRoot.ProcessEvent( f29_local1, f29_local0 ) end function RequestLeaveMenuByName( f30_arg0 ) local f30_local0 = { name = "leavemenu", menu = f30_arg0 } LUI.UIRoot.BlockButtonInput( Engine.GetLuiRoot(), true, "RequestLeaveMenuByName" ) local f30_local1 = Engine.GetLuiRoot() f30_local1:processEvent( f30_local0 ) end function RequestRestoreMenu( f31_arg0, f31_arg1, f31_arg2, f31_arg3, f31_arg4 ) local f31_local0 = { name = "restoreMenu", menu = f31_arg1, immediate = true, replaceTop = f31_arg4, exclusiveController = f31_arg2, controller = f31_arg3 } local f31_local1 = Engine.GetLuiRoot() LUI.UIRoot.BlockButtonInput( f31_local1, true, "RequestRestoreMenu" ) LUI.UIRoot.ProcessEvent( f31_local1, f31_local0 ) end function RequestCloseAllMenus( f32_arg0, f32_arg1 ) LUI.UIRoot.ProcessEvent( Engine.GetLuiRoot(), { name = "closeallmenus", menu = f32_arg1 } ) end function RequestSetStack( f33_arg0, f33_arg1 ) LUI.UIRoot.ProcessEvent( Engine.GetLuiRoot(), { name = "setStack", stackData = f33_arg1, immediate = true } ) end function RequestAddMenuAndSetStack( f34_arg0, f34_arg1, f34_arg2, f34_arg3, f34_arg4, f34_arg5, f34_arg6 ) local f34_local0 = { name = "addmenu_setstack", menu = f34_arg1, exclusiveController = f34_arg2, controller = f34_arg3, replaceTop = f34_arg4, data = f34_arg5, stackData = f34_arg6 } local f34_local1 = Engine.GetLuiRoot() LUI.UIRoot.BlockButtonInput( f34_local1, true, "RequestAddMenuAndSetStack" ) LUI.UIRoot.ProcessEvent( f34_local1, f34_local0 ) end function openOldMenuHandler( f35_arg0, f35_arg1 ) f35_arg0.flowManager:openOldMenu( f35_arg1, f35_arg0 ) LUI.UIRoot.BlockButtonInput( f35_arg0, false, "openOldMenu" ) end function openOldMenu( f36_arg0, f36_arg1, f36_arg2 ) local f36_local0 = f36_arg1.menu f36_arg0:CloseAllModalMenus() local f36_local1 = GetTopMenuInfo( f36_arg0.menuInfoStack ) local self = LUI.UIElement.new() local f36_local3 = f0_local1( f36_local0, self, true ) f36_arg0:CloseVisibleInStack( f36_arg1.replaceTop ) local f36_local4 = f36_arg2:getChildById( "mouse_cursor" ) if f36_local4 then f36_local4:close() end f36_arg0.menuRoot:addElement( self ) if f36_arg1.replaceTop then f36_arg0:PopMenuInfo() end f36_arg0:PushMenuInfo( f36_local3 ) Engine.SetLuiInUse( false ) Engine.OpenOldMenu( f36_local0, f36_arg1.controller, f36_arg1.ignorePriority ) return f36_local3.menu end function closeAllMenusHandler( f37_arg0, f37_arg1 ) f37_arg0.flowManager:closeAllMenus( f37_arg0, f37_arg1 ) end function closeAllMenus( f38_arg0, f38_arg1, f38_arg2 ) Engine.SetLuiInUse( false ) for f38_local0 = #f38_arg0.menuInfoStack, 1, -1 do local f38_local3 = f38_arg0.menuInfoStack[f38_local0] f38_arg0:CloseMenuInfo( f38_local3, true ) f38_arg0:PopMenuInfo( f38_local3 ) end local f38_local0 = f38_arg1:getChildById( "mouse_cursor" ) if f38_local0 then f38_local0:close() end f38_arg0.menuInfoStack = {} end function IsInStack( f39_arg0, f39_arg1 ) local f39_local0 = false for f39_local4, f39_local5 in ipairs( f39_arg0.menuInfoStack ) do if f39_local5.name == f39_arg1 and not f39_local5.isOldMenu then f39_local0 = true break end end return f39_local0 end function AnyActiveMenusInStack( f40_arg0 ) local f40_local0 = f40_arg0.flowManager if f40_local0.menuInfoStack then for f40_local4, f40_local5 in ipairs( f40_local0.menuInfoStack ) do if f40_local5.menu ~= nil then return true end end end return false end function IsMenuOpenAndVisible( f41_arg0, f41_arg1 ) local f41_local0 = f41_arg0.flowManager if f41_local0.menuInfoStack then for f41_local4, f41_local5 in ipairs( f41_local0.menuInfoStack ) do if f41_local5.name == f41_arg1 and f41_local5.menu ~= nil then return true end end end return false end function IsMenuInStack( f42_arg0, f42_arg1 ) local f42_local0 = f42_arg0.flowManager if f42_local0.menuInfoStack then for f42_local4, f42_local5 in ipairs( f42_local0.menuInfoStack ) do if f42_local5.name == f42_arg1 then return true end end end return false end function IsMenuTopmost( f43_arg0, f43_arg1 ) local f43_local0 = f43_arg0.flowManager if f43_local0.menuInfoStack then local f43_local1 = f43_local0.menuInfoStack[#f43_local0.menuInfoStack] if f43_local1 ~= nil and f43_local1.name == f43_arg1 then return true end end return false end function GetTopOpenAndVisibleMenuName() local f44_local0 = nil local f44_local1 = Engine.GetLuiRoot() if f44_local1 then local f44_local2 = f44_local1.flowManager if f44_local2.menuInfoStack then for f44_local6, f44_local7 in ipairs( f44_local2.menuInfoStack ) do if f44_local7.name and f44_local7.menu and not f44_local7.isModal then f44_local0 = f44_local7.name end end end end return f44_local0 end function restoreMenuHandler( f45_arg0, f45_arg1 ) f45_arg0.flowManager:restoreMenu( f45_arg1, f45_arg0 ) LUI.UIRoot.BlockButtonInput( f45_arg0, false, "restoreMenu" ) end function restoreMenu( f46_arg0, f46_arg1, f46_arg2 ) local f46_local0 = f46_arg1.menu Engine.SetLuiInUse( true ) local f46_local1 = nil if not IsInStack( f46_arg0, f46_local0 ) then return addMenu( f46_arg0, f46_arg1, f46_arg2 ) end local f46_local2 = GetTopMenuInfo( f46_arg0.menuInfoStack ) if f46_local2.name == f46_local0 then return f46_local2.menu end local f46_local3 = nil local f46_local4 = false for f46_local5 = #f46_arg0.menuInfoStack, 1, -1 do local f46_local8 = f46_arg0.menuInfoStack[f46_local5] if f46_local8.name ~= f46_local0 then else f46_local3 = f46_local8 break end if not f46_local8.isModal then if f46_local8.isPopup then f46_local4 = true end f46_arg0:CloseMenuInfo( f46_local8 ) f46_arg0:PopMenuInfo( f46_arg0.menuInfoStack[f46_local5] ) end end assert( f46_local3 ) return f46_arg0:RestoreMenuInfo( f46_local3, f46_arg2, f46_local4 ) end function addMenuHandler( f47_arg0, f47_arg1 ) if ShouldDelayAgainstSpam( f47_arg0 ) and f47_arg1.menu ~= "mp_pause_menu" then LUI.UIRoot.ProcessEvent( f47_arg0, f47_arg1 ) else local f47_local0 = f47_arg0.flowManager.antiSpam f47_local0.lastOpenedMenu = Engine.GetMilliseconds() f47_local0.countOpenedMenusRecently = f47_local0.countOpenedMenusRecently + 1 f47_arg0.flowManager:addMenu( f47_arg1, f47_arg0 ) LUI.UIRoot.BlockButtonInput( f47_arg0, false, "addMenu" ) end end function addMenuAndSetStackHandler( f48_arg0, f48_arg1 ) f48_arg0.flowManager:addMenu( f48_arg1, f48_arg0 ) f48_arg0.flowManager:setStack( f48_arg0, f48_arg1 ) LUI.UIRoot.BlockButtonInput( f48_arg0, false, "addMenu_setStack" ) end function addMenu( f49_arg0, f49_arg1, f49_arg2 ) local f49_local0 = f49_arg1.menu if IsMenuOpenAndVisible( f49_arg2, f49_local0 ) then return end Engine.SetLuiInUse( true ) local f49_local1 = Engine.GetBytesFree() local f49_local2 = nil if f49_arg1.exclusiveController then DebugPrint( "Setting exclusiveControllerIndex to " .. tostring( f49_arg1.controller ) ) f49_local2 = f49_arg1.controller end f49_arg0:CloseVisibleInStack( f49_arg1.replaceTop ) local f49_local3 = f0_local1( f49_local0 ) f49_arg0:SetMenuBuildProps( f49_local3, f49_arg1.data ) f49_local3.exclusiveControllerIndex = f49_local2 if f49_arg1.replaceTop then f49_arg0:PopMenuInfo() end local f49_local4 = f49_arg0:GetMenuScopedData( f49_local3 ) local f49_local5 = f49_arg0:GetMenuBuildProps( f49_local3 ) if f49_local2 then f49_local4.exclusiveControllerIndex = f49_local2 end for f49_local9, f49_local10 in pairs( f49_local5 ) do f49_local4[f49_local9] = f49_local10 end LUI.ActiveScoped = f49_local4 f49_arg0:PushMenuInfo( f49_local3 ) f49_local6 = LUI.MenuBuilder.buildMenu( f49_local0, f49_local5 ) assert( f49_local6, "Could not build " .. f49_local0 ) f49_local3.menu = f49_local6 f49_arg0.menuRoot:addElement( f49_local6 ) tryAddMouseCursor( f49_arg2 ) f49_local6:processEvent( { name = "update_navigation", dispatchChildren = true } ) f49_local6:processEvent( { name = "menu_create", dispatchChildren = true, controller = f49_local2 } ) if not f0_local0( f49_arg0.menuInfoStack ) then if GetTopMenuInfo( f49_arg0.menuInfoStack ) == f49_local3 then f49_local6:processEvent( { name = "gain_focus", focusType = FocusType.MenuFlow } ) end elseif not f49_local3.isModal then f49_local6:processEvent( { name = "popup_active", dispatchChildren = true } ) end f49_local7 = Engine.GetBytesFree() if not Engine.BBPrint( "lua_menu_info", "menu_name %s memory_delta_bytes %d init_free_bytes %d post_free_bytes %d in_game %d completed_menu %d", f49_local0, f49_local7 - f49_local1, f49_local1, f49_local7, Engine.InFrontend(), true ) then DebugPrint( "Failed to write to blackbox" ) end LUI.ActiveScoped = nil return f49_local3.menu end function popupMenuHandler( f50_arg0, f50_arg1 ) f50_arg0.flowManager:popupMenu( f50_arg1, f50_arg0 ) LUI.UIRoot.BlockButtonInput( f50_arg0, false, "popupMenu " .. f50_arg1.menu ) end function popupMenu( f51_arg0, f51_arg1, f51_arg2 ) local f51_local0 = f51_arg1.menu if IsMenuOpenAndVisible( f51_arg2, f51_local0 ) then return end Engine.SetLuiInUse( true ) local f51_local1 = Engine.GetBytesFree() local f51_local2 = f51_arg0.menuInfoStack[#f51_arg0.menuInfoStack] local f51_local3 = nil if f51_arg1.exclusiveController then f51_local3 = f51_arg1.controller end local f51_local4 = f0_local1( f51_local0 ) f51_arg0:SetMenuBuildProps( f51_local4, f51_arg1.data ) f51_local4.exclusiveControllerIndex = f51_local3 if f51_arg1.isModal then f51_local4.isModal = true end f51_local4.isPopup = true local f51_local5 = f51_arg0:GetMenuScopedData( f51_local4 ) local f51_local6 = f51_arg0:GetMenuBuildProps( f51_local4 ) if f51_local3 then f51_local5.exclusiveControllerIndex = f51_local3 end for f51_local10, f51_local11 in pairs( f51_local6 ) do f51_local5[f51_local10] = f51_local11 end LUI.ActiveScoped = f51_local5 if f51_local2 then if f51_arg1.replaceTop then assert( f51_local4.isModal ~= true, "Replacing top with a modal dialog is not supported!" ) f51_arg0:CloseMenuInfo( f51_local2 ) elseif not f51_local2.isModal then if f51_local2.menu ~= nil then f51_local2.menu:saveState() f51_local2.menu:processEvent( { name = "lose_focus" } ) f51_local2.menu:processEvent( { name = "popup_active", dispatchChildren = true, popup_name = f51_local0 } ) end else for f51_local7 = #f51_arg0.menuInfoStack, 1, -1 do if not f51_arg0.menuInfoStack[f51_local7].isPopup and f51_arg0.menuInfoStack[f51_local7].menu ~= nil then f51_arg0.menuInfoStack[f51_local7].menu:processEvent( { name = "popup_active", dispatchChildren = true, popup_name = f51_local0 } ) break end end end end if f51_arg1.replaceTop then assert( f51_local4.isModal ~= true, "Replacing top with a modal dialog is not supported!" ) f51_arg0.menuInfoStack[#f51_arg0.menuInfoStack] = nil end f51_arg0:PushMenuInfo( f51_local4 ) f51_local7 = LUI.MenuBuilder.buildMenu( f51_local0, f51_local6 ) assert( f51_local7, "Could not build " .. f51_local0 ) if f51_arg1.isModal then f51_local7:setPriority( LUI.FlowManager.modal_priority ) end f51_local4.menu = f51_local7 f51_arg0.menuRoot:addElement( f51_local7 ) f51_local7:processEvent( { name = "update_navigation", dispatchChildren = true } ) f51_local7:processEvent( { name = "menu_create", dispatchChildren = true, controller = f51_local3 } ) if not f0_local0( f51_arg0.menuInfoStack ) then if GetTopMenuInfo( f51_arg0.menuInfoStack ) == f51_local4 then f51_local7:processEvent( { name = "gain_focus" } ) end elseif not f51_local4.isModal then f51_local7:processEvent( { name = "popup_active", dispatchChildren = true } ) end f51_local8 = Engine.GetBytesFree() if not Engine.BBPrint( "lua_menu_info", "menu_name %s memory_delta_bytes %d init_free_bytes %d post_free_bytes %d in_game %d completed_menu %d", f51_local0, f51_local8 - f51_local1, f51_local1, f51_local8, Engine.InFrontend(), true ) then DebugPrint( "Failed to write to blackbox" ) end LUI.ActiveScoped = nil return f51_local4.menu end function leaveMenuHandler( f52_arg0, f52_arg1 ) if ShouldDelayAgainstSpam( f52_arg0 ) then LUI.UIRoot.ProcessEvent( f52_arg0, f52_arg1 ) else local f52_local0 = f52_arg0.flowManager.antiSpam f52_local0.lastOpenedMenu = Engine.GetMilliseconds() f52_local0.countOpenedMenusRecently = f52_local0.countOpenedMenusRecently + 1 f52_arg0.flowManager:leaveMenu( f52_arg0, f52_arg1 ) LUI.UIRoot.BlockButtonInput( f52_arg0, false, "leaveMenu" ) end end function leaveMenuByNameHandler( f53_arg0, f53_arg1 ) RequestLeaveMenuByName( f53_arg1.menu ) LUI.UIRoot.BlockButtonInput( f53_arg0, false, "leaveMenuByName" ) end function leaveMenu( f54_arg0, f54_arg1, f54_arg2 ) local f54_local0 = nil if f54_arg2.element then for f54_local1 = #f54_arg0.menuInfoStack, 1, -1 do local f54_local4 = f54_arg0.menuInfoStack[f54_local1] if f54_local4.menu and IsElementAChildOf( f54_arg2.element, f54_local4.menu ) then f54_local0 = f54_local4 break end end if not f54_local0 then DebugPrint( "Warning: LeaveMenu was called with an element ref, but that element was not found, it is likely the menu was already closed." ) return nil end end if not f54_local0 and f54_arg2.menu then for f54_local1 = #f54_arg0.menuInfoStack, 1, -1 do local f54_local4 = f54_arg0.menuInfoStack[f54_local1] if f54_local4.name == f54_arg2.menu then f54_local0 = f54_local4 break end end if not f54_local0 then DebugPrint( "Warning: LeaveMenu was called with a menu name, but that menu was not found in the stack, it is likely the menu was already closed: " .. f54_arg2.menu ) return nil end end if not f54_local0 and not f54_arg2.menu and not f54_arg2.element then f54_local0 = GetTopMenuInfo( f54_arg0.menuInfoStack ) end if not f54_local0 then DebugPrint( "WARNING: LeaveMenu failed because the requested menu could not be found or the menu stack is empty." ) return elseif f54_local0.menu then f54_arg0:CloseMenuInfo( f54_local0 ) end f54_arg0:PopMenuInfo( f54_local0 ) if not f54_local0.isModal then Engine.PlaySound( CoD.SFX.SelectBack ) end local f54_local1 = GetTopMenuInfo( f54_arg0.menuInfoStack ) if Engine.InFrontend and Engine.InFrontend() then assert( f54_local1, "LUI Error: No menu to back out to, stack is empty" ) end local f54_local2 = Engine.SetLuiInUse local f54_local3 if f54_local1 ~= nil then f54_local3 = not f54_local1.isOldMenu else f54_local3 = false end f54_local2( f54_local3 ) if f54_local1 then if f54_local1.isOldMenu then f54_local2 = f54_arg1:getChildById( "mouse_cursor" ) if f54_local2 then f54_local2:close() end else return f54_arg0:RestoreMenuInfo( f54_local1, f54_arg1, f54_local0.isPopup ) end end f54_local2 = f54_arg1:getChildById( "mouse_cursor" ) if f54_local2 then f54_local2:close() end return nil end function setStackHandler( f55_arg0, f55_arg1 ) f55_arg0.flowManager:setStack( f55_arg0, f55_arg1 ) end function setStack( f56_arg0, f56_arg1, f56_arg2 ) DebugPrint( "FlowManager: Rewriting menu stack " ) local f56_local0 = GetTopMenuInfo( f56_arg0.menuInfoStack ) if f56_arg0.debug then local f56_local1 = "" for f56_local6, f56_local7 in ipairs( f56_arg0.menuInfoStack ) do local f56_local8 = f56_local1 local f56_local5 if f56_local6 > 1 then f56_local5 = " > " if not f56_local5 then else f56_local1 = f56_local8 .. f56_local5 .. f56_local7.name end end f56_local5 = "" end DebugPrint( " Current stack: " .. f56_local1 ) f56_local2 = "" for f56_local7, f56_local8 in ipairs( f56_arg2.stackData ) do local f56_local5 = f56_local2 local f56_local9 if f56_local7 > 1 then f56_local9 = " > " if not f56_local9 then else f56_local2 = f56_local5 .. f56_local9 .. f56_local8.name end end f56_local9 = "" end DebugPrint( " Requesting: " .. f56_local2 .. " > " .. f56_local0.name ) end local f56_local1 = 0 for f56_local6, f56_local7 in ipairs( f56_arg0.menuInfoStack ) do if not (not f56_arg2.stackData[f56_local6] or f56_arg2.stackData[f56_local6].name ~= f56_local7.name) or f56_local6 == #f56_arg2.stackData + 1 and f56_local0.name == f56_local7.name then f56_local1 = f56_local6 end end for f56_local2 = #f56_arg0.menuInfoStack - 1, f56_local1 + 1, -1 do if not f56_arg0.menuInfoStack[f56_local2 + 1] or not f56_arg0.menuInfoStack[f56_local2 + 1].isModal then f56_arg0:CloseMenuInfo( f56_arg0.menuInfoStack[f56_local2] ) f56_arg0:PopMenuInfo( f56_arg0.menuInfoStack[f56_local2] ) end end for f56_local2 = f56_local1 + 1, #f56_arg2.stackData, 1 do f56_local7 = f0_local1( f56_arg2.stackData[f56_local2].name ) f56_arg0:SetMenuBuildProps( f56_local7, f56_arg2.stackData[f56_local2].data ) f56_arg0:PushMenuInfo( f56_local7, true ) end end function CheckRestoreFocus( f57_arg0 ) if f57_arg0.menuInfoStack[#f57_arg0.menuInfoStack] and f57_arg0.menuInfoStack[#f57_arg0.menuInfoStack].menu and not f57_arg0.menuInfoStack[#f57_arg0.menuInfoStack].menu:getFirstInFocus() then DebugPrint( "FLowManager: No child in focus, trying to restore focus. This should probably only happen when using a mouse" ) f57_arg0.menuInfoStack[#f57_arg0.menuInfoStack].menu:processEvent( { name = "gain_focus" } ) end end function SaveMenuStack( f58_arg0 ) local f58_local0 = f58_arg0.flowManager local f58_local1 = {} if f58_local0.menuInfoStack then for f58_local8, f58_local9 in ipairs( f58_local0.menuInfoStack ) do local f58_local10 = {} for f58_local5, f58_local6 in pairs( f58_local9 ) do if f58_local5 == "menu" then if f58_local6 then f58_local10.menu = true else f58_local10.menu = false goto basicblock_9: end end f58_local10[f58_local5] = f58_local6 end if f58_local0.menuInfoData[f58_local9] and f58_local0.menuInfoData[f58_local9].scopedData then DebugPrint( "WARNING: Menu scoped data lost during the debug luiReload process, UI may act inconsistent" ) end f58_local1[#f58_local1 + 1] = f58_local10 end end return serialize.persist( {}, f58_local1 ) end function RestoreMenuStack( f59_arg0, f59_arg1 ) if f59_arg1 then local f59_local0 = f59_arg0.flowManager for f59_local7, f59_local8 in ipairs( serialize.unpersist( {}, f59_arg1 ) ) do local f59_local9 = f0_local1() for f59_local4, f59_local5 in pairs( f59_local8 ) do if f59_local4 ~= "menu" then f59_local9[f59_local4] = f59_local5 end end f59_local0:PushMenuInfo( f59_local9, false ) if f59_local8.menu then if not f59_local8.isOldMenu then LUI.ActiveScoped = f59_local0:GetMenuScopedData( f59_local9 ) f59_local9.menu = LUI.MenuBuilder.buildMenu( f59_local8.name, f59_local0:GetMenuBuildProps( f59_local9 ) ) f59_local0.menuRoot:addElement( f59_local9.menu ) f59_local9.menu:processEvent( { name = "update_navigation", dispatchChildren = true } ) f59_local9.menu:processEvent( { name = "menu_create", dispatchChildren = true, stackRestore = true, controller = f59_local9.exclusiveControllerIndex } ) LUI.ActiveScoped = nil else Engine.SetLuiInUse( false ) Engine.OpenOldMenu( f59_local8.name ) end end end f59_local1 = f59_local0.menuInfoStack[#f59_local0.menuInfoStack] if f59_local1 and f59_local1.menu then Engine.SetLuiInUse( true ) f59_local1.menu:processEvent( { name = "gain_focus" } ) tryAddMouseCursor( f59_arg0 ) end end end m_flowEvents = { addmenu = addMenuHandler, addmenu_setstack = addMenuAndSetStackHandler, openOldMenu = openOldMenuHandler, popupmenu = popupMenuHandler, leavemenu = leaveMenuHandler, leavemenubyname = leaveMenuByNameHandler, restoreMenu = restoreMenuHandler, closeallmenus = closeAllMenusHandler, setStack = setStackHandler } LockTable( _M )