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

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