Posibilidad de escoger diferentes configuraciónes prefijadas de teclas de control desde el fichero de configuración

This commit is contained in:
2022-11-29 18:05:38 +01:00
parent 82aa91bead
commit c63298b555
3 changed files with 89 additions and 33 deletions

View File

@@ -64,6 +64,14 @@ enum not_pos_e
pos_right pos_right
}; };
// Tipos de control de teclado
enum ctrl_schem_e
{
ctrl_cursor,
ctrl_opqa,
ctrl_wasd
};
// Estructura para las opciones de las notificaciones // Estructura para las opciones de las notificaciones
struct op_notification_t struct op_notification_t
{ {
@@ -136,6 +144,7 @@ struct options_t
online_t online; // Datos del servicio online online_t online; // Datos del servicio online
op_notification_t notifications; // Opciones relativas a las notificaciones; op_notification_t notifications; // Opciones relativas a las notificaciones;
op_screen_t screen; // Opciones relativas a la clase screen op_screen_t screen; // Opciones relativas a la clase screen
ctrl_schem_e keys; // Teclas usadas para jugar
}; };
// Calcula el cuadrado de la distancia entre dos puntos // Calcula el cuadrado de la distancia entre dos puntos

View File

@@ -57,9 +57,6 @@ Director::Director(int argc, char *argv[])
screen->setBorderColor(borderColor); screen->setBorderColor(borderColor);
debug = new Debug(renderer, screen, asset); debug = new Debug(renderer, screen, asset);
music = JA_LoadMusic(asset->get("title.ogg").c_str()); music = JA_LoadMusic(asset->get("title.ogg").c_str());
// Inicializa los servicios online
// initOnline();
} }
Director::~Director() Director::~Director()
@@ -112,10 +109,13 @@ void Director::initOptions()
// Crea el puntero a la estructura de opciones // Crea el puntero a la estructura de opciones
options = new options_t; options = new options_t;
// Version // Version del archivo de configuración
options->configVersion = "v1.06.1"; options->configVersion = "v1.06.1";
// Opciones dee video // Opciones de control
options->keys = ctrl_cursor;
// Opciones de video
options->gameWidth = GAMECANVAS_WIDTH; options->gameWidth = GAMECANVAS_WIDTH;
options->gameHeight = GAMECANVAS_HEIGHT; options->gameHeight = GAMECANVAS_HEIGHT;
options->videoMode = 0; options->videoMode = 0;
@@ -312,6 +312,21 @@ bool Director::saveConfig()
file << "## VERSION\n"; file << "## VERSION\n";
file << "configVersion=" + options->configVersion + "\n"; file << "configVersion=" + options->configVersion + "\n";
file << "\n## CONTROL OPTIONS\n";
file << "## keys = CURSOR | OPQA | WASD\n";
if (options->keys == ctrl_cursor)
{
file << "keys=CURSOR\n";
}
else if (options->keys == ctrl_opqa)
{
file << "keys=OPQA\n";
}
else if (options->keys == ctrl_wasd)
{
file << "keys=WASD\n";
}
file << "\n## VISUAL OPTIONS\n"; file << "\n## VISUAL OPTIONS\n";
if (options->videoMode == 0) if (options->videoMode == 0)
{ {
@@ -1009,6 +1024,22 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
options->configVersion = value; options->configVersion = value;
} }
else if (var == "keys")
{
if (value == "OPQA")
{
options->keys = ctrl_opqa;
}
else if (value == "WASD")
{
options->keys = ctrl_wasd;
}
else
{
options->keys = ctrl_cursor;
}
}
else if (var == "videoMode") else if (var == "videoMode")
{ {
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP") if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
@@ -1169,10 +1200,26 @@ void Director::initInput()
input->discoverGameController(); input->discoverGameController();
// Asigna inputs a teclas // Asigna inputs a teclas
if (options->keys == ctrl_cursor)
{
input->bindKey(INPUT_UP, SDL_SCANCODE_UP); input->bindKey(INPUT_UP, SDL_SCANCODE_UP);
input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT); input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT); input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
}
else if (options->keys == ctrl_opqa)
{
input->bindKey(INPUT_UP, SDL_SCANCODE_Q);
input->bindKey(INPUT_LEFT, SDL_SCANCODE_O);
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_P);
}
else if (options->keys == ctrl_wasd)
{
input->bindKey(INPUT_UP, SDL_SCANCODE_W);
input->bindKey(INPUT_LEFT, SDL_SCANCODE_A);
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_D);
}
input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
input->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN); input->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
input->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE); input->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
input->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_SPACE); input->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_SPACE);