diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp new file mode 100644 index 0000000..63fcbc5 --- /dev/null +++ b/source/global_inputs.cpp @@ -0,0 +1,84 @@ +#include "global_inputs.h" +#include "section.h" +#include "screen.h" +#include "input.h" +#include "lang.h" +#include "options.h" + +// Termina +void quit(section::options_e code) +{ + if (Screen::get()->notificationsAreActive()) + { + section::name = section::NAME_QUIT; + section::options = code; + } + else + { + Screen::get()->showNotification(lang::getText(94)); + } +} + +// Reinicia +void reset() +{ + section::name = section::NAME_INIT; + Screen::get()->showNotification("Reset"); +} + +// Activa o desactiva el audio +void switchAudio() +{ + options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled; + JA_EnableMusic(options.audio.music.enabled); + JA_EnableSound(options.audio.sound.enabled); + Screen::get()->showNotification("Audio " + boolToOnOff(options.audio.music.enabled)); +} + +// Comprueba los inputs que se pueden introducir en cualquier sección del juego +void checkGlobalInputs() +{ + // Comprueba si se sale con el teclado + if (Input::get()->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) + { + quit(section::OPTIONS_QUIT_NORMAL); + return; + } + + // Comprueba si se va a resetear el juego + else if (Input::get()->checkInput(input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) + { + reset(); + return; + } + + else if (Input::get()->checkInput(input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) + { + switchAudio(); + return; + } + + for (int i = 0; i < Input::get()->getNumControllers(); ++i) + { + // Comprueba si se sale con el mando + if (Input::get()->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 + else if (Input::get()->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) + { + reset(); + return; + } + + // Comprueba si se va a activar o desactivar el audio + else if (Input::get()->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) + { + switchAudio(); + return; + } + } +} \ No newline at end of file diff --git a/source/global_inputs.h b/source/global_inputs.h new file mode 100644 index 0000000..37e86dd --- /dev/null +++ b/source/global_inputs.h @@ -0,0 +1,2 @@ +// Comprueba los inputs que se pueden introducir en cualquier sección del juego +void checkGlobalInputs(); \ No newline at end of file diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 4daa62e..0e05e52 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -1,7 +1,8 @@ -#include "hiscore_table.h" -#include "param.h" -#include "options.h" #include +#include "global_inputs.h" +#include "hiscore_table.h" +#include "options.h" +#include "param.h" // Constructor HiScoreTable::HiScoreTable(JA_Music_t *music) @@ -192,21 +193,6 @@ void HiScoreTable::checkEvents() // Comprueba las entradas void HiScoreTable::checkInput() { - // Comprueba si se sale con el teclado - if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - quit(section::OPTIONS_QUIT_NORMAL); - return; - } - - // Comprueba si se va a resetear el juego - if (input->checkInput(input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - section::name = section::NAME_INIT; - screen->showNotification("Reset"); - return; - } - // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) if (input->checkAnyButtonPressed()) { @@ -216,36 +202,11 @@ void HiScoreTable::checkInput() 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)) - { - section::name = section::NAME_LOGO; - screen->showNotification("Reset"); - return; - } - - // Comprueba si se va a activar o desactivar el audio - if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) - { - options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled; - JA_EnableMusic(options.audio.music.enabled); - JA_EnableSound(options.audio.sound.enabled); - screen->showNotification("Audio " + boolToOnOff(options.audio.music.enabled)); - return; - } - } - // Comprueba el input para el resto de objetos screen->checkInput(); + + // Comprueba los inputs que se pueden introducir en cualquier sección del juego + checkGlobalInputs(); } // Bucle para la pantalla de instrucciones @@ -341,18 +302,4 @@ std::string HiScoreTable::format(int number) } return result; -} - -// Termina -void HiScoreTable::quit(section::options_e code) -{ - if (screen->notificationsAreActive()) - { - section::name = section::NAME_QUIT; - section::options = code; - } - else - { - screen->showNotification(lang::getText(94)); - } } \ No newline at end of file diff --git a/source/instructions.cpp b/source/instructions.cpp index 3cd5f2e..687e2fd 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -1,6 +1,7 @@ #include "instructions.h" #include "param.h" #include "options.h" +#include "global_inputs.h" #include // Constructor @@ -322,21 +323,6 @@ void Instructions::checkEvents() // Comprueba las entradas void Instructions::checkInput() { - // Comprueba si se sale con el teclado - if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - quit(section::OPTIONS_QUIT_NORMAL); - return; - } - - // Comprueba si se va a resetear el juego - if (input->checkInput(input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - section::name = section::NAME_INIT; - screen->showNotification("Reset"); - return; - } - // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) if (input->checkAnyButtonPressed()) { @@ -346,36 +332,11 @@ void Instructions::checkInput() 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)) - { - section::name = section::NAME_LOGO; - screen->showNotification("Reset"); - return; - } - - // Comprueba si se va a activar o desactivar el audio - if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) - { - options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled; - JA_EnableMusic(options.audio.music.enabled); - JA_EnableSound(options.audio.sound.enabled); - screen->showNotification("Audio " + boolToOnOff(options.audio.music.enabled)); - return; - } - } - // Comprueba el input para el resto de objetos screen->checkInput(); + + // Comprueba los inputs que se pueden introducir en cualquier sección del juego + checkGlobalInputs(); } // Bucle para la pantalla de instrucciones @@ -388,18 +349,4 @@ void Instructions::run() checkEvents(); // Tiene que ir antes del render render(); } -} - -// Termina -void Instructions::quit(section::options_e code) -{ - if (screen->notificationsAreActive()) - { - section::name = section::NAME_QUIT; - section::options = code; - } - else - { - screen->showNotification(lang::getText(94)); - } } \ No newline at end of file diff --git a/source/instructions.h b/source/instructions.h index da55336..c569364 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -81,9 +81,6 @@ private: // Recarga todas las texturas void reloadTextures(); - // Termina - void quit(section::options_e code); - public: // Constructor Instructions(JA_Music_t *music); diff --git a/source/intro.cpp b/source/intro.cpp index f21baf5..b2f2ce8 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -1,6 +1,7 @@ +#include "global_inputs.h" #include "intro.h" -#include "param.h" #include "options.h" +#include "param.h" // Constructor Intro::Intro(JA_Music_t *music) @@ -192,21 +193,6 @@ void Intro::checkEvents() // Comprueba las entradas void Intro::checkInput() { - // Comprueba si se sale con el teclado - if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - quit(section::OPTIONS_QUIT_NORMAL); - return; - } - - // Comprueba si se va a resetear el juego - if (input->checkInput(input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - section::name = section::NAME_INIT; - screen->showNotification("Reset"); - return; - } - // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) if (input->checkAnyButtonPressed()) { @@ -216,36 +202,11 @@ void Intro::checkInput() 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)) - { - section::name = section::NAME_INIT; - screen->showNotification("Reset"); - return; - } - - // Comprueba si se va a activar o desactivar el audio - if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) - { - options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled; - JA_EnableMusic(options.audio.music.enabled); - JA_EnableSound(options.audio.sound.enabled); - screen->showNotification("Audio " + boolToOnOff(options.audio.music.enabled)); - return; - } - } - // Comprueba el input para el resto de objetos screen->checkInput(); + + // Comprueba los inputs que se pueden introducir en cualquier sección del juego + checkGlobalInputs(); } // Actualiza las escenas de la intro @@ -467,18 +428,4 @@ void Intro::run() checkEvents(); // Tiene que ir antes del render render(); } -} - -// Termina -void Intro::quit(section::options_e code) -{ - if (screen->notificationsAreActive()) - { - section::name = section::NAME_QUIT; - section::options = code; - } - else - { - screen->showNotification(lang::getText(94)); - } } \ No newline at end of file diff --git a/source/intro.h b/source/intro.h index e465dae..39a3c33 100644 --- a/source/intro.h +++ b/source/intro.h @@ -55,9 +55,6 @@ private: // Recarga todas las texturas void reloadTextures(); - // Termina - void quit(section::options_e code); - public: // Constructor Intro(JA_Music_t *music); diff --git a/source/logo.cpp b/source/logo.cpp index 2bd237d..57254f2 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,6 +1,7 @@ #include "logo.h" #include "param.h" #include "options.h" +#include "global_inputs.h" #include // Constructor @@ -103,21 +104,6 @@ void Logo::checkEvents() // Comprueba las entradas void Logo::checkInput() { - // Comprueba si se sale con el teclado - if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - quit(section::OPTIONS_QUIT_NORMAL); - return; - } - - // Comprueba si se va a resetear el juego - if (input->checkInput(input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - section::name = section::NAME_INIT; - screen->showNotification("Reset"); - return; - } - // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) if (input->checkAnyButtonPressed()) { @@ -127,36 +113,11 @@ void Logo::checkInput() 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)) - { - section::name = section::NAME_INIT; - screen->showNotification("Reset"); - return; - } - - // Comprueba si se va a activar o desactivar el audio - if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) - { - options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled; - JA_EnableMusic(options.audio.music.enabled); - JA_EnableSound(options.audio.sound.enabled); - screen->showNotification("Audio " + boolToOnOff(options.audio.music.enabled)); - return; - } - } - // Comprueba el input para el resto de objetos screen->checkInput(); + + // Comprueba los inputs que se pueden introducir en cualquier sección del juego + checkGlobalInputs(); } // Gestiona el logo de JAILGAME @@ -348,18 +309,4 @@ void Logo::run() checkEvents(); // Tiene que ir antes del render render(); } -} - -// Termina -void Logo::quit(section::options_e code) -{ - if (screen->notificationsAreActive()) - { - section::name = section::NAME_QUIT; - section::options = code; - } - else - { - screen->showNotification(lang::getText(94)); - } } \ No newline at end of file diff --git a/source/logo.h b/source/logo.h index 36d9526..40b0e25 100644 --- a/source/logo.h +++ b/source/logo.h @@ -66,9 +66,6 @@ private: // Recarga todas las texturas void reloadTextures(); - // Termina - void quit(section::options_e code); - public: // Constructor Logo(); diff --git a/source/title.cpp b/source/title.cpp index dcc6938..0b0a443 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -1,6 +1,7 @@ -#include "title.h" -#include "param.h" +#include "global_inputs.h" #include "options.h" +#include "param.h" +#include "title.h" // Constructor Title::Title(JA_Music_t *music) @@ -247,21 +248,6 @@ void Title::checkInput() // TECLADO // ////////////////////////////////////////////////// - // Comprueba si se sale con el teclado - if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - quit(section::OPTIONS_QUIT_NORMAL); - return; - } - - // Comprueba si se va a resetear el juego - if (input->checkInput(input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - section::name = section::NAME_INIT; - screen->showNotification("Reset"); - return; - } - // Comprueba el teclado para empezar a jugar if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { @@ -278,32 +264,6 @@ 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)) - { - section::name = section::NAME_LOGO; - screen->showNotification("Reset"); - return; - } - - // Comprueba si se va a activar o desactivar el audio - if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) - { - options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled; - JA_EnableMusic(options.audio.music.enabled); - JA_EnableSound(options.audio.sound.enabled); - screen->showNotification("Audio " + boolToOnOff(options.audio.music.enabled)); - return; - } - // Comprueba si se va a intercambiar la asignación de mandos a jugadores if (input->checkModInput(input_service, input_swap_controllers, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) { @@ -334,6 +294,9 @@ void Title::checkInput() // Comprueba el input para el resto de objetos screen->checkInput(); defineButtons->checkInput(); + + // Comprueba los inputs que se pueden introducir en cualquier sección del juego + checkGlobalInputs(); } // Bucle para el titulo del juego @@ -402,18 +365,4 @@ void Title::swapControllers() screen->showNotification(text[0], text[1]); resetCounter(); -} - -// Termina -void Title::quit(section::options_e code) -{ - if (screen->notificationsAreActive()) - { - section::name = section::NAME_QUIT; - section::options = code; - } - else - { - screen->showNotification(lang::getText(94)); - } } \ No newline at end of file diff --git a/source/title.h b/source/title.h index ef84080..80389cc 100644 --- a/source/title.h +++ b/source/title.h @@ -96,9 +96,6 @@ private: // Intercambia la asignación de mandos a los jugadores void swapControllers(); - // Termina - void quit(section::options_e code); - public: // Constructor Title(JA_Music_t *music);