diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index 4bc60a33b3..cd7facaa73 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -32,6 +32,7 @@ namespace OpenRA.Widgets // Equivalent to OnMouseUp, but without an input arg public Action OnClick = () => {}; + public Action OnDoubleClick = () => {}; public Action OnKeyPress = _ => {}; public ButtonWidget() @@ -93,8 +94,16 @@ namespace OpenRA.Widgets return false; var disabled = IsDisabled(); + if (Focused && mi.Event == MouseInputEvent.Up && mi.MultiTapCount == 2) + { + if (!disabled) + { + OnDoubleClick(); + return LoseFocus(mi); + } + } // Only fire the onMouseUp event if we successfully lost focus, and were pressed - if (Focused && mi.Event == MouseInputEvent.Up) + else if (Focused && mi.Event == MouseInputEvent.Up) { if (Depressed && !disabled) OnMouseUp(mi); diff --git a/OpenRA.Game/Widgets/ScrollItemWidget.cs b/OpenRA.Game/Widgets/ScrollItemWidget.cs index 17bcb77d0a..d5deb1ef09 100644 --- a/OpenRA.Game/Widgets/ScrollItemWidget.cs +++ b/OpenRA.Game/Widgets/ScrollItemWidget.cs @@ -52,5 +52,12 @@ namespace OpenRA.Widgets w.OnClick = onClick; return w; } + + public static ScrollItemWidget Setup(ScrollItemWidget template, Func isSelected, Action onClick, Action onDoubleClick) + { + var w = Setup(template, isSelected, onClick); + w.OnDoubleClick = onDoubleClick; + return w; + } } } \ No newline at end of file diff --git a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs index d2cd7fea0f..3ef283e959 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs @@ -22,6 +22,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic { GameServer currentServer; ScrollItemWidget serverTemplate; + Action OpenLobby; + Action OnExit; enum SearchStatus { Fetching, Failed, NoGames, Hidden } SearchStatus searchStatus = SearchStatus.Fetching; @@ -41,6 +43,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic public ServerBrowserLogic(Widget widget, Action openLobby, Action onExit) { var panel = widget; + OpenLobby = openLobby; + OnExit = onExit; var sl = panel.Get("SERVER_LIST"); // Menu buttons @@ -56,17 +60,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var join = panel.Get("JOIN_BUTTON"); join.IsDisabled = () => currentServer == null || !currentServer.CanJoin(); - join.OnClick = () => - { - if (currentServer == null) - return; - - var host = currentServer.Address.Split(':')[0]; - var port = int.Parse(currentServer.Address.Split(':')[1]); - - Ui.CloseWindow(); - ConnectionLogic.Connect(host, port, openLobby, onExit); - }; + join.OnClick = () => Join(currentServer); panel.Get("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; @@ -82,6 +76,18 @@ namespace OpenRA.Mods.RA.Widgets.Logic ServerList.Query(games => RefreshServerList(panel, games)); } + void Join(GameServer server) + { + if (server == null || !server.CanJoin()) + return; + + var host = server.Address.Split(':')[0]; + var port = int.Parse(server.Address.Split(':')[1]); + + Ui.CloseWindow(); + ConnectionLogic.Connect(host, port, OpenLobby, OnExit); + } + string GetPlayersLabel(GameServer game) { if (game == null || game.Players == 0) @@ -149,7 +155,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var canJoin = game.CanJoin(); - var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game); + var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game, () => Join(game)); var preview = item.Get("MAP_PREVIEW"); preview.Map = () => GetMapPreview(game);