fixes #2799: double click on server to join

This commit is contained in:
Sascha Biedermann
2013-03-21 18:14:57 +01:00
parent 942cbb2fe2
commit 594e3c14e6
3 changed files with 35 additions and 13 deletions

View File

@@ -32,6 +32,7 @@ namespace OpenRA.Widgets
// Equivalent to OnMouseUp, but without an input arg
public Action OnClick = () => {};
public Action OnDoubleClick = () => {};
public Action<KeyInput> 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);

View File

@@ -52,5 +52,12 @@ namespace OpenRA.Widgets
w.OnClick = onClick;
return w;
}
public static ScrollItemWidget Setup(ScrollItemWidget template, Func<bool> isSelected, Action onClick, Action onDoubleClick)
{
var w = Setup(template, isSelected, onClick);
w.OnDoubleClick = onDoubleClick;
return w;
}
}
}

View File

@@ -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<ScrollPanelWidget>("SERVER_LIST");
// Menu buttons
@@ -56,17 +60,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var join = panel.Get<ButtonWidget>("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<ButtonWidget>("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<MapPreviewWidget>("MAP_PREVIEW");
preview.Map = () => GetMapPreview(game);