From 938e4ad0114956e9c2dbbda0746476a98df4f56c Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 3 Oct 2024 17:37:33 +0200 Subject: [PATCH] =?UTF-8?q?La=20targeta=20d'ajuda=20ja=20ix=20amb=20els=20?= =?UTF-8?q?mandos=20i=20s'ha=20de=20deixar=20apretat=20el=20bot=C3=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/director.cpp | 31 +++---- source/game.cpp | 4 +- source/global_inputs.cpp | 171 ++++++++++++++++++++++++--------------- source/global_inputs.h | 11 ++- source/hiscore_table.cpp | 38 ++++----- source/instructions.cpp | 42 +++++----- source/intro.cpp | 36 ++++----- source/logo.cpp | 28 +++---- source/title.cpp | 4 +- 9 files changed, 209 insertions(+), 156 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index e9ffc3d..204a230 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -19,20 +19,21 @@ #include "asset.h" // for Asset, assetType #include "dbgtxt.h" // for dbg_init #include "game.h" // for Game, GAME_MODE_DEMO_OFF, GAME_... -#include "hiscore_table.h" // for HiScoreTable -#include "input.h" // for inputs_e, Input -#include "instructions.h" // for Instructions -#include "intro.h" // for Intro -#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound -#include "logo.h" // for Logo -#include "manage_hiscore_table.h" // for ManageHiScoreTable -#include "on_screen_help.h" // for OnScreenHelp -#include "options.h" // for options, loadOptionsFile, saveO... -#include "param.h" // for param, loadParamsFromFile -#include "screen.h" // for Screen -#include "section.h" // for name_e, name, options, options_e -#include "title.h" // for Title -#include "utils.h" // for music_file_t, sound_file_t, opt... +#include "global_inputs.h" +#include "hiscore_table.h" // for HiScoreTable +#include "input.h" // for inputs_e, Input +#include "instructions.h" // for Instructions +#include "intro.h" // for Intro +#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound +#include "logo.h" // for Logo +#include "manage_hiscore_table.h" // for ManageHiScoreTable +#include "on_screen_help.h" // for OnScreenHelp +#include "options.h" // for options, loadOptionsFile, saveO... +#include "param.h" // for param, loadParamsFromFile +#include "screen.h" // for Screen +#include "section.h" // for name_e, name, options, options_e +#include "title.h" // for Title +#include "utils.h" // for music_file_t, sound_file_t, opt... #ifndef _WIN32 #include // for getpwuid, passwd @@ -106,6 +107,8 @@ Director::Director(int argc, char *argv[]) // Carga las musicas del juego loadMusics(); + + globalInputs::init(); } Director::~Director() diff --git a/source/game.cpp b/source/game.cpp index bfcd3f0..724c1ad 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -16,7 +16,7 @@ #include "enemy_formations.h" // for stage_t, EnemyFormations, enemyIni... #include "explosions.h" // for Explosions #include "fade.h" // for Fade, FADE_RANDOM_SQUARE, FADE_VEN... -#include "global_inputs.h" // for checkGlobalInputs +#include "global_inputs.h" // for globalInputs::check #include "input.h" // for inputs_e, Input, INPUT_DO_NOT_ALLO... #include "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK #include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L... @@ -2306,7 +2306,7 @@ void Game::checkInput() screen->checkInput(); // Comprueba los inputs que se pueden introducir en cualquier sección del juego - checkGlobalInputs(); + globalInputs::check(); } // Pinta diferentes mensajes en la pantalla diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index 04cde0b..3958fd4 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -9,86 +9,129 @@ #include "section.h" // for options_e, name, name_e, options #include "utils.h" // for op_audio_t, options_t, op_music_t, boolToOnOff -// Termina -void quit(section::options_e code) +namespace globalInputs { - if (Screen::get()->notificationsAreActive()) - { - section::name = section::NAME_QUIT; - section::options = code; - } - else - { - Screen::get()->showNotification(lang::getText(94)); - } -} + // Variables + std::vector servicePressedCounter; -// 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)) + // Inicializa variables + void init() { - 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_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) - { - OnScreenHelp::get()->toggleState(); - 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)) + const int numInputs = Input::get()->getNumControllers() + 1; + servicePressedCounter.reserve(numInputs); + for (int i = 0; i < numInputs; ++i) { - quit(section::OPTIONS_QUIT_SHUTDOWN); + 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()->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) + else if (Input::get()->checkInput(input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) { 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)) + 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; + } + } } } \ No newline at end of file diff --git a/source/global_inputs.h b/source/global_inputs.h index 37e86dd..f905641 100644 --- a/source/global_inputs.h +++ b/source/global_inputs.h @@ -1,2 +1,9 @@ -// Comprueba los inputs que se pueden introducir en cualquier sección del juego -void checkGlobalInputs(); \ No newline at end of file +namespace globalInputs +{ + + // Inicializa variables + void init(); + + // Comprueba los inputs que se pueden introducir en cualquier sección del juego + void check(); +} \ No newline at end of file diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 69eebd2..01537d5 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -1,22 +1,22 @@ #include "hiscore_table.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_GetTicks -#include // for SDL_WINDOWEVENT_SIZE_CHANGED -#include // for max -#include // for vector -#include "asset.h" // for Asset -#include "background.h" // for Background -#include "fade.h" // for Fade, FADE_IN, FADE_OUT, FADE_RANDOM... -#include "global_inputs.h" // for checkGlobalInputs -#include "input.h" // for Input -#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state -#include "lang.h" // for getText -#include "options.h" // for options -#include "param.h" // for param -#include "screen.h" // for Screen -#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW, TXT_COLOR -#include "utils.h" // for param_t, paramGame_t, hiScoreEntry_t +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_GetTicks +#include // for SDL_WINDOWEVENT_SIZE_CHANGED +#include // for max +#include // for vector +#include "asset.h" // for Asset +#include "background.h" // for Background +#include "fade.h" // for Fade, FADE_IN, FADE_OUT, FADE_RANDOM... +#include "global_inputs.h" // for globalInputs::check +#include "input.h" // for Input +#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state +#include "lang.h" // for getText +#include "options.h" // for options +#include "param.h" // for param +#include "screen.h" // for Screen +#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW, TXT_COLOR +#include "utils.h" // for param_t, paramGame_t, hiScoreEntry_t // Constructor HiScoreTable::HiScoreTable(JA_Music_t *music) @@ -220,7 +220,7 @@ void HiScoreTable::checkInput() screen->checkInput(); // Comprueba los inputs que se pueden introducir en cualquier sección del juego - checkGlobalInputs(); + globalInputs::check(); } // Bucle para la pantalla de instrucciones diff --git a/source/instructions.cpp b/source/instructions.cpp index 6becc67..63305ba 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -1,24 +1,24 @@ #include "instructions.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_GetTicks -#include // for SDL_WINDOWEVENT_SIZE_CHANGED -#include // for max -#include // for basic_string -#include "asset.h" // for Asset -#include "fade.h" // for Fade, FADE_FULLSCREEN, FADE_IN -#include "global_inputs.h" // for checkGlobalInputs -#include "input.h" // for Input -#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state -#include "lang.h" // for getText -#include "param.h" // for param -#include "screen.h" // for Screen -#include "section.h" // for name, name_e, options, options_e -#include "sprite.h" // for Sprite -#include "text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_SHADOW -#include "texture.h" // for Texture -#include "tiled_bg.h" // for Tiledbg, TILED_MODE_STATIC -#include "utils.h" // for param_t, paramGame_t, color_t, shdwT... +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_GetTicks +#include // for SDL_WINDOWEVENT_SIZE_CHANGED +#include // for max +#include // for basic_string +#include "asset.h" // for Asset +#include "fade.h" // for Fade, FADE_FULLSCREEN, FADE_IN +#include "global_inputs.h" // for globalInputs::check +#include "input.h" // for Input +#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state +#include "lang.h" // for getText +#include "param.h" // for param +#include "screen.h" // for Screen +#include "section.h" // for name, name_e, options, options_e +#include "sprite.h" // for Sprite +#include "text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_SHADOW +#include "texture.h" // for Texture +#include "tiled_bg.h" // for Tiledbg, TILED_MODE_STATIC +#include "utils.h" // for param_t, paramGame_t, color_t, shdwT... struct JA_Music_t; // Constructor @@ -353,7 +353,7 @@ void Instructions::checkInput() screen->checkInput(); // Comprueba los inputs que se pueden introducir en cualquier sección del juego - checkGlobalInputs(); + globalInputs::check(); } // Bucle para la pantalla de instrucciones diff --git a/source/intro.cpp b/source/intro.cpp index 4e7910c..0396afc 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -1,21 +1,21 @@ #include "intro.h" -#include // for SDL_Renderer -#include // for SDL_GetTicks -#include // for SDL_WINDOWEVENT_SIZE_CHANGED -#include // for basic_string -#include "asset.h" // for Asset -#include "global_inputs.h" // for checkGlobalInputs -#include "input.h" // for Input -#include "jail_audio.h" // for JA_StopMusic, JA_PlayMusic -#include "lang.h" // for getText -#include "param.h" // for param -#include "screen.h" // for Screen -#include "section.h" // for name, name_e, options, options_e -#include "smart_sprite.h" // for SmartSprite -#include "text.h" // for Text -#include "texture.h" // for Texture -#include "utils.h" // for paramGame_t, param_t, zone_t, BLOCK -#include "writer.h" // for Writer +#include // for SDL_Renderer +#include // for SDL_GetTicks +#include // for SDL_WINDOWEVENT_SIZE_CHANGED +#include // for basic_string +#include "asset.h" // for Asset +#include "global_inputs.h" // for globalInputs::check +#include "input.h" // for Input +#include "jail_audio.h" // for JA_StopMusic, JA_PlayMusic +#include "lang.h" // for getText +#include "param.h" // for param +#include "screen.h" // for Screen +#include "section.h" // for name, name_e, options, options_e +#include "smart_sprite.h" // for SmartSprite +#include "text.h" // for Text +#include "texture.h" // for Texture +#include "utils.h" // for paramGame_t, param_t, zone_t, BLOCK +#include "writer.h" // for Writer struct JA_Music_t; // Constructor @@ -221,7 +221,7 @@ void Intro::checkInput() screen->checkInput(); // Comprueba los inputs que se pueden introducir en cualquier sección del juego - checkGlobalInputs(); + globalInputs::check(); } // Actualiza las escenas de la intro diff --git a/source/logo.cpp b/source/logo.cpp index c228a12..87f062a 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,17 +1,17 @@ #include "logo.h" -#include // for SDL_Renderer -#include // for SDL_GetTicks -#include // for SDL_WINDOWEVENT_SIZE_CHANGED -#include // for basic_string -#include "asset.h" // for Asset -#include "global_inputs.h" // for checkGlobalInputs -#include "input.h" // for Input -#include "jail_audio.h" // for JA_StopMusic -#include "param.h" // for param -#include "screen.h" // for Screen -#include "section.h" // for name, name_e, options, options_e -#include "sprite.h" // for Sprite -#include "texture.h" // for Texture +#include // for SDL_Renderer +#include // for SDL_GetTicks +#include // for SDL_WINDOWEVENT_SIZE_CHANGED +#include // for basic_string +#include "asset.h" // for Asset +#include "global_inputs.h" // for globalInputs::check +#include "input.h" // for Input +#include "jail_audio.h" // for JA_StopMusic +#include "param.h" // for param +#include "screen.h" // for Screen +#include "section.h" // for name, name_e, options, options_e +#include "sprite.h" // for Sprite +#include "texture.h" // for Texture // Constructor Logo::Logo() @@ -126,7 +126,7 @@ void Logo::checkInput() screen->checkInput(); // Comprueba los inputs que se pueden introducir en cualquier sección del juego - checkGlobalInputs(); + globalInputs::check(); } // Gestiona el logo de JAILGAME diff --git a/source/title.cpp b/source/title.cpp index 259586c..9594168 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -8,7 +8,7 @@ #include "define_buttons.h" // for DefineButtons #include "fade.h" // for Fade, FADE_RANDOM_SQUARE #include "game_logo.h" // for GameLogo -#include "global_inputs.h" // for checkGlobalInputs +#include "global_inputs.h" // for globalInputs::check #include "input.h" // for Input, inputs_e, INPUT_DO_NOT_ALLOW_RE... #include "jail_audio.h" // for JA_GetMusicState, JA_Music_state, JA_P... #include "lang.h" // for getText @@ -318,7 +318,7 @@ void Title::checkInput() defineButtons->checkInput(); // Comprueba los inputs que se pueden introducir en cualquier sección del juego - checkGlobalInputs(); + globalInputs::check(); } // Bucle para el titulo del juego