69 lines
2.2 KiB
C++
69 lines
2.2 KiB
C++
#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
|
||
class Input;
|
||
class Text;
|
||
enum class InputType : int;
|
||
|
||
struct DefineButtonsButton
|
||
{
|
||
std::string label; // Texto en pantalla para el botón
|
||
InputType input; // Input asociado
|
||
SDL_GameControllerButton button; // Botón del mando correspondiente
|
||
};
|
||
|
||
// Clase Bullet
|
||
class DefineButtons
|
||
{
|
||
private:
|
||
// Objetos
|
||
Input *input_; // Objeto pata gestionar la entrada
|
||
std::shared_ptr<Text> text_; // Objeto para escribir texto
|
||
|
||
// Variables
|
||
bool enabled_; // 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
|
||
std::vector<std::string> controller_names_; // Nombres de los mandos
|
||
|
||
// Incrementa el indice de los botones
|
||
void incIndexButton();
|
||
|
||
// Comprueba el botón que se ha pulsado
|
||
void doControllerButtonDown(SDL_ControllerButtonEvent *event);
|
||
|
||
// Asigna los botones definidos al input
|
||
void bindButtons();
|
||
|
||
// Guarda los cambios en las opciones
|
||
void saveBindingsToOptions();
|
||
|
||
public:
|
||
// Constructor
|
||
explicit DefineButtons(std::unique_ptr<Text> text);
|
||
|
||
// Destructor
|
||
~DefineButtons() = default;
|
||
|
||
// Dibuja el objeto en pantalla
|
||
void render();
|
||
|
||
// Comprueba las entradas
|
||
void checkInput();
|
||
|
||
// Habilita el objeto
|
||
bool enable(int index);
|
||
|
||
// Comprueba si está habilitado
|
||
bool isEnabled();
|
||
|
||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||
void swapControllers();
|
||
}; |