Skip to content

Commit

Permalink
Merge pull request OpenRA#6993 from Mailaender/server-browser-colors
Browse files Browse the repository at this point in the history
Color coded the server browser and added a filter for password protected games
  • Loading branch information
chrisforbes committed Dec 10, 2014
2 parents af0be2f + a57b780 commit d72dfe3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
55 changes: 43 additions & 12 deletions OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum SearchStatus { Fetching, Failed, NoGames, Hidden }
bool showWaiting = true;
bool showEmpty = true;
bool showStarted = true;
bool showProtected = true;
bool showIncompatible = false;

public string ProgressLabelText()
Expand Down Expand Up @@ -100,6 +101,13 @@ public ServerBrowserLogic(Widget widget, Action onStart, Action onExit)
showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; RefreshServerList(); };
}

var showProtectedCheckbox = panel.GetOrNull<CheckboxWidget>("PASSWORD_PROTECTED");
if (showProtectedCheckbox != null)
{
showProtectedCheckbox.IsChecked = () => showProtected;
showProtectedCheckbox.OnClick = () => { showProtected ^= true; RefreshServerList(); };
}

var showIncompatibleCheckbox = panel.GetOrNull<CheckboxWidget>("INCOMPATIBLE_VERSION");
if (showIncompatibleCheckbox != null)
{
Expand Down Expand Up @@ -155,6 +163,7 @@ void RefreshServerListInner(IEnumerable<GameServer> games)
continue;

var canJoin = game.CanJoin();
var compatible = game.CompatibleVersion();

var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game, () => Join(game));

Expand All @@ -166,54 +175,54 @@ void RefreshServerListInner(IEnumerable<GameServer> games)
var title = item.GetOrNull<LabelWidget>("TITLE");
if (title != null)
{
title.GetText = () => game.Protected ? ("(Password) " + game.Name) : game.Name;
title.GetColor = () => canJoin ? title.TextColor : Color.Gray;
title.GetText = () => game.Name;
title.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : title.TextColor;
}

var maptitle = item.GetOrNull<LabelWidget>("MAP");
if (title != null)
{
maptitle.GetText = () => map.Title;
maptitle.GetColor = () => canJoin ? maptitle.TextColor : Color.Gray;
maptitle.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : maptitle.TextColor;
}

var players = item.GetOrNull<LabelWidget>("PLAYERS");
if (players != null)
{
players.GetText = () => "{0} / {1}".F(game.Players, game.MaxPlayers)
+ (game.Spectators > 0 ? " ({0} Spectator{1})".F(game.Spectators, game.Spectators > 1 ? "s" : "") : "");
players.GetColor = () => canJoin ? players.TextColor : Color.Gray;
players.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : players.TextColor;
}

var state = item.GetOrNull<LabelWidget>("STATE");
if (state != null)
{
state.GetText = () => GetStateLabel(game);
state.GetColor = () => canJoin ? state.TextColor : Color.Gray;
state.GetColor = () => GetStateColor(game, state, !compatible || !canJoin);
}

var ip = item.GetOrNull<LabelWidget>("IP");
if (ip != null)
{
ip.GetText = () => game.Address;
ip.GetColor = () => canJoin ? ip.TextColor : Color.Gray;
ip.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : ip.TextColor;
}

var version = item.GetOrNull<LabelWidget>("VERSION");
if (version != null)
{
version.GetText = () => GenerateModLabel(game);
version.IsVisible = () => !game.CompatibleVersion();
version.GetColor = () => canJoin ? version.TextColor : Color.Gray;
version.IsVisible = () => !compatible;
version.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : version.TextColor;
}

var location = item.GetOrNull<LabelWidget>("LOCATION");
if (location != null)
{
var cachedServerLocation = LobbyUtils.LookupCountry(game.Address.Split(':')[0]);
location.GetText = () => cachedServerLocation;
location.IsVisible = () => game.CompatibleVersion();
location.GetColor = () => canJoin ? location.TextColor : Color.Gray;
location.IsVisible = () => compatible;
location.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : location.TextColor;
}

if (!Filtered(game))
Expand Down Expand Up @@ -293,8 +302,6 @@ static string GetStateLabel(GameServer game)
if (game == null)
return "";

if (game.State == (int)ServerState.WaitingPlayers)
return "Waiting for players";
if (game.State == (int)ServerState.GameStarted)
{
try
Expand All @@ -307,12 +314,33 @@ static string GetStateLabel(GameServer game)
return "In progress";
}
}

if (game.Protected)
return "Password protected";

if (game.State == (int)ServerState.WaitingPlayers)
return "Waiting for players";

if (game.State == (int)ServerState.ShuttingDown)
return "Server shutting down";

return "Unknown server state";
}

static Color GetStateColor(GameServer game, LabelWidget label, bool darkened)
{
if (game.Protected && game.State == (int)ServerState.WaitingPlayers)
return darkened ? Color.DarkRed : Color.Red;

if (game.State == (int)ServerState.WaitingPlayers)
return darkened ? Color.LimeGreen : Color.Lime;

if (game.State == (int)ServerState.GameStarted)
return darkened ? Color.Chocolate : Color.Orange;

return label.TextColor;
}

public static string GenerateModLabel(GameServer s)
{
ModMetadata mod;
Expand All @@ -338,6 +366,9 @@ bool Filtered(GameServer game)
if (!game.CompatibleVersion() && !showIncompatible)
return true;

if (game.Protected && !showProtected)
return true;

return false;
}
}
Expand Down
14 changes: 12 additions & 2 deletions mods/cnc/chrome/serverbrowser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,34 @@ Container@SERVERBROWSER_PANEL:
Width: 100
Height: 20
Text: Waiting
TextColor: 50,205,50
Checkbox@EMPTY:
X: 180
Y: 468
Width: 100
Height: 20
Text: Empty
Checkbox@ALREADY_STARTED:
X: 280
X: 270
Y: 468
Width: 100
Height: 20
Text: Started
TextColor: 255,165,0
Checkbox@PASSWORD_PROTECTED:
X: 370
Y: 468
Width: 100
Height: 20
Text: Protected
TextColor: 255,0,0
Checkbox@INCOMPATIBLE_VERSION:
X: 380
X: 480
Y: 468
Width: 100
Height: 20
Text: Incompatible
TextColor: 190,190,190
Button@REFRESH_BUTTON:
X: PARENT_RIGHT - WIDTH - 20
Y: 465
Expand Down
12 changes: 11 additions & 1 deletion mods/ra/chrome/serverbrowser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Background@SERVERBROWSER_PANEL:
Width: 100
Height: 20
Text: Waiting
TextColor: 50,205,50
Checkbox@EMPTY:
X: 180
Y: 50
Expand All @@ -38,12 +39,21 @@ Background@SERVERBROWSER_PANEL:
Width: 100
Height: 20
Text: Started
Checkbox@INCOMPATIBLE_VERSION:
TextColor: 255,165,0
Checkbox@PASSWORD_PROTECTED:
X: 380
Y: 50
Width: 100
Height: 20
Text: Protected
TextColor: 255,0,0
Checkbox@INCOMPATIBLE_VERSION:
X: 480
Y: 50
Width: 100
Height: 20
Text: Incompatible
TextColor: 190,190,190
ScrollPanel@SERVER_LIST:
X: 20
Y: 80
Expand Down

0 comments on commit d72dfe3

Please sign in to comment.