From 58d3a7597630f843eb5e806cb3d9dca932204861 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 24 Sep 2023 09:40:53 +0200 Subject: [PATCH] EnterID ya recibe bien el JailerID en caso de tenerlo ya definido previamente --- source/enter_id.cpp | 37 ++++++++++++++++++++++++++++++++++--- source/enter_id.h | 7 +++++-- source/title.cpp | 1 - 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/source/enter_id.cpp b/source/enter_id.cpp index 2884fc5..464559d 100644 --- a/source/enter_id.cpp +++ b/source/enter_id.cpp @@ -35,9 +35,7 @@ EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t counter = 0; ticks = 0; ticksSpeed = 15; - pos = 0; - name[pos] = 0; - maxLenght = 15; + initName(); // Escribe el texto en la textura fillTexture(); @@ -286,4 +284,37 @@ void EnterID::endSection() { loopRunning = false; initOnline(); +} + +// Inicializa el vector utilizado para almacenar el texto que se escribe en pantalla +void EnterID::initName() +{ + std::cout << options->online.jailerID << std::endl; + + // Calcula el tamaño del vector + name[0] = 0; + maxLenght = sizeof(name) / sizeof(name[pos]); + + // Inicializa el vector con ceros + for (int i = 0; i < maxLenght; ++i) + { + name[i] = 0; + } + + // Si no hay definido ningun JailerID, coloca el cursor en primera posición + if (options->online.jailerID == "") + { + pos = 0; + } + else + {// En caso contrario, copia el texto al vector y coloca el cursor en posición + const int len = std::min((int)options->online.jailerID.size(), maxLenght); + for (int i = 0; i < len; ++i) + { + name[i] = (char)options->online.jailerID[i]; + } + pos = len; + } + + std::cout << (std::string)name << std::endl; } \ No newline at end of file diff --git a/source/enter_id.h b/source/enter_id.h index 5fb3240..d4a98c7 100644 --- a/source/enter_id.h +++ b/source/enter_id.h @@ -40,8 +40,8 @@ private: std::vector texts; // Vector con los textos std::string cursor; // Contiene el caracter que se muestra como cursor - char name[15]; - int pos; + char name[15]; // Aqui se guardan los caracteres de las teclas que se van pulsando + int pos; // Posición actual en el vector name int maxLenght; // Tamaño máximo del jailerID // Actualiza las variables @@ -65,6 +65,9 @@ private: // Termina la sección void endSection(); + // Inicializa el vector utilizado para almacenar el texto que se escribe en pantalla + void initName(); + public: // Constructor EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t *section); diff --git a/source/title.cpp b/source/title.cpp index c4b42ec..f45ba03 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -699,7 +699,6 @@ void Title::checkEvents() switch (eventHandler->key.keysym.scancode) { case SDL_SCANCODE_A: - std::cout << "PULSA A" << std::endl; runEnterID(); break;