Ya se guardan las asignaciones de los botones en el fichero de configuración
This commit is contained in:
@@ -404,18 +404,38 @@ void Input::printBindings(int device, int index)
|
||||
}
|
||||
|
||||
// Muestra el nombre del mando
|
||||
std::cout << "\n" << controllerNames[index] << std::endl;
|
||||
std::cout << "\n"
|
||||
<< controllerNames[index] << std::endl;
|
||||
|
||||
// Muestra los botones asignados
|
||||
for (auto bi : buttonInputs)
|
||||
{
|
||||
std::cout << to_String(bi) << " : " << gameControllerBindings[index][bi].button << std::endl;
|
||||
std::cout << to_string(bi) << " : " << gameControllerBindings[index][bi].button << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
||||
SDL_GameControllerButton Input::getControllerBinding(int index, inputs_e input)
|
||||
{
|
||||
return gameControllerBindings[index][input].button;
|
||||
}
|
||||
|
||||
// Obtiene el indice a partir del nombre del mando
|
||||
int Input::getIndexByName(std::string name)
|
||||
{
|
||||
for (int i = 0; i < numGamepads; ++i)
|
||||
{
|
||||
if (controllerNames[i] == name)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Convierte un inputs_e a std::string
|
||||
std::string Input::to_String(inputs_e input)
|
||||
std::string Input::to_string(inputs_e input)
|
||||
{
|
||||
if (input == input_fire_left)
|
||||
{
|
||||
@@ -438,4 +458,30 @@ std::string Input::to_String(inputs_e input)
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
// Convierte un std::string a inputs_e
|
||||
inputs_e Input::to_inputs_e(std::string name)
|
||||
{
|
||||
if (name == "input_fire_left")
|
||||
{
|
||||
return input_fire_left;
|
||||
}
|
||||
|
||||
if (name == "input_fire_center")
|
||||
{
|
||||
return input_fire_center;
|
||||
}
|
||||
|
||||
if (name == "input_fire_right")
|
||||
{
|
||||
return input_fire_right;
|
||||
}
|
||||
|
||||
if (name == "input_start")
|
||||
{
|
||||
return input_start;
|
||||
}
|
||||
|
||||
return input_null;
|
||||
}
|
||||
@@ -89,9 +89,6 @@ private:
|
||||
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
|
||||
bool enabled; // Indica si está habilitado
|
||||
|
||||
// Convierte un inputs_e a std::string
|
||||
std::string to_String(inputs_e input);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Input(std::string file);
|
||||
@@ -140,6 +137,18 @@ public:
|
||||
|
||||
// Muestra por consola los controles asignados
|
||||
void printBindings(int device = INPUT_USE_KEYBOARD, int index = 0);
|
||||
|
||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
||||
SDL_GameControllerButton getControllerBinding(int index, inputs_e input);
|
||||
|
||||
// Convierte un inputs_e a std::string
|
||||
std::string to_string(inputs_e input);
|
||||
|
||||
// Convierte un std::string a inputs_e
|
||||
inputs_e to_inputs_e(std::string name);
|
||||
|
||||
// Obtiene el indice a partir del nombre del mando
|
||||
int getIndexByName(std::string name);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include "texture.h"
|
||||
#include "jail_audio.h"
|
||||
#include "input.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -86,14 +87,6 @@ struct demoKeys_t
|
||||
Uint8 fireRight;
|
||||
};
|
||||
|
||||
// Estructura para albergar métodos de control
|
||||
struct input_t
|
||||
{
|
||||
int id; // Identificador en el vector de mandos
|
||||
std::string name; // Nombre del dispositivo
|
||||
Uint8 deviceType; // Tipo de dispositivo (teclado o mando)
|
||||
};
|
||||
|
||||
// Estructura con las opciones para el borde
|
||||
struct op_border_t
|
||||
{
|
||||
@@ -149,19 +142,28 @@ struct op_audio_t
|
||||
// Estructura para las opciones del juego
|
||||
struct op_game_t
|
||||
{
|
||||
Uint8 difficulty; // Dificultad del juego
|
||||
Uint8 playerSelected; // Jugador seleccionado para el modo 1P
|
||||
std::vector<input_t> input; // Modo de control (teclado o mando)
|
||||
Uint8 language; // Idioma usado en el juego
|
||||
Uint8 difficulty; // Dificultad del juego
|
||||
Uint8 language; // Idioma usado en el juego
|
||||
};
|
||||
|
||||
// Estructura para los controles del juego
|
||||
struct op_controller_t
|
||||
{
|
||||
int index; // Indice en el vector de mandos
|
||||
Uint8 deviceType; // Indica si se utilizará teclado o mando o ambos
|
||||
std::string name; // Nombre del dispositivo
|
||||
std::vector<inputs_e> inputs; // Listado de inputs
|
||||
std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input
|
||||
};
|
||||
|
||||
// Estructura con todas las opciones de configuración del programa
|
||||
struct options_t
|
||||
{
|
||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||
op_game_t game; // Opciones para el propio juego
|
||||
op_video_t video; // Opciones relativas a la clase screen
|
||||
op_audio_t audio; // Opciones para el audio
|
||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||
op_game_t game; // Opciones para el propio juego
|
||||
op_video_t video; // Opciones relativas a la clase screen
|
||||
op_audio_t audio; // Opciones para el audio
|
||||
std::vector<op_controller_t> controller; // Opciones con las asignaciones del mando para cada jugador
|
||||
};
|
||||
|
||||
// Estructura para almacenar todos los parámetros del juego
|
||||
|
||||
Reference in New Issue
Block a user