define_buttons ja acaba be de definir els buttons
This commit is contained in:
@@ -20,7 +20,7 @@ DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
|
||||
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);
|
||||
buttons_.emplace_back(lang::getText(99), InputType::SERVICE, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||
{
|
||||
@@ -33,19 +33,17 @@ void DefineButtons::render()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
text_->writeCentered(x_, y_ - 10, lang::getText(100) + std::to_string(options.controller[index_controller_].player_id));
|
||||
text_->writeCentered(x_, y_, controller_names_[index_controller_]);
|
||||
text_->writeCentered(x_, y_ + 10, buttons_[index_button_].label);
|
||||
text_->writeCentered(x_, y_ - 10, lang::getText(100) + std::to_string(options.controller.at(index_controller_).player_id));
|
||||
text_->writeCentered(x_, y_, controller_names_.at(index_controller_));
|
||||
text_->writeCentered(x_, y_ + 10, buttons_.at(index_button_).label);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el botón que se ha pulsado
|
||||
void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent &event)
|
||||
{
|
||||
size_t i = input_->getJoyIndex(event.which);
|
||||
|
||||
// Solo pillamos botones del mando que toca
|
||||
if (i != index_controller_)
|
||||
// Solo pilla botones del mando que toca
|
||||
if (input_->getJoyIndex(event.which) != static_cast<int>(index_controller_))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -53,7 +51,7 @@ void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent &event)
|
||||
const auto button = static_cast<SDL_GameControllerButton>(event.button);
|
||||
if (checkButtonNotInUse(button))
|
||||
{
|
||||
buttons_[index_button_].button = button;
|
||||
buttons_.at(index_button_).button = button;
|
||||
incIndexButton();
|
||||
}
|
||||
}
|
||||
@@ -61,9 +59,9 @@ void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent &event)
|
||||
// Asigna los botones definidos al input_
|
||||
void DefineButtons::bindButtons()
|
||||
{
|
||||
for (size_t i = 0; i < buttons_.size(); ++i)
|
||||
for (const auto &button : buttons_)
|
||||
{
|
||||
input_->bindGameControllerButton(index_controller_, buttons_[i].input, buttons_[i].button);
|
||||
input_->bindGameControllerButton(index_controller_, button.input, button.button);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,13 +83,11 @@ void DefineButtons::checkEvents()
|
||||
section::options = section::Options::QUIT_WITH_KEYBOARD;
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
{
|
||||
doControllerButtonDown(event.cbutton);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -114,15 +110,12 @@ bool DefineButtons::enable(int index)
|
||||
}
|
||||
|
||||
// Comprueba si está habilitado
|
||||
bool DefineButtons::isEnabled()
|
||||
{
|
||||
return enabled_;
|
||||
}
|
||||
bool DefineButtons::isEnabled() { return enabled_; }
|
||||
|
||||
// Incrementa el indice de los botones
|
||||
void DefineButtons::incIndexButton()
|
||||
{
|
||||
index_button_++;
|
||||
++index_button_;
|
||||
|
||||
// Comprueba si ha finalizado
|
||||
if (index_button_ == buttons_.size())
|
||||
@@ -133,8 +126,6 @@ void DefineButtons::incIndexButton()
|
||||
// Guarda los cambios en las opciones
|
||||
saveBindingsToOptions();
|
||||
|
||||
// input_->allActive(index_controller_);
|
||||
|
||||
// Reinicia variables
|
||||
index_button_ = 0;
|
||||
index_controller_ = 0;
|
||||
@@ -146,10 +137,11 @@ void DefineButtons::incIndexButton()
|
||||
void DefineButtons::saveBindingsToOptions()
|
||||
{
|
||||
// Modifica las opciones para colocar los valores asignados
|
||||
options.controller[index_controller_].name = input_->getControllerName(index_controller_);
|
||||
for (int j = 0; j < (int)options.controller[index_controller_].inputs.size(); ++j)
|
||||
auto &controller = options.controller.at(index_controller_);
|
||||
controller.name = input_->getControllerName(index_controller_);
|
||||
for (size_t j = 0; j < controller.inputs.size(); ++j)
|
||||
{
|
||||
options.controller[index_controller_].buttons[j] = input_->getControllerBinding(index_controller_, options.controller[index_controller_].inputs[j]);
|
||||
controller.buttons.at(j) = input_->getControllerBinding(index_controller_, controller.inputs.at(j));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user