From ea1ad507a00113af87c594eeca2a65166b34bb72 Mon Sep 17 00:00:00 2001 From: WantedDV <122710241+WantedDV@users.noreply.github.com> Date: Sat, 10 Feb 2024 12:28:15 -0330 Subject: [PATCH] organize menu lua - fix some whitespace --- ui_scripts/hud_info/__init__.lua | 2 +- ui_scripts/hud_info/hud.lua | 8 +- ui_scripts/lobby/__init__.lua | 96 +------------------ ui_scripts/lobby/menu_xboxlive.lua | 112 +++++++++++++++++++++++ ui_scripts/lobby/menu_xboxlive_lobby.lua | 95 +++++++++++++++++++ ui_scripts/patches/__init__.lua | 2 +- ui_scripts/scoreboard/__init__.lua | 2 +- ui_scripts/server_list/__init__.lua | 1 - ui_scripts/stats/__init__.lua | 1 + 9 files changed, 217 insertions(+), 102 deletions(-) create mode 100644 ui_scripts/lobby/menu_xboxlive.lua create mode 100644 ui_scripts/lobby/menu_xboxlive_lobby.lua diff --git a/ui_scripts/hud_info/__init__.lua b/ui_scripts/hud_info/__init__.lua index 07dfbdd..4b5a89a 100644 --- a/ui_scripts/hud_info/__init__.lua +++ b/ui_scripts/hud_info/__init__.lua @@ -3,4 +3,4 @@ if (game:issingleplayer()) then end require("settings") -require("hud") \ No newline at end of file +require("hud") diff --git a/ui_scripts/hud_info/hud.lua b/ui_scripts/hud_info/hud.lua index 405ebab..d1edab2 100644 --- a/ui_scripts/hud_info/hud.lua +++ b/ui_scripts/hud_info/hud.lua @@ -106,17 +106,17 @@ function infoelement(data) b = 0.6, } }) - + value:addElement(LUI.UITimer.new(data.interval, "update")) value:setText(data.getvalue()) value:addEventHandler("update", function() value:setText(data.getvalue()) end) - + container:addElement(background) container:addElement(label) container:addElement(value) - + return container end @@ -156,7 +156,7 @@ LUI.MenuBuilder.m_types_build["mp_hud"] = function() infobar:removeAllChildren() populateinfobar(infobar) end) - + hud.static:addElement(infobar) return hud diff --git a/ui_scripts/lobby/__init__.lua b/ui_scripts/lobby/__init__.lua index f3ac913..761aced 100644 --- a/ui_scripts/lobby/__init__.lua +++ b/ui_scripts/lobby/__init__.lua @@ -2,97 +2,5 @@ if (game:issingleplayer() or not Engine.InFrontend()) then return end -local MPLobbyPublic = LUI.mp_menus.MPLobbyPublic - -function StartButtonAction(f2_arg0, f2_arg1) - Engine.SetDvarInt("party_minplayers", 1) -end - -function StartButtonText(f5_arg0, f5_arg1) - f5_arg0:processEvent({ - name = "refresh_disabled" - }) - f5_arg0:setText(Engine.Localize("@LUA_MENU_START_GAME")) -end - -function OnLeaveLobby(f6_arg0) - LUI.MarketingPanel.ClearViewedMessages({ - LUI.MarketingLocation.Lobby - }) - LUI.FlowManager.RequestLeaveMenu(f6_arg0) -end - -function OnGameSetup(f10_arg0, f10_arg1) - LUI.FlowManager.RequestAddMenu(f10_arg0, "gamesetup_menu_main", true, f10_arg1.controller, false) -end - -function menu_xboxlive_lobby(f7_arg0, f7_arg1) - local f7_local0 = false - if not Engine.IsZombiesMode() and Engine.GetDvarBool("ui_opensummary") then - f7_local0 = true - end - if Engine.IsZombiesMode() then - ZombiesUpdateMapBkg() - end - local f7_local1 = LUI.MPLobbyBase.new(f7_arg0, { - menu_title = "@PLATFORM_UI_HEADER_PLAY_MP_CAPS", - has_match_summary = true, - has_new_item_usage_widget = true - }, true) - f7_local1:setClass(LUI.MPLobbyPublic) - if Engine.IsMultiplayer() then - f7_local1:AddReadyUpButton("pt_AliensReadyUpPublicInUse", StartButtonAction, false, StartButtonText) - end - if Engine.IsCoreMode() then - f7_local1:AddNewItemsWidget() - f7_local1:AddCACButton() - f7_local1:AddCAOButton() - f7_local1:AddArmoryButton() - end - f7_local1:AddOptionsButton() - if not f7_local1:CheckAddMapAndMarketingPanels(f7_local0) then - f7_local1:registerEventHandler("CheckAddMapAndMarketingPanels", function(element, event) - LUI.MPLobbyPublic.CheckAddMapAndMarketingPanels(element, f7_local0) - end) - local self = LUI.UITimer.new(100, "CheckAddMapAndMarketingPanels") - self.id = "MPLobbyPublic_add_map_timer" - f7_local1.mapTimer = self - f7_local1:addElement(self) - end - f7_local1:registerEventHandler("exit_public_lobby", OnLeaveLobby) - f7_local1:registerEventHandler("player_joined", Cac.PlayerJoinedEvent) - f7_local1:registerEventHandler("loadout_request", Cac.PlayerJoinedEvent) - Lobby.EnteredLobby() - if f7_local0 then - LUI.InventoryUtils.ProcessLootExpiration() - end - return f7_local1 -end - -LUI.MenuBuilder.m_types_build["menu_xboxlive_lobby"] = menu_xboxlive_lobby - -LUI.FlowManager.RegisterMenuStack("menu_xboxlive_lobby", function() - if Engine.IsCoreMode() and Playlist.GetPreselectedCategoryClass() ~= 8 then - return { - "mp_main_menu", - "menu_xboxlive", - "FindGameMenu", - "FindGameSubMenu" - } - else - return { - "mp_main_menu", - "menu_xboxlive", - "FindGameMenu" - } - end -end) -VLobby.InitMenuMode("menu_xboxlive_lobby", VirtualLobbyModes.LUI_MODE_LOBBY, function() - if LUI.MPLobbyBase.UseReadyUp then - Lobby.ClearLocalReadyUpFlag() - end - local f10_local0 = PersistentBackground.StackFunc(nil) - f10_local0() -end, LUI.MPLobbyBase.CollectGarbage) - -LUI.FlowManager.RegisterStackResumeBehaviour("menu_xboxlive_lobby", PersistentBackground.StackFunc(nil)) +require("menu_xboxlive") +require("menu_xboxlive_lobby") diff --git a/ui_scripts/lobby/menu_xboxlive.lua b/ui_scripts/lobby/menu_xboxlive.lua new file mode 100644 index 0000000..f69d9ec --- /dev/null +++ b/ui_scripts/lobby/menu_xboxlive.lua @@ -0,0 +1,112 @@ +local Lobby = Lobby +local MPLobbyOnline = LUI.mp_menus.MPLobbyOnline +local MenuData = LUI.mp_menus.MenuData +local MPLobbyUtils = LUI.mp_menus.MPLobbyUtils + +game:addlocalizedstring("LUA_MENU_SERVERLIST", "Server List") +game:addlocalizedstring("LUA_MENU_SERVERLIST_DESC", "Browse available servers."); + +LeaveXboxLive = function(f5_arg0) + local f73_local0 = Engine.GetFirstActiveController() + if f73_local0 ~= nil then + Engine.ExecNow("xstopprivateparty", f73_local0) + Cac.NotifyVirtualLobby("leave_lobby", Engine.GetXUIDByController(f73_local0)) + Engine.SetSplitScreen(false) + Engine.ExecNow("forcesplitscreencontrol menu_xboxlive_CLOSE", f73_local0) + else + Engine.Exec("xstopprivateparty") + end +end + +function LeaveLobby(a1) + LUI.MarketingPanel.ClearViewedMessages({ LUI.MarketingLocation.CaC, LUI.MarketingLocation.PlayOnline, + LUI.MarketingLocation.CaO }) + LeaveXboxLive() + LUI.FlowManager.RequestLeaveMenuByName("menu_xboxlive_lobby", nil, true) +end + +function menu_xboxlive(a1, a2) + Engine.SetDvarBool("ui_opensummary", false) + local menu = LUI.MPLobbyBase.new(a1, { + menu_title = "@PLATFORM_UI_HEADER_PLAY_MP_CAPS", + memberListState = Lobby.MemberListStates.Prelobby, + has_new_item_usage_widget = true + }) + + menu:setClass(LUI.MPLobbyOnline) + + menu.handleGamepadButton = MPLobbyOnline.menu_xboxlive_handleGamepadButton + if Engine.IsCoreMode() then + menu:AddNewItemsWidget() + end + + -- server list button + local serverListButton = menu:AddButton("@LUA_MENU_SERVERLIST", function(a1, a2) + LUI.FlowManager.RequestAddMenu(a1, "menu_systemlink_join", true, nil) + end) + serverListButton:setDisabledRefreshRate(500) + + -- private match button + privateMatchButton = menu:AddButton("@MENU_PRIVATE_MATCH", MPLobbyOnline.OnPrivateMatch, + MPLobbyOnline.disablePrivateMatchButton) + privateMatchButton:rename("menu_xboxlive_private_match") + privateMatchButton:setDisabledRefreshRate(500) + + -- combat training button + if Engine.IsCoreMode() then + game:addlocalizedstring("LUA_MENU_COMBAT", "Combat Training"); + game:addlocalizedstring("LUA_MENU_COMBAT_DESC", "Rank up offline with bots."); + + local FindGameButton = menu:AddButton("@LUA_MENU_COMBAT", + MPLobbyOnline.OnPublicMatch, MPLobbyOnline.disablePublicMatchButton) + FindGameButton:rename("menu_xboxlive_find_game") + FindGameButton:setDisabledRefreshRate(500) + end + + if Engine.IsCoreMode() then + menu:AddCACButton() + menu:AddCAOButton() + menu:AddArmoryButton() + end + + if not Engine.IsCoreMode() then + local leaderboardButton = menu:AddButton("@LUA_MENU_LEADERBOARD", "OpLeaderboardMain") + leaderboardButton:rename("OperatorMenu_leaderboard") + end + + if Engine.IsZombiesMode() then + menu:AddButton("@ZOMBIES_MENU_MOVIES", "ZombiesMoviesMenu") + end + + menu:AddOptionsButton() + local natType = Lobby.GetNATType() + if natType then + menu:AddHelp({ + name = "add_button_helper_text", + button_ref = "nat", + helper_text = Engine.Localize("NETWORK_YOURNATTYPE", natType), + side = "left", + clickable = false + }) + end + if Engine.IsZombiesMode() then + menu:AddZombiesStats(true) + end + + menu.isSignInMenu = true + menu:registerEventHandler("gain_focus", LUI.MPLobbyOnline.OnGainFocus) + menu:registerEventHandler("player_joined", Cac.PlayerJoinedEvent) + menu:registerEventHandler("exit_live_lobby", LeaveLobby) + + if PersistentBackground.IsCurrent(PersistentBackground.Variants.AARBackground) then + PersistentBackground.Hide(PersistentBackground.Duration) + end + + if Engine.IsCoreMode() then + Engine.ExecNow("eliteclan_refresh", Engine.GetFirstActiveController()) + end + + return menu +end + +LUI.MenuBuilder.m_types_build["menu_xboxlive"] = menu_xboxlive diff --git a/ui_scripts/lobby/menu_xboxlive_lobby.lua b/ui_scripts/lobby/menu_xboxlive_lobby.lua new file mode 100644 index 0000000..f4e02bd --- /dev/null +++ b/ui_scripts/lobby/menu_xboxlive_lobby.lua @@ -0,0 +1,95 @@ +local MPLobbyPublic = LUI.mp_menus.MPLobbyPublic + +function StartButtonAction(f2_arg0, f2_arg1) + Engine.SetDvarInt("party_minplayers", 1) +end + +function StartButtonText(f5_arg0, f5_arg1) + f5_arg0:processEvent({ + name = "refresh_disabled" + }) + f5_arg0:setText(Engine.Localize("@LUA_MENU_START_GAME")) +end + +function OnLeaveLobby(f6_arg0) + LUI.MarketingPanel.ClearViewedMessages({ + LUI.MarketingLocation.Lobby + }) + LUI.FlowManager.RequestLeaveMenu(f6_arg0) +end + +function OnGameSetup(f10_arg0, f10_arg1) + LUI.FlowManager.RequestAddMenu(f10_arg0, "gamesetup_menu_main", true, f10_arg1.controller, false) +end + +function menu_xboxlive_lobby(f7_arg0, f7_arg1) + local f7_local0 = false + if not Engine.IsZombiesMode() and Engine.GetDvarBool("ui_opensummary") then + f7_local0 = true + end + if Engine.IsZombiesMode() then + ZombiesUpdateMapBkg() + end + local f7_local1 = LUI.MPLobbyBase.new(f7_arg0, { + menu_title = "@PLATFORM_UI_HEADER_PLAY_MP_CAPS", + has_match_summary = true, + has_new_item_usage_widget = true + }, true) + f7_local1:setClass(LUI.MPLobbyPublic) + if Engine.IsMultiplayer() then + f7_local1:AddReadyUpButton("pt_AliensReadyUpPublicInUse", StartButtonAction, false, StartButtonText) + -- f7_local1:AddButton( "@LUA_MENU_GAME_SETUP", OnGameSetup ) -- WIP + end + if Engine.IsCoreMode() then + f7_local1:AddNewItemsWidget() + f7_local1:AddCACButton() + f7_local1:AddCAOButton() + f7_local1:AddArmoryButton() + end + f7_local1:AddOptionsButton() + if not f7_local1:CheckAddMapAndMarketingPanels(f7_local0) then + f7_local1:registerEventHandler("CheckAddMapAndMarketingPanels", function(element, event) + LUI.MPLobbyPublic.CheckAddMapAndMarketingPanels(element, f7_local0) + end) + local self = LUI.UITimer.new(100, "CheckAddMapAndMarketingPanels") + self.id = "MPLobbyPublic_add_map_timer" + f7_local1.mapTimer = self + f7_local1:addElement(self) + end + f7_local1:registerEventHandler("exit_public_lobby", OnLeaveLobby) + f7_local1:registerEventHandler("player_joined", Cac.PlayerJoinedEvent) + f7_local1:registerEventHandler("loadout_request", Cac.PlayerJoinedEvent) + Lobby.EnteredLobby() + if f7_local0 then + LUI.InventoryUtils.ProcessLootExpiration() + end + return f7_local1 +end + +LUI.MenuBuilder.m_types_build["menu_xboxlive_lobby"] = menu_xboxlive_lobby + +LUI.FlowManager.RegisterMenuStack("menu_xboxlive_lobby", function() + if Engine.IsCoreMode() and Playlist.GetPreselectedCategoryClass() ~= 8 then + return { + "mp_main_menu", + "menu_xboxlive", + "FindGameMenu", + "FindGameSubMenu" + } + else + return { + "mp_main_menu", + "menu_xboxlive", + "FindGameMenu" + } + end +end) +VLobby.InitMenuMode("menu_xboxlive_lobby", VirtualLobbyModes.LUI_MODE_LOBBY, function() + if LUI.MPLobbyBase.UseReadyUp then + Lobby.ClearLocalReadyUpFlag() + end + local f10_local0 = PersistentBackground.StackFunc(nil) + f10_local0() +end, LUI.MPLobbyBase.CollectGarbage) + +LUI.FlowManager.RegisterStackResumeBehaviour("menu_xboxlive_lobby", PersistentBackground.StackFunc(nil)) diff --git a/ui_scripts/patches/__init__.lua b/ui_scripts/patches/__init__.lua index d0f4ffc..76790b2 100644 --- a/ui_scripts/patches/__init__.lua +++ b/ui_scripts/patches/__init__.lua @@ -10,7 +10,7 @@ end function CanChangeTeam() local f9_local0 = GameX.GetGameMode() local f9_local1 - if f9_local0 ~= "aliens" and Engine.TableLookup( GameTypesTable.File, GameTypesTable.Cols.Ref, f9_local0, GameTypesTable.Cols.TeamChoice ) == "1" then + if f9_local0 ~= "aliens" and Engine.TableLookup(GameTypesTable.File, GameTypesTable.Cols.Ref, f9_local0, GameTypesTable.Cols.TeamChoice) == "1" then f9_local1 = not MLG.IsMLGSpectator() else f9_local1 = false diff --git a/ui_scripts/scoreboard/__init__.lua b/ui_scripts/scoreboard/__init__.lua index a72cfce..f13240e 100644 --- a/ui_scripts/scoreboard/__init__.lua +++ b/ui_scripts/scoreboard/__init__.lua @@ -13,7 +13,7 @@ scoreboard.maxPlayersOnTeam = GetTeamLimitForMaxPlayers(GetPartyMaxPlayers()) scoreboard.scoreColumns.ping = { width = Engine.IsZombiesMode() and 90 or 60, title = "LUA_MENU_PING", - getter = function (scoreinfo) + getter = function(scoreinfo) return scoreinfo.ping == 0 and "BOT" or tostring(scoreinfo.ping) end } diff --git a/ui_scripts/server_list/__init__.lua b/ui_scripts/server_list/__init__.lua index 9c64fab..f66517b 100644 --- a/ui_scripts/server_list/__init__.lua +++ b/ui_scripts/server_list/__init__.lua @@ -2,5 +2,4 @@ if (game:issingleplayer() or not Engine.InFrontend()) then return end -require("lobby") require("serverlist") diff --git a/ui_scripts/stats/__init__.lua b/ui_scripts/stats/__init__.lua index 16a2431..4887079 100644 --- a/ui_scripts/stats/__init__.lua +++ b/ui_scripts/stats/__init__.lua @@ -38,6 +38,7 @@ game:addlocalizedstring("LUA_MENU_RANK_DESC", "Edit rank.") local armorybutton = LUI.MPLobbyBase.AddArmoryButton LUI.MPLobbyBase.AddArmoryButton = function(menu) + -- armorybutton(menu) -- disabled armory button until support for supply drops is added menu:AddButton("@LUA_MENU_STATS", function(a1, a2) LUI.FlowManager.RequestAddMenu(a1, "menu_stats", true, nil) end) -- 2.34.1