Guardada en el fichero de configuración la asignación de cada mando a cada jugador

This commit is contained in:
2024-09-15 13:29:05 +02:00
parent 8fc217f0e3
commit c40c59275a
3 changed files with 27 additions and 9 deletions

View File

@@ -48,7 +48,7 @@ Director::Director(int argc, char *argv[])
// Carga los parametros para configurar el juego
const std::string paramFilePath = paramFileArgument == "--320x240" ? asset->get("param_320x240.txt") : asset->get("param_320x256.txt");
loadParams(paramFilePath);
loadParams(paramFilePath);
// Carga el fichero de configuración
loadConfigFile();
@@ -776,6 +776,7 @@ bool Director::saveConfigFile()
{
const std::string joyIndex = std::to_string(index + 1);
file << "controller" + joyIndex + ".name=" + options->controller[index].name + "\n";
file << "controller" + joyIndex + ".player=" + std::to_string(options->controller[index].playerId) + "\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";
@@ -1065,6 +1066,11 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
options->controller[0].name = value;
}
else if (var == "controller1.player")
{
options->controller[0].playerId = std::max(1, std::min(2, std::stoi(value)));
}
else if (var == "controller1.inputs.fire_left")
{
options->controller[0].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
@@ -1095,6 +1101,11 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
options->controller[1].name = value;
}
else if (var == "controller2.player")
{
options->controller[1].playerId = std::max(1, std::min(2, std::stoi(value)));
}
else if (var == "controller2.inputs.fire_left")
{
options->controller[1].buttons[0] = (SDL_GameControllerButton)std::stoi(value);

View File

@@ -3,39 +3,39 @@
// Comprueba el botón de servicio del controlador "index"
int checkServiceButton(Input *input, int index)
{
if (input->checkInput(input_service, true, INPUT_USE_GAMECONTROLLER, index))
if (input->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
if (input->checkInput(input_start, false, INPUT_USE_GAMECONTROLLER, index))
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
return SERVICE_EXIT;
}
else if (input->checkInput(input_fire_left, false, INPUT_USE_GAMECONTROLLER, index))
else if (input->checkInput(input_fire_left, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
return SERVICE_CONFIG;
}
else if (input->checkInput(input_fire_center, false, INPUT_USE_GAMECONTROLLER, index))
else if (input->checkInput(input_fire_center, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
return SERVICE_SHADERS;
}
else if (input->checkInput(input_fire_right, false, INPUT_USE_GAMECONTROLLER, index))
else if (input->checkInput(input_fire_right, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
return SERVICE_PAUSE;
}
else if (input->checkInput(input_up, false, INPUT_USE_GAMECONTROLLER, index))
else if (input->checkInput(input_up, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
return SERVICE_SWAP_CONTROLLERS;
}
else if (input->checkInput(input_down, false, INPUT_USE_GAMECONTROLLER, index))
else if (input->checkInput(input_down, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
return SERVICE_RESET;
}
else if (input->checkInput(input_left, false, INPUT_USE_GAMECONTROLLER, index))
else if (input->checkInput(input_left, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
return SERVICE_MUTE;
}

View File

@@ -277,6 +277,11 @@ void Title::checkInput()
section->options = SECTION_OPTIONS_QUIT_SHUTDOWN;
break;
case SERVICE_RESET:
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
case SERVICE_SHADERS:
screen->switchShaders();
break;
@@ -287,6 +292,8 @@ void Title::checkInput()
case SERVICE_SWAP_CONTROLLERS:
defineButtons->swapControllers();
screen->showNotification("Swap Controllers");
resetCounter();
break;
default: