145 lines
4.6 KiB
C++
145 lines
4.6 KiB
C++
#include "global_inputs.h"
|
|
#include <string> // 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 "notifier.h" // for Notifier
|
|
#include "options.h" // for options
|
|
#include "on_screen_help.h"
|
|
#include "screen.h" // for Screen
|
|
#include "section.h" // for SectionOptions, name, SectionName, options
|
|
#include "utils.h" // for OptionsAudio, Options, OptionsMusic, boolToOnOff
|
|
|
|
namespace globalInputs
|
|
{
|
|
// Variables
|
|
std::vector<int> service_pressed_counter;
|
|
|
|
// Inicializa variables
|
|
void init()
|
|
{
|
|
const auto num_inputs = Input::get()->getNumControllers() + 1;
|
|
service_pressed_counter.reserve(num_inputs);
|
|
for (int i = 0; i < num_inputs; ++i)
|
|
{
|
|
service_pressed_counter.push_back(0);
|
|
}
|
|
}
|
|
|
|
// Termina
|
|
void quit(section::Options code)
|
|
{
|
|
const std::string exit_code = "QUIT";
|
|
auto code_found = stringInVector(Notifier::get()->getCodes(), exit_code);
|
|
if (code_found)
|
|
{
|
|
section::name = section::Name::QUIT;
|
|
section::options = code;
|
|
}
|
|
else
|
|
{
|
|
#ifdef ARCADE
|
|
const int index = code == section::Options::QUIT_NORMAL ? 94 : 116;
|
|
Notifier::get()->showText(lang::getText(index), std::string(), -1, exit_code);
|
|
#else
|
|
Notifier::get()->showText(lang::getText(94), std::string(), -1, exit_code);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
// Reinicia
|
|
void reset()
|
|
{
|
|
section::name = section::Name::INIT;
|
|
Notifier::get()->showText("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);
|
|
Notifier::get()->showText("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(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
{
|
|
quit(section::Options::QUIT_WITH_KEYBOARD);
|
|
return;
|
|
}
|
|
|
|
// Comprueba si se va a resetear el juego
|
|
else if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
{
|
|
reset();
|
|
return;
|
|
}
|
|
|
|
else if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
{
|
|
switchAudio();
|
|
return;
|
|
}
|
|
|
|
else if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
{
|
|
service_pressed_counter[0]++;
|
|
|
|
if (service_pressed_counter[0] >= 3000)
|
|
{
|
|
OnScreenHelp::get()->toggleState();
|
|
service_pressed_counter[0] = 0;
|
|
}
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
service_pressed_counter[0] = 0;
|
|
}
|
|
|
|
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
|
{
|
|
// Comprueba si se sale con el mando
|
|
if (Input::get()->checkModInput(InputType::SERVICE, InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
{
|
|
quit(section::Options::QUIT_WITH_CONTROLLER);
|
|
return;
|
|
}
|
|
|
|
// Comprueba si se va a resetear el juego
|
|
else if (Input::get()->checkModInput(InputType::SERVICE, InputType::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(InputType::SERVICE, InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
{
|
|
switchAudio();
|
|
return;
|
|
}
|
|
|
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
{
|
|
service_pressed_counter[i + 1]++;
|
|
|
|
if (service_pressed_counter[i + 1] >= 3000)
|
|
{
|
|
OnScreenHelp::get()->toggleState();
|
|
service_pressed_counter[i + 1] = 0;
|
|
}
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
service_pressed_counter[i + 1] = 0;
|
|
}
|
|
}
|
|
}
|
|
} |