Skip to content

Commit

Permalink
Improves Esc key behavior in lobby and asset browser.
Browse files Browse the repository at this point in the history
Pressing Esc will now close window if text field is empty.
  • Loading branch information
deniz1a committed Jun 8, 2015
1 parent b5262dc commit ca5ebb5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
30 changes: 18 additions & 12 deletions OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs
Expand Up @@ -52,6 +52,16 @@ public AssetBrowserLogic(Widget widget, Action onExit, World world)
panel = widget;
assetSource = GlobalFileSystem.MountedFolders.First();

var closeButton = panel.GetOrNull<ButtonWidget>("CLOSE_BUTTON");
if (closeButton != null)
closeButton.OnClick = () =>
{
if (isVideoLoaded)
player.Stop();
Ui.CloseWindow();
onExit();
};

var ticker = panel.GetOrNull<LogicTickerWidget>("ANIMATION_TICKER");
if (ticker != null)
{
Expand Down Expand Up @@ -113,8 +123,14 @@ public AssetBrowserLogic(Widget widget, Action onExit, World world)
filenameInput.OnTextEdited = () => ApplyFilter(filenameInput.Text);
filenameInput.OnEscKey = () =>
{
filenameInput.Text = null;
filenameInput.OnTextEdited();
if (filenameInput.Text.Length == 0)
closeButton.OnClick();
else
{
filenameInput.Text = null;
filenameInput.OnTextEdited();
}
return true;
};
var frameContainer = panel.GetOrNull("FRAME_SELECTOR");
Expand Down Expand Up @@ -220,16 +236,6 @@ public AssetBrowserLogic(Widget widget, Action onExit, World world)
assetList = panel.Get<ScrollPanelWidget>("ASSET_LIST");
template = panel.Get<ScrollItemWidget>("ASSET_TEMPLATE");
PopulateAssetList();

var closeButton = panel.GetOrNull<ButtonWidget>("CLOSE_BUTTON");
if (closeButton != null)
closeButton.OnClick = () =>
{
if (isVideoLoaded)
player.Stop();
Ui.CloseWindow();
onExit();
};
}

void SelectNextFrame()
Expand Down
10 changes: 9 additions & 1 deletion OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs
Expand Up @@ -547,7 +547,15 @@ void CloseWindow()
else
return true;
};
chatTextField.OnEscKey = () => { chatTextField.Text = null; return true; };
chatTextField.OnEscKey = () =>
{
if (chatTextField.Text.Length == 0)
disconnectButton.OnClick();
else
chatTextField.Text = null;
return true;
};

chatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY");
chatTemplate = chatPanel.Get("CHAT_TEMPLATE");
Expand Down

0 comments on commit ca5ebb5

Please sign in to comment.