Android: open Pause when losing focus

This commit is contained in:
MoNTE48 2019-11-12 19:44:52 +01:00
parent a659963c24
commit a24f1c0f99
4 changed files with 29 additions and 11 deletions

View File

@ -22,8 +22,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "inputhandler.h"
#include "mainmenumanager.h"
#if defined(__ANDROID__)
#include "porting_android.h"
#endif
#ifdef __IOS__
#include "porting_ios.h"
#endif
#if defined(__ANDROID__) || defined(__IOS__)
extern void external_pause_game();
#endif
@ -34,9 +41,8 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
*/
if (isMenuActive()) {
#ifdef HAVE_TOUCHSCREENGUI
if (m_touchscreengui) {
if (m_touchscreengui)
m_touchscreengui->Toggle(false);
}
#endif
return g_menumgr.preprocessEvent(event);
}
@ -63,6 +69,11 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
}
#endif
#if defined(__ANDROID__)
if (event.SystemEvent.AndroidCmd.Cmd == APP_CMD_TERM_WINDOW)
external_pause_game();
#endif
#ifdef __IOS__
if (event.EventType == irr::EET_APPLICATION_EVENT) {
if (event.ApplicationEvent.EventType == irr::EAET_DID_PAUSE) {

View File

@ -1229,8 +1229,11 @@ public:
void run();
void shutdown();
#ifdef __IOS__
#if defined(__ANDROID__) || defined(__IOS__)
void pauseGame();
#endif
#ifdef __IOS__
void customStatustext(const std::wstring &text, float time);
#endif
void pauseAnimation(bool is_paused);
@ -1747,13 +1750,17 @@ void Game::run()
void Game::shutdown()
{
#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 8
if (g_settings->get("3d_mode") == "pageflip") {
if (g_settings->get("3d_mode") == "pageflip")
driver->setRenderTarget(irr::video::ERT_STEREO_BOTH_BUFFERS);
}
#endif
if (current_formspec)
current_formspec->quitMenu();
#ifdef HAVE_TOUCHSCREENGUI
g_touchscreengui->hide();
#endif
showOverlayMessage(wgettext("Shutting down..."), 0, 0, false);
if (clouds)
@ -4626,7 +4633,7 @@ void Game::readSettings()
}
#ifdef __IOS__
#if defined(__ANDROID__) || defined(__IOS__)
void Game::pauseGame()
{
g_touchscreengui->handleReleaseAll();
@ -4635,7 +4642,9 @@ void Game::pauseGame()
showPauseMenu();
runData.pause_game_timer = 0;
}
#endif
#ifdef __IOS__
void Game::customStatustext(const std::wstring &text, float time)
{
m_statustext = text;
@ -4914,14 +4923,16 @@ void the_game(bool *kill,
g_game = NULL;
}
#ifdef __IOS__
#if defined(__ANDROID__) || defined(__IOS__)
void external_pause_game()
{
if (!g_game)
return;
g_game->pauseGame();
}
#endif
#ifdef __IOS__
void external_statustext(const char *text, float duration)
{
if (!g_game)

View File

@ -524,7 +524,6 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) {
}
}
#ifdef __IOS__
void TouchScreenGUI::handleReleaseAll()
{
m_known_ids.clear();
@ -533,7 +532,6 @@ void TouchScreenGUI::handleReleaseAll()
for(int i = 0; i < after_last_element_id; i++)
m_buttons[i].ids.clear();
}
#endif
void TouchScreenGUI::translateEvent(const SEvent &event) {
if (!m_visible) {

View File

@ -109,9 +109,7 @@ public:
void show();
#ifdef __IOS__
void handleReleaseAll();
#endif
private:
IrrlichtDevice *m_device;