1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 18:19:43 +01:00

Working back button

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

View file

@ -2558,7 +2558,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 //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) 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; game.jumpheld = false;
} }
@ -2568,7 +2568,7 @@ void titleinput(void)
if (!game.jumpheld && graphics.fademode == FADE_NONE) 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) 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; game.jumpheld = true;
} }
@ -2587,7 +2587,7 @@ void titleinput(void)
if (game.menustart if (game.menustart
&& game.menucountdown <= 0 && 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) if (game.currentmenuname == Menu::language && loc::pre_title_lang_menu)
{ {
@ -2606,10 +2606,18 @@ void titleinput(void)
map.nexttowercolour(); map.nexttowercolour();
} }
else if (game.currentmenuname == Menu::mainmenu) else if (game.currentmenuname == Menu::mainmenu)
{
if (key.pressed_android_back)
{
// Minimize the game!!! (Android only)
SDL_MinimizeWindow(gameScreen.m_window);
}
else
{ {
game.createmenu(Menu::youwannaquit); game.createmenu(Menu::youwannaquit);
map.nexttowercolour(); map.nexttowercolour();
} }
}
else else
{ {
if (game.slidermode != SLIDER_NONE) if (game.slidermode != SLIDER_NONE)

View file

@ -261,6 +261,8 @@ void KeyPoll::Poll(void)
touch::reset(); touch::reset();
pressed_android_back = false;
while (SDL_PollEvent(&evt)) while (SDL_PollEvent(&evt))
{ {
switch (evt.type) switch (evt.type)
@ -275,6 +277,11 @@ void KeyPoll::Poll(void)
pressedbackspace = true; 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 */ #ifdef __APPLE__ /* OSX prefers the command keys over the alt keys. -flibit */
altpressed = keymap[SDLK_LGUI] || keymap[SDLK_RGUI]; altpressed = keymap[SDLK_LGUI] || keymap[SDLK_RGUI];
#else #else
@ -625,9 +632,9 @@ void KeyPoll::Poll(void)
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (evt.key.keysym.sym != SDLK_AC_BACK) 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; using_touch = false;
} }
if (evt.key.repeat == 0) if (evt.key.repeat == 0)
{ {
hidemouse = true; hidemouse = true;

View file

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

View file

@ -609,6 +609,9 @@ int main(int argc, char *argv[])
/* We already do the button swapping in ButtonGlyphs, disable SDL's swapping */ /* We already do the button swapping in ButtonGlyphs, disable SDL's swapping */
SDL_SetHintWithPriority(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0", SDL_HINT_OVERRIDE); 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)) if(!FILESYSTEM_init(argv[0], baseDir, assetsPath, langDir, fontsDir))
{ {
vlog_error("Unable to initialize filesystem!"); vlog_error("Unable to initialize filesystem!");