Al redefinir botons, ja no pots repetir botó. Util per als qui tenim la ma tremolosa i apretem dos voltes sense voler
This commit is contained in:
@@ -16,11 +16,11 @@ 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_X);
|
||||
buttons_.emplace_back(lang::getText(96), InputType::FIRE_CENTER, SDL_CONTROLLER_BUTTON_Y);
|
||||
buttons_.emplace_back(lang::getText(97), InputType::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
|
||||
buttons_.emplace_back(lang::getText(98), InputType::START, SDL_CONTROLLER_BUTTON_START);
|
||||
buttons_.emplace_back(lang::getText(99), InputType::EXIT, SDL_CONTROLLER_BUTTON_BACK);
|
||||
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::EXIT, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||
{
|
||||
@@ -40,9 +40,9 @@ void DefineButtons::render()
|
||||
}
|
||||
|
||||
// Comprueba el botón que se ha pulsado
|
||||
void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent *event)
|
||||
void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent &event)
|
||||
{
|
||||
int i = input_->getJoyIndex(event->which);
|
||||
size_t i = input_->getJoyIndex(event.which);
|
||||
|
||||
// Solo pillamos botones del mando que toca
|
||||
if (i != index_controller_)
|
||||
@@ -50,14 +50,18 @@ void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
buttons_[index_button_].button = (SDL_GameControllerButton)event->button;
|
||||
incIndexButton();
|
||||
const auto button = static_cast<SDL_GameControllerButton>(event.button);
|
||||
if (checkButtonNotInUse(button))
|
||||
{
|
||||
buttons_[index_button_].button = button;
|
||||
incIndexButton();
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna los botones definidos al input_
|
||||
void DefineButtons::bindButtons()
|
||||
{
|
||||
for (int i = 0; i < (int)buttons_.size(); ++i)
|
||||
for (size_t i = 0; i < buttons_.size(); ++i)
|
||||
{
|
||||
input_->bindGameControllerButton(index_controller_, buttons_[i].input, buttons_[i].button);
|
||||
}
|
||||
@@ -84,7 +88,7 @@ void DefineButtons::checkInput()
|
||||
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
{
|
||||
doControllerButtonDown(&event.cbutton);
|
||||
doControllerButtonDown(event.cbutton);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -121,7 +125,7 @@ void DefineButtons::incIndexButton()
|
||||
index_button_++;
|
||||
|
||||
// Comprueba si ha finalizado
|
||||
if (index_button_ == (int)buttons_.size())
|
||||
if (index_button_ == buttons_.size())
|
||||
{
|
||||
// Asigna los botones definidos al input_
|
||||
bindButtons();
|
||||
@@ -152,7 +156,18 @@ void DefineButtons::saveBindingsToOptions()
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void DefineButtons::swapControllers()
|
||||
{
|
||||
const int temp = options.controller[0].player_id;
|
||||
options.controller[0].player_id = options.controller[1].player_id;
|
||||
options.controller[1].player_id = temp;
|
||||
}
|
||||
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)
|
||||
{
|
||||
for (const auto &b : buttons_)
|
||||
{
|
||||
if (b.button == button)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user