Merge pull request #334 from mjkzy/server-list

Replace "Find Game" with "Server List"
This commit is contained in:
Maurice Heumann 2022-03-14 19:18:57 +01:00 committed by GitHub
commit 2699575d5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 180 additions and 23 deletions

View File

@ -0,0 +1,6 @@
if (not LUI.mp_menus) then
return
end
require("lobby")
require("serverlist")

View File

@ -0,0 +1,90 @@
local Lobby = luiglobals.Lobby
local MPLobbyOnline = LUI.mp_menus.MPLobbyOnline
local MenuData = LUI.mp_menus.MenuData
game:addlocalizedstring("LUA_MENU_SERVERLIST", "Server List")
game:addlocalizedstring("LUA_MENU_SERVERLIST_DESC", "Browse available servers.");
function LeaveLobby(a1)
LUI.MarketingPanel.ClearViewedMessages({LUI.MarketingLocation.CaC, LUI.MarketingLocation.PlayOnline,
LUI.MarketingLocation.CaO})
LeaveXboxLive()
LUI.FlowManager.RequestLeaveMenuByName("menu_xboxlive", 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
local serverListButton = menu:AddButton("@LUA_MENU_SERVERLIST", function(a1, a2)
LUI.FlowManager.RequestAddMenu(a1, "menu_systemlink_join", true, nil)
end)
serverListButton:setDisabledRefreshRate(500)
if Engine.IsCoreMode() then
menu:AddCACButton()
menu:AddCAOButton()
menu:AddArmoryButton()
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
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", luiglobals.Cac.PlayerJoinedEvent)
menu:registerEventHandler("exit_live_lobby", LeaveLobby)
if luiglobals.PersistentBackground.IsCurrent(luiglobals.PersistentBackground.Variants.AARBackground) then
luiglobals.PersistentBackground.Hide(luiglobals.PersistentBackground.Duration)
end
if Engine.IsCoreMode() then
Engine.ExecNow("eliteclan_refresh", Engine.GetFirstActiveController())
end
if Engine.IsZombiesMode() then
MenuData.MenuWaitForContent(menu, true, false, function()
MPLobbyOnline.ZombiesOnContentLoaded(menu)
end)
end
return menu
end
LUI.MenuBuilder.m_types_build["menu_xboxlive"] = menu_xboxlive

View File

@ -0,0 +1,77 @@
local Lobby = luiglobals.Lobby
local SystemLinkJoinMenu = LUI.mp_menus.SystemLinkJoinMenu
if (not SystemLinkJoinMenu) then
return
end
game:addlocalizedstring("PLATFORM_SYSTEM_LINK_TITLE", "SERVER LIST")
game:addlocalizedstring("MENU_NUMPLAYERS", "Players")
game:addlocalizedstring("MENU_PING", "Ping")
local offsets = {10, 400, 600, 900, 1075}
local columns = {"@MENU_HOST_NAME", "@MENU_MAP", "@MENU_TYPE1", "@MENU_NUMPLAYERS", "@MENU_PING"}
SystemLinkJoinMenu.AddServerButton = function(menu, controller, index)
local serverInformation = nil
local button = menu:AddButton("", SystemLinkJoinMenu.OnJoinGame)
if index == nil then
button:makeNotFocusable()
serverInformation = function(i)
return Engine.Localize(columns[i])
end
else
button:makeFocusable()
button.index = index
serverInformation = function(i)
return Lobby.GetServerData(controller, index, i - 1)
end
end
for size = 1, #offsets do
SystemLinkJoinMenu.MakeText(button, offsets[size], serverInformation(size))
end
return button
end
function menu_systemlink_join(f19_arg0, f19_arg1)
local menu = LUI.MenuTemplate.new(f19_arg0, {
menu_title = "@PLATFORM_SYSTEM_LINK_TITLE",
menu_width = CoD.DesignGridHelper(28)
})
Lobby.BuildServerList(Engine.GetFirstActiveController())
Lobby.RefreshServerList(Engine.GetFirstActiveController())
SystemLinkJoinMenu.UpdateGameList(menu)
menu:registerEventHandler("updateGameList", SystemLinkJoinMenu.UpdateGameList)
menu:addElement(LUI.UITimer.new(250, "updateGameList"))
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(f10_arg0, f10_arg1)
SystemLinkJoinMenu.RefreshServers(f10_arg0, f10_arg1, menu)
end)
menu:AddHelp({
name = "add_button_helper_text",
button_ref = "button_action",
helper_text = Engine.Localize("@MENU_JOIN_GAME1"),
side = "right",
clickable = false,
priority = -1000
})
menu:AddBackButton()
return menu
end
LUI.MenuBuilder.m_types_build["menu_systemlink_join"] = menu_systemlink_join

View File

@ -143,18 +143,13 @@ namespace server_list
if (column == 3)
{
auto num_spaces = 20;
if (servers[i].clients >= 10) num_spaces -= 2;
if (servers[i].max_clients >= 10) num_spaces -= 2;
if (servers[i].bots >= 10) num_spaces -= 2;
std::string spaces;
while (num_spaces > 0)
{
spaces.append(" ");
num_spaces--;
return utils::string::va("%d/%d [%d]", servers[i].clients, servers[i].max_clients,
servers[i].bots);
}
return utils::string::va("%d/%d [%d]%s%d", servers[i].clients, servers[index].max_clients,
servers[i].bots, spaces.data(), servers[i].ping);
if (column == 4)
{
return servers[i].ping ? utils::string::va("%d", servers[i].ping) : "";
}
return "";
@ -376,17 +371,6 @@ namespace server_list
{
if (!game::environment::is_mp()) return;
localized_strings::override("PLATFORM_SYSTEM_LINK_TITLE", "SERVER LIST");
localized_strings::override("LUA_MENU_STORE", "Server List");
localized_strings::override("LUA_MENU_STORE_DESC", "Browse available servers.");
// shitty ping workaround
localized_strings::override("MENU_NUMPLAYERS", "Type");
localized_strings::override("MENU_TYPE1", "Players"s + " " + "Ping");
// hook LUI_OpenMenu to show server list instead of store popup
utils::hook::call(0x1404D5550, &lui_open_menu_stub);
// replace UI_RunMenuScript call in LUI_CoD_LuaCall_RefreshServerList to our refresh_servers
utils::hook::call(0x1400F5AA1, &refresh_server_list);
utils::hook::call(0x1400F5F26, &join_server);