New serverbrowser for RA and CNC

This commit is contained in:
Curtis S
2011-11-06 22:49:40 -07:00
parent 49bf93085f
commit 77fc6199fe
4 changed files with 146 additions and 261 deletions

View File

@@ -52,6 +52,15 @@ namespace OpenRA.Network
if (Game.CurrentMods.Count != Mods.Count())
return false;
// Don't have the map locally
if (!Game.modData.AvailableMaps.ContainsKey(Map))
return false;
return CompatibleVersion();
}
public bool CompatibleVersion()
{
return UsefulMods.All(m => Game.CurrentMods.ContainsKey(m.Key)
&& AreVersionsCompatible(m.Value, Game.CurrentMods[m.Key].Version));
}

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Network;
using OpenRA.Widgets;
@@ -78,34 +79,33 @@ namespace OpenRA.Mods.RA.Widgets.Logic
progressText.IsVisible = () => searchStatus != SearchStatus.Hidden;
progressText.GetText = ProgressLabelText;
// Map preview
var preview = panel.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
preview.Map = () => CurrentMap();
preview.IsVisible = () => CurrentMap() != null;
// Server info
var infoPanel = panel.GetWidget("SERVER_INFO");
infoPanel.IsVisible = () => currentServer != null;
infoPanel.GetWidget<LabelWidget>("SERVER_IP").GetText = () => currentServer.Address;
infoPanel.GetWidget<LabelWidget>("SERVER_MODS").GetText = () => ServerBrowserLogic.GenerateModsLabel(currentServer);
infoPanel.GetWidget<LabelWidget>("MAP_TITLE").GetText = () => (CurrentMap() != null) ? CurrentMap().Title : "Unknown";
infoPanel.GetWidget<LabelWidget>("MAP_PLAYERS").GetText = () => GetPlayersLabel(currentServer);
ServerList.Query(games => RefreshServerList(panel, games));
}
string GetPlayersLabel(GameServer game)
{
if (game == null)
if (game == null || game.Players == 0)
return "";
var map = Game.modData.FindMapByUid(game.Map);
return map == null ? "{0}".F(currentServer.Players) : "{0} / {1}".F(currentServer.Players, map.PlayerCount);
var maxPlayers = map == null ? "?" : (object)map.PlayerCount;
return "{0} / {1}".F(game.Players, maxPlayers);
}
Map CurrentMap()
string GetStateLabel(GameServer game)
{
return (currentServer == null) ? null : Game.modData.FindMapByUid(currentServer.Map);
if (game == null)
return "";
if (game.State == 1) return "Waiting for players";
if (game.State == 2) return "Playing";
else return "Unknown";
}
Map GetMapPreview(GameServer game)
{
return (game == null) ? null : Game.modData.FindMapByUid(game.Map);
}
static string GenerateModLabel(KeyValuePair<string,string> mod)
@@ -134,32 +134,62 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return;
}
var gamesWaiting = games.Where(g => g.CanJoin());
if (gamesWaiting.Count() == 0)
if (games.Count() == 0)
{
searchStatus = SearchStatus.NoGames;
return;
}
searchStatus = SearchStatus.Hidden;
currentServer = gamesWaiting.FirstOrDefault();
currentServer = games.FirstOrDefault();
foreach (var loop in gamesWaiting)
foreach (var loop in games)
{
var game = loop;
var canJoin = game.CanJoin();
var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game);
item.GetWidget<LabelWidget>("TITLE").GetText = () => game.Name;
var preview = item.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
preview.Map = () => GetMapPreview(game);
preview.IsVisible = () => GetMapPreview(game) != null;
var title = item.GetWidget<LabelWidget>("TITLE");
title.GetText = () => game.Name;
// TODO: Use game.MapTitle once the server supports it
item.GetWidget<LabelWidget>("MAP").GetText = () =>
var maptitle = item.GetWidget<LabelWidget>("MAP");
maptitle.GetText = () =>
{
var map = Game.modData.FindMapByUid(game.Map);
return map == null ? "Unknown" : map.Title;
return map == null ? "Unknown Map" : 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;
var players = item.GetWidget<LabelWidget>("PLAYERS");
players.GetText = () => GetPlayersLabel(game);
var state = item.GetWidget<LabelWidget>("STATE");
state.GetText = () => GetStateLabel(game);
var ip = item.GetWidget<LabelWidget>("IP");
ip.GetText = () => game.Address;
var version = item.GetWidget<LabelWidget>("VERSION");
version.GetText = () => GenerateModsLabel(game);
version.IsVisible = () => !game.CompatibleVersion();
if (!canJoin)
{
title.GetColor = () => Color.Gray;
maptitle.GetColor = () => Color.Gray;
players.GetColor = () => Color.Gray;
state.GetColor = () => Color.Gray;
ip.GetColor = () => Color.Gray;
version.GetColor = () => Color.Gray;
}
sl.AddChild(item);
}
}

View File

@@ -3,18 +3,18 @@ Container@SERVERBROWSER_PANEL:
Logic:ServerBrowserLogic
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - 500)/2
Width:740
Width:540
Height:535
Children:
Label@TITLE:
Text:Find Server
Width:740
Width:540
Y:0-25
Font:BigBold
Contrast:true
Align:Center
Background@bg:
Width:740
Width:540
Height:500
Background:panel-black
Children:
@@ -22,77 +22,61 @@ Container@SERVERBROWSER_PANEL:
Id:SERVER_LIST
X:15
Y:30
Width:710
Height:315
Width:510
Height:450
Children:
ScrollItem@SERVER_TEMPLATE:
Id:SERVER_TEMPLATE
Width:PARENT_RIGHT-27
Height:25
Height:68
X:2
Y:0
Children:
MapPreview@MAP_PREVIEW:
Id:MAP_PREVIEW
X:2
Y:2
Width:64
Height:64
Label@TITLE:
X:10
Id:TITLE
X:70
Width:200
Height:25
Font:Bold
Label@MAP:
Id:MAP
X:PARENT_RIGHT-450
Align:Center
X:70
Y:20
Width:250
Height:25
Height:25
Label@PLAYERS:
Id:PLAYERS
X:PARENT_RIGHT-200
Align:Center
X:70
Y:40
Width:50
Height:25
Label@STATE:
Id:STATE
Width:140
X:PARENT_RIGHT-150
Align:Right
Height:25
Font:Bold
Label@IP:
Id:IP
Width:140
X:PARENT_RIGHT-150
Align:Center
Y:20
Align:Right
Height:25
Label@VERSION:
Id:VERSION
Width:140
X:PARENT_RIGHT-150
Y:40
Align:Right
Height:25
Container@SERVER_LABELS:
Width:710-25
Height:25
X:15
Y:5
Children:
Label@TITLE:
Width:125
Height:25
X:0
Y:0
Text:Title
Align:Center
Font:Bold
Label@MAP:
Id:MAP
X:PARENT_RIGHT-450
Align:Center
Width:250
Height:25
Text:Map
Font:Bold
Label@PLAYERS:
Id:PLAYERS
X:PARENT_RIGHT-200
Align:Center
Width:50
Height:25
Text:Players
Font:Bold
Label@IP:
Id:IP
Width:140
X:PARENT_RIGHT-150
Align:Center
Height:25
Text:Address
Font:Bold
Label@PROGRESS_LABEL:
Id:PROGRESS_LABEL
X:22
@@ -102,95 +86,6 @@ Container@SERVERBROWSER_PANEL:
Font:Bold
Align:Center
Visible:false
Background@MAP_BG:
X:15
Y:355
Width:130
Height:130
Background:panel-gray
Children:
MapPreview@MAP_PREVIEW:
Id:MAP_PREVIEW
X:1
Y:1
Width:128
Height:128
Container@SERVER_INFO:
Id:SERVER_INFO
Width:PARENT_RIGHT
Height:PARENT_BOTTOM
Visible:false
Children:
Container@STATS_BIN:
X:150
Y:375
Width:150
Children:
Label@SERVER_IP_LABEL:
Id:SERVER_IP_LABEL
X:0
Y:0
Align:Right
Width:70
Height:20
Text:Server:
Font:Bold
Label@SERVER_IP:
Id:SERVER_IP
X:70
Y:0
Align:Left
Width:70
Height:20
Label@MAP_PLAYERS_LABEL:
Id:MAP_PLAYERS_LABEL
X:0
Y:20
Align:Right
Width:70
Height:20
Text:Players:
Font:Bold
Label@MAP_PLAYERS:
Id:MAP_PLAYERS
X:70
Y:20
Align:Left
Width:70
Height:20
Label@MAP_TITLE_LABEL:
Id:MAP_TITLE_LABEL
X:0
Y:40
Align:Right
Width:70
Height:20
Text:Map:
Font:Bold
Label@MAP_TITLE:
Id:MAP_TITLE
X:70
Y:40
Align:Left
Width:70
Height:20
Label@SERVER_MODS_LABEL:
Id:SERVER_MODS_LABEL
X:0
Y:60
Align:Right
Width:70
Height:20
Text:Mods:
Font:Bold
Label@SERVER_MODS:
Id:SERVER_MODS
X:70
Y:63
Align:Left
VAlign:Top
Width:70
Height:20
Button@BACK_BUTTON:
Id:BACK_BUTTON
Key:escape
@@ -201,7 +96,7 @@ Container@SERVERBROWSER_PANEL:
Text:Back
Button@REFRESH_BUTTON:
Id:REFRESH_BUTTON
X:450
X:250
Y:499
Width:140
Height:35
@@ -209,8 +104,8 @@ Container@SERVERBROWSER_PANEL:
Button@JOIN_BUTTON:
Id:JOIN_BUTTON
Key:return
X:600
X:400
Y:499
Width:140
Height:35
Text:Join
Text:Join

View File

@@ -3,8 +3,8 @@ Background@JOINSERVER_BG:
Logic:ServerBrowserLogic
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:700
Height:410
Width:540
Height:535
Children:
Label@JOINSERVER_LABEL_TITLE:
Id:JOINSERVER_LABEL_TITLE
@@ -19,119 +19,70 @@ Background@JOINSERVER_BG:
Id:SERVER_LIST
X:20
Y:50
Width:390
Height:300
Width:500
Height:425
Children:
ScrollItem@SERVER_TEMPLATE:
Id:SERVER_TEMPLATE
Width:PARENT_RIGHT-27
Height:25
Height:68
X:2
Y:0
Children:
MapPreview@MAP_PREVIEW:
Id:MAP_PREVIEW
X:2
Y:2
Width:64
Height:64
Label@TITLE:
X:10
Id:TITLE
X:70
Width:200
Height:25
Font:Bold
Label@MAP:
Id:MAP
X:210
Width:100
X:70
Y:20
Width:250
Height:25
Label@PLAYERS:
Id:PLAYERS
Visible:False
X:70
Y:40
Width:50
Height:25
Label@STATE:
Id:STATE
Width:140
X:PARENT_RIGHT-150
Align:Right
Height:25
Font:Bold
Label@IP:
Id:IP
Visible:False
Width:140
X:PARENT_RIGHT-150
Y:20
Align:Right
Height:25
Label@VERSION:
Id:VERSION
Width:140
X:PARENT_RIGHT-150
Y:40
Align:Right
Height:25
Label@PROGRESS_LABEL:
Id:PROGRESS_LABEL
X:150
X:(PARENT_RIGHT - WIDTH) / 2
Y:PARENT_BOTTOM / 2 - HEIGHT
Width:150
Height:30
Text:Fetching games...
Align:Center
Container@SERVER_INFO:
Id:SERVER_INFO
X:0
Y:0
Width:PARENT_RIGHT
Height:PARENT_BOTTOM
Visible:false
Children:
MapPreview@MAP_PREVIEW:
Id:MAP_PREVIEW
X:PARENT_RIGHT-241
Y:30
Width:192
Height:192
Label@SERVER_IP_LABEL:
Id:SERVER_IP_LABEL
X:PARENT_RIGHT - 200 - WIDTH
Y:230
Align:Right
Width:70
Height:20
Text:Server:
Font:Bold
Label@SERVER_IP:
Id:SERVER_IP
X:PARENT_RIGHT - 195
Y:230
Align:Left
Width:70
Height:20
Label@MAP_PLAYERS_LABEL:
Id:MAP_PLAYERS_LABEL
X:PARENT_RIGHT - 200 - WIDTH
Y:250
Align:Right
Width:70
Height:20
Text:Players:
Font:Bold
Label@MAP_PLAYERS:
Id:MAP_PLAYERS
X:PARENT_RIGHT - 195
Y:250
Align:Left
Width:70
Height:20
Label@MAP_TITLE_LABEL:
Id:MAP_TITLE_LABEL
X:PARENT_RIGHT - 200 - WIDTH
Y:270
Align:Right
Width:70
Height:20
Text:Map:
Font:Bold
Label@MAP_TITLE:
Id:MAP_TITLE
X:PARENT_RIGHT - 195
Y:270
Align:Left
Width:70
Height:20
Label@SERVER_MODS_LABEL:
Id:SERVER_MODS_LABEL
X:PARENT_RIGHT - 200 - WIDTH
Y:290
Align:Right
Width:70
Height:20
Text:Mods:
Font:Bold
Label@SERVER_MODS:
Id:SERVER_MODS
X:PARENT_RIGHT - 195
Y:293
Align:Left
VAlign:Top
Width:70
Height:20
Align:Center
Button@REFRESH_BUTTON:
Id:REFRESH_BUTTON
X:20