Ya se guardan las asignaciones de los botones en el fichero de configuración

This commit is contained in:
2024-07-07 19:22:36 +02:00
parent 38dc63ef02
commit caca21cba5
7 changed files with 232 additions and 68 deletions

View File

@@ -98,7 +98,6 @@ void Director::initInput()
#endif
// Busca si hay mandos conectados
input->discoverGameControllers();
const int numGamePads = input->getNumControllers();
// Teclado - Movimiento del jugador
input->bindKey(input_up, SDL_SCANCODE_UP);
@@ -120,8 +119,9 @@ void Director::initInput()
input->bindKey(input_window_fullscreen, SDL_SCANCODE_F3);
input->bindKey(input_video_shaders, SDL_SCANCODE_F4);
const int numGamePads = input->getNumControllers();
for (int i = 0; i < numGamePads; ++i)
{
{
// Mando - Movimiento del jugador
input->bindGameControllerButton(i, input_up, SDL_CONTROLLER_BUTTON_DPAD_UP);
input->bindGameControllerButton(i, input_down, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
@@ -139,19 +139,24 @@ void Director::initInput()
input->bindGameControllerButton(i, input_exit, SDL_CONTROLLER_BUTTON_BACK);
}
// Pone valores por defecto a las opciones de control
options->game.input.clear();
// Comprueba si ha de modificar las asignaciones por las que hay en las opciones en caso de coincidir el nombre del mando
for (int i = 0; i < numGamePads; ++i)
for (int index = 0; index < (int)options->controller.size(); ++index)
if (input->getControllerName(i) == options->controller[index].name)
for (int j = 0; j < (int)options->controller[index].inputs.size(); ++j)
{
input->bindGameControllerButton(i, options->controller[index].inputs[j], options->controller[index].buttons[j]);
}
input_t i;
i.id = 0;
i.name = "MANDO 1";
i.deviceType = INPUT_USE_ANY;
options->game.input.push_back(i);
i.id = 1;
i.name = "MANDO 2";
i.deviceType = INPUT_USE_GAMECONTROLLER;
options->game.input.push_back(i);
// Modifica las opciones para colocar los valores asignados
for (int index = 0; index < numGamePads; ++index)
{
options->controller[index].name = input->getControllerName(index);
for (int j = 0; j < (int)options->controller[index].inputs.size(); ++j)
{
options->controller[index].buttons[j] = input->getControllerBinding(index, options->controller[index].inputs[j]);
}
}
}
// Inicializa JailAudio
@@ -411,19 +416,10 @@ void Director::initOptions()
// Crea el puntero a la estructura de opciones
options = new options_t;
// Pone unos valores por defecto para las opciones de control
options->game.input.clear();
// Pone unos valores por defecto para las opciones
input_t inp;
inp.id = 0;
inp.name = "GAME CONTROLLER";
inp.deviceType = INPUT_USE_GAMECONTROLLER;
options->game.input.push_back(inp);
inp.id = 1;
inp.name = "GAME CONTROLLER";
inp.deviceType = INPUT_USE_GAMECONTROLLER;
options->game.input.push_back(inp);
// Opciones varias
options->console = false;
// Opciones de video
options->video.mode = 0;
@@ -443,11 +439,38 @@ void Director::initOptions()
options->audio.sound.enabled = true;
options->audio.sound.volume = 64;
// Opciones varios
options->game.playerSelected = 0;
// Opciones de juego
options->game.difficulty = DIFFICULTY_NORMAL;
options->game.language = ba_BA;
options->console = false;
// Opciones de control
options->controller.clear();
op_controller_t c;
const int numPlayers = 2;
for (int index = 0; index < numPlayers; ++index)
{
c.index = index;
c.deviceType = INPUT_USE_GAMECONTROLLER;
c.name = "NO NAME";
c.inputs.clear();
c.inputs.push_back(input_fire_left);
c.inputs.push_back(input_fire_center);
c.inputs.push_back(input_fire_right);
c.inputs.push_back(input_start);
c.inputs.push_back(input_exit);
c.buttons.clear();
c.buttons.push_back(SDL_CONTROLLER_BUTTON_X);
c.buttons.push_back(SDL_CONTROLLER_BUTTON_Y);
c.buttons.push_back(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
c.buttons.push_back(SDL_CONTROLLER_BUTTON_START);
c.buttons.push_back(SDL_CONTROLLER_BUTTON_BACK);
options->controller.push_back(c);
}
options->controller[0].deviceType = INPUT_USE_ANY; // El primer jugador puede usar tanto el teclado como el primer mando
}
// Comprueba los parametros del programa
@@ -653,12 +676,33 @@ bool Director::saveConfigFile()
// Opciones del juego
file << "\n\n## GAME\n";
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
file << "## game.difficulty [0: easy, 1: normal, 2: hard]\n";
file << "\n";
file << "game.language=" + std::to_string(options->game.language) + "\n";
file << "game.difficulty=" + std::to_string(options->game.difficulty) + "\n";
file << "game.input0=" + std::to_string(options->game.input[0].deviceType) + "\n";
file << "game.input1=" + std::to_string(options->game.input[1].deviceType) + "\n";
// Opciones de mandos
file << "\n\n## CONTROLLERS\n";
file << "\n";
const int numPlayers = 2;
for (int index = 0; index < numPlayers; ++index)
{
const std::string joyIndex = std::to_string(index + 1);
file << "controller" + joyIndex + ".name=" + options->controller[index].name + "\n";
file << "controller" + joyIndex + ".inputs.fire_left=" + std::to_string((int)options->controller[index].buttons[0]) + "\n";
file << "controller" + joyIndex + ".inputs.fire_center=" + std::to_string((int)options->controller[index].buttons[1]) + "\n";
file << "controller" + joyIndex + ".inputs.fire_right=" + std::to_string((int)options->controller[index].buttons[2]) + "\n";
file << "controller" + joyIndex + ".inputs.fire_start=" + std::to_string((int)options->controller[index].buttons[3]) + "\n";
file << "controller" + joyIndex + ".inputs.fire_exit=" + std::to_string((int)options->controller[index].buttons[4]) + "\n";
if (index < numPlayers - 1)
{
file << "\n";
}
}
// Cierra el fichero
file.close();
@@ -924,14 +968,65 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
options->game.difficulty = std::stoi(value);
}
else if (var == "game.input0")
// Opciones de mandos
else if (var == "controller1.name")
{
options->game.input[0].deviceType = std::stoi(value);
options->controller[0].name = value;
}
else if (var == "game.input1")
else if (var == "controller1.inputs.fire_left")
{
options->game.input[1].deviceType = std::stoi(value);
options->controller[0].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
}
else if (var == "controller1.inputs.fire_center")
{
options->controller[0].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
}
else if (var == "controller1.inputs.fire_right")
{
options->controller[0].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
}
else if (var == "controller1.inputs.fire_start")
{
options->controller[0].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
}
else if (var == "controller1.inputs.fire_exit")
{
options->controller[0].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
}
else if (var == "controller2.name")
{
options->controller[1].name = value;
}
else if (var == "controller2.inputs.fire_left")
{
options->controller[1].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
}
else if (var == "controller2.inputs.fire_center")
{
options->controller[1].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
}
else if (var == "controller2.inputs.fire_right")
{
options->controller[1].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
}
else if (var == "controller2.inputs.fire_start")
{
options->controller[1].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
}
else if (var == "controller2.inputs.fire_exit")
{
options->controller[1].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
}
// Lineas vacias o que empiezan por comentario