Persist MP game server filters.
This commit is contained in:
@@ -52,12 +52,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Download currentQuery;
|
||||
Widget serverList;
|
||||
|
||||
bool showWaiting = true;
|
||||
bool showEmpty = true;
|
||||
bool showStarted = false;
|
||||
bool showProtected = true;
|
||||
bool showIncompatible = false;
|
||||
|
||||
public string ProgressLabelText()
|
||||
{
|
||||
switch (searchStatus)
|
||||
@@ -145,40 +139,48 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
progressText.IsVisible = () => searchStatus != SearchStatus.Hidden;
|
||||
progressText.GetText = ProgressLabelText;
|
||||
|
||||
var gs = Game.Settings.Game;
|
||||
Action<MPGameFilters> toggleFilterFlag = f =>
|
||||
{
|
||||
gs.MPGameFilters ^= f;
|
||||
Game.Settings.Save();
|
||||
RefreshServerList();
|
||||
};
|
||||
|
||||
var filtersPanel = Ui.LoadWidget("MULTIPLAYER_FILTER_PANEL", null, new WidgetArgs());
|
||||
var showWaitingCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("WAITING_FOR_PLAYERS");
|
||||
if (showWaitingCheckbox != null)
|
||||
{
|
||||
showWaitingCheckbox.IsChecked = () => showWaiting;
|
||||
showWaitingCheckbox.OnClick = () => { showWaiting ^= true; RefreshServerList(); };
|
||||
showWaitingCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Waiting);
|
||||
showWaitingCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Waiting);
|
||||
}
|
||||
|
||||
var showEmptyCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("EMPTY");
|
||||
if (showEmptyCheckbox != null)
|
||||
{
|
||||
showEmptyCheckbox.IsChecked = () => showEmpty;
|
||||
showEmptyCheckbox.OnClick = () => { showEmpty ^= true; RefreshServerList(); };
|
||||
showEmptyCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Empty);
|
||||
showEmptyCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Empty);
|
||||
}
|
||||
|
||||
var showAlreadyStartedCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("ALREADY_STARTED");
|
||||
if (showAlreadyStartedCheckbox != null)
|
||||
{
|
||||
showAlreadyStartedCheckbox.IsChecked = () => showStarted;
|
||||
showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; RefreshServerList(); };
|
||||
showAlreadyStartedCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Started);
|
||||
showAlreadyStartedCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Started);
|
||||
}
|
||||
|
||||
var showProtectedCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("PASSWORD_PROTECTED");
|
||||
if (showProtectedCheckbox != null)
|
||||
{
|
||||
showProtectedCheckbox.IsChecked = () => showProtected;
|
||||
showProtectedCheckbox.OnClick = () => { showProtected ^= true; RefreshServerList(); };
|
||||
showProtectedCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Protected);
|
||||
showProtectedCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Protected);
|
||||
}
|
||||
|
||||
var showIncompatibleCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("INCOMPATIBLE_VERSION");
|
||||
if (showIncompatibleCheckbox != null)
|
||||
{
|
||||
showIncompatibleCheckbox.IsChecked = () => showIncompatible;
|
||||
showIncompatibleCheckbox.OnClick = () => { showIncompatible ^= true; RefreshServerList(); };
|
||||
showIncompatibleCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Incompatible);
|
||||
showIncompatibleCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Incompatible);
|
||||
}
|
||||
|
||||
var filtersButton = widget.GetOrNull<DropDownButtonWidget>("FILTERS_DROPDOWNBUTTON");
|
||||
@@ -541,19 +543,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
bool Filtered(GameServer game)
|
||||
{
|
||||
if (game.State == (int)ServerState.GameStarted && !showStarted)
|
||||
var filters = Game.Settings.Game.MPGameFilters;
|
||||
if (game.State == (int)ServerState.GameStarted && !filters.HasFlag(MPGameFilters.Started))
|
||||
return true;
|
||||
|
||||
if (game.State == (int)ServerState.WaitingPlayers && !showWaiting && game.Players != 0)
|
||||
if (game.State == (int)ServerState.WaitingPlayers && !filters.HasFlag(MPGameFilters.Waiting) && game.Players != 0)
|
||||
return true;
|
||||
|
||||
if (game.Players == 0 && !showEmpty)
|
||||
if (game.Players == 0 && !filters.HasFlag(MPGameFilters.Empty))
|
||||
return true;
|
||||
|
||||
if (!game.IsCompatible && !showIncompatible)
|
||||
if (!game.IsCompatible && !filters.HasFlag(MPGameFilters.Incompatible))
|
||||
return true;
|
||||
|
||||
if (game.Protected && !showProtected)
|
||||
if (game.Protected && !filters.HasFlag(MPGameFilters.Protected))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user