68 lines
2.1 KiB
C++
68 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL_events.h> // for SDL_ControllerButtonEvent
|
|
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton
|
|
#include <string> // for string, basic_string
|
|
#include <vector> // for vector
|
|
#include "input.h" // for inputs_e
|
|
#include "text.h"
|
|
#include <memory>
|
|
|
|
struct db_button_t
|
|
{
|
|
std::string label; // Texto en pantalla para el botón
|
|
inputs_e 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<db_button_t> buttons; // Vector con las nuevas definiciones de botones/acciones
|
|
int indexController; // Indice del controlador a reasignar
|
|
int indexButton; // Indice para saber qué bot´çon se está definiendo
|
|
std::vector<std::string> controllerNames; // 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
|
|
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();
|
|
}; |