From f9eb62beee1742a4d2deb5e12790c3c8d62f308b Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 25 Sep 2011 15:25:39 +1300 Subject: [PATCH] tidy uid->map lookup in ServerBrowser implementations --- OpenRA.Game/ModData.cs | 4 ++++ .../Widgets/Logic/CncServerBrowserLogic.cs | 16 +++++++--------- .../Widgets/Logic/ServerBrowserLogic.cs | 3 +-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index b8cc61d97a..efbbf63259 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -116,6 +116,10 @@ namespace OpenRA return ret; } + public Map FindMapByUid(string uid) + { + return AvailableMaps.ContainsKey(uid) ? AvailableMaps[uid] : null; + } } public interface ILoadScreen diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncServerBrowserLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncServerBrowserLogic.cs index d2b4cb8ae7..eece503e66 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncServerBrowserLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncServerBrowserLogic.cs @@ -105,19 +105,13 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic if (game == null) return ""; - var map = GetMap(game.Map); + var map = Game.modData.FindMapByUid(game.Map); return map == null ? "{0}".F(currentServer.Players) : "{0} / {1}".F(currentServer.Players, map.PlayerCount); } Map CurrentMap() { - return (currentServer == null) ? null : GetMap(currentServer.Map); - } - - static Map GetMap(string uid) - { - return (!Game.modData.AvailableMaps.ContainsKey(uid)) - ? null : Game.modData.AvailableMaps[uid]; + return (currentServer == null) ? null : Game.modData.FindMapByUid(currentServer.Map); } public void RefreshServerList(Widget panel, IEnumerable games) @@ -151,7 +145,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game); item.GetWidget("TITLE").GetText = () => game.Name; // TODO: Use game.MapTitle once the server supports it - item.GetWidget("MAP").GetText = () => {var map = GetMap(game.Map); return map == null ? "Unknown" : map.Title;}; + item.GetWidget("MAP").GetText = () => + { + var map = Game.modData.FindMapByUid(game.Map); + return map == null ? "Unknown" : map.Title; + }; // TODO: Use game.MaxPlayers once the server supports it item.GetWidget("PLAYERS").GetText = () => GetPlayersLabel(game); item.GetWidget("IP").GetText = () => game.Address; diff --git a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs index 70b1235b3d..841832d853 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs @@ -81,8 +81,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic Map CurrentMap() { - return (currentServer == null || !Game.modData.AvailableMaps.ContainsKey(currentServer.Map)) - ? null : Game.modData.AvailableMaps[currentServer.Map]; + return (currentServer == null) ? null : Game.modData.FindMapByUid(currentServer.Map); } public static string GenerateModsLabel(GameServer s)