#include "global_inputs.h" #include // Para SDL_RenderSetIntegerScale #include // Para SDL_FALSE, SDL_TRUE #include // Para operator+, string, to_string, basic_string #include // Para vector #include "asset.h" // Para Asset #include "input.h" // Para Input, InputDeviceToUse, InputType, INP... #include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundVolume #include "lang.h" // Para getText, Code, getNextLangCode, loadFro... #include "notifier.h" // Para Notifier #include "on_screen_help.h" // Para OnScreenHelp #include "options.h" // Para Options, options, OptionsGame, OptionsV... #include "screen.h" // Para Screen, ScreenVideoMode #include "section.h" // Para Name, name, Options, options, AttractMode #include "utils.h" // Para boolToOnOff namespace globalInputs { // Variables int service_pressed_counter = 0; bool service_pressed = false; // Termina void quit(section::Options code) { const std::string CODE = "QUIT"; if (Notifier::get()->checkCode(CODE)) { // Si la notificación de salir está activa, cambia de sección section::name = section::Name::QUIT; section::options = code; } else { // Si la notificación de salir no está activa, muestra la notificación #ifdef ARCADE const int INDEX = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94; Notifier::get()->show({lang::getText(INDEX), std::string()}, -1, CODE); #else Notifier::get()->show({lang::getText(94), std::string()}, -1, CODE); #endif } } // Reinicia void reset() { const std::string CODE = "RESET"; if (Notifier::get()->checkCode(CODE)) { section::name = section::Name::INIT; Notifier::get()->show({lang::getText(111)}); } else { Notifier::get()->show({lang::getText(125), std::string()}, -1, CODE); } } // Activa o desactiva el audio void toggleAudio() { options.audio.enabled = !options.audio.enabled; if (options.audio.enabled) { JA_SetMusicVolume(to_JA_volume(options.audio.music.volume)); JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume)); } else { JA_SetMusicVolume(0); JA_SetSoundVolume(0); } Notifier::get()->show({"Audio " + boolToOnOff(options.audio.enabled)}); } // Cambia el modo de escalado entero void toggleintegerScale() { options.video.integer_scale = !options.video.integer_scale; SDL_RenderSetIntegerScale(Screen::get()->getRenderer(), options.video.integer_scale ? SDL_TRUE : SDL_FALSE); Screen::get()->setVideoMode(); Notifier::get()->show({lang::getText(134) + " " + boolToOnOff(options.video.integer_scale)}); } // Activa o desactiva los shaders void toggleShaders() { Screen::get()->toggleShaders(); Notifier::get()->show({lang::getText(135) + " " + boolToOnOff(options.video.shaders)}); } // Obtiene una fichero a partir de un lang::Code std::string getLangFile(lang::Code code) { switch (code) { case lang::Code::ba_BA: return Asset::get()->get("ba_BA.txt"); break; case lang::Code::es_ES: return Asset::get()->get("es_ES.txt"); break; default: return Asset::get()->get("en_UK.txt"); break; } } // Obtiene una cadena a partir de un lang::Code std::string getLangName(lang::Code code) { switch (code) { case lang::Code::ba_BA: return " \"ba_BA\""; break; case lang::Code::es_ES: return " \"es_ES\""; break; default: return " \"en_UK\""; break; } } // Cambia el idioma void changeLang() { const std::string CODE = "LANG"; if (Notifier::get()->checkCode(CODE)) { options.game.language = lang::getNextLangCode(options.game.language); lang::loadFromFile(getLangFile(static_cast(options.game.language))); section::name = section::Name::INIT; section::options = section::Options::RELOAD; Notifier::get()->show({lang::getText(127) + getLangName(options.game.language)}); } else { const auto NEXT = lang::getNextLangCode(options.game.language); Notifier::get()->show({lang::getText(126) + getLangName(NEXT), std::string()}, -1, CODE); } } // Cambia el modo de disparo void toggleFireMode() { options.game.autofire = !options.game.autofire; Notifier::get()->show({lang::getText(130) + " " + boolToOnOff(options.game.autofire)}); } // Salta una sección del juego void skip_section() { switch (section::name) { case section::Name::INTRO: JA_StopMusic(); /* Continua en el case de abajo */ case section::Name::LOGO: case section::Name::HI_SCORE_TABLE: case section::Name::INSTRUCTIONS: { section::name = section::Name::TITLE; section::options = section::Options::TITLE_1; section::attract_mode = section::AttractMode::TITLE_TO_DEMO; break; } default: break; } } // Comprueba los inputs que se pueden introducir en cualquier sección del juego void check() { // Teclado { // Comprueba el teclado para cambiar entre pantalla completa y ventana if (Input::get()->checkInput(InputType::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { Screen::get()->toggleVideoMode(); const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? lang::getText(132) : lang::getText(133); Notifier::get()->show({mode}); return; } // Comprueba el teclado para decrementar el tamaño de la ventana if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { if (Screen::get()->decWindowZoom()) { Notifier::get()->show({lang::getText(131) + " x" + std::to_string(options.video.window.zoom)}); } return; } // Comprueba el teclado para incrementar el tamaño de la ventana if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { if (Screen::get()->incWindowZoom()) { Notifier::get()->show({lang::getText(131) + " x" + std::to_string(options.video.window.zoom)}); } return; } // Salir if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { quit(section::Options::QUIT_WITH_KEYBOARD); return; } // Saltar sección if (Input::get()->checkAnyButtonPressed()) { skip_section(); return; } // Reset if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { reset(); return; } // Audio if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { toggleAudio(); return; } // Autofire if (Input::get()->checkInput(InputType::AUTO_FIRE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { toggleFireMode(); return; } // Idioma if (Input::get()->checkInput(InputType::CHANGE_LANG, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { changeLang(); return; } // Shaders if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { toggleShaders(); return; } if (Input::get()->checkInput(InputType::VIDEO_INTEGER_SCALE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { toggleintegerScale(); return; } #ifdef DEBUG // Comprueba el teclado para mostrar la información de debug if (Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { Screen::get()->toggleDebugInfo(); return; } #endif // OnScreenHelp if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { service_pressed = true; return; } } // Mandos { for (int i = 0; i < Input::get()->getNumControllers(); ++i) { // Salir if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) { quit(section::Options::QUIT_WITH_CONTROLLER); return; } // Reset if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) { reset(); return; } // Audio if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) { toggleAudio(); return; } // Shaders if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) { toggleShaders(); return; } #ifdef DEBUG // Debug Info if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) { Screen::get()->toggleDebugInfo(); return; } #endif // OnScreenHelp if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) { service_pressed = true; return; } } } } // Actualiza variables void update() { if (service_pressed) { ++service_pressed_counter; if (service_pressed_counter >= 200) { OnScreenHelp::get()->toggleState(); service_pressed_counter = 0; } } else { service_pressed_counter = 0; } service_pressed = false; } }