From 84cb994da57e8c346a630e507ab14f17e0013f31 Mon Sep 17 00:00:00 2001 From: m Date: Wed, 2 Mar 2022 17:21:09 -0600 Subject: [PATCH] add Server List button --- data/ui_scripts/server_list/__init__.lua | 145 +-------------------- data/ui_scripts/server_list/lobby.lua | 66 ++++++++++ data/ui_scripts/server_list/serverlist.lua | 145 +++++++++++++++++++++ 3 files changed, 213 insertions(+), 143 deletions(-) create mode 100644 data/ui_scripts/server_list/lobby.lua create mode 100644 data/ui_scripts/server_list/serverlist.lua diff --git a/data/ui_scripts/server_list/__init__.lua b/data/ui_scripts/server_list/__init__.lua index a5532b0a..40ef8d17 100644 --- a/data/ui_scripts/server_list/__init__.lua +++ b/data/ui_scripts/server_list/__init__.lua @@ -1,143 +1,2 @@ -local Lobby = luiglobals.Lobby -local SystemLinkJoinMenu = LUI.mp_menus.SystemLinkJoinMenu - -if (not SystemLinkJoinMenu) then - return -end - -local offsets = { - 10, - 500, - 950, - 700, - 1100, -} - -local columns = { - "@MENU_HOST_NAME", - "@MENU_MAP", - "Players", - "@MENU_TYPE1", - "Ping", -} - -SystemLinkJoinMenu.AddHeaderButton = function(menu, f12_arg1, width) - local state = CoD.CreateState(0, f12_arg1, nil, nil, CoD.AnchorTypes.TopLeft) - state.width = width - local element = LUI.UIElement.new(state) - local button = SystemLinkJoinMenu.CreateButton("header", 24) - - button:addElement(LUI.Divider.new(CoD.CreateState(nil, 0, nil, nil, CoD.AnchorTypes.TopLeftRight), 40, LUI.Divider.Grey)) - button:makeNotFocusable() - button:addElement(LUI.Divider.new(CoD.CreateState(nil, 0, nil, nil, CoD.AnchorTypes.BottomLeftRight), 40, LUI.Divider.Grey)) - - local gettext = function(i) - return Engine.Localize(columns[i]) - end - - for i = 1, #offsets do - SystemLinkJoinMenu.MakeText(button.textHolder, offsets[i], gettext(i), nil) - end - - element:addElement(button) - menu:addElement(element) -end - -SystemLinkJoinMenu.AddServerButton = function(menu, controller, index) - local button = SystemLinkJoinMenu.CreateButton(index or "header", 24) - button:makeFocusable() - button.index = index - button:addEventHandler("button_action", SystemLinkJoinMenu.OnJoinGame) - - local gettext = function(i) - return Lobby.GetServerData(controller, index, i - 1) - end - - for i = 1, #offsets do - SystemLinkJoinMenu.MakeText(button.textHolder, offsets[i], gettext(i), luiglobals.Colors.h1.medium_grey) - end - - menu.list:addElement(button) - return button -end - -SystemLinkJoinMenu.MakeText = function(menu, f5_arg1, text, color) - local state = CoD.CreateState(f5_arg1, nil, f5_arg1 + 200, nil, CoD.AnchorTypes.Left) - state.font = CoD.TextSettings.TitleFontSmall.Font - state.top = -6 - state.height = 14 - state.alignment = LUI.Alignment.Left - state.glow = LUI.GlowState.None - state.color = color - - local el = LUI.UIText.new(state) - el:registerAnimationState("focused", { - color = luiglobals.Colors.white - }) - - el:registerEventHandler("focused", function(element, event) - element:animateToState("focused", 0) - end) - - el:registerEventHandler("unfocused", function(element, event) - element:animateToState("default", 0) - end) - - el:setText(text) - menu:addElement(el) -end - -function menu_systemlink_join(f19_arg0, f19_arg1) - local width = 1145 - - local menu = LUI.MenuTemplate.new(f19_arg0, { - menu_title = "@PLATFORM_SYSTEM_LINK_TITLE", - menu_width = width, - menu_top_indent = 20, - disableDeco = true, - spacing = 1 - }) - - SystemLinkJoinMenu.AddHeaderButton(menu, 80, width) - SystemLinkJoinMenu.AddLowerCounter(menu, width) - SystemLinkJoinMenu.UpdateCounterText(menu, nil) - Lobby.BuildServerList(Engine.GetFirstActiveController()) - - menu.list:registerEventHandler(LUI.UIScrollIndicator.UpdateEvent, function(element, event) - SystemLinkJoinMenu.UpdateCounterText(menu, event) - end) - - SystemLinkJoinMenu.UpdateGameList(menu) - menu:registerEventHandler("updateGameList", SystemLinkJoinMenu.UpdateGameList) - menu:addElement(LUI.UITimer.new(250, "updateGameList")) - - LUI.ButtonHelperText.ClearHelperTextObjects(menu.help, { - side = "all" - }) - - menu:AddHelp({ - name = "add_button_helper_text", - button_ref = "button_alt1", - helper_text = Engine.Localize("@MENU_SB_TOOLTIP_BTN_REFRESH"), - side = "right", - clickable = true, - priority = -1000 - }, function(f21_arg0, f21_arg1) - SystemLinkJoinMenu.RefreshServers(f21_arg0, f21_arg1, menu) - end) - - menu:AddHelp({ - name = "add_button_helper_text", - button_ref = "button_action", - helper_text = Engine.Localize("@MENU_JOIN_GAME1"), - side = "left", - clickable = false, - priority = -1000 - }, nil, nil, true) - - menu:AddBackButton() - - return menu -end - -LUI.MenuBuilder.m_types_build["menu_systemlink_join"] = menu_systemlink_join +require("lobby") +require("serverlist") diff --git a/data/ui_scripts/server_list/lobby.lua b/data/ui_scripts/server_list/lobby.lua new file mode 100644 index 00000000..348e95af --- /dev/null +++ b/data/ui_scripts/server_list/lobby.lua @@ -0,0 +1,66 @@ +local Lobby = luiglobals.Lobby +local MPLobbyOnline = LUI.mp_menus.MPLobbyOnline + +function LeaveLobby(f5_arg0) + LeaveXboxLive() + if Lobby.IsInPrivateParty() == false or Lobby.IsPrivatePartyHost() then + LUI.FlowManager.RequestLeaveMenuByName("menu_xboxlive") + Engine.ExecNow("clearcontrollermap") + end +end + +function menu_xboxlive(f16_arg0, f16_arg1) + local menu = LUI.MPLobbyBase.new(f16_arg0, { + menu_title = "@PLATFORM_UI_HEADER_PLAY_MP_CAPS", + memberListState = Lobby.MemberListStates.Prelobby + }) + + menu:setClass(LUI.MPLobbyOnline) + + local serverListButton = menu:AddButton("SERVER LIST", function (a1, a2) + LUI.FlowManager.RequestAddMenu(a1, "menu_systemlink_join", true, nil) + end) + serverListButton:setDisabledRefreshRate(500) + if Engine.IsCoreMode() then + menu:AddCACButton() + menu:AddBarracksButton() + menu:AddPersonalizationButton() + -- menu:AddDepotButton() + end + + serverListButton = menu:AddButton("@MENU_PRIVATE_MATCH", MPLobbyOnline.OnPrivateMatch, MPLobbyOnline.disablePrivateMatchButton) + serverListButton:rename("menu_xboxlive_private_match") + serverListButton:setDisabledRefreshRate(500) + if not Engine.IsCoreMode() then + local leaderboardButton = menu:AddButton("@LUA_MENU_LEADERBOARD", "OpLeaderboardMain") + leaderboardButton:rename("OperatorMenu_leaderboard") + end + + menu:AddOptionsButton() + local natType = Lobby.GetNATType() + if natType then + local natTypeText = Engine.Localize("NETWORK_YOURNATTYPE", natType) + local properties = CoD.CreateState(nil, nil, 2, -62, CoD.AnchorTypes.BottomRight) + properties.width = 250 + properties.height = CoD.TextSettings.BodyFontVeryTiny.Height + properties.font = CoD.TextSettings.BodyFontVeryTiny.Font + properties.color = luiglobals.Colors.white + properties.alpha = 0.25 + local self = LUI.UIText.new(properties) + self:setText(natTypeText) + menu:addElement(self) + end + + menu.isSignInMenu = true + menu:registerEventHandler("gain_focus", LUI.MPLobbyOnline.OnGainFocus) + menu:registerEventHandler("player_joined", luiglobals.Cac.PlayerJoinedEvent) + menu:registerEventHandler("exit_live_lobby", LeaveLobby) + + 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/data/ui_scripts/server_list/serverlist.lua b/data/ui_scripts/server_list/serverlist.lua new file mode 100644 index 00000000..ca597cee --- /dev/null +++ b/data/ui_scripts/server_list/serverlist.lua @@ -0,0 +1,145 @@ +local Lobby = luiglobals.Lobby +local SystemLinkJoinMenu = LUI.mp_menus.SystemLinkJoinMenu + +if (not SystemLinkJoinMenu) then + return +end + +local offsets = { + 10, + 500, + 950, + 700, + 1100, +} + +local columns = { + "@MENU_HOST_NAME", + "@MENU_MAP", + "Players", + "@MENU_TYPE1", + "Ping", +} + +SystemLinkJoinMenu.AddHeaderButton = function(menu, f12_arg1, width) + local state = CoD.CreateState(0, f12_arg1, nil, nil, CoD.AnchorTypes.TopLeft) + state.width = width + local element = LUI.UIElement.new(state) + local button = SystemLinkJoinMenu.CreateButton("header", 24) + + button:addElement(LUI.Divider.new(CoD.CreateState(nil, 0, nil, nil, CoD.AnchorTypes.TopLeftRight), 40, LUI.Divider.Grey)) + button:makeNotFocusable() + button:addElement(LUI.Divider.new(CoD.CreateState(nil, 0, nil, nil, CoD.AnchorTypes.BottomLeftRight), 40, LUI.Divider.Grey)) + + local gettext = function(i) + return Engine.Localize(columns[i]) + end + + for i = 1, #offsets do + SystemLinkJoinMenu.MakeText(button.textHolder, offsets[i], gettext(i), nil) + end + + element:addElement(button) + menu:addElement(element) +end + +SystemLinkJoinMenu.AddServerButton = function(menu, controller, index) + local button = SystemLinkJoinMenu.CreateButton(index or "header", 24) + button:makeFocusable() + button.index = index + button:addEventHandler("button_action", SystemLinkJoinMenu.OnJoinGame) + + local gettext = function(i) + return Lobby.GetServerData(controller, index, i - 1) + end + + for i = 1, #offsets do + SystemLinkJoinMenu.MakeText(button.textHolder, offsets[i], gettext(i), luiglobals.Colors.h1.medium_grey) + end + + menu.list:addElement(button) + return button +end + +SystemLinkJoinMenu.MakeText = function(menu, f5_arg1, text, color) + local state = CoD.CreateState(f5_arg1, nil, f5_arg1 + 200, nil, CoD.AnchorTypes.Left) + state.font = CoD.TextSettings.TitleFontSmall.Font + state.top = -6 + state.height = 14 + state.alignment = LUI.Alignment.Left + state.glow = LUI.GlowState.None + state.color = color + + local el = LUI.UIText.new(state) + el:registerAnimationState("focused", { + color = luiglobals.Colors.white + }) + + el:registerEventHandler("focused", function(element, event) + element:animateToState("focused", 0) + end) + + el:registerEventHandler("unfocused", function(element, event) + element:animateToState("default", 0) + end) + + el:setText(text) + menu:addElement(el) +end + +function menu_systemlink_join(f19_arg0, f19_arg1) + local width = 1145 + + local menu = LUI.MenuTemplate.new(f19_arg0, { + menu_title = "@PLATFORM_SYSTEM_LINK_TITLE", + menu_width = width, + menu_top_indent = 20, + disableDeco = true, + spacing = 1 + }) + + SystemLinkJoinMenu.AddHeaderButton(menu, 80, width) + SystemLinkJoinMenu.AddLowerCounter(menu, width) + SystemLinkJoinMenu.UpdateCounterText(menu, nil) + Lobby.BuildServerList(Engine.GetFirstActiveController()) + + menu.list:registerEventHandler(LUI.UIScrollIndicator.UpdateEvent, function(element, event) + SystemLinkJoinMenu.UpdateCounterText(menu, event) + end) + + SystemLinkJoinMenu.UpdateGameList(menu) + menu:registerEventHandler("updateGameList", SystemLinkJoinMenu.UpdateGameList) + menu:addElement(LUI.UITimer.new(250, "updateGameList")) + + LUI.ButtonHelperText.ClearHelperTextObjects(menu.help, { + side = "all" + }) + + menu:AddHelp({ + name = "add_button_helper_text", + button_ref = "button_alt1", + helper_text = Engine.Localize("@MENU_SB_TOOLTIP_BTN_REFRESH"), + side = "right", + clickable = true, + priority = -1000 + }, function(f21_arg0, f21_arg1) + SystemLinkJoinMenu.RefreshServers(f21_arg0, f21_arg1, menu) + end) + + menu:AddHelp({ + name = "add_button_helper_text", + button_ref = "button_action", + helper_text = Engine.Localize("@MENU_JOIN_GAME1"), + side = "left", + clickable = false, + priority = -1000 + }, nil, nil, true) + + menu:AddBackButton() + + Lobby.RefreshServerList(Engine.GetFirstActiveController()) + + return menu +end + +LUI.MenuBuilder.m_types_build["menu_systemlink_join"] = menu_systemlink_join