diff --git a/source/title.cpp b/source/title.cpp index a41eced..73f476f 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -225,9 +225,7 @@ void Title::checkEvents() break; case SDLK_3: - defineButtons->swapControllers(); - screen->showNotification("Swap Controllers"); - resetCounter(); + swapControllers(); break; default: @@ -291,9 +289,7 @@ void Title::checkInput() break; case SERVICE_SWAP_CONTROLLERS: - defineButtons->swapControllers(); - screen->showNotification("Swap Controllers"); - resetCounter(); + swapControllers(); break; default: @@ -342,4 +338,30 @@ void Title::reLoadTextures() void Title::resetCounter() { counter = 0; +} + +// Intercambia la asignación de mandos a los jugadores +void Title::swapControllers() +{ + const int numControllers = input->getNumControllers(); + + if (numControllers == 0) + { + return; + } + + defineButtons->swapControllers(); + const std::string text0 = "Jugador " + std::to_string(options->controller[0].playerId) + " -> " + options->controller[0].name; + const std::string text1 = "Jugador " + std::to_string(options->controller[1].playerId) + " -> " + options->controller[1].name; + + if (numControllers == 1) + { + screen->showNotification(text0); + } + else + { + screen->showNotification(text0, text1); + } + + resetCounter(); } \ No newline at end of file diff --git a/source/title.h b/source/title.h index a1ac30b..e9dbcc4 100644 --- a/source/title.h +++ b/source/title.h @@ -97,6 +97,9 @@ private: // Reinicia el contador interno void resetCounter(); + // Intercambia la asignación de mandos a los jugadores + void swapControllers(); + public: // Constructor Title(Screen *screen, Asset *asset, Input *input, options_t *options, Lang *lang, param_t *param, section_t *section, JA_Music_t *music);