#include "global_inputs.h" #include // for basic_string, operator+ #include "input.h" // for Input, inputs_e, INPUT_DO_NOT_ALLOW_REPEAT #include "jail_audio.h" // for JA_EnableMusic, JA_EnableSound #include "lang.h" // for getText #include "options.h" // for options #include "on_screen_help.h" #include "screen.h" // for Screen #include "section.h" // for options_e, name, name_e, options #include "utils.h" // for op_audio_t, options_t, op_music_t, boolToOnOff namespace globalInputs { // Variables std::vector servicePressedCounter; // Inicializa variables void init() { const int numInputs = Input::get()->getNumControllers() + 1; servicePressedCounter.reserve(numInputs); for (int i = 0; i < numInputs; ++i) { servicePressedCounter.push_back(0); } } // 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 check() { // 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; } else if (Input::get()->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { servicePressedCounter[0]++; if (servicePressedCounter[0] >= 3000) { OnScreenHelp::get()->toggleState(); servicePressedCounter[0] = 0; } return; } else { servicePressedCounter[0] = 0; } 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; } if (Input::get()->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) { servicePressedCounter[i + 1]++; if (servicePressedCounter[i + 1] >= 3000) { OnScreenHelp::get()->toggleState(); servicePressedCounter[i + 1] = 0; } return; } else { servicePressedCounter[i + 1] = 0; } } } }