color code the server browser and filter protected

closes #4495
This commit is contained in:
Matthias Mailänder
2014-11-23 12:09:20 +01:00
parent 279e425431
commit a57b7800c0
3 changed files with 66 additions and 15 deletions

View File

@@ -37,6 +37,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
bool showWaiting = true; bool showWaiting = true;
bool showEmpty = true; bool showEmpty = true;
bool showStarted = true; bool showStarted = true;
bool showProtected = true;
bool showIncompatible = false; bool showIncompatible = false;
public string ProgressLabelText() public string ProgressLabelText()
@@ -100,6 +101,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; RefreshServerList(); }; 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"); var showIncompatibleCheckbox = panel.GetOrNull<CheckboxWidget>("INCOMPATIBLE_VERSION");
if (showIncompatibleCheckbox != null) if (showIncompatibleCheckbox != null)
{ {
@@ -155,6 +163,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
continue; continue;
var canJoin = game.CanJoin(); var canJoin = game.CanJoin();
var compatible = game.CompatibleVersion();
var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game, () => Join(game)); var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game, () => Join(game));
@@ -166,15 +175,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var title = item.GetOrNull<LabelWidget>("TITLE"); var title = item.GetOrNull<LabelWidget>("TITLE");
if (title != null) if (title != null)
{ {
title.GetText = () => game.Protected ? ("(Password) " + game.Name) : game.Name; title.GetText = () => game.Name;
title.GetColor = () => canJoin ? title.TextColor : Color.Gray; title.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : title.TextColor;
} }
var maptitle = item.GetOrNull<LabelWidget>("MAP"); var maptitle = item.GetOrNull<LabelWidget>("MAP");
if (title != null) if (title != null)
{ {
maptitle.GetText = () => map.Title; 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"); var players = item.GetOrNull<LabelWidget>("PLAYERS");
@@ -182,29 +191,29 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
players.GetText = () => "{0} / {1}".F(game.Players, game.MaxPlayers) players.GetText = () => "{0} / {1}".F(game.Players, game.MaxPlayers)
+ (game.Spectators > 0 ? " ({0} Spectator{1})".F(game.Spectators, game.Spectators > 1 ? "s" : "") : ""); + (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"); var state = item.GetOrNull<LabelWidget>("STATE");
if (state != null) if (state != null)
{ {
state.GetText = () => GetStateLabel(game); state.GetText = () => GetStateLabel(game);
state.GetColor = () => canJoin ? state.TextColor : Color.Gray; state.GetColor = () => GetStateColor(game, state, !compatible || !canJoin);
} }
var ip = item.GetOrNull<LabelWidget>("IP"); var ip = item.GetOrNull<LabelWidget>("IP");
if (ip != null) if (ip != null)
{ {
ip.GetText = () => game.Address; 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"); var version = item.GetOrNull<LabelWidget>("VERSION");
if (version != null) if (version != null)
{ {
version.GetText = () => GenerateModLabel(game); version.GetText = () => GenerateModLabel(game);
version.IsVisible = () => !game.CompatibleVersion(); version.IsVisible = () => !compatible;
version.GetColor = () => canJoin ? version.TextColor : Color.Gray; version.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : version.TextColor;
} }
var location = item.GetOrNull<LabelWidget>("LOCATION"); var location = item.GetOrNull<LabelWidget>("LOCATION");
@@ -212,8 +221,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
var cachedServerLocation = LobbyUtils.LookupCountry(game.Address.Split(':')[0]); var cachedServerLocation = LobbyUtils.LookupCountry(game.Address.Split(':')[0]);
location.GetText = () => cachedServerLocation; location.GetText = () => cachedServerLocation;
location.IsVisible = () => game.CompatibleVersion(); location.IsVisible = () => compatible;
location.GetColor = () => canJoin ? location.TextColor : Color.Gray; location.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : location.TextColor;
} }
if (!Filtered(game)) if (!Filtered(game))
@@ -293,8 +302,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (game == null) if (game == null)
return ""; return "";
if (game.State == (int)ServerState.WaitingPlayers)
return "Waiting for players";
if (game.State == (int)ServerState.GameStarted) if (game.State == (int)ServerState.GameStarted)
{ {
try try
@@ -307,12 +314,33 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return "In progress"; 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) if (game.State == (int)ServerState.ShuttingDown)
return "Server shutting down"; return "Server shutting down";
return "Unknown server state"; 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) public static string GenerateModLabel(GameServer s)
{ {
ModMetadata mod; ModMetadata mod;
@@ -338,6 +366,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (!game.CompatibleVersion() && !showIncompatible) if (!game.CompatibleVersion() && !showIncompatible)
return true; return true;
if (game.Protected && !showProtected)
return true;
return false; return false;
} }
} }

View File

@@ -30,6 +30,7 @@ Container@SERVERBROWSER_PANEL:
Width: 100 Width: 100
Height: 20 Height: 20
Text: Waiting Text: Waiting
TextColor: 50,205,50
Checkbox@EMPTY: Checkbox@EMPTY:
X: 180 X: 180
Y: 468 Y: 468
@@ -37,17 +38,26 @@ Container@SERVERBROWSER_PANEL:
Height: 20 Height: 20
Text: Empty Text: Empty
Checkbox@ALREADY_STARTED: Checkbox@ALREADY_STARTED:
X: 280 X: 270
Y: 468 Y: 468
Width: 100 Width: 100
Height: 20 Height: 20
Text: Started 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: Checkbox@INCOMPATIBLE_VERSION:
X: 380 X: 480
Y: 468 Y: 468
Width: 100 Width: 100
Height: 20 Height: 20
Text: Incompatible Text: Incompatible
TextColor: 190,190,190
Button@REFRESH_BUTTON: Button@REFRESH_BUTTON:
X: PARENT_RIGHT - WIDTH - 20 X: PARENT_RIGHT - WIDTH - 20
Y: 465 Y: 465

View File

@@ -26,6 +26,7 @@ Background@SERVERBROWSER_PANEL:
Width: 100 Width: 100
Height: 20 Height: 20
Text: Waiting Text: Waiting
TextColor: 50,205,50
Checkbox@EMPTY: Checkbox@EMPTY:
X: 180 X: 180
Y: 50 Y: 50
@@ -38,12 +39,21 @@ Background@SERVERBROWSER_PANEL:
Width: 100 Width: 100
Height: 20 Height: 20
Text: Started Text: Started
Checkbox@INCOMPATIBLE_VERSION: TextColor: 255,165,0
Checkbox@PASSWORD_PROTECTED:
X: 380 X: 380
Y: 50 Y: 50
Width: 100 Width: 100
Height: 20 Height: 20
Text: Protected
TextColor: 255,0,0
Checkbox@INCOMPATIBLE_VERSION:
X: 480
Y: 50
Width: 100
Height: 20
Text: Incompatible Text: Incompatible
TextColor: 190,190,190
ScrollPanel@SERVER_LIST: ScrollPanel@SERVER_LIST:
X: 20 X: 20
Y: 80 Y: 80