Persist MP game server filters.
This commit is contained in:
@@ -23,6 +23,17 @@ namespace OpenRA
|
|||||||
public enum MouseScrollType { Disabled, Standard, Inverted, Joystick }
|
public enum MouseScrollType { Disabled, Standard, Inverted, Joystick }
|
||||||
public enum StatusBarsType { Standard, DamageShow, AlwaysShow }
|
public enum StatusBarsType { Standard, DamageShow, AlwaysShow }
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
public enum MPGameFilters
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Waiting = 1,
|
||||||
|
Empty = 2,
|
||||||
|
Protected = 4,
|
||||||
|
Started = 8,
|
||||||
|
Incompatible = 16
|
||||||
|
}
|
||||||
|
|
||||||
public class ServerSettings
|
public class ServerSettings
|
||||||
{
|
{
|
||||||
[Desc("Sets the server name.")]
|
[Desc("Sets the server name.")]
|
||||||
@@ -182,6 +193,8 @@ namespace OpenRA
|
|||||||
|
|
||||||
public bool FetchNews = true;
|
public bool FetchNews = true;
|
||||||
public string NewsUrl = "http://master.openra.net/gamenews";
|
public string NewsUrl = "http://master.openra.net/gamenews";
|
||||||
|
|
||||||
|
public MPGameFilters MPGameFilters = MPGameFilters.Waiting | MPGameFilters.Empty | MPGameFilters.Protected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class KeySettings
|
public class KeySettings
|
||||||
|
|||||||
@@ -52,12 +52,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Download currentQuery;
|
Download currentQuery;
|
||||||
Widget serverList;
|
Widget serverList;
|
||||||
|
|
||||||
bool showWaiting = true;
|
|
||||||
bool showEmpty = true;
|
|
||||||
bool showStarted = false;
|
|
||||||
bool showProtected = true;
|
|
||||||
bool showIncompatible = false;
|
|
||||||
|
|
||||||
public string ProgressLabelText()
|
public string ProgressLabelText()
|
||||||
{
|
{
|
||||||
switch (searchStatus)
|
switch (searchStatus)
|
||||||
@@ -145,40 +139,48 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
progressText.IsVisible = () => searchStatus != SearchStatus.Hidden;
|
progressText.IsVisible = () => searchStatus != SearchStatus.Hidden;
|
||||||
progressText.GetText = ProgressLabelText;
|
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 filtersPanel = Ui.LoadWidget("MULTIPLAYER_FILTER_PANEL", null, new WidgetArgs());
|
||||||
var showWaitingCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("WAITING_FOR_PLAYERS");
|
var showWaitingCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("WAITING_FOR_PLAYERS");
|
||||||
if (showWaitingCheckbox != null)
|
if (showWaitingCheckbox != null)
|
||||||
{
|
{
|
||||||
showWaitingCheckbox.IsChecked = () => showWaiting;
|
showWaitingCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Waiting);
|
||||||
showWaitingCheckbox.OnClick = () => { showWaiting ^= true; RefreshServerList(); };
|
showWaitingCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Waiting);
|
||||||
}
|
}
|
||||||
|
|
||||||
var showEmptyCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("EMPTY");
|
var showEmptyCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("EMPTY");
|
||||||
if (showEmptyCheckbox != null)
|
if (showEmptyCheckbox != null)
|
||||||
{
|
{
|
||||||
showEmptyCheckbox.IsChecked = () => showEmpty;
|
showEmptyCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Empty);
|
||||||
showEmptyCheckbox.OnClick = () => { showEmpty ^= true; RefreshServerList(); };
|
showEmptyCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
var showAlreadyStartedCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("ALREADY_STARTED");
|
var showAlreadyStartedCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("ALREADY_STARTED");
|
||||||
if (showAlreadyStartedCheckbox != null)
|
if (showAlreadyStartedCheckbox != null)
|
||||||
{
|
{
|
||||||
showAlreadyStartedCheckbox.IsChecked = () => showStarted;
|
showAlreadyStartedCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Started);
|
||||||
showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; RefreshServerList(); };
|
showAlreadyStartedCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Started);
|
||||||
}
|
}
|
||||||
|
|
||||||
var showProtectedCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("PASSWORD_PROTECTED");
|
var showProtectedCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("PASSWORD_PROTECTED");
|
||||||
if (showProtectedCheckbox != null)
|
if (showProtectedCheckbox != null)
|
||||||
{
|
{
|
||||||
showProtectedCheckbox.IsChecked = () => showProtected;
|
showProtectedCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Protected);
|
||||||
showProtectedCheckbox.OnClick = () => { showProtected ^= true; RefreshServerList(); };
|
showProtectedCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Protected);
|
||||||
}
|
}
|
||||||
|
|
||||||
var showIncompatibleCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("INCOMPATIBLE_VERSION");
|
var showIncompatibleCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("INCOMPATIBLE_VERSION");
|
||||||
if (showIncompatibleCheckbox != null)
|
if (showIncompatibleCheckbox != null)
|
||||||
{
|
{
|
||||||
showIncompatibleCheckbox.IsChecked = () => showIncompatible;
|
showIncompatibleCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Incompatible);
|
||||||
showIncompatibleCheckbox.OnClick = () => { showIncompatible ^= true; RefreshServerList(); };
|
showIncompatibleCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Incompatible);
|
||||||
}
|
}
|
||||||
|
|
||||||
var filtersButton = widget.GetOrNull<DropDownButtonWidget>("FILTERS_DROPDOWNBUTTON");
|
var filtersButton = widget.GetOrNull<DropDownButtonWidget>("FILTERS_DROPDOWNBUTTON");
|
||||||
@@ -541,19 +543,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
bool Filtered(GameServer game)
|
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;
|
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;
|
return true;
|
||||||
|
|
||||||
if (game.Players == 0 && !showEmpty)
|
if (game.Players == 0 && !filters.HasFlag(MPGameFilters.Empty))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!game.IsCompatible && !showIncompatible)
|
if (!game.IsCompatible && !filters.HasFlag(MPGameFilters.Incompatible))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (game.Protected && !showProtected)
|
if (game.Protected && !filters.HasFlag(MPGameFilters.Protected))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user