This commit is contained in:
2024-10-23 22:18:46 +02:00
parent 6e2f80d8ce
commit 8c98430b68
2 changed files with 20 additions and 43 deletions

View File

@@ -10,49 +10,22 @@
// Constructor
DefineButtons::DefineButtons(std::unique_ptr<Text> 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));
}
}

View File

@@ -1,10 +1,10 @@
#pragma once
#include <SDL2/SDL_events.h> // for SDL_ControllerButtonEvent
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton
#include <memory> // for shared_ptr, unique_ptr
#include <string> // for string
#include <vector> // for vector
#include <SDL2/SDL_events.h> // for SDL_ControllerButtonEvent
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton
#include <memory> // for shared_ptr, unique_ptr
#include <string> // for string
#include <vector> // 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> 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<DefineButtonsButton> 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<std::string> controller_names_; // Nombres de los mandos
// Incrementa el indice de los botones