Continuem estandaritzant noms
This commit is contained in:
@@ -7,109 +7,115 @@
|
||||
#include "utils.h" // for OptionsController, Options, Param, ParamGame
|
||||
|
||||
// Constructor
|
||||
DefineButtons::DefineButtons(std::unique_ptr<Text> text)
|
||||
: text(std::move(text))
|
||||
DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
|
||||
: text_(std::move(text_))
|
||||
{
|
||||
// Copia punteros a los objetos
|
||||
input = Input::get();
|
||||
input_ = Input::get();
|
||||
|
||||
// Inicializa variables
|
||||
enabled = false;
|
||||
x = param.game.width / 2;
|
||||
y = param.title.press_start_position;
|
||||
indexController = 0;
|
||||
indexButton = 0;
|
||||
enabled_ = false;
|
||||
x_ = param.game.width / 2;
|
||||
y_ = param.title.press_start_position;
|
||||
index_controller_ = 0;
|
||||
index_button_ = 0;
|
||||
|
||||
buttons.clear();
|
||||
db_button_t button;
|
||||
buttons_.clear();
|
||||
DefineButtonsButton button;
|
||||
|
||||
button.label = lang::getText(95);
|
||||
button.input = input_fire_left;
|
||||
button.button = SDL_CONTROLLER_BUTTON_X;
|
||||
buttons.push_back(button);
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(96);
|
||||
button.input = input_fire_center;
|
||||
button.button = SDL_CONTROLLER_BUTTON_Y;
|
||||
buttons.push_back(button);
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(97);
|
||||
button.input = input_fire_right;
|
||||
button.button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
|
||||
buttons.push_back(button);
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(98);
|
||||
button.input = input_start;
|
||||
button.button = SDL_CONTROLLER_BUTTON_START;
|
||||
buttons.push_back(button);
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(99);
|
||||
button.input = input_exit;
|
||||
button.button = SDL_CONTROLLER_BUTTON_BACK;
|
||||
buttons.push_back(button);
|
||||
buttons_.push_back(button);
|
||||
|
||||
for (int i = 0; i < input->getNumControllers(); ++i)
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||
{
|
||||
controllerNames.push_back(input->getControllerName(i));
|
||||
controller_names_.push_back(input_->getControllerName(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el objeto en pantalla
|
||||
void DefineButtons::render()
|
||||
{
|
||||
if (enabled)
|
||||
if (enabled_)
|
||||
{
|
||||
text->writeCentered(x, y - 10, lang::getText(100) + std::to_string(options.controller[indexController].player_id));
|
||||
text->writeCentered(x, y, controllerNames[indexController]);
|
||||
text->writeCentered(x, y + 10, buttons[indexButton].label);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el botón que se ha pulsado
|
||||
void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent *event)
|
||||
{
|
||||
int i = input->getJoyIndex(event->which);
|
||||
int i = input_->getJoyIndex(event->which);
|
||||
|
||||
// Solo pillamos botones del mando que toca
|
||||
if (i != indexController)
|
||||
if (i != index_controller_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
buttons[indexButton].button = (SDL_GameControllerButton)event->button;
|
||||
buttons_[index_button_].button = (SDL_GameControllerButton)event->button;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
// Asigna los botones definidos al input
|
||||
// Asigna los botones definidos al input_
|
||||
void DefineButtons::bindButtons()
|
||||
{
|
||||
for (int i = 0; i < (int)buttons.size(); ++i)
|
||||
for (int i = 0; i < (int)buttons_.size(); ++i)
|
||||
{
|
||||
input->bindGameControllerButton(indexController, buttons[i].input, buttons[i].button);
|
||||
input_->bindGameControllerButton(index_controller_, buttons_[i].input, buttons_[i].button);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void DefineButtons::checkInput()
|
||||
{
|
||||
if (enabled)
|
||||
if (enabled_)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::options = section::OPTIONS_QUIT_NORMAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (event.type == SDL_CONTROLLERBUTTONDOWN)
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
{
|
||||
doControllerButtonDown(&event.cbutton);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,11 +124,11 @@ void DefineButtons::checkInput()
|
||||
// Habilita el objeto
|
||||
bool DefineButtons::enable(int index)
|
||||
{
|
||||
if (index < input->getNumControllers())
|
||||
if (index < input_->getNumControllers())
|
||||
{
|
||||
enabled = true;
|
||||
indexController = index;
|
||||
indexButton = 0;
|
||||
enabled_ = true;
|
||||
index_controller_ = index;
|
||||
index_button_ = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -132,29 +138,29 @@ bool DefineButtons::enable(int index)
|
||||
// Comprueba si está habilitado
|
||||
bool DefineButtons::isEnabled()
|
||||
{
|
||||
return enabled;
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
// Incrementa el indice de los botones
|
||||
void DefineButtons::incIndexButton()
|
||||
{
|
||||
indexButton++;
|
||||
index_button_++;
|
||||
|
||||
// Comprueba si ha finalizado
|
||||
if (indexButton == (int)buttons.size())
|
||||
if (index_button_ == (int)buttons_.size())
|
||||
{
|
||||
// Asigna los botones definidos al input
|
||||
// Asigna los botones definidos al input_
|
||||
bindButtons();
|
||||
|
||||
// Guarda los cambios en las opciones
|
||||
saveBindingsToOptions();
|
||||
|
||||
input->allActive(indexController);
|
||||
input_->allActive(index_controller_);
|
||||
|
||||
// Reinicia variables
|
||||
indexButton = 0;
|
||||
indexController = 0;
|
||||
enabled = false;
|
||||
index_button_ = 0;
|
||||
index_controller_ = 0;
|
||||
enabled_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,10 +168,10 @@ void DefineButtons::incIndexButton()
|
||||
void DefineButtons::saveBindingsToOptions()
|
||||
{
|
||||
// Modifica las opciones para colocar los valores asignados
|
||||
options.controller[indexController].name = input->getControllerName(indexController);
|
||||
for (int j = 0; j < (int)options.controller[indexController].inputs.size(); ++j)
|
||||
options.controller[index_controller_].name = input_->getControllerName(index_controller_);
|
||||
for (int j = 0; j < (int)options.controller[index_controller_].inputs.size(); ++j)
|
||||
{
|
||||
options.controller[indexController].buttons[j] = input->getControllerBinding(indexController, options.controller[indexController].inputs[j]);
|
||||
options.controller[index_controller_].buttons[j] = input_->getControllerBinding(index_controller_, options.controller[index_controller_].inputs[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user