tidy uid->map lookup in ServerBrowser implementations

This commit is contained in:
Chris Forbes
2011-09-25 15:25:39 +13:00
parent 6b602d5262
commit f9eb62beee
3 changed files with 12 additions and 11 deletions

View File

@@ -116,6 +116,10 @@ namespace OpenRA
return ret;
}
public Map FindMapByUid(string uid)
{
return AvailableMaps.ContainsKey(uid) ? AvailableMaps[uid] : null;
}
}
public interface ILoadScreen

View File

@@ -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<GameServer> games)
@@ -151,7 +145,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game);
item.GetWidget<LabelWidget>("TITLE").GetText = () => game.Name;
// TODO: Use game.MapTitle once the server supports it
item.GetWidget<LabelWidget>("MAP").GetText = () => {var map = GetMap(game.Map); return map == null ? "Unknown" : map.Title;};
item.GetWidget<LabelWidget>("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<LabelWidget>("PLAYERS").GetText = () => GetPlayersLabel(game);
item.GetWidget<LabelWidget>("IP").GetText = () => game.Address;

View File

@@ -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)