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:
2024-11-03 11:07:58 +01:00
parent a1ccb6102a
commit 86cd7b0f16
11 changed files with 306 additions and 293 deletions

View File

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