polish serverbrowser filters

This commit is contained in:
Matthias Mailänder
2013-04-10 10:43:30 +02:00
parent 43492b920d
commit 2cdeb112fe
2 changed files with 57 additions and 59 deletions

View File

@@ -14,6 +14,7 @@ using System.Linq;
using System.Drawing; using System.Drawing;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Network; using OpenRA.Network;
using OpenRA.Server;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic namespace OpenRA.Mods.RA.Widgets.Logic
@@ -31,8 +32,6 @@ 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 showCompatibleVersionsOnly = false;
bool showThisModOnly = false;
public string ProgressLabelText() public string ProgressLabelText()
{ {
@@ -103,20 +102,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; ServerList.Query(games => RefreshServerList(panel, games)); };
} }
var showCompatibleVersionsOnlyCheckbox = panel.GetOrNull<CheckboxWidget>("COMPATIBLE_VERSION");
if (showCompatibleVersionsOnlyCheckbox != null)
{
showCompatibleVersionsOnlyCheckbox.IsChecked = () => showCompatibleVersionsOnly;
showCompatibleVersionsOnlyCheckbox.OnClick = () => { showCompatibleVersionsOnly ^= true; ServerList.Query(games => RefreshServerList(panel, games)); };
}
var showThisModOnlyCheckbox = panel.GetOrNull<CheckboxWidget>("THIS_MOD");
if (showThisModOnlyCheckbox != null)
{
showThisModOnlyCheckbox.IsChecked = () => showThisModOnly;
showThisModOnlyCheckbox.OnClick = () => { showThisModOnly ^= true; ServerList.Query(games => RefreshServerList(panel, games)); };
}
ServerList.Query(games => RefreshServerList(panel, games)); ServerList.Query(games => RefreshServerList(panel, games));
} }
@@ -148,9 +133,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (game == null) if (game == null)
return ""; return "";
if (game.State == 1) return "Waiting for players"; if (game.State == (int)ServerState.WaitingPlayers)
if (game.State == 2) return "Playing"; return "Waiting for players";
else return "Unknown"; if (game.State == (int)ServerState.GameStarted)
return "Playing";
if (game.State == (int)ServerState.ShuttingDown)
return "Server shutting down";
return "Unknown server state";
} }
Map GetMapPreview(GameServer game) Map GetMapPreview(GameServer game)
@@ -171,7 +161,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return s.UsefulMods.Select(m => GenerateModLabel(m)).JoinWith("\n"); return s.UsefulMods.Select(m => GenerateModLabel(m)).JoinWith("\n");
} }
public static string GetPing(GameServer s) static string GetPing(GameServer s)
{ {
if (s.Latency > -1) if (s.Latency > -1)
return "Ping: {0} ms".F(s.Latency); return "Ping: {0} ms".F(s.Latency);
@@ -179,7 +169,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return "Ping: ? ms"; return "Ping: ? ms";
} }
public void PingServerList(Widget panel, IEnumerable<GameServer> games) void PingServerList(Widget panel, IEnumerable<GameServer> games)
{ {
searchStatus = SearchStatus.Pinging; searchStatus = SearchStatus.Pinging;
@@ -198,6 +188,20 @@ namespace OpenRA.Mods.RA.Widgets.Logic
RefreshServerList(panel, games); RefreshServerList(panel, games);
} }
bool Filtered(GameServer game)
{
if ((game.State == (int)ServerState.GameStarted) && !showStarted)
return true;
if ((game.State == (int)ServerState.WaitingPlayers) && !showWaiting)
return true;
if ((game.Players == 0) && !showEmpty)
return true;
return false;
}
public void RefreshServerList(Widget panel, IEnumerable<GameServer> games) public void RefreshServerList(Widget panel, IEnumerable<GameServer> games)
{ {
var sl = panel.Get<ScrollPanelWidget>("SERVER_LIST"); var sl = panel.Get<ScrollPanelWidget>("SERVER_LIST");
@@ -226,27 +230,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
var game = loop; var game = loop;
if (game == null)
continue;
if (game.State == 3) // server shutting down
continue;
if ((game.State == 2) && !showStarted)
continue;
if ((game.State == 1) && !showWaiting)
continue;
if ((game.Players == 0) && !showEmpty)
continue;
if (!game.CompatibleVersion() && showCompatibleVersionsOnly)
continue;
if (!game.UsefulMods.Any(m => Game.CurrentMods.ContainsKey(m.Key)) && showThisModOnly)
continue;
var canJoin = game.CanJoin(); var canJoin = game.CanJoin();
var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game, () => Join(game)); var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game, () => Join(game));
@@ -297,8 +280,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
state.GetColor = () => Color.Gray; state.GetColor = () => Color.Gray;
ip.GetColor = () => Color.Gray; ip.GetColor = () => Color.Gray;
version.GetColor = () => Color.Gray; version.GetColor = () => Color.Gray;
if (ping != null)
ping.GetColor = () => Color.Gray;
} }
if (!Filtered(game))
sl.AddChild(item); sl.AddChild(item);
} }
} }

View File

@@ -23,33 +23,45 @@ Background@JOINSERVER_BG:
Checkbox@WAITING_FOR_PLAYERS: Checkbox@WAITING_FOR_PLAYERS:
X:80 X:80
Y:50 Y:50
Width:300 Width:170
Height:20 Height:20
Text:waiting for players Text:Waiting For Players
Checkbox@EMPTY: Checkbox@EMPTY:
X:250 X:250
Y:50 Y:50
Width:300 Width:100
Height:20 Height:20
Text:empty Text:Empty
Checkbox@ALREADY_STARTED: Checkbox@ALREADY_STARTED:
X:350 X:350
Y:50 Y:50
Width:300 Width:100
Height:20 Height:20
Text:already started Text:Already Started
Checkbox@COMPATIBLE_VERSION: DropDownButton@VERSIONS:
X:80 X:20
Y:80 Y:80
Width:300 Width:150
Height:20 Height:25
Text:compatible versions only Font:Bold
Checkbox@THIS_MOD: Text:All Versions
X:300 Disabled: yes
DropDownButton@MODS:
X:190
Y:80 Y:80
Width:300 Width:150
Height:20 Height:25
Text:this mod only Font:Bold
Text:All Mods
Disabled: yes
DropDownButton@MAPS:
X:360
Y:80
Width:150
Height:25
Font:Bold
Text:All Maps
Disabled: yes
ScrollPanel@SERVER_LIST: ScrollPanel@SERVER_LIST:
X:20 X:20
Y:110 Y:110