diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index bdab4fc..b61760c 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -10,49 +10,22 @@ // Constructor DefineButtons::DefineButtons(std::unique_ptr text_) - : text_(std::move(text_)) + : input_(Input::get()), + text_(std::move(text_)) { - // Copia punteros a los objetos - input_ = Input::get(); - // Inicializa variables - enabled_ = false; x_ = param.game.width / 2; y_ = param.title.press_start_position; - index_controller_ = 0; - index_button_ = 0; - buttons_.clear(); - DefineButtonsButton button; - - button.label = lang::getText(95); - button.input = InputType::FIRE_LEFT; - button.button = SDL_CONTROLLER_BUTTON_X; - buttons_.push_back(button); - - button.label = lang::getText(96); - button.input = InputType::FIRE_CENTER; - button.button = SDL_CONTROLLER_BUTTON_Y; - buttons_.push_back(button); - - button.label = lang::getText(97); - button.input = InputType::FIRE_RIGHT; - button.button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; - buttons_.push_back(button); - - button.label = lang::getText(98); - button.input = InputType::START; - button.button = SDL_CONTROLLER_BUTTON_START; - buttons_.push_back(button); - - button.label = lang::getText(99); - button.input = InputType::EXIT; - button.button = SDL_CONTROLLER_BUTTON_BACK; - buttons_.push_back(button); + 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); for (int i = 0; i < input_->getNumControllers(); ++i) { - controller_names_.push_back(input_->getControllerName(i)); + controller_names_.emplace_back(input_->getControllerName(i)); } } diff --git a/source/define_buttons.h b/source/define_buttons.h index 385be41..bd1dd29 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -1,10 +1,10 @@ #pragma once -#include // for SDL_ControllerButtonEvent -#include // for SDL_GameControllerButton -#include // for shared_ptr, unique_ptr -#include // for string -#include // for vector +#include // for SDL_ControllerButtonEvent +#include // for SDL_GameControllerButton +#include // for shared_ptr, unique_ptr +#include // for string +#include // for vector class Input; class Text; enum class InputType : int; @@ -14,6 +14,10 @@ struct DefineButtonsButton std::string label; // Texto en pantalla para el botón InputType input; // Input asociado SDL_GameControllerButton button; // Botón del mando correspondiente + + // Constructor + DefineButtonsButton(const std::string &lbl, InputType inp, SDL_GameControllerButton btn) + : label(lbl), input(inp), button(btn) {} }; // Clase Bullet @@ -25,12 +29,12 @@ private: std::shared_ptr text_; // Objeto para escribir texto // Variables - bool enabled_; // Indica si el objeto está habilitado + bool enabled_ = false; // Indica si el objeto está habilitado int x_; // Posición donde dibujar el texto int y_; // Posición donde dibujar el texto std::vector buttons_; // Vector con las nuevas definiciones de botones/acciones - int index_controller_; // Indice del controlador a reasignar - int index_button_; // Indice para saber qué bot´çon se está definiendo + int index_controller_ = 0; // Indice del controlador a reasignar + int index_button_ = 0; // Indice para saber qué bot´çon se está definiendo std::vector controller_names_; // Nombres de los mandos // Incrementa el indice de los botones