Afegit global_inputs.c

El audio no es podía mutejar amb el teclat, soles amb els mandos
This commit is contained in:
2024-09-28 17:08:09 +02:00
parent 289d01b0fa
commit 4febe8b7c0
11 changed files with 112 additions and 301 deletions

84
source/global_inputs.cpp Normal file
View File

@@ -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;
}
}
}

2
source/global_inputs.h Normal file
View File

@@ -0,0 +1,2 @@
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
void checkGlobalInputs();

View File

@@ -1,7 +1,8 @@
#include "hiscore_table.h"
#include "param.h"
#include "options.h"
#include <iostream> #include <iostream>
#include "global_inputs.h"
#include "hiscore_table.h"
#include "options.h"
#include "param.h"
// Constructor // Constructor
HiScoreTable::HiScoreTable(JA_Music_t *music) HiScoreTable::HiScoreTable(JA_Music_t *music)
@@ -192,21 +193,6 @@ void HiScoreTable::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void HiScoreTable::checkInput() 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) // Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
if (input->checkAnyButtonPressed()) if (input->checkAnyButtonPressed())
{ {
@@ -216,36 +202,11 @@ void HiScoreTable::checkInput()
return; 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 // Comprueba el input para el resto de objetos
screen->checkInput(); screen->checkInput();
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
checkGlobalInputs();
} }
// Bucle para la pantalla de instrucciones // Bucle para la pantalla de instrucciones
@@ -341,18 +302,4 @@ std::string HiScoreTable::format(int number)
} }
return result; 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));
}
} }

View File

@@ -1,6 +1,7 @@
#include "instructions.h" #include "instructions.h"
#include "param.h" #include "param.h"
#include "options.h" #include "options.h"
#include "global_inputs.h"
#include <iostream> #include <iostream>
// Constructor // Constructor
@@ -322,21 +323,6 @@ void Instructions::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Instructions::checkInput() 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) // Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
if (input->checkAnyButtonPressed()) if (input->checkAnyButtonPressed())
{ {
@@ -346,36 +332,11 @@ void Instructions::checkInput()
return; 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 // Comprueba el input para el resto de objetos
screen->checkInput(); screen->checkInput();
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
checkGlobalInputs();
} }
// Bucle para la pantalla de instrucciones // Bucle para la pantalla de instrucciones
@@ -388,18 +349,4 @@ void Instructions::run()
checkEvents(); // Tiene que ir antes del render checkEvents(); // Tiene que ir antes del render
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));
}
} }

View File

@@ -81,9 +81,6 @@ private:
// Recarga todas las texturas // Recarga todas las texturas
void reloadTextures(); void reloadTextures();
// Termina
void quit(section::options_e code);
public: public:
// Constructor // Constructor
Instructions(JA_Music_t *music); Instructions(JA_Music_t *music);

View File

@@ -1,6 +1,7 @@
#include "global_inputs.h"
#include "intro.h" #include "intro.h"
#include "param.h"
#include "options.h" #include "options.h"
#include "param.h"
// Constructor // Constructor
Intro::Intro(JA_Music_t *music) Intro::Intro(JA_Music_t *music)
@@ -192,21 +193,6 @@ void Intro::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Intro::checkInput() 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) // Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
if (input->checkAnyButtonPressed()) if (input->checkAnyButtonPressed())
{ {
@@ -216,36 +202,11 @@ void Intro::checkInput()
return; 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 // Comprueba el input para el resto de objetos
screen->checkInput(); screen->checkInput();
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
checkGlobalInputs();
} }
// Actualiza las escenas de la intro // Actualiza las escenas de la intro
@@ -467,18 +428,4 @@ void Intro::run()
checkEvents(); // Tiene que ir antes del render checkEvents(); // Tiene que ir antes del render
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));
}
} }

View File

@@ -55,9 +55,6 @@ private:
// Recarga todas las texturas // Recarga todas las texturas
void reloadTextures(); void reloadTextures();
// Termina
void quit(section::options_e code);
public: public:
// Constructor // Constructor
Intro(JA_Music_t *music); Intro(JA_Music_t *music);

View File

@@ -1,6 +1,7 @@
#include "logo.h" #include "logo.h"
#include "param.h" #include "param.h"
#include "options.h" #include "options.h"
#include "global_inputs.h"
#include <iostream> #include <iostream>
// Constructor // Constructor
@@ -103,21 +104,6 @@ void Logo::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Logo::checkInput() 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) // Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
if (input->checkAnyButtonPressed()) if (input->checkAnyButtonPressed())
{ {
@@ -127,36 +113,11 @@ void Logo::checkInput()
return; 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 // Comprueba el input para el resto de objetos
screen->checkInput(); screen->checkInput();
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
checkGlobalInputs();
} }
// Gestiona el logo de JAILGAME // Gestiona el logo de JAILGAME
@@ -348,18 +309,4 @@ void Logo::run()
checkEvents(); // Tiene que ir antes del render checkEvents(); // Tiene que ir antes del render
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));
}
} }

View File

@@ -66,9 +66,6 @@ private:
// Recarga todas las texturas // Recarga todas las texturas
void reloadTextures(); void reloadTextures();
// Termina
void quit(section::options_e code);
public: public:
// Constructor // Constructor
Logo(); Logo();

View File

@@ -1,6 +1,7 @@
#include "title.h" #include "global_inputs.h"
#include "param.h"
#include "options.h" #include "options.h"
#include "param.h"
#include "title.h"
// Constructor // Constructor
Title::Title(JA_Music_t *music) Title::Title(JA_Music_t *music)
@@ -247,21 +248,6 @@ void Title::checkInput()
// TECLADO // // 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 // Comprueba el teclado para empezar a jugar
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) 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) 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 // 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)) 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 // Comprueba el input para el resto de objetos
screen->checkInput(); screen->checkInput();
defineButtons->checkInput(); defineButtons->checkInput();
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
checkGlobalInputs();
} }
// Bucle para el titulo del juego // Bucle para el titulo del juego
@@ -402,18 +365,4 @@ void Title::swapControllers()
screen->showNotification(text[0], text[1]); screen->showNotification(text[0], text[1]);
resetCounter(); 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));
}
} }

View File

@@ -96,9 +96,6 @@ private:
// Intercambia la asignación de mandos a los jugadores // Intercambia la asignación de mandos a los jugadores
void swapControllers(); void swapControllers();
// Termina
void quit(section::options_e code);
public: public:
// Constructor // Constructor
Title(JA_Music_t *music); Title(JA_Music_t *music);