From 5eff33cc6567082b6b4e2c94d00f0f9d8311fab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 7 Apr 2013 13:51:40 +0200 Subject: [PATCH 1/6] added serverbrowser filters --- .../Widgets/Logic/ServerBrowserLogic.cs | 57 ++++++++++++++++--- mods/ra/chrome/serverbrowser.yaml | 43 +++++++++++++- 2 files changed, 90 insertions(+), 10 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs index 8b738d2283..10cc1e79bc 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs @@ -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("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("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("WAITING_FOR_PLAYERS"); + showWaitingCheckbox.IsChecked = () => showWaiting; + showWaitingCheckbox.OnClick = () => { showWaiting ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + + var showEmptyCheckbox = panel.Get("EMPTY"); + showEmptyCheckbox.IsChecked = () => showEmpty; + showEmptyCheckbox.OnClick = () => { showEmpty ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + + var showAlreadyStartedCheckbox = panel.Get("ALREADY_STARTED"); + showAlreadyStartedCheckbox.IsChecked = () => showStarted; + showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + + var showCompatibleVersionsOnlyCheckbox = panel.Get("COMPATIBLE_VERSION"); + showCompatibleVersionsOnlyCheckbox.IsChecked = () => showCompatibleVersionsOnly; + showCompatibleVersionsOnlyCheckbox.OnClick = () => { showCompatibleVersionsOnly ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + + var showThisModOnlyCheckbox = panel.Get("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("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)); diff --git a/mods/ra/chrome/serverbrowser.yaml b/mods/ra/chrome/serverbrowser.yaml index 8e96dc2d90..2c5efdc514 100644 --- a/mods/ra/chrome/serverbrowser.yaml +++ b/mods/ra/chrome/serverbrowser.yaml @@ -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 From 2a9cfc620375a52332063325e4f52757f448513e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 7 Apr 2013 15:06:14 +0200 Subject: [PATCH 2/6] added game server pinging --- OpenRA.Game/Network/GameServer.cs | 17 ++++++++ .../Widgets/Logic/ServerBrowserLogic.cs | 41 ++++++++++++++++++- mods/ra/chrome/serverbrowser.yaml | 22 +++++++--- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Network/GameServer.cs b/OpenRA.Game/Network/GameServer.cs index fed810d5fb..c31e2a01cd 100644 --- a/OpenRA.Game/Network/GameServer.cs +++ b/OpenRA.Game/Network/GameServer.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.NetworkInformation; namespace OpenRA.Network { @@ -65,5 +66,21 @@ namespace OpenRA.Network return UsefulMods.All(m => Game.CurrentMods.ContainsKey(m.Key) && AreVersionsCompatible(m.Value, Game.CurrentMods[m.Key].Version)); } + + public int Latency = -1; + bool hasBeenPinged; + public void Ping() + { + if (!hasBeenPinged) + { + hasBeenPinged = true; + var pingSender = new Ping(); + PingReply reply = pingSender.Send(Address.Split(':')[0]); + if (reply != null && reply.Status == IPStatus.Success) + Latency = (int)reply.RoundtripTime; + else + Latency = -1; + } + } } } diff --git a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs index 10cc1e79bc..5301818b52 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic Action OpenLobby; Action OnExit; - enum SearchStatus { Fetching, Failed, NoGames, Hidden } + enum SearchStatus { Fetching, Failed, NoGames, Hidden, Pinging } SearchStatus searchStatus = SearchStatus.Fetching; bool showWaiting = true; @@ -41,6 +41,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic case SearchStatus.Fetching: return "Fetching game list..."; case SearchStatus.Failed: return "Failed to contact master server."; case SearchStatus.NoGames: return "No games found."; + case SearchStatus.Pinging: return "Pinging compatible servers."; default: return ""; } } @@ -58,6 +59,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching; refreshButton.OnClick = () => ServerList.Query(games => RefreshServerList(panel, games)); + var pingButton = panel.Get("PING_BUTTON"); + pingButton.IsDisabled = () => searchStatus == SearchStatus.Pinging || + searchStatus == SearchStatus.Fetching || searchStatus == SearchStatus.Failed; + pingButton.OnClick = () => ServerList.Query(games => PingServerList(panel, games)); + var join = panel.Get("JOIN_BUTTON"); join.IsDisabled = () => currentServer == null || !currentServer.CanJoin(); join.OnClick = () => Join(currentServer); @@ -147,6 +153,33 @@ namespace OpenRA.Mods.RA.Widgets.Logic return s.UsefulMods.Select(m => GenerateModLabel(m)).JoinWith("\n"); } + public static string GetPing(GameServer s) + { + if (s.Latency > -1) + return "Ping: {0} ms".F(s.Latency); + else + return "Ping: ? ms"; + } + + public void PingServerList(Widget panel, IEnumerable games) + { + searchStatus = SearchStatus.Pinging; + + foreach (var loop in games.Where(g => g.CanJoin())) + { + var game = loop; + + if (game == null) + continue; + + game.Ping(); + } + + searchStatus = SearchStatus.Hidden; + + RefreshServerList(panel, games); + } + public void RefreshServerList(Widget panel, IEnumerable games) { var sl = panel.Get("SERVER_LIST"); @@ -229,6 +262,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic version.GetText = () => GenerateModsLabel(game); version.IsVisible = () => !game.CompatibleVersion(); + var ping = item.Get("PING"); + ping.GetText = () => GetPing(game); + ping.IsVisible = () => game.CompatibleVersion(); + + // TODO: Display game.Location once https://github.com/OpenRA/OpenRAMasterServer/pull/12 is merged + if (!canJoin) { title.GetColor = () => Color.Gray; diff --git a/mods/ra/chrome/serverbrowser.yaml b/mods/ra/chrome/serverbrowser.yaml index 2c5efdc514..0271d38dbe 100644 --- a/mods/ra/chrome/serverbrowser.yaml +++ b/mods/ra/chrome/serverbrowser.yaml @@ -101,25 +101,37 @@ Background@JOINSERVER_BG: Y:40 Align:Right Height:25 - + Label@PING: + Width:140 + X:PARENT_RIGHT-150 + Y:40 + Align:Right + Height:25 Label@PROGRESS_LABEL: X:(PARENT_RIGHT - WIDTH) / 2 Y:PARENT_BOTTOM / 2 - HEIGHT Width:150 Height:30 Text:Fetching games... - Align:Center + Align:Center Button@REFRESH_BUTTON: X:20 Y:PARENT_BOTTOM - 45 - Width:120 + Width:100 Height:25 Text:Refresh Font:Bold + Button@PING_BUTTON: + X:140 + Y:PARENT_BOTTOM - 45 + Width:100 + Height:25 + Text:Ping + Font:Bold Button@JOIN_BUTTON: X:PARENT_RIGHT - 140 - 130 Y:PARENT_BOTTOM - 45 - Width:120 + Width:100 Height:25 Text:Join Font:Bold @@ -127,7 +139,7 @@ Background@JOINSERVER_BG: Button@BACK_BUTTON: X:PARENT_RIGHT - 140 Y:PARENT_BOTTOM - 45 - Width:120 + Width:100 Height:25 Text:Cancel Font:Bold From 1069a89332685eae2c48d330e2088bc81d087ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 7 Apr 2013 19:08:41 +0200 Subject: [PATCH 3/6] made filters and ping button optional --- .../Widgets/Logic/ServerBrowserLogic.cs | 67 ++++++++++++------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs index 5301818b52..8385afe51b 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic bool showWaiting = true; bool showEmpty = true; - bool showStarted = false; + bool showStarted = true; bool showCompatibleVersionsOnly = false; bool showThisModOnly = false; @@ -59,10 +59,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching; refreshButton.OnClick = () => ServerList.Query(games => RefreshServerList(panel, games)); - var pingButton = panel.Get("PING_BUTTON"); - pingButton.IsDisabled = () => searchStatus == SearchStatus.Pinging || - searchStatus == SearchStatus.Fetching || searchStatus == SearchStatus.Failed; - pingButton.OnClick = () => ServerList.Query(games => PingServerList(panel, games)); + var pingButton = panel.GetOrNull("PING_BUTTON"); + if (pingButton != null) + { + pingButton.IsDisabled = () => searchStatus == SearchStatus.Pinging || + searchStatus == SearchStatus.Fetching || searchStatus == SearchStatus.Failed; + pingButton.OnClick = () => ServerList.Query(games => PingServerList(panel, games)); + } var join = panel.Get("JOIN_BUTTON"); join.IsDisabled = () => currentServer == null || !currentServer.CanJoin(); @@ -79,25 +82,40 @@ namespace OpenRA.Mods.RA.Widgets.Logic progressText.IsVisible = () => searchStatus != SearchStatus.Hidden; progressText.GetText = ProgressLabelText; - var showWaitingCheckbox = panel.Get("WAITING_FOR_PLAYERS"); - showWaitingCheckbox.IsChecked = () => showWaiting; - showWaitingCheckbox.OnClick = () => { showWaiting ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + var showWaitingCheckbox = panel.GetOrNull("WAITING_FOR_PLAYERS"); + if (showWaitingCheckbox != null) + { + showWaitingCheckbox.IsChecked = () => showWaiting; + showWaitingCheckbox.OnClick = () => { showWaiting ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + } - var showEmptyCheckbox = panel.Get("EMPTY"); - showEmptyCheckbox.IsChecked = () => showEmpty; - showEmptyCheckbox.OnClick = () => { showEmpty ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + var showEmptyCheckbox = panel.GetOrNull("EMPTY"); + if (showEmptyCheckbox != null) + { + showEmptyCheckbox.IsChecked = () => showEmpty; + showEmptyCheckbox.OnClick = () => { showEmpty ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + } - var showAlreadyStartedCheckbox = panel.Get("ALREADY_STARTED"); - showAlreadyStartedCheckbox.IsChecked = () => showStarted; - showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + var showAlreadyStartedCheckbox = panel.GetOrNull("ALREADY_STARTED"); + if (showAlreadyStartedCheckbox != null) + { + showAlreadyStartedCheckbox.IsChecked = () => showStarted; + showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + } - var showCompatibleVersionsOnlyCheckbox = panel.Get("COMPATIBLE_VERSION"); - showCompatibleVersionsOnlyCheckbox.IsChecked = () => showCompatibleVersionsOnly; - showCompatibleVersionsOnlyCheckbox.OnClick = () => { showCompatibleVersionsOnly ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + var showCompatibleVersionsOnlyCheckbox = panel.GetOrNull("COMPATIBLE_VERSION"); + if (showCompatibleVersionsOnlyCheckbox != null) + { + showCompatibleVersionsOnlyCheckbox.IsChecked = () => showCompatibleVersionsOnly; + showCompatibleVersionsOnlyCheckbox.OnClick = () => { showCompatibleVersionsOnly ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + } - var showThisModOnlyCheckbox = panel.Get("THIS_MOD"); - showThisModOnlyCheckbox.IsChecked = () => showThisModOnly; - showThisModOnlyCheckbox.OnClick = () => { showThisModOnly ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + var showThisModOnlyCheckbox = panel.GetOrNull("THIS_MOD"); + if (showThisModOnlyCheckbox != null) + { + showThisModOnlyCheckbox.IsChecked = () => showThisModOnly; + showThisModOnlyCheckbox.OnClick = () => { showThisModOnly ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + } ServerList.Query(games => RefreshServerList(panel, games)); } @@ -262,9 +280,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic version.GetText = () => GenerateModsLabel(game); version.IsVisible = () => !game.CompatibleVersion(); - var ping = item.Get("PING"); - ping.GetText = () => GetPing(game); - ping.IsVisible = () => game.CompatibleVersion(); + var ping = item.GetOrNull("PING"); + if (ping != null) + { + ping.GetText = () => GetPing(game); + ping.IsVisible = () => game.CompatibleVersion(); + } // TODO: Display game.Location once https://github.com/OpenRA/OpenRAMasterServer/pull/12 is merged From 43492b920dae1a6f9ece53009fa511e7a312b002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 7 Apr 2013 19:31:08 +0200 Subject: [PATCH 4/6] Ping.SendAsync to reduce UI freezing --- OpenRA.Game/Network/GameServer.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/OpenRA.Game/Network/GameServer.cs b/OpenRA.Game/Network/GameServer.cs index c31e2a01cd..d2cf4c918a 100644 --- a/OpenRA.Game/Network/GameServer.cs +++ b/OpenRA.Game/Network/GameServer.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.NetworkInformation; +using System.Threading; namespace OpenRA.Network { @@ -75,9 +76,21 @@ namespace OpenRA.Network { hasBeenPinged = true; var pingSender = new Ping(); - PingReply reply = pingSender.Send(Address.Split(':')[0]); - if (reply != null && reply.Status == IPStatus.Success) - Latency = (int)reply.RoundtripTime; + pingSender.PingCompleted += new PingCompletedEventHandler(pongRecieved); + AutoResetEvent waiter = new AutoResetEvent(false); + pingSender.SendAsync(Address.Split(':')[0], waiter); + } + } + + void pongRecieved(object sender, PingCompletedEventArgs e) + { + if (e.Cancelled || e.Error != null) + Latency = -1; + else + { + PingReply pong = e.Reply; + if (pong != null && pong.Status == IPStatus.Success) + Latency = (int)pong.RoundtripTime; else Latency = -1; } From 2cdeb112fe5ca9026c7e64ee1e9ac52f6e41f88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Wed, 10 Apr 2013 10:43:30 +0200 Subject: [PATCH 5/6] polish serverbrowser filters --- .../Widgets/Logic/ServerBrowserLogic.cs | 72 ++++++++----------- mods/ra/chrome/serverbrowser.yaml | 44 +++++++----- 2 files changed, 57 insertions(+), 59 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs index 8385afe51b..49d262f242 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs @@ -14,6 +14,7 @@ using System.Linq; using System.Drawing; using OpenRA.FileFormats; using OpenRA.Network; +using OpenRA.Server; using OpenRA.Widgets; namespace OpenRA.Mods.RA.Widgets.Logic @@ -31,8 +32,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic bool showWaiting = true; bool showEmpty = true; bool showStarted = true; - bool showCompatibleVersionsOnly = false; - bool showThisModOnly = false; public string ProgressLabelText() { @@ -103,20 +102,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; } - var showCompatibleVersionsOnlyCheckbox = panel.GetOrNull("COMPATIBLE_VERSION"); - if (showCompatibleVersionsOnlyCheckbox != null) - { - showCompatibleVersionsOnlyCheckbox.IsChecked = () => showCompatibleVersionsOnly; - showCompatibleVersionsOnlyCheckbox.OnClick = () => { showCompatibleVersionsOnly ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; - } - - var showThisModOnlyCheckbox = panel.GetOrNull("THIS_MOD"); - if (showThisModOnlyCheckbox != null) - { - showThisModOnlyCheckbox.IsChecked = () => showThisModOnly; - showThisModOnlyCheckbox.OnClick = () => { showThisModOnly ^= true; 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) return ""; - if (game.State == 1) return "Waiting for players"; - if (game.State == 2) return "Playing"; - else return "Unknown"; + if (game.State == (int)ServerState.WaitingPlayers) + return "Waiting for players"; + 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) @@ -171,7 +161,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic return s.UsefulMods.Select(m => GenerateModLabel(m)).JoinWith("\n"); } - public static string GetPing(GameServer s) + static string GetPing(GameServer s) { if (s.Latency > -1) return "Ping: {0} ms".F(s.Latency); @@ -179,7 +169,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic return "Ping: ? ms"; } - public void PingServerList(Widget panel, IEnumerable games) + void PingServerList(Widget panel, IEnumerable games) { searchStatus = SearchStatus.Pinging; @@ -198,6 +188,20 @@ namespace OpenRA.Mods.RA.Widgets.Logic 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 games) { var sl = panel.Get("SERVER_LIST"); @@ -226,27 +230,6 @@ 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)); @@ -297,9 +280,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic state.GetColor = () => Color.Gray; ip.GetColor = () => Color.Gray; version.GetColor = () => Color.Gray; + if (ping != null) + ping.GetColor = () => Color.Gray; } - sl.AddChild(item); + if (!Filtered(game)) + sl.AddChild(item); } } } diff --git a/mods/ra/chrome/serverbrowser.yaml b/mods/ra/chrome/serverbrowser.yaml index 0271d38dbe..4e4c4b5669 100644 --- a/mods/ra/chrome/serverbrowser.yaml +++ b/mods/ra/chrome/serverbrowser.yaml @@ -23,33 +23,45 @@ Background@JOINSERVER_BG: Checkbox@WAITING_FOR_PLAYERS: X:80 Y:50 - Width:300 + Width:170 Height:20 - Text:waiting for players + Text:Waiting For Players Checkbox@EMPTY: X:250 Y:50 - Width:300 + Width:100 Height:20 - Text:empty + Text:Empty Checkbox@ALREADY_STARTED: X:350 Y:50 - Width:300 + Width:100 Height:20 - Text:already started - Checkbox@COMPATIBLE_VERSION: - X:80 + Text:Already Started + DropDownButton@VERSIONS: + X:20 Y:80 - Width:300 - Height:20 - Text:compatible versions only - Checkbox@THIS_MOD: - X:300 + Width:150 + Height:25 + Font:Bold + Text:All Versions + Disabled: yes + DropDownButton@MODS: + X:190 Y:80 - Width:300 - Height:20 - Text:this mod only + Width:150 + Height:25 + 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: X:20 Y:110 From c9180aaf8605bac1a9d111fe5dd99a8f67a70257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 12 Apr 2013 12:13:42 +0200 Subject: [PATCH 6/6] simplify the selection boxes and use existing checks --- .../Widgets/Logic/ServerBrowserLogic.cs | 13 +++++- mods/ra/chrome/serverbrowser.yaml | 44 ++++++------------- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs index 49d262f242..124375c205 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs @@ -32,6 +32,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic bool showWaiting = true; bool showEmpty = true; bool showStarted = true; + bool showIncompatible = false; public string ProgressLabelText() { @@ -102,6 +103,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; } + var showIncompatibleCheckbox = panel.GetOrNull("INCOMPATIBLE_VERSION"); + if (showIncompatibleCheckbox != null) + { + showIncompatibleCheckbox.IsChecked = () => showIncompatible; + showIncompatibleCheckbox.OnClick = () => { showIncompatible ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; + } + ServerList.Query(games => RefreshServerList(panel, games)); } @@ -199,6 +207,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic if ((game.Players == 0) && !showEmpty) return true; + if (!game.CompatibleVersion() && !showIncompatible) + return true; + return false; } @@ -270,8 +281,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic ping.IsVisible = () => game.CompatibleVersion(); } - // TODO: Display game.Location once https://github.com/OpenRA/OpenRAMasterServer/pull/12 is merged - if (!canJoin) { title.GetColor = () => Color.Gray; diff --git a/mods/ra/chrome/serverbrowser.yaml b/mods/ra/chrome/serverbrowser.yaml index 4e4c4b5669..18ce40484d 100644 --- a/mods/ra/chrome/serverbrowser.yaml +++ b/mods/ra/chrome/serverbrowser.yaml @@ -3,7 +3,7 @@ Background@JOINSERVER_BG: X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2 Width:540 - Height:535 + Height:505 Children: Label@JOINSERVER_LABEL_TITLE: X:0 @@ -23,48 +23,30 @@ Background@JOINSERVER_BG: Checkbox@WAITING_FOR_PLAYERS: X:80 Y:50 - Width:170 + Width:100 Height:20 - Text:Waiting For Players + Text:Waiting Checkbox@EMPTY: - X:250 + X:180 Y:50 Width:100 Height:20 Text:Empty Checkbox@ALREADY_STARTED: - X:350 + X:280 Y:50 Width:100 Height:20 - Text:Already Started - DropDownButton@VERSIONS: - X:20 - Y:80 - Width:150 - Height:25 - Font:Bold - Text:All Versions - Disabled: yes - DropDownButton@MODS: - X:190 - Y:80 - Width:150 - Height:25 - Font:Bold - Text:All Mods - Disabled: yes - DropDownButton@MAPS: - X:360 - Y:80 - Width:150 - Height:25 - Font:Bold - Text:All Maps - Disabled: yes + Text:Started + Checkbox@INCOMPATIBLE_VERSION: + X:380 + Y:50 + Width:100 + Height:20 + Text:Incompatible ScrollPanel@SERVER_LIST: X:20 - Y:110 + Y:80 Width:500 Height:355 Children: