diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 71a4e0b..0a65d5a 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -504,4 +504,10 @@ void Screen::displayInfo() // Resolution dbg_print(0, 0, infoResolution.c_str(), 255, 255, 0); } +} + +// Indica si hay alguna notificación activa en pantalla +bool Screen::notificationsAreActive() +{ + return notify->active(); } \ No newline at end of file diff --git a/source/common/screen.h b/source/common/screen.h index c573ccc..90eee9d 100644 --- a/source/common/screen.h +++ b/source/common/screen.h @@ -134,6 +134,9 @@ public: // Muestra una notificación de texto por pantalla; void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1); + // Indica si hay alguna notificación activa en pantalla + bool notificationsAreActive(); + // Obtiene el puntero al renderizador SDL_Renderer *getRenderer(); }; \ No newline at end of file diff --git a/source/game.cpp b/source/game.cpp index 478a83a..65c5458 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -2040,13 +2040,19 @@ void Game::checkInput() // Comprueba si se sale con el teclado if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { - section->name = SECTION_PROG_QUIT; - section->options = SECTION_OPTIONS_QUIT_NORMAL; + quit(SECTION_OPTIONS_QUIT_NORMAL); return; } for (int i = 0; i < input->getNumControllers(); ++i) { + // Comprueba si se sale con el mando + if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) + { + quit(SECTION_OPTIONS_QUIT_SHUTDOWN); + return; + } + // Comprueba si se va a resetear el juego if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) { @@ -2809,4 +2815,18 @@ int Game::getController(int playerId) } return -1; +} + +// Termina +void Game::quit(int code) +{ + if (screen->notificationsAreActive()) + { + section->name = SECTION_PROG_QUIT; + section->options = code; + } + else + { + screen->showNotification("Torna a polsar per eixir"); + } } \ No newline at end of file diff --git a/source/game.h b/source/game.h index 4c6e54d..4bb8e9d 100644 --- a/source/game.h +++ b/source/game.h @@ -446,6 +446,9 @@ private: // Obtiene un controlador a partir del "id" del jugador int getController(int playerId); + // Termina + void quit(int code); + public: // Constructor Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music); diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index d3b26a9..e38b5aa 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -197,8 +197,7 @@ void HiScoreTable::checkInput() // Comprueba si se sale con el teclado if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { - section->name = SECTION_PROG_QUIT; - section->options = SECTION_OPTIONS_QUIT_NORMAL; + quit(SECTION_OPTIONS_QUIT_NORMAL); return; } @@ -213,6 +212,13 @@ void HiScoreTable::checkInput() for (int i = 0; i < input->getNumControllers(); ++i) { + // Comprueba si se sale con el mando + if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) + { + quit(SECTION_OPTIONS_QUIT_SHUTDOWN); + return; + } + // Comprueba si se va a resetear el juego if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) { @@ -329,4 +335,18 @@ std::string HiScoreTable::format(int number) } return result; +} + +// Termina +void HiScoreTable::quit(int code) +{ + if (screen->notificationsAreActive()) + { + section->name = SECTION_PROG_QUIT; + section->options = code; + } + else + { + screen->showNotification("Torna a polsar per eixir"); + } } \ No newline at end of file diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 172869a..3ac0f39 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -78,6 +78,9 @@ private: // Gestiona el fade void updateFade(); + // Termina + void quit(int code); + public: // Constructor HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music); diff --git a/source/instructions.cpp b/source/instructions.cpp index 2f6277a..6109608 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -327,8 +327,7 @@ void Instructions::checkInput() // Comprueba si se sale con el teclado if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { - section->name = SECTION_PROG_QUIT; - section->options = SECTION_OPTIONS_QUIT_NORMAL; + quit(SECTION_OPTIONS_QUIT_NORMAL); return; } @@ -343,6 +342,13 @@ void Instructions::checkInput() for (int i = 0; i < input->getNumControllers(); ++i) { + // Comprueba si se sale con el mando + if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) + { + quit(SECTION_OPTIONS_QUIT_SHUTDOWN); + return; + } + // Comprueba si se va a resetear el juego if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) { @@ -377,3 +383,17 @@ void Instructions::run() render(); } } + +// Termina +void Instructions::quit(int code) +{ + if (screen->notificationsAreActive()) + { + section->name = SECTION_PROG_QUIT; + section->options = code; + } + else + { + screen->showNotification("Torna a polsar per eixir"); + } +} \ No newline at end of file diff --git a/source/instructions.h b/source/instructions.h index cb604ca..38a4f77 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -85,6 +85,9 @@ private: // Recarga todas las texturas void reloadTextures(); + // Termina + void quit(int code); + public: // Constructor Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music); diff --git a/source/intro.cpp b/source/intro.cpp index adb2596..6cb3531 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -196,8 +196,7 @@ void Intro::checkInput() // Comprueba si se sale con el teclado if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { - section->name = SECTION_PROG_QUIT; - section->options = SECTION_OPTIONS_QUIT_NORMAL; + quit(SECTION_OPTIONS_QUIT_NORMAL); return; } @@ -209,9 +208,16 @@ void Intro::checkInput() section->options = SECTION_OPTIONS_TITLE_1; return; } - + for (int i = 0; i < input->getNumControllers(); ++i) - { + { + // Comprueba si se sale con el mando + if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) + { + quit(SECTION_OPTIONS_QUIT_SHUTDOWN); + return; + } + // Comprueba si se va a resetear el juego if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) { @@ -455,3 +461,17 @@ void Intro::run() render(); } } + +// Termina +void Intro::quit(int code) +{ + if (screen->notificationsAreActive()) + { + section->name = SECTION_PROG_QUIT; + section->options = code; + } + else + { + screen->showNotification("Torna a polsar per eixir"); + } +} \ No newline at end of file diff --git a/source/intro.h b/source/intro.h index 7012c19..d595631 100644 --- a/source/intro.h +++ b/source/intro.h @@ -59,6 +59,9 @@ private: // Recarga todas las texturas void reloadTextures(); + // Termina + void quit(int code); + public: // Constructor Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music); diff --git a/source/logo.cpp b/source/logo.cpp index 1bdd92b..702722e 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -107,8 +107,7 @@ void Logo::checkInput() // Comprueba si se sale con el teclado if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { - section->name = SECTION_PROG_QUIT; - section->options = SECTION_OPTIONS_QUIT_NORMAL; + quit(SECTION_OPTIONS_QUIT_NORMAL); return; } @@ -126,8 +125,7 @@ void Logo::checkInput() // Comprueba si se sale con el mando if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) { - section->name = SECTION_PROG_QUIT; - section->options = SECTION_OPTIONS_QUIT_SHUTDOWN; + quit(SECTION_OPTIONS_QUIT_SHUTDOWN); return; } @@ -335,4 +333,18 @@ void Logo::run() checkEvents(); // Tiene que ir antes del render render(); } +} + +// Termina +void Logo::quit(int code) +{ + if (screen->notificationsAreActive()) + { + section->name = SECTION_PROG_QUIT; + section->options = code; + } + else + { + screen->showNotification("Torna a polsar per eixir"); + } } \ No newline at end of file diff --git a/source/logo.h b/source/logo.h index 1373909..9910f73 100644 --- a/source/logo.h +++ b/source/logo.h @@ -68,6 +68,9 @@ private: // Recarga todas las texturas void reloadTextures(); + // Termina + void quit(int code); + public: // Constructor Logo(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section); diff --git a/source/title.cpp b/source/title.cpp index aa6cb8c..d786a7f 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -252,8 +252,7 @@ void Title::checkInput() // Comprueba si se sale con el teclado if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { - section->name = SECTION_PROG_QUIT; - section->options = SECTION_OPTIONS_QUIT_NORMAL; + quit(SECTION_OPTIONS_QUIT_NORMAL); return; } @@ -273,6 +272,14 @@ void Title::checkInput() for (int i = 0; i < input->getNumControllers(); ++i) { + + // Comprueba si se sale con el mando + if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) + { + quit(SECTION_OPTIONS_QUIT_SHUTDOWN); + return; + } + // Comprueba si se va a resetear el juego if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) { @@ -389,4 +396,18 @@ void Title::swapControllers() screen->showNotification(text[0], text[1]); resetCounter(); +} + +// Termina +void Title::quit(int code) +{ + if (screen->notificationsAreActive()) + { + section->name = SECTION_PROG_QUIT; + section->options = code; + } + else + { + screen->showNotification("Torna a polsar per eixir"); + } } \ No newline at end of file diff --git a/source/title.h b/source/title.h index 291e40a..5326be0 100644 --- a/source/title.h +++ b/source/title.h @@ -100,6 +100,9 @@ private: // Intercambia la asignación de mandos a los jugadores void swapControllers(); + // Termina + void quit(int code); + public: // Constructor Title(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music);