From 9f50249ca859faf21512c28dbc7e13b11cfd26c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Mon, 16 Oct 2023 23:37:59 +0200 Subject: [PATCH] Handle back button on android --- src/gui/console/ConsoleView.cpp | 2 +- src/gui/elementsearch/ElementSearchActivity.cpp | 1 + src/gui/font/FontEditor.h | 2 ++ src/gui/game/GameView.cpp | 6 ++++++ src/gui/interface/Window.cpp | 2 +- src/gui/localbrowser/LocalBrowserView.cpp | 2 +- src/gui/search/SearchView.cpp | 2 +- 7 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/gui/console/ConsoleView.cpp b/src/gui/console/ConsoleView.cpp index c6529c00a..fffae9600 100644 --- a/src/gui/console/ConsoleView.cpp +++ b/src/gui/console/ConsoleView.cpp @@ -25,7 +25,7 @@ ConsoleView::ConsoleView(): void ConsoleView::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - if ((ui::Engine::Ref().GraveExitsConsole && scan == SDL_SCANCODE_GRAVE && key != '~') || key == SDLK_ESCAPE) + if ((ui::Engine::Ref().GraveExitsConsole && scan == SDL_SCANCODE_GRAVE && key != '~') || key == SDLK_ESCAPE || key == SDLK_AC_BACK) { if (!repeat) doClose = true; diff --git a/src/gui/elementsearch/ElementSearchActivity.cpp b/src/gui/elementsearch/ElementSearchActivity.cpp index f0f86e94b..474c16b5e 100644 --- a/src/gui/elementsearch/ElementSearchActivity.cpp +++ b/src/gui/elementsearch/ElementSearchActivity.cpp @@ -254,6 +254,7 @@ void ElementSearchActivity::OnKeyPress(int key, int scan, bool repeat, bool shif if(firstResult) gameController->SetActiveTool(0, firstResult); case SDLK_ESCAPE: + case SDLK_AC_BACK: exit = true; break; case SDLK_LSHIFT: diff --git a/src/gui/font/FontEditor.h b/src/gui/font/FontEditor.h index 51d064f6c..8f3063cbe 100644 --- a/src/gui/font/FontEditor.h +++ b/src/gui/font/FontEditor.h @@ -16,6 +16,8 @@ namespace ui constexpr int MAX_WIDTH = 64; class FontEditor: public ui::Window { + void HandleExit(); + private: ByteString dataFile; std::map fontWidths; diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index c98317321..19d9c2781 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1597,6 +1597,12 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, { switch (key) { + case SDLK_AC_BACK: + if (ALLOW_QUIT) + { + ui::Engine::Ref().ConfirmExit(); + } + break; case SDLK_TAB: //Tab c->ChangeBrush(); break; diff --git a/src/gui/interface/Window.cpp b/src/gui/interface/Window.cpp index d63ccf0d5..f0368d1ba 100644 --- a/src/gui/interface/Window.cpp +++ b/src/gui/interface/Window.cpp @@ -366,7 +366,7 @@ void Window::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, b if (!stop) OnKeyPress(key, scan, repeat, shift, ctrl, alt); - if (key == SDLK_ESCAPE) + if (key == SDLK_ESCAPE || key == SDLK_AC_BACK) OnTryExit(Escape); if (key == SDLK_KP_ENTER || key == SDLK_RETURN) diff --git a/src/gui/localbrowser/LocalBrowserView.cpp b/src/gui/localbrowser/LocalBrowserView.cpp index 03b177a4e..a08b96ccd 100644 --- a/src/gui/localbrowser/LocalBrowserView.cpp +++ b/src/gui/localbrowser/LocalBrowserView.cpp @@ -201,7 +201,7 @@ void LocalBrowserView::OnKeyPress(int key, int scan, bool repeat, bool shift, bo { if (repeat) return; - if (key == SDLK_ESCAPE) + if (key == SDLK_ESCAPE || key == SDLK_AC_BACK) c->Exit(); else if (key == SDLK_LCTRL || key == SDLK_RCTRL) c->SetMoveToFront(false); diff --git a/src/gui/search/SearchView.cpp b/src/gui/search/SearchView.cpp index 6d72097a0..edb5eba49 100644 --- a/src/gui/search/SearchView.cpp +++ b/src/gui/search/SearchView.cpp @@ -643,7 +643,7 @@ void SearchView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctr { if (repeat) return; - if (key == SDLK_ESCAPE) + if (key == SDLK_ESCAPE || key == SDLK_AC_BACK) c->Exit(); else if ((focusedComponent_ != pageTextbox && focusedComponent_ != searchField) && scan == SDL_SCANCODE_A && ctrl) c->SelectAllSaves();