From 04935c652db118c4c56cf24761ae5be01fbf5b89 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 15 Sep 2024 13:03:53 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adidas=20nuevas=20funciones=20al=20bot?= =?UTF-8?q?=C3=B3n=20de=20servicio=20El=20bot=C3=B3n=20de=20servicio=20se?= =?UTF-8?q?=20puede=20usar=20en=20cualquier=20secci=C3=B3n=20del=20juego?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/common/input.cpp | 8 ++++++- source/common/input.h | 6 +++--- source/common/screen.cpp | 10 ++++----- source/director.cpp | 14 ++++++------- source/game.cpp | 45 +++++++++++++++++++++++++++++++--------- source/hiscore_table.cpp | 20 +++++++++++++++++- source/instructions.cpp | 20 +++++++++++++++++- source/intro.cpp | 20 +++++++++++++++++- source/logo.cpp | 22 +++++++++++++++++++- source/main.cpp | 3 ++- source/service.cpp | 15 ++++++++++++++ source/service.h | 16 +++++++++----- source/title.cpp | 11 +++++++--- source/title.h | 1 - 14 files changed, 171 insertions(+), 40 deletions(-) diff --git a/source/common/input.cpp b/source/common/input.cpp index 8869064..6ecbf94 100644 --- a/source/common/input.cpp +++ b/source/common/input.cpp @@ -225,7 +225,13 @@ bool Input::checkAnyInput(int device, int index) // Comprueba si hay algún botón pulsado. Devuelve 0 en caso de no encontrar nada o el indice del dispositivo + 1. Se hace así para poder gastar el valor devuelto como un valor "booleano" int Input::checkAnyButtonPressed(bool repeat) { - // Solo comprueba los botones + // Si está pulsado el botón de servicio, ningún botón se puede considerar pulsado + if (checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_ANY)) + { + return 0; + } + + // Solo comprueba los botones definidos previamente for (auto bi : buttonInputs) { // Comprueba el teclado diff --git a/source/common/input.h b/source/common/input.h index a7ffab7..a9f32e4 100644 --- a/source/common/input.h +++ b/source/common/input.h @@ -44,8 +44,8 @@ enum inputs_e input_number_of_inputs }; -#define ALLOW_REPEAT true -#define DO_NOT_ALLOW_REPEAT false +#define INPUT_ALLOW_REPEAT true +#define INPUT_DO_NOT_ALLOW_REPEAT false #define INPUT_USE_KEYBOARD 0 #define INPUT_USE_GAMECONTROLLER 1 @@ -111,7 +111,7 @@ public: bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0); // Comprueba si hay algún botón pulsado - int checkAnyButtonPressed(bool repeat = DO_NOT_ALLOW_REPEAT); + int checkAnyButtonPressed(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT); // Busca si hay mandos conectados bool discoverGameControllers(); diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 9ebe5f8..b5938aa 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -319,21 +319,21 @@ void Screen::update() void Screen::checkInput() { #ifndef ARCADE - if (input->checkInput(input_window_fullscreen, DO_NOT_ALLOW_REPEAT)) + if (input->checkInput(input_window_fullscreen, INPUT_DO_NOT_ALLOW_REPEAT)) { switchVideoMode(); const std::string mode = options->video.mode == SCREEN_VIDEO_MODE_WINDOW ? "Window" : "Fullscreen"; showNotification(mode + " mode"); } - else if (input->checkInput(input_window_dec_size, DO_NOT_ALLOW_REPEAT)) + else if (input->checkInput(input_window_dec_size, INPUT_DO_NOT_ALLOW_REPEAT)) { decWindowSize(); const std::string size = std::to_string(options->video.window.size); showNotification("Window size x" + size); } - else if (input->checkInput(input_window_inc_size, DO_NOT_ALLOW_REPEAT)) + else if (input->checkInput(input_window_inc_size, INPUT_DO_NOT_ALLOW_REPEAT)) { incWindowSize(); const std::string size = std::to_string(options->video.window.size); @@ -341,12 +341,12 @@ void Screen::checkInput() } #endif - if (input->checkInput(input_video_shaders, DO_NOT_ALLOW_REPEAT)) + if (input->checkInput(input_video_shaders, INPUT_DO_NOT_ALLOW_REPEAT)) { switchShaders(); } - else if (input->checkInput(input_showinfo, DO_NOT_ALLOW_REPEAT)) + else if (input->checkInput(input_showinfo, INPUT_DO_NOT_ALLOW_REPEAT)) { showInfo = !showInfo; } diff --git a/source/director.cpp b/source/director.cpp index be9adba..b009224 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -511,7 +511,7 @@ void Director::initOptions() c.inputs.push_back(input_fire_center); c.inputs.push_back(input_fire_right); c.inputs.push_back(input_start); - c.inputs.push_back(input_exit); + c.inputs.push_back(input_service); c.buttons.clear(); c.buttons.push_back(SDL_CONTROLLER_BUTTON_X); @@ -779,8 +779,8 @@ bool Director::saveConfigFile() file << "controller" + joyIndex + ".inputs.fire_left=" + std::to_string((int)options->controller[index].buttons[0]) + "\n"; file << "controller" + joyIndex + ".inputs.fire_center=" + std::to_string((int)options->controller[index].buttons[1]) + "\n"; file << "controller" + joyIndex + ".inputs.fire_right=" + std::to_string((int)options->controller[index].buttons[2]) + "\n"; - file << "controller" + joyIndex + ".inputs.fire_start=" + std::to_string((int)options->controller[index].buttons[3]) + "\n"; - file << "controller" + joyIndex + ".inputs.fire_exit=" + std::to_string((int)options->controller[index].buttons[4]) + "\n"; + file << "controller" + joyIndex + ".inputs.start=" + std::to_string((int)options->controller[index].buttons[3]) + "\n"; + file << "controller" + joyIndex + ".inputs.service=" + std::to_string((int)options->controller[index].buttons[4]) + "\n"; if (index < numPlayers - 1) { @@ -1080,12 +1080,12 @@ bool Director::setOptions(options_t *options, std::string var, std::string value options->controller[0].buttons[2] = (SDL_GameControllerButton)std::stoi(value); } - else if (var == "controller1.inputs.fire_start") + else if (var == "controller1.inputs.start") { options->controller[0].buttons[3] = (SDL_GameControllerButton)std::stoi(value); } - else if (var == "controller1.inputs.fire_exit") + else if (var == "controller1.inputs.service") { options->controller[0].buttons[4] = (SDL_GameControllerButton)std::stoi(value); } @@ -1110,12 +1110,12 @@ bool Director::setOptions(options_t *options, std::string var, std::string value options->controller[1].buttons[2] = (SDL_GameControllerButton)std::stoi(value); } - else if (var == "controller2.inputs.fire_start") + else if (var == "controller2.inputs.start") { options->controller[1].buttons[3] = (SDL_GameControllerButton)std::stoi(value); } - else if (var == "controller2.inputs.fire_exit") + else if (var == "controller2.inputs.service") { options->controller[1].buttons[4] = (SDL_GameControllerButton)std::stoi(value); } diff --git a/source/game.cpp b/source/game.cpp index 8abe241..b152f11 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1,4 +1,5 @@ #include "game.h" +#include "service.h" #define GAME_OVER_COUNTER 350 @@ -124,7 +125,7 @@ void Game::init(int playerID) // Obtiene el "id" del jugador que va a jugar Player *player = getPlayer(playerID); - + // Cambia el estado del jugador seleccionado player->setStatusPlaying(PLAYER_STATUS_PLAYING); @@ -2038,20 +2039,37 @@ void Game::updateMenace() void Game::checkInput() { // Comprueba las teclas que afectan al programa (solo para el primer jugador) - if (input->checkInput(input_exit, DO_NOT_ALLOW_REPEAT)) + if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT)) { section->name = SECTION_PROG_QUIT; + section->options = SECTION_OPTIONS_QUIT_NORMAL; return; } - else if (input->checkInput(input_reset, DO_NOT_ALLOW_REPEAT)) + // Comprueba el botón de SERVICE + switch (checkServiceButton(input, 0)) + { + case SERVICE_EXIT: + { + section->name = SECTION_PROG_QUIT; + section->options = SECTION_OPTIONS_QUIT_SHUTDOWN; + break; + } + + case SERVICE_SHADERS: + { + screen->switchShaders(); + break; + } + + case SERVICE_RESET: { section->name = SECTION_PROG_LOGO; screen->showNotification("Reset"); - return; + break; } - else if (input->checkInput(input_mute, DO_NOT_ALLOW_REPEAT)) + case SERVICE_MUTE: { const bool value = !options->audio.music.enabled; options->audio.music.enabled = value; @@ -2060,12 +2078,19 @@ void Game::checkInput() JA_EnableSound(value); const std::string text = value ? "on" : "off"; screen->showNotification("Audio " + text); - return; + break; } - else if (input->checkInput(input_pause, DO_NOT_ALLOW_REPEAT)) + case SERVICE_PAUSE: { pause(!paused); + break; + } + + default: + { + break; + } } // Modo Demo activo @@ -2153,7 +2178,7 @@ void Game::checkInput() if (player->isPlaying()) { // Input a la izquierda - if (input->checkInput(input_left, ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index)) + if (input->checkInput(input_left, INPUT_ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index)) { player->setInput(input_left); #ifdef RECORDING @@ -2163,7 +2188,7 @@ void Game::checkInput() else { // Input a la derecha - if (input->checkInput(input_right, ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index)) + if (input->checkInput(input_right, INPUT_ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index)) { player->setInput(input_right); #ifdef RECORDING @@ -2242,7 +2267,7 @@ void Game::checkInput() else { // Si no está jugando, el botón de start le permite continuar jugando - if (input->checkInput(input_start, ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index)) + if (input->checkInput(input_start, INPUT_ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index)) { // Si no ha entrado ya en el estado de game over, entonces se puede continuar if (gameOverCounter == GAME_OVER_COUNTER) diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index a74873d..6d8936c 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -1,4 +1,5 @@ #include "hiscore_table.h" +#include "service.h" #include // Constructor @@ -194,9 +195,10 @@ void HiScoreTable::checkEvents() // Comprueba las entradas void HiScoreTable::checkInput() { - if (input->checkInput(input_exit, DO_NOT_ALLOW_REPEAT)) + if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT)) { section->name = SECTION_PROG_QUIT; + section->options = SECTION_OPTIONS_QUIT_NORMAL; } else if (input->checkAnyButtonPressed()) @@ -206,6 +208,22 @@ void HiScoreTable::checkInput() section->options = SECTION_OPTIONS_TITLE_1; } + // Comprueba el botón de SERVICE + switch (checkServiceButton(input, 0)) + { + case SERVICE_EXIT: + section->name = SECTION_PROG_QUIT; + section->options = SECTION_OPTIONS_QUIT_SHUTDOWN; + break; + + case SERVICE_SHADERS: + screen->switchShaders(); + break; + + default: + break; + } + // Comprueba el input para el resto de objetos screen->checkInput(); } diff --git a/source/instructions.cpp b/source/instructions.cpp index 6e01dcd..7ff7001 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -1,4 +1,5 @@ #include "instructions.h" +#include "service.h" #include // Constructor @@ -323,9 +324,10 @@ void Instructions::checkEvents() // Comprueba las entradas void Instructions::checkInput() { - if (input->checkInput(input_exit, DO_NOT_ALLOW_REPEAT)) + if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT)) { section->name = SECTION_PROG_QUIT; + section->options = SECTION_OPTIONS_QUIT_NORMAL; } else if (input->checkAnyButtonPressed()) @@ -335,6 +337,22 @@ void Instructions::checkInput() section->options = SECTION_OPTIONS_TITLE_1; } + // Comprueba el botón de SERVICE + switch (checkServiceButton(input, 0)) + { + case SERVICE_EXIT: + section->name = SECTION_PROG_QUIT; + section->options = SECTION_OPTIONS_QUIT_SHUTDOWN; + break; + + case SERVICE_SHADERS: + screen->switchShaders(); + break; + + default: + break; + } + // Comprueba el input para el resto de objetos screen->checkInput(); } diff --git a/source/intro.cpp b/source/intro.cpp index be5a3c0..531c9f2 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -1,4 +1,5 @@ #include "intro.h" +#include "service.h" // Constructor Intro::Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music) @@ -193,9 +194,10 @@ void Intro::checkEvents() // Comprueba las entradas void Intro::checkInput() { - if (input->checkInput(input_exit, DO_NOT_ALLOW_REPEAT)) + if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT)) { section->name = SECTION_PROG_QUIT; + section->options = SECTION_OPTIONS_QUIT_NORMAL; } else if (input->checkAnyButtonPressed()) @@ -205,6 +207,22 @@ void Intro::checkInput() section->options = SECTION_OPTIONS_TITLE_1; } + // Comprueba el botón de SERVICE + switch (checkServiceButton(input, 0)) + { + case SERVICE_EXIT: + section->name = SECTION_PROG_QUIT; + section->options = SECTION_OPTIONS_QUIT_SHUTDOWN; + break; + + case SERVICE_SHADERS: + screen->switchShaders(); + break; + + default: + break; + } + // Comprueba el input para el resto de objetos screen->checkInput(); } diff --git a/source/logo.cpp b/source/logo.cpp index 02b6f31..baea64d 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,4 +1,5 @@ #include "logo.h" +#include "service.h" #include // Constructor @@ -103,9 +104,11 @@ void Logo::checkEvents() // Comprueba las entradas void Logo::checkInput() { - if (input->checkInput(input_exit, DO_NOT_ALLOW_REPEAT)) + if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT)) { section->name = SECTION_PROG_QUIT; + section->options = SECTION_OPTIONS_QUIT_NORMAL; + return; } else if (input->checkAnyButtonPressed()) @@ -114,6 +117,23 @@ void Logo::checkInput() section->options = SECTION_OPTIONS_TITLE_1; } + // Comprueba el botón de SERVICE + switch (checkServiceButton(input, 0)) + { + case SERVICE_EXIT: + section->name = SECTION_PROG_QUIT; + section->options = SECTION_OPTIONS_QUIT_SHUTDOWN; + return; + break; + + case SERVICE_SHADERS: + screen->switchShaders(); + break; + + default: + break; + } + // Comprueba el input para el resto de objetos screen->checkInput(); } diff --git a/source/main.cpp b/source/main.cpp index 65a8457..60928f3 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -23,7 +23,8 @@ int main(int argc, char *argv[]) // Destruye el objeto Director delete director; - std::cout << "\nGame end" << std::endl; + const std::string endType = exit == SECTION_OPTIONS_QUIT_NORMAL ? "to terminal" : "shutdown"; + std::cout << "\nGame end -> " << endType << std::endl; return exit; } diff --git a/source/service.cpp b/source/service.cpp index 78ed70d..fa6026e 100644 --- a/source/service.cpp +++ b/source/service.cpp @@ -24,6 +24,21 @@ int checkServiceButton(Input *input, int index) { return SERVICE_PAUSE; } + + else if (input->checkInput(input_up, false, INPUT_USE_GAMECONTROLLER, index)) + { + return SERVICE_SWAP_CONTROLLERS; + } + + else if (input->checkInput(input_down, false, INPUT_USE_GAMECONTROLLER, index)) + { + return SERVICE_RESET; + } + + else if (input->checkInput(input_left, false, INPUT_USE_GAMECONTROLLER, index)) + { + return SERVICE_MUTE; + } } return SERVICE_NULL; diff --git a/source/service.h b/source/service.h index d75c29c..4924502 100644 --- a/source/service.h +++ b/source/service.h @@ -5,11 +5,17 @@ #include "common/input.h" #include "const.h" -#define SERVICE_NULL 0 -#define SERVICE_EXIT 1 -#define SERVICE_CONFIG 2 -#define SERVICE_SHADERS 3 -#define SERVICE_PAUSE 4 +enum service_e +{ + SERVICE_NULL, + SERVICE_EXIT, + SERVICE_CONFIG, + SERVICE_SHADERS, + SERVICE_PAUSE, + SERVICE_SWAP_CONTROLLERS, + SERVICE_RESET, + SERVICE_MUTE +}; // Comprueba el botón de servicio del controlador "index" int checkServiceButton(Input *input, int index); \ No newline at end of file diff --git a/source/title.cpp b/source/title.cpp index b9803d5..e9ad7d6 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -1,4 +1,5 @@ #include "title.h" +#include "service.h" // Constructor Title::Title(Screen *screen, Asset *asset, Input *input, options_t *options, Lang *lang, param_t *param, section_t *section, JA_Music_t *music) @@ -248,14 +249,14 @@ void Title::checkInput() ////////////////////////////////////////////////// // Comprueba el teclado para salir - if (input->checkInput(input_exit, DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) + if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { section->name = SECTION_PROG_QUIT; section->options = SECTION_OPTIONS_QUIT_NORMAL; } // Comprueba el teclado para empezar a jugar - if (input->checkInput(input_start, false, INPUT_USE_KEYBOARD)) + if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { if (section->options == SECTION_OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP) { @@ -284,6 +285,10 @@ void Title::checkInput() defineButtons->enable(0); break; + case SERVICE_SWAP_CONTROLLERS: + defineButtons->swapControllers(); + break; + default: break; } @@ -291,7 +296,7 @@ void Title::checkInput() // Comprueba el botón de START de los mandos for (int i = 0; i < input->getNumControllers(); ++i) { - if (input->checkInput(input_start, false, INPUT_USE_GAMECONTROLLER, i)) + if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) { if (section->options == SECTION_OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP) { diff --git a/source/title.h b/source/title.h index d49b18e..a1ac30b 100644 --- a/source/title.h +++ b/source/title.h @@ -20,7 +20,6 @@ #include "tiledbg.h" #include "game_logo.h" #include "define_buttons.h" -#include "service.h" // Textos #define TEXT_COPYRIGHT "@2020,2024 JailDesigner"