added serverbrowser filters

This commit is contained in:
Matthias Mailänder
2013-04-07 13:51:40 +02:00
parent b649b4b7bb
commit 5eff33cc65
2 changed files with 90 additions and 10 deletions

View File

@@ -28,6 +28,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
enum SearchStatus { Fetching, Failed, NoGames, Hidden }
SearchStatus searchStatus = SearchStatus.Fetching;
bool showWaiting = true;
bool showEmpty = true;
bool showStarted = false;
bool showCompatibleVersionsOnly = false;
bool showThisModOnly = false;
public string ProgressLabelText()
{
switch (searchStatus)
@@ -50,13 +56,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
// Menu buttons
var refreshButton = panel.Get<ButtonWidget>("REFRESH_BUTTON");
refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching;
refreshButton.OnClick = () =>
{
searchStatus = SearchStatus.Fetching;
sl.RemoveChildren();
currentServer = null;
ServerList.Query(games => RefreshServerList(panel, games));
};
refreshButton.OnClick = () => ServerList.Query(games => RefreshServerList(panel, games));
var join = panel.Get<ButtonWidget>("JOIN_BUTTON");
join.IsDisabled = () => currentServer == null || !currentServer.CanJoin();
@@ -73,6 +73,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic
progressText.IsVisible = () => searchStatus != SearchStatus.Hidden;
progressText.GetText = ProgressLabelText;
var showWaitingCheckbox = panel.Get<CheckboxWidget>("WAITING_FOR_PLAYERS");
showWaitingCheckbox.IsChecked = () => showWaiting;
showWaitingCheckbox.OnClick = () => { showWaiting ^= true; ServerList.Query(games => RefreshServerList(panel, games)); };
var showEmptyCheckbox = panel.Get<CheckboxWidget>("EMPTY");
showEmptyCheckbox.IsChecked = () => showEmpty;
showEmptyCheckbox.OnClick = () => { showEmpty ^= true; ServerList.Query(games => RefreshServerList(panel, games)); };
var showAlreadyStartedCheckbox = panel.Get<CheckboxWidget>("ALREADY_STARTED");
showAlreadyStartedCheckbox.IsChecked = () => showStarted;
showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; ServerList.Query(games => RefreshServerList(panel, games)); };
var showCompatibleVersionsOnlyCheckbox = panel.Get<CheckboxWidget>("COMPATIBLE_VERSION");
showCompatibleVersionsOnlyCheckbox.IsChecked = () => showCompatibleVersionsOnly;
showCompatibleVersionsOnlyCheckbox.OnClick = () => { showCompatibleVersionsOnly ^= true; ServerList.Query(games => RefreshServerList(panel, games)); };
var showThisModOnlyCheckbox = panel.Get<CheckboxWidget>("THIS_MOD");
showThisModOnlyCheckbox.IsChecked = () => showThisModOnly;
showThisModOnlyCheckbox.OnClick = () => { showThisModOnly ^= true; ServerList.Query(games => RefreshServerList(panel, games)); };
ServerList.Query(games => RefreshServerList(panel, games));
}
@@ -131,6 +151,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
var sl = panel.Get<ScrollPanelWidget>("SERVER_LIST");
searchStatus = SearchStatus.Fetching;
sl.RemoveChildren();
currentServer = null;
@@ -153,6 +175,27 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
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 item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game, () => Join(game));

View File

@@ -7,17 +7,54 @@ Background@JOINSERVER_BG:
Children:
Label@JOINSERVER_LABEL_TITLE:
X:0
Y:20
Y:15
Width:PARENT_RIGHT
Height:25
Text:Join Server
Align:Center
Font:Bold
Label@SHOW_LABEL_TITLE:
X:20
Y:45
Width:20
Height:25
Text:Show:
Font:Bold
Checkbox@WAITING_FOR_PLAYERS:
X:80
Y:50
Width:300
Height:20
Text:waiting for players
Checkbox@EMPTY:
X:250
Y:50
Width:300
Height:20
Text:empty
Checkbox@ALREADY_STARTED:
X:350
Y:50
Width:300
Height:20
Text:already started
Checkbox@COMPATIBLE_VERSION:
X:80
Y:80
Width:300
Height:20
Text:compatible versions only
Checkbox@THIS_MOD:
X:300
Y:80
Width:300
Height:20
Text:this mod only
ScrollPanel@SERVER_LIST:
X:20
Y:50
Y:110
Width:500
Height:425
Height:355
Children:
ScrollItem@SERVER_TEMPLATE:
Width:PARENT_RIGHT-27