Working back button

This commit is contained in:
NyakoFox 2024-04-11 22:29:24 -03:00
parent 55208b9487
commit 206fac9ab4
4 changed files with 25 additions and 6 deletions

View File

@ -2552,7 +2552,7 @@ void titleinput(void)
//In the menu system, all keypresses are single taps rather than holds. Therefore this test has to be done for all presses
if (!game.press_action && !game.press_left && !game.press_right && !key.isDown(27) && !key.isDown(game.controllerButton_esc)
&& !touch::button_tapped(TOUCH_BUTTON_CANCEL))
&& !touch::button_tapped(TOUCH_BUTTON_CANCEL) && !key.pressed_android_back)
{
game.jumpheld = false;
}
@ -2562,7 +2562,7 @@ void titleinput(void)
if (!game.jumpheld && graphics.fademode == FADE_NONE)
{
if (game.press_action || game.press_left || game.press_right || game.press_map || key.isDown(27) || key.isDown(game.controllerButton_esc)
|| touch::button_tapped(TOUCH_BUTTON_CANCEL))
|| touch::button_tapped(TOUCH_BUTTON_CANCEL) || key.pressed_android_back)
{
game.jumpheld = true;
}
@ -2581,7 +2581,7 @@ void titleinput(void)
if (game.menustart
&& game.menucountdown <= 0
&& (key.isDown(27) || key.isDown(game.controllerButton_esc) || touch::button_tapped(TOUCH_BUTTON_CANCEL)))
&& (key.isDown(27) || key.isDown(game.controllerButton_esc) || touch::button_tapped(TOUCH_BUTTON_CANCEL) || key.pressed_android_back))
{
if (game.currentmenuname == Menu::language && loc::pre_title_lang_menu)
{
@ -2601,8 +2601,16 @@ void titleinput(void)
}
else if (game.currentmenuname == Menu::mainmenu)
{
game.createmenu(Menu::youwannaquit);
map.nexttowercolour();
if (key.pressed_android_back)
{
// Minimize the game!!! (Android only)
SDL_MinimizeWindow(gameScreen.m_window);
}
else
{
game.createmenu(Menu::youwannaquit);
map.nexttowercolour();
}
}
else
{

View File

@ -252,6 +252,8 @@ void KeyPoll::Poll(void)
touch::reset();
pressed_android_back = false;
while (SDL_PollEvent(&evt))
{
switch (evt.type)
@ -266,6 +268,11 @@ void KeyPoll::Poll(void)
pressedbackspace = true;
}
if (evt.key.keysym.sym == SDLK_AC_BACK)
{
pressed_android_back = true;
}
#ifdef __APPLE__ /* OSX prefers the command keys over the alt keys. -flibit */
altpressed = keymap[SDLK_LGUI] || keymap[SDLK_RGUI];
#else
@ -605,9 +612,9 @@ void KeyPoll::Poll(void)
case SDL_KEYDOWN:
if (evt.key.keysym.sym != SDLK_AC_BACK)
{
// If we hit the back button on Android, this doesn't mean we're not using touch
using_touch = false;
}
if (evt.key.repeat == 0)
{
hidemouse = true;

View File

@ -73,6 +73,7 @@ public:
bool linealreadyemptykludge;
bool using_touch;
bool pressed_android_back;
private:
std::map<SDL_JoystickID, SDL_GameController*> controllers;

View File

@ -567,6 +567,9 @@ int main(int argc, char *argv[])
/* We already do the button swapping in ButtonGlyphs, disable SDL's swapping */
SDL_SetHintWithPriority(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0", SDL_HINT_OVERRIDE);
/* We want to capture back inputs */
SDL_SetHintWithPriority(SDL_HINT_ANDROID_TRAP_BACK_BUTTON, "1", SDL_HINT_OVERRIDE);
if(!FILESYSTEM_init(argv[0], baseDir, assetsPath, langDir, fontsDir))
{
vlog_error("Unable to initialize filesystem!");