Ja es pot gastar el teclat com a control independent del primer mando
Ja pot jugar un jugador amb teclat i altre amb mando Es pot asignar el teclat a qualsevol dels dos jugadors Continua podentse gastar mando i teclat a l'hora per al mateix jugador
This commit is contained in:
@@ -16,11 +16,7 @@ DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
|
||||
x_ = param.game.width / 2;
|
||||
y_ = param.title.press_start_position;
|
||||
|
||||
buttons_.emplace_back(lang::getText(95), InputType::FIRE_LEFT, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(96), InputType::FIRE_CENTER, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(97), InputType::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(98), InputType::START, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(99), InputType::SERVICE, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
clearButtons();
|
||||
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||
{
|
||||
@@ -33,7 +29,7 @@ void DefineButtons::render()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
text_->writeCentered(x_, y_ - 10, lang::getText(100) + std::to_string(options.controller.at(index_controller_).player_id));
|
||||
text_->writeCentered(x_, y_ - 10, lang::getText(100) + std::to_string(options.controllers.at(index_controller_).player_id));
|
||||
text_->writeCentered(x_, y_, controller_names_.at(index_controller_));
|
||||
text_->writeCentered(x_, y_ + 10, buttons_.at(index_button_).label);
|
||||
}
|
||||
@@ -103,6 +99,7 @@ bool DefineButtons::enable(int index)
|
||||
enabled_ = true;
|
||||
index_controller_ = index;
|
||||
index_button_ = 0;
|
||||
clearButtons();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -126,9 +123,9 @@ void DefineButtons::incIndexButton()
|
||||
// Guarda los cambios en las opciones
|
||||
saveBindingsToOptions();
|
||||
|
||||
// Reinicia variables
|
||||
index_button_ = 0;
|
||||
index_controller_ = 0;
|
||||
// Deshabilita
|
||||
//index_controller_ = 0;
|
||||
//index_button_ = 0;
|
||||
enabled_ = false;
|
||||
}
|
||||
}
|
||||
@@ -137,7 +134,7 @@ void DefineButtons::incIndexButton()
|
||||
void DefineButtons::saveBindingsToOptions()
|
||||
{
|
||||
// Modifica las opciones para colocar los valores asignados
|
||||
auto &controller = options.controller.at(index_controller_);
|
||||
auto &controller = options.controllers.at(index_controller_);
|
||||
controller.name = input_->getControllerName(index_controller_);
|
||||
for (size_t j = 0; j < controller.inputs.size(); ++j)
|
||||
{
|
||||
@@ -145,12 +142,6 @@ void DefineButtons::saveBindingsToOptions()
|
||||
}
|
||||
}
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void DefineButtons::swapControllers()
|
||||
{
|
||||
std::swap(options.controller[0].player_id, options.controller[1].player_id);
|
||||
}
|
||||
|
||||
// Comprueba que un botón no esté ya asignado
|
||||
bool DefineButtons::checkButtonNotInUse(SDL_GameControllerButton button)
|
||||
{
|
||||
@@ -163,3 +154,14 @@ bool DefineButtons::checkButtonNotInUse(SDL_GameControllerButton button)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Limpia la asignación de botones
|
||||
void DefineButtons::clearButtons()
|
||||
{
|
||||
buttons_.clear();
|
||||
buttons_.emplace_back(lang::getText(95), InputType::FIRE_LEFT, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(96), InputType::FIRE_CENTER, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(97), InputType::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(98), InputType::START, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(99), InputType::SERVICE, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
}
|
||||
@@ -52,6 +52,9 @@ private:
|
||||
// Comprueba que un botón no esté ya asignado
|
||||
bool checkButtonNotInUse(SDL_GameControllerButton button);
|
||||
|
||||
// Limpia la asignación de botones
|
||||
void clearButtons();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit DefineButtons(std::unique_ptr<Text> text);
|
||||
@@ -70,7 +73,4 @@ public:
|
||||
|
||||
// Comprueba si está habilitado
|
||||
bool isEnabled();
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void swapControllers();
|
||||
};
|
||||
@@ -192,16 +192,16 @@ void Director::bindInputs()
|
||||
}
|
||||
|
||||
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
|
||||
for (size_t i = 0; i < num_gamepads; ++i)
|
||||
const size_t max_controllers = std::min(2, num_gamepads);
|
||||
for (size_t i = 0; i < max_controllers; ++i)
|
||||
{
|
||||
for (size_t index = 0; index < options.controller.size(); ++index)
|
||||
for (auto &controller : options.controllers)
|
||||
{
|
||||
if (Input::get()->getControllerName(i) == options.controller.at(index).name)
|
||||
if (Input::get()->getControllerName(i) == controller.name)
|
||||
{
|
||||
options.controller.at(index).plugged = true;
|
||||
for (size_t j = 0; j < options.controller.at(index).inputs.size(); ++j)
|
||||
for (size_t j = 0; j < controller.inputs.size(); ++j)
|
||||
{
|
||||
Input::get()->bindGameControllerButton(i, options.controller.at(index).inputs.at(j), options.controller.at(index).buttons.at(j));
|
||||
Input::get()->bindGameControllerButton(i, controller.inputs.at(j), controller.buttons.at(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,13 +220,17 @@ void Director::bindInputs()
|
||||
Input::get()->bindGameControllerButton(i, InputType::SWAP_CONTROLLERS, InputType::UP);
|
||||
}
|
||||
|
||||
// Guarda las asignaciones de botones en las opciones
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
// Guarda las asignaciones de botones en las opciones de los dos primeros mandos
|
||||
for (size_t i = 0; i < max_controllers; ++i)
|
||||
{
|
||||
options.controller.at(i).name = Input::get()->getControllerName(i);
|
||||
for (size_t j = 0; j < options.controller.at(i).inputs.size(); ++j)
|
||||
// Variables asociadas al mando
|
||||
options.controllers.at(i).index = i;
|
||||
options.controllers.at(i).name = Input::get()->getControllerName(i);
|
||||
options.controllers.at(i).plugged = true;
|
||||
// Asignaciones de botones
|
||||
for (size_t j = 0; j < options.controllers.at(i).inputs.size(); ++j)
|
||||
{
|
||||
options.controller.at(i).buttons.at(j) = Input::get()->getControllerBinding(i, options.controller.at(i).inputs.at(j));
|
||||
options.controllers.at(i).buttons.at(j) = Input::get()->getControllerBinding(i, options.controllers.at(i).inputs.at(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1591,12 +1591,12 @@ std::shared_ptr<Player> Game::getPlayer(int id)
|
||||
// Obtiene un controlador a partir del "id" del jugador
|
||||
int Game::getController(int player_id)
|
||||
{
|
||||
auto it = std::find_if(options.controller.begin(), options.controller.end(), [player_id](const auto &controller)
|
||||
auto it = std::find_if(options.controllers.begin(), options.controllers.end(), [player_id](const auto &controller)
|
||||
{ return controller.player_id == player_id; });
|
||||
|
||||
if (it != options.controller.end())
|
||||
if (it != options.controllers.end())
|
||||
{
|
||||
return std::distance(options.controller.begin(), it);
|
||||
return std::distance(options.controllers.begin(), it);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -1619,15 +1619,15 @@ void Game::checkPauseInput()
|
||||
{
|
||||
// Comprueba los mandos
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||
if (input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||
input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||
input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
pause(!paused_);
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el teclado
|
||||
if (input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
pause(!paused_);
|
||||
return;
|
||||
@@ -1723,17 +1723,17 @@ void Game::handlePlayersInput()
|
||||
// Maneja las entradas de movimiento y disparo para un jugador en modo normal.
|
||||
void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
|
||||
{
|
||||
const auto controllerIndex = player->getController();
|
||||
const auto &controller = options.controllers.at(player->getController());
|
||||
const bool autofire = player->isPowerUp() || options.game.autofire;
|
||||
|
||||
if (input_->checkInput(InputType::LEFT, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
if (input_->checkInput(InputType::LEFT, INPUT_ALLOW_REPEAT, controller.type, controller.index))
|
||||
{
|
||||
player->setInput(InputType::LEFT);
|
||||
#ifdef RECORDING
|
||||
demo_.keys.left = 1;
|
||||
#endif
|
||||
}
|
||||
else if (input_->checkInput(InputType::RIGHT, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::RIGHT, INPUT_ALLOW_REPEAT, controller.type, controller.index))
|
||||
{
|
||||
player->setInput(InputType::RIGHT);
|
||||
#ifdef RECORDING
|
||||
@@ -1748,27 +1748,27 @@ void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
|
||||
#endif
|
||||
}
|
||||
|
||||
handleFireInputs(player, autofire, controllerIndex); // Verifica y maneja todas las posibles entradas de disparo.
|
||||
handleFireInputs(player, autofire, player->getController()); // Verifica y maneja todas las posibles entradas de disparo.
|
||||
}
|
||||
|
||||
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
|
||||
void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controllerIndex)
|
||||
{
|
||||
if (input_->checkInput(InputType::FIRE_CENTER, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
if (input_->checkInput(InputType::FIRE_CENTER, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
handleFireInput(player, BulletType::UP);
|
||||
#ifdef RECORDING
|
||||
demo_.keys.fire = 1;
|
||||
#endif
|
||||
}
|
||||
else if (input_->checkInput(InputType::FIRE_LEFT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::FIRE_LEFT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
handleFireInput(player, BulletType::LEFT);
|
||||
#ifdef RECORDING
|
||||
demo_.keys.fire_left = 1;
|
||||
#endif
|
||||
}
|
||||
else if (input_->checkInput(InputType::FIRE_RIGHT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::FIRE_RIGHT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
handleFireInput(player, BulletType::RIGHT);
|
||||
#ifdef RECORDING
|
||||
@@ -1781,15 +1781,15 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
|
||||
void Game::handlePlayerContinue(const std::shared_ptr<Player> &player)
|
||||
{
|
||||
const auto controllerIndex = player->getController();
|
||||
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
player->setPlayingState(PlayerState::PLAYING);
|
||||
}
|
||||
|
||||
// Disminuye el contador de continuación si se presiona cualquier botón de disparo.
|
||||
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index) ||
|
||||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index) ||
|
||||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
||||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
||||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
player->decContinueCounter();
|
||||
}
|
||||
@@ -1799,9 +1799,9 @@ void Game::handlePlayerContinue(const std::shared_ptr<Player> &player)
|
||||
void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
||||
{
|
||||
const auto controllerIndex = player->getController();
|
||||
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index) ||
|
||||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index) ||
|
||||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
||||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
||||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
if (player->getRecordNamePos() == 7)
|
||||
{
|
||||
@@ -1815,15 +1815,15 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
||||
player->setInput(InputType::RIGHT);
|
||||
}
|
||||
}
|
||||
else if (input_->checkInput(InputType::UP, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::UP, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
player->setInput(InputType::UP);
|
||||
}
|
||||
else if (input_->checkInput(InputType::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
player->setInput(InputType::DOWN);
|
||||
}
|
||||
else if (input_->checkInput(InputType::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
player->setInput(InputType::LEFT);
|
||||
}
|
||||
@@ -1833,7 +1833,7 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
||||
player->setInput(InputType::RIGHT);
|
||||
}
|
||||
*/
|
||||
else if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
player->setInput(InputType::START);
|
||||
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace globalInputs
|
||||
{
|
||||
#ifndef ARCADE
|
||||
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
||||
if (Input::get()->checkInput(InputType::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
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 ? "Window" : "Fullscreen";
|
||||
@@ -87,7 +87,7 @@ namespace globalInputs
|
||||
}
|
||||
|
||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||
if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
Screen::get()->decWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
@@ -96,7 +96,7 @@ namespace globalInputs
|
||||
}
|
||||
|
||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||
if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
Screen::get()->incWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
@@ -105,28 +105,28 @@ namespace globalInputs
|
||||
}
|
||||
#endif
|
||||
// Salir
|
||||
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
quit(section::Options::QUIT_WITH_KEYBOARD);
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset
|
||||
if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
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, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
toggleAudio();
|
||||
return;
|
||||
}
|
||||
|
||||
// Shaders
|
||||
if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
Screen::get()->toggleShaders();
|
||||
return;
|
||||
@@ -134,14 +134,14 @@ namespace globalInputs
|
||||
|
||||
#ifdef DEBUG
|
||||
// Comprueba el teclado para mostrar la información de debug
|
||||
if (Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
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, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
service_pressed_counter[0]++;
|
||||
|
||||
@@ -161,47 +161,47 @@ namespace globalInputs
|
||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||
{
|
||||
// Salir
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
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, INPUT_USE_GAMECONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
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, INPUT_USE_GAMECONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
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, INPUT_USE_GAMECONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
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))
|
||||
{
|
||||
Screen::get()->toggleShaders();
|
||||
return;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
// Debug Info
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
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, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
service_pressed_counter[i + 1]++;
|
||||
|
||||
|
||||
@@ -68,18 +68,13 @@ void Input::bindGameControllerButton(int controller_index, InputType input_targe
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool Input::checkInput(InputType input, bool repeat, int device, int controller_index)
|
||||
bool Input::checkInput(InputType input, bool repeat, InputDeviceToUse device, int controller_index)
|
||||
{
|
||||
bool success_keyboard = false;
|
||||
bool success_controller = false;
|
||||
const int input_index = static_cast<int>(input);
|
||||
|
||||
if (device == INPUT_USE_ANY)
|
||||
{
|
||||
controller_index = 0;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
@@ -123,8 +118,8 @@ bool Input::checkInput(InputType input, bool repeat, int device, int controller_
|
||||
}
|
||||
}
|
||||
|
||||
if (gameControllerFound() && controller_index < num_gamepads_)
|
||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
||||
if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_)
|
||||
if ((device == InputDeviceToUse::CONTROLLER) || (device == InputDeviceToUse::ANY))
|
||||
{
|
||||
success_controller = checkAxisInput(input, controller_index);
|
||||
if (!success_controller)
|
||||
@@ -174,14 +169,14 @@ bool Input::checkInput(InputType input, bool repeat, int device, int controller_
|
||||
}
|
||||
|
||||
// Comprueba si hay almenos un input activo
|
||||
bool Input::checkAnyInput(int device, int controller_index)
|
||||
bool Input::checkAnyInput(InputDeviceToUse device, int controller_index)
|
||||
{
|
||||
if (device == INPUT_USE_ANY)
|
||||
if (device == InputDeviceToUse::ANY)
|
||||
{
|
||||
controller_index = 0;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
@@ -197,7 +192,7 @@ bool Input::checkAnyInput(int device, int controller_index)
|
||||
|
||||
if (gameControllerFound())
|
||||
{
|
||||
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY)
|
||||
if (device == InputDeviceToUse::CONTROLLER || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
for (int i = 0; i < (int)controller_bindings_.size(); ++i)
|
||||
{
|
||||
@@ -217,7 +212,7 @@ bool Input::checkAnyInput(int device, int controller_index)
|
||||
int Input::checkAnyButtonPressed(bool repeat)
|
||||
{
|
||||
// Si está pulsado el botón de servicio, ningún botón se puede considerar pulsado
|
||||
if (checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_ANY))
|
||||
if (checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::ANY))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -226,7 +221,7 @@ int Input::checkAnyButtonPressed(bool repeat)
|
||||
for (auto bi : button_inputs_)
|
||||
{
|
||||
// Comprueba el teclado
|
||||
if (checkInput(bi, repeat, INPUT_USE_KEYBOARD))
|
||||
if (checkInput(bi, repeat, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -234,7 +229,7 @@ int Input::checkAnyButtonPressed(bool repeat)
|
||||
// Comprueba los mandos
|
||||
for (int i = 0; i < num_gamepads_; ++i)
|
||||
{
|
||||
if (checkInput(bi, repeat, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (checkInput(bi, repeat, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
return i + 1;
|
||||
}
|
||||
@@ -328,14 +323,14 @@ int Input::getJoyIndex(int id) const
|
||||
}
|
||||
|
||||
// Muestra por consola los controles asignados
|
||||
void Input::printBindings(int device, int controller_index) const
|
||||
void Input::printBindings(InputDeviceToUse device, int controller_index) const
|
||||
{
|
||||
if (device == INPUT_USE_ANY || device == INPUT_USE_KEYBOARD)
|
||||
if (device == InputDeviceToUse::ANY || device == InputDeviceToUse::KEYBOARD)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_GAMECONTROLLER)
|
||||
if (device == InputDeviceToUse::CONTROLLER)
|
||||
{
|
||||
if (controller_index >= num_gamepads_)
|
||||
{
|
||||
@@ -417,3 +412,9 @@ bool Input::checkAxisInput(InputType input, int controller_index) const
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el indice de mando que usará el teclado
|
||||
void Input::setKeyboardIndex(int index)
|
||||
{
|
||||
keyboard_index_ = index;
|
||||
}
|
||||
@@ -11,9 +11,9 @@
|
||||
connectedControllers es un vector donde estan todos los mandos encontrados [0 .. n]
|
||||
checkInput requiere de un indice para comprobar las pulsaciónes de un controlador en concreto [0 .. n]
|
||||
device contiene el tipo de dispositivo a comprobar:
|
||||
INPUT_USE_KEYBOARD solo mirará el teclado
|
||||
INPUT_USE_GAMECONTROLLER solo mirará el controlador especificado (Si no se especifica, el primero)
|
||||
INPUT_USE_ANY mirará tanto el teclado como el PRIMER controlador
|
||||
InputDeviceToUse::KEYBOARD solo mirará el teclado
|
||||
InputDeviceToUse::CONTROLLER solo mirará el controlador especificado (Si no se especifica, el primero)
|
||||
InputDeviceToUse::ANY mirará tanto el teclado como el PRIMER controlador
|
||||
*/
|
||||
|
||||
enum class InputType : int
|
||||
@@ -52,9 +52,12 @@ enum class InputType : int
|
||||
constexpr bool INPUT_ALLOW_REPEAT = true;
|
||||
constexpr bool INPUT_DO_NOT_ALLOW_REPEAT = false;
|
||||
|
||||
constexpr int INPUT_USE_KEYBOARD = 0;
|
||||
constexpr int INPUT_USE_GAMECONTROLLER = 1;
|
||||
constexpr int INPUT_USE_ANY = 2;
|
||||
enum class InputDeviceToUse : int
|
||||
{
|
||||
KEYBOARD = 0,
|
||||
CONTROLLER = 1,
|
||||
ANY = 2,
|
||||
};
|
||||
|
||||
class Input
|
||||
{
|
||||
@@ -92,6 +95,7 @@ private:
|
||||
int num_joysticks_ = 0; // Número de joysticks conectados
|
||||
int num_gamepads_ = 0; // Número de mandos conectados
|
||||
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt
|
||||
int keyboard_index_ = 0;
|
||||
|
||||
// Comprueba el eje del mando
|
||||
bool checkAxisInput(InputType input, int controller_index = 0) const;
|
||||
@@ -120,10 +124,10 @@ public:
|
||||
void bindGameControllerButton(int controller_index, InputType inputTarget, InputType inputSource);
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool checkInput(InputType input, bool repeat = true, int device = INPUT_USE_ANY, int controller_index = 0);
|
||||
bool checkInput(InputType input, bool repeat = true, InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0);
|
||||
|
||||
// Comprueba si hay almenos un input activo
|
||||
bool checkAnyInput(int device = INPUT_USE_ANY, int controller_index = 0);
|
||||
bool checkAnyInput(InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0);
|
||||
|
||||
// Comprueba si hay algún botón pulsado
|
||||
int checkAnyButtonPressed(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT);
|
||||
@@ -144,7 +148,7 @@ public:
|
||||
int getJoyIndex(int id) const;
|
||||
|
||||
// Muestra por consola los controles asignados
|
||||
void printBindings(int device = INPUT_USE_KEYBOARD, int controller_index = 0) const;
|
||||
void printBindings(InputDeviceToUse device = InputDeviceToUse::KEYBOARD, int controller_index = 0) const;
|
||||
|
||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
||||
SDL_GameControllerButton getControllerBinding(int controller_index, InputType input) const;
|
||||
@@ -157,4 +161,7 @@ public:
|
||||
|
||||
// Obtiene el indice a partir del nombre del mando
|
||||
int getIndexByName(const std::string &name) const;
|
||||
|
||||
// Establece el indice de mando que usará el teclado
|
||||
void setKeyboardIndex(int index);
|
||||
};
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <fstream> // para basic_ostream, operator<<, basi...
|
||||
#include <iostream> // para cout
|
||||
#include <vector> // para vector
|
||||
#include "input.h" // para inputs_e, INPUT_USE_ANY, INPUT_...
|
||||
#include "input.h" // para inputs_e, InputDeviceToUse::ANY, INPUT_...
|
||||
#include "lang.h" // para lang_e
|
||||
#include "screen.h" // para ScreenVideoMode, ScreenFilter
|
||||
#include "utils.h" // para OptionsController, Options, op_...
|
||||
@@ -45,37 +45,11 @@ void initOptions()
|
||||
options.game.autofire = true;
|
||||
|
||||
// Opciones de control
|
||||
options.controller.clear();
|
||||
OptionsController c;
|
||||
|
||||
constexpr int num_players = 2;
|
||||
for (int index = 0; index < num_players; ++index)
|
||||
{
|
||||
c.index = index;
|
||||
c.player_id = index + 1;
|
||||
c.device_type = INPUT_USE_GAMECONTROLLER;
|
||||
c.name = "NO NAME";
|
||||
c.plugged = false;
|
||||
|
||||
// Inputs que se guardan en las opciones y, por tanto, a disco
|
||||
c.inputs.clear();
|
||||
c.inputs.push_back(InputType::FIRE_LEFT);
|
||||
c.inputs.push_back(InputType::FIRE_CENTER);
|
||||
c.inputs.push_back(InputType::FIRE_RIGHT);
|
||||
c.inputs.push_back(InputType::START);
|
||||
c.inputs.push_back(InputType::SERVICE);
|
||||
|
||||
// Botones asociados a los inputs anteriores
|
||||
c.buttons.clear();
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_X);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_Y);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_B);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_START);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_BACK);
|
||||
|
||||
options.controller.push_back(c);
|
||||
}
|
||||
options.controller.at(0).device_type = INPUT_USE_ANY; // El primer jugador puede usar tanto el teclado como el primer mando
|
||||
options.controllers.clear();
|
||||
options.controllers.resize(2);
|
||||
options.controllers.at(0).player_id = 1;
|
||||
options.controllers.at(1).player_id = 2;
|
||||
setKeyboardToPlayer(1);
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
@@ -129,12 +103,11 @@ bool loadOptionsFile(std::string file_path)
|
||||
options.video.mode = ScreenVideoMode::WINDOW;
|
||||
}
|
||||
|
||||
if (options.video.window.size < 1 || options.video.window.size > 4)
|
||||
{
|
||||
options.video.window.size = 3;
|
||||
}
|
||||
options.video.window.size = std::clamp(options.video.window.size, 1, 4);
|
||||
|
||||
if (options.game.language != lang::Code::en_UK && options.game.language != lang::Code::ba_BA && options.game.language != lang::Code::es_ES)
|
||||
if (options.game.language != lang::Code::en_UK &&
|
||||
options.game.language != lang::Code::ba_BA &&
|
||||
options.game.language != lang::Code::es_ES)
|
||||
{
|
||||
options.game.language = lang::Code::en_UK;
|
||||
}
|
||||
@@ -156,73 +129,54 @@ bool saveOptionsFile(std::string file_path)
|
||||
std::cout << "Writing file: " << getFileName(file_path) << std::endl;
|
||||
|
||||
// Opciones de video
|
||||
const auto value_video_mode_winow = std::to_string(static_cast<int>(ScreenVideoMode::WINDOW));
|
||||
const auto value_video_mode_fullscreen = std::to_string(static_cast<int>(ScreenVideoMode::FULLSCREEN));
|
||||
const auto value_filter_nearest = std::to_string(static_cast<int>(ScreenFilter::NEAREST));
|
||||
const auto value_filter_lineal = std::to_string(static_cast<int>(ScreenFilter::LINEAL));
|
||||
|
||||
file << "## VIDEO\n";
|
||||
file << "## video.mode [" << value_video_mode_winow << ": window, " << value_video_mode_fullscreen << ": fullscreen]\n";
|
||||
file << "## video.filter [" << value_filter_nearest << ": nearest, " << value_filter_lineal << ": lineal]\n";
|
||||
file << "## video.mode [" << static_cast<int>(ScreenVideoMode::WINDOW) << ": window, " << static_cast<int>(ScreenVideoMode::FULLSCREEN) << ": fullscreen]\n";
|
||||
file << "## video.filter [" << static_cast<int>(ScreenFilter::NEAREST) << ": nearest, " << static_cast<int>(ScreenFilter::LINEAL) << ": lineal]\n";
|
||||
file << "\n";
|
||||
|
||||
const auto valueVideoMode = std::to_string(static_cast<int>(options.video.mode));
|
||||
file << "video.mode=" << valueVideoMode << "\n";
|
||||
|
||||
file << "video.window.size=" + std::to_string(options.video.window.size) + "\n";
|
||||
|
||||
const auto valueFilter = std::to_string(static_cast<int>(options.video.filter));
|
||||
file << "video.filter=" << valueFilter << "\n";
|
||||
|
||||
file << "video.v_sync=" + boolToString(options.video.v_sync) + "\n";
|
||||
file << "video.integer_scale=" + boolToString(options.video.integer_scale) + "\n";
|
||||
file << "video.shaders=" + boolToString(options.video.shaders) + "\n";
|
||||
file << "video.mode=" << static_cast<int>(options.video.mode) << "\n";
|
||||
file << "video.window.size=" << options.video.window.size << "\n";
|
||||
file << "video.filter=" << static_cast<int>(options.video.filter) << "\n";
|
||||
file << "video.v_sync=" << boolToString(options.video.v_sync) << "\n";
|
||||
file << "video.integer_scale=" << boolToString(options.video.integer_scale) << "\n";
|
||||
file << "video.shaders=" << boolToString(options.video.shaders) << "\n";
|
||||
|
||||
// Opciones de audio
|
||||
file << "\n\n## AUDIO\n";
|
||||
file << "## volume [0 .. 100]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "audio.enabled=" + boolToString(options.audio.enabled) + "\n";
|
||||
file << "audio.volume=" + std::to_string(options.audio.volume) + "\n";
|
||||
file << "audio.music.enabled=" + boolToString(options.audio.music.enabled) + "\n";
|
||||
file << "audio.music.volume=" + std::to_string(options.audio.music.volume) + "\n";
|
||||
file << "audio.sound.enabled=" + boolToString(options.audio.sound.enabled) + "\n";
|
||||
file << "audio.sound.volume=" + std::to_string(options.audio.sound.volume) + "\n";
|
||||
file << "audio.enabled=" << boolToString(options.audio.enabled) << "\n";
|
||||
file << "audio.volume=" << options.audio.volume << "\n";
|
||||
file << "audio.music.enabled=" << boolToString(options.audio.music.enabled) << "\n";
|
||||
file << "audio.music.volume=" << options.audio.music.volume << "\n";
|
||||
file << "audio.sound.enabled=" << boolToString(options.audio.sound.enabled) << "\n";
|
||||
file << "audio.sound.volume=" << options.audio.sound.volume << "\n";
|
||||
|
||||
// Opciones del juego
|
||||
const auto value_difficulty_easy = std::to_string(static_cast<int>(GameDifficulty::EASY));
|
||||
const auto value_difficulty_normal = std::to_string(static_cast<int>(GameDifficulty::NORMAL));
|
||||
const auto value_difficulty_hard = std::to_string(static_cast<int>(GameDifficulty::HARD));
|
||||
file << "\n\n## GAME\n";
|
||||
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
|
||||
file << "## game.difficulty [" << value_difficulty_easy << ": easy, " << value_difficulty_normal << ": normal, " << value_difficulty_hard << ": hard]\n";
|
||||
file << "## game.difficulty [" << static_cast<int>(GameDifficulty::EASY) << ": easy, " << static_cast<int>(GameDifficulty::NORMAL) << ": normal, " << static_cast<int>(GameDifficulty::HARD) << ": hard]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "game.language=" + std::to_string(static_cast<int>(options.game.language)) + "\n";
|
||||
file << "game.difficulty=" + std::to_string(static_cast<int>(options.game.difficulty)) + "\n";
|
||||
file << "game.autofire=" + boolToString(options.game.autofire) + "\n";
|
||||
file << "game.language=" << static_cast<int>(options.game.language) << "\n";
|
||||
file << "game.difficulty=" << static_cast<int>(options.game.difficulty) << "\n";
|
||||
file << "game.autofire=" << boolToString(options.game.autofire) << "\n";
|
||||
|
||||
// Opciones de mandos
|
||||
file << "\n\n## CONTROLLERS\n";
|
||||
file << "\n";
|
||||
|
||||
const int num_players = 2;
|
||||
for (int index = 0; index < num_players; ++index)
|
||||
for (const auto &controller : options.controllers)
|
||||
{
|
||||
const std::string joyIndex = std::to_string(index + 1);
|
||||
file << "controller" + joyIndex + ".name=" + options.controller[index].name + "\n";
|
||||
file << "controller" + joyIndex + ".player=" + std::to_string(options.controller[index].player_id) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_left=" + std::to_string((int)options.controller[index].buttons[0]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_center=" + std::to_string((int)options.controller[index].buttons[1]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_right=" + std::to_string((int)options.controller[index].buttons[2]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.start=" + std::to_string((int)options.controller[index].buttons[3]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.service=" + std::to_string((int)options.controller[index].buttons[4]) + "\n";
|
||||
|
||||
if (index < num_players - 1)
|
||||
{
|
||||
file << "\n";
|
||||
}
|
||||
file << "\n";
|
||||
file << "controller." << controller.index << ".name=" << controller.name << "\n";
|
||||
file << "controller." << controller.index << ".player=" << controller.player_id << "\n";
|
||||
file << "controller." << controller.index << ".type=" << static_cast<int>(controller.type) << "\n";
|
||||
file << "controller." << controller.index << ".button.fire_left=" << controller.buttons.at(0) << "\n";
|
||||
file << "controller." << controller.index << ".button.fire_center=" << controller.buttons.at(1) << "\n";
|
||||
file << "controller." << controller.index << ".button.fire_right=" << controller.buttons.at(2) << "\n";
|
||||
file << "controller." << controller.index << ".button.start=" << controller.buttons.at(3) << "\n";
|
||||
file << "controller." << controller.index << ".button.service=" << controller.buttons.at(4) << "\n";
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
@@ -242,7 +196,6 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
{
|
||||
options.video.mode = static_cast<ScreenVideoMode>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "video.window.size")
|
||||
{
|
||||
options.video.window.size = std::stoi(value);
|
||||
@@ -251,22 +204,18 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
options.video.window.size = 3;
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "video.filter")
|
||||
{
|
||||
options.video.filter = static_cast<ScreenFilter>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "video.shaders")
|
||||
{
|
||||
options.video.shaders = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.integer_scale")
|
||||
{
|
||||
options.video.integer_scale = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.v_sync")
|
||||
{
|
||||
options.video.v_sync = stringToBool(value);
|
||||
@@ -277,7 +226,6 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
{
|
||||
options.audio.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.volume")
|
||||
{
|
||||
options.audio.volume = std::stoi(value);
|
||||
@@ -286,17 +234,14 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
{
|
||||
options.audio.music.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.music.volume")
|
||||
{
|
||||
options.audio.music.volume = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.sound.enabled")
|
||||
{
|
||||
options.audio.sound.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.sound.volume")
|
||||
{
|
||||
options.audio.sound.volume = std::stoi(value);
|
||||
@@ -307,93 +252,85 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
{
|
||||
options.game.language = static_cast<lang::Code>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "game.difficulty")
|
||||
{
|
||||
options.game.difficulty = static_cast<GameDifficulty>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "game.autofire")
|
||||
{
|
||||
options.game.autofire = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de mandos
|
||||
else if (var == "controller1.name")
|
||||
else if (var == "controller.0.name")
|
||||
{
|
||||
options.controller[0].name = value;
|
||||
options.controllers.at(0).name = value;
|
||||
}
|
||||
|
||||
else if (var == "controller1.player")
|
||||
else if (var == "controller.0.player")
|
||||
{
|
||||
options.controller[0].player_id = std::max(1, std::min(2, std::stoi(value)));
|
||||
options.controllers.at(0).player_id = std::clamp(std::stoi(value), 1, 2);
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_left")
|
||||
else if (var == "controller.0.type")
|
||||
{
|
||||
options.controller[0].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(0).type = static_cast<InputDeviceToUse>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_center")
|
||||
else if (var == "controller.0.button.fire_left")
|
||||
{
|
||||
options.controller[0].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(0).buttons.at(0) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_right")
|
||||
else if (var == "controller.0.button.fire_center")
|
||||
{
|
||||
options.controller[0].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(0).buttons.at(1) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.start")
|
||||
else if (var == "controller.0.button.fire_right")
|
||||
{
|
||||
options.controller[0].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(0).buttons.at(2) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.service")
|
||||
else if (var == "controller.0.button.start")
|
||||
{
|
||||
options.controller[0].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(0).buttons.at(3) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller2.name")
|
||||
else if (var == "controller.0.button.service")
|
||||
{
|
||||
options.controller[1].name = value;
|
||||
options.controllers.at(0).buttons.at(4) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller2.player")
|
||||
else if (var == "controller.1.name")
|
||||
{
|
||||
options.controller[1].player_id = std::max(1, std::min(2, std::stoi(value)));
|
||||
options.controllers.at(1).name = value;
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_left")
|
||||
else if (var == "controller.1.player")
|
||||
{
|
||||
options.controller[1].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(1).player_id = std::clamp(std::stoi(value), 1, 2);
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_center")
|
||||
else if (var == "controller.1.type")
|
||||
{
|
||||
options.controller[1].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(1).type = static_cast<InputDeviceToUse>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_right")
|
||||
else if (var == "controller.1.button.fire_left")
|
||||
{
|
||||
options.controller[1].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(1).buttons.at(0) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.start")
|
||||
else if (var == "controller.1.button.fire_center")
|
||||
{
|
||||
options.controller[1].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(1).buttons.at(1) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.service")
|
||||
else if (var == "controller.1.button.fire_right")
|
||||
{
|
||||
options.controller[1].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(1).buttons.at(2) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.1.button.start")
|
||||
{
|
||||
options.controllers.at(1).buttons.at(3) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.1.button.service")
|
||||
{
|
||||
options.controllers.at(1).buttons.at(4) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
// Lineas vacias o que empiezan por comentario
|
||||
else if (var.empty() || var.starts_with("#"))
|
||||
{
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
@@ -408,3 +345,45 @@ int to_JA_volume(int vol)
|
||||
vol = vol * 1.28f;
|
||||
return std::clamp(vol, 0, 128);
|
||||
}
|
||||
|
||||
// Asigna el teclado al jugador
|
||||
void setKeyboardToPlayer(int player_id)
|
||||
{
|
||||
for (auto &controller : options.controllers)
|
||||
{
|
||||
if (controller.player_id == player_id)
|
||||
{
|
||||
controller.type = InputDeviceToUse::ANY;
|
||||
}
|
||||
else
|
||||
{
|
||||
controller.type = InputDeviceToUse::CONTROLLER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Intercambia el teclado de jugador
|
||||
void swapOptionsKeyboard()
|
||||
{
|
||||
std::swap(options.controllers.at(0).type, options.controllers.at(1).type);
|
||||
}
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void swapOptionsControllers()
|
||||
{
|
||||
std::swap(options.controllers.at(0).player_id, options.controllers.at(1).player_id);
|
||||
std::swap(options.controllers.at(0).type, options.controllers.at(1).type);
|
||||
}
|
||||
|
||||
// Averigua quien está usando el teclado
|
||||
int getPlayerWhoUsesKeyboard()
|
||||
{
|
||||
for (auto &controller : options.controllers)
|
||||
{
|
||||
if (controller.type == InputDeviceToUse::ANY)
|
||||
{
|
||||
return controller.player_id;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include "manage_hiscore_table.h"
|
||||
#include <vector> // Para vector
|
||||
#include "input.h"
|
||||
#include <string>
|
||||
enum class InputType : int;
|
||||
enum class ScreenFilter : int;
|
||||
@@ -57,8 +58,8 @@ struct OptionsAudio
|
||||
{
|
||||
OptionsMusic music; // Opciones para la música
|
||||
OptionsSound sound; // Opciones para los efectos de sonido
|
||||
bool enabled; // Indica si el audio está activo o no
|
||||
int volume; // Volumen al que suenan el audio
|
||||
bool enabled; // Indica si el audio está activo o no
|
||||
int volume; // Volumen al que suenan el audio
|
||||
};
|
||||
|
||||
// Estructura para las opciones del juego
|
||||
@@ -75,25 +76,35 @@ struct OptionsController
|
||||
{
|
||||
int index; // Indice en el vector de mandos
|
||||
int player_id; // Jugador asociado al mando
|
||||
Uint8 device_type; // Indica si se utilizará teclado o mando o ambos
|
||||
InputDeviceToUse type; // Indica si se utilizará teclado o mando o ambos
|
||||
std::string name; // Nombre del dispositivo
|
||||
bool plugged; // Indica si el mando se encuentra conectado
|
||||
std::vector<InputType> inputs; // Listado de inputs
|
||||
std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input
|
||||
|
||||
// Constructor por defecto
|
||||
OptionsController()
|
||||
: index(-1), player_id(-1), type(InputDeviceToUse::CONTROLLER), name(""), plugged(false)
|
||||
{
|
||||
inputs = {InputType::FIRE_LEFT, InputType::FIRE_CENTER, InputType::FIRE_RIGHT, InputType::START, InputType::SERVICE};
|
||||
buttons = {SDL_CONTROLLER_BUTTON_X, SDL_CONTROLLER_BUTTON_Y, SDL_CONTROLLER_BUTTON_B, SDL_CONTROLLER_BUTTON_START, SDL_CONTROLLER_BUTTON_BACK};
|
||||
}
|
||||
};
|
||||
|
||||
// Estructura con todas las opciones de configuración del programa
|
||||
struct Options
|
||||
{
|
||||
OptionsGame game; // Opciones para el propio juego
|
||||
OptionsVideo video; // Opciones relativas a la clase screen
|
||||
OptionsAudio audio; // Opciones para el audio
|
||||
std::vector<OptionsController> controller; // Opciones con las asignaciones del mando para cada jugador
|
||||
OptionsGame game; // Opciones para el propio juego
|
||||
OptionsVideo video; // Opciones relativas a la clase screen
|
||||
OptionsAudio audio; // Opciones para el audio
|
||||
std::vector<OptionsController> controllers; // Opciones con las asignaciones del mando para cada jugador
|
||||
};
|
||||
|
||||
// Variables
|
||||
extern Options options;
|
||||
|
||||
void initOptions();
|
||||
|
||||
// Carga el fichero de configuración
|
||||
bool loadOptionsFile(std::string file_path);
|
||||
|
||||
@@ -102,3 +113,15 @@ bool saveOptionsFile(std::string file_path);
|
||||
|
||||
// Convierte valores de 0 a 100 en valores de 0 a 128
|
||||
int to_JA_volume(int vol);
|
||||
|
||||
// Asigna el teclado al jugador
|
||||
void setKeyboardToPlayer(int player_id);
|
||||
|
||||
// Intercambia el teclado de jugador
|
||||
void swapOptionsKeyboard();
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void swapOptionsControllers();
|
||||
|
||||
// Averigua quien está usando el teclado
|
||||
int getPlayerWhoUsesKeyboard();
|
||||
@@ -171,6 +171,9 @@ void Title::render()
|
||||
// Comprueba los eventos
|
||||
void Title::checkEvents()
|
||||
{
|
||||
// Comprueba el input para el resto de objetos
|
||||
define_buttons_->checkEvents();
|
||||
|
||||
// Si define_buttons_ está habilitado, es él quien gestiona los eventos
|
||||
if (!define_buttons_->isEnabled())
|
||||
{
|
||||
@@ -195,32 +198,33 @@ void Title::checkEvents()
|
||||
{
|
||||
switch (event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_1:
|
||||
case SDLK_1: // Redefine los botones del mando #0
|
||||
{
|
||||
if (define_buttons_->enable(0))
|
||||
resetCounter();
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_2:
|
||||
case SDLK_2: // Redefine los botones del mando #1
|
||||
{
|
||||
if (define_buttons_->enable(1))
|
||||
resetCounter();
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_3:
|
||||
case SDLK_3: // Intercambia los mandos entre los dos jugadores
|
||||
{
|
||||
swapControllers();
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_4:
|
||||
case SDLK_4: // Muestra la asignacion de mandos
|
||||
{
|
||||
showControllers();
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_5: // Intercambia la asignación del teclado
|
||||
{
|
||||
swapKeyboard();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -235,55 +239,38 @@ void Title::checkInput()
|
||||
// Comprueba los controladores solo si no se estan definiendo los botones
|
||||
if (!define_buttons_->isEnabled())
|
||||
{
|
||||
// Comprueba el teclado para empezar a jugar
|
||||
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
// Comprueba los métodos de control
|
||||
for (const auto &controller : options.controllers)
|
||||
{
|
||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index) &&
|
||||
!Input::get()->checkInput(InputType::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
|
||||
{
|
||||
fade_->activate();
|
||||
post_fade_ = options.controller[0].player_id;
|
||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||
{
|
||||
fade_->activate();
|
||||
post_fade_ = controller.player_id;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los mandos
|
||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||
{
|
||||
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) &&
|
||||
Input::get()->checkInput(InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
|
||||
{
|
||||
swapControllers();
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba si algun mando quiere ser configurado
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) &&
|
||||
Input::get()->checkInput(InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
|
||||
{
|
||||
define_buttons_->enable(i);
|
||||
define_buttons_->enable(controller.index);
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el botón de START de los mandos
|
||||
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
// Si no está el botón de servicio activo
|
||||
if (!Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||
{
|
||||
fade_->activate();
|
||||
post_fade_ = options.controller[i].player_id;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el input para el resto de objetos
|
||||
define_buttons_->checkEvents();
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
globalInputs::check();
|
||||
}
|
||||
@@ -316,10 +303,17 @@ void Title::swapControllers()
|
||||
if (Input::get()->getNumControllers() == 0)
|
||||
return;
|
||||
|
||||
define_buttons_->swapControllers();
|
||||
swapOptionsControllers();
|
||||
showControllers();
|
||||
}
|
||||
|
||||
// Intercambia el teclado de jugador
|
||||
void Title::swapKeyboard()
|
||||
{
|
||||
swapOptionsKeyboard();
|
||||
Notifier::get()->showText("Teclat per al jugador " + std::to_string(getPlayerWhoUsesKeyboard()));
|
||||
}
|
||||
|
||||
// Muestra información sobre los controles y los jugadores
|
||||
void Title::showControllers()
|
||||
{
|
||||
@@ -332,16 +326,16 @@ void Title::showControllers()
|
||||
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
|
||||
{
|
||||
// Ejemplo: el jugador 1 tiene el mando 2
|
||||
playerControllerIndex.at(options.controller.at(i).player_id - 1) = i;
|
||||
playerControllerIndex.at(options.controllers.at(i).player_id - 1) = i;
|
||||
}
|
||||
|
||||
// Genera el texto correspondiente
|
||||
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
|
||||
{
|
||||
const size_t index = playerControllerIndex.at(i);
|
||||
if (options.controller.at(index).plugged)
|
||||
if (options.controllers.at(index).plugged)
|
||||
{
|
||||
text.at(i) = lang::getText(100) + std::to_string(i + 1) + ": " + options.controller.at(index).name;
|
||||
text.at(i) = lang::getText(100) + std::to_string(i + 1) + ": " + options.controllers.at(index).name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,9 @@ private:
|
||||
// Intercambia la asignación de mandos a los jugadores
|
||||
void swapControllers();
|
||||
|
||||
// Intercambia el teclado de jugador
|
||||
void swapKeyboard();
|
||||
|
||||
// Muestra información sobre los controles y los jugadores
|
||||
void showControllers();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user